def testAsDictFromDict(self):
        cq = ComposedQuery('coreA')
        cq.setCoreQuery(core='coreA', query='Q0')
        cq.addFilterQuery(core='coreA', query='Q1')
        cq.addFilterQuery(core='coreA', query='Q2')
        cq.addFacet(core='coreA', facet='F0')
        cq.addFacet(core='coreA', facet='F1')
        cq.setCoreQuery(core='coreB', query='Q3')
        cq.addMatch(dict(core='coreA', uniqueKey='keyA'), dict(core='coreB', key='keyB'))
        cq.addUnite(dict(core='coreA', query='AQuery'), dict(core='coreB', query='anotherQuery'))
        cq.start = 0
        cq.sortKeys = [dict(sortBy='field', sortDescending=True)]
        cq.clustering = True
        cq.clusteringConfig = {'clusteringEps': 0.2}

        d = cq.asDict()
        cq2 = ComposedQuery.fromDict(d)
        self.assertEquals('coreA', cq2.resultsFrom)
        self.assertEquals(0, cq2.start)
        self.assertEquals(None, cq2.stop)
        self.assertEquals(['Q0', 'Q1', 'Q2'], cq2.queriesFor('coreA'))
        self.assertEquals(['F0', 'F1'], cq2.facetsFor('coreA'))
        self.assertEquals('keyA', cq2.keyName('coreA', 'coreB'))
        self.assertEquals('keyB', cq2.keyName('coreB', 'coreA'))
        self.assertEqual(1, len(cq2.unites))
        queries = list(cq2.unites[0].queries())
        self.assertEquals(({'core': 'coreA', 'keyName': 'keyA', 'query': 'AQuery'}, 'keyA'), queries[0])
        self.assertEquals(({'core': 'coreB', 'keyName': 'keyB', 'query': 'anotherQuery'}, 'keyA'), queries[1])
        self.assertEquals({'clusteringEps': 0.2}, cq2.clusteringConfig)
    def testAsDictFromDict(self):
        cq = ComposedQuery('coreA')
        cq.setCoreQuery(core='coreA', query='Q0')
        cq.addFilterQuery(core='coreA', query='Q1')
        cq.addFilterQuery(core='coreA', query='Q2')
        cq.relationalFilter = '{"type": "madeUpJoinQuery"}'
        cq.addFacet(core='coreA', facet='F0')
        cq.addFacet(core='coreA', facet='F1')
        cq.setCoreQuery(core='coreB', query='Q3')
        cq.addMatch(dict(core='coreA', uniqueKey='keyA'),
                    dict(core='coreB', key='keyB'))
        cq.addUnite(dict(core='coreA', query='AQuery'),
                    dict(core='coreB', query='anotherQuery'))
        cq.start = 0
        cq.sortKeys = [dict(sortBy='field', sortDescending=True)]
        cq.clustering = True
        cq.clusteringConfig = {'clusteringEps': 0.2}
        cq.rankQueryScoreRatio = 0.75

        d = cq.asDict()
        cq2 = ComposedQuery.fromDict(d)
        self.assertEquals('coreA', cq2.resultsFrom)
        self.assertEquals(0, cq2.start)
        self.assertEquals(None, cq2.stop)
        self.assertEquals(['Q0', 'Q1', 'Q2'], cq2.queriesFor('coreA'))
        self.assertEquals('{"type": "madeUpJoinQuery"}', cq2.relationalFilter)
        self.assertEquals(['F0', 'F1'], cq2.facetsFor('coreA'))
        self.assertEquals('keyA', cq2.keyName('coreA', 'coreB'))
        self.assertEquals('keyB', cq2.keyName('coreB', 'coreA'))
        self.assertEqual(1, len(cq2.unites))
        queries = list(cq2.unites[0].queries())
        self.assertEquals(({
            'core': 'coreA',
            'keyName': 'keyA',
            'query': 'AQuery'
        }, 'keyA'), queries[0])
        self.assertEquals(({
            'core': 'coreB',
            'keyName': 'keyB',
            'query': 'anotherQuery'
        }, 'keyA'), queries[1])
        self.assertEquals({'clusteringEps': 0.2}, cq2.clusteringConfig)
        self.assertEquals(0.75, cq2.rankQueryScoreRatio)
Пример #3
0
    def testAsDictFromDict(self):
        cq = ComposedQuery('coreA')
        cq.setCoreQuery(core='coreA', query='Q0')
        cq.addFilterQuery(core='coreA', query='Q1')
        cq.addFilterQuery(core='coreA', query='Q2')
        cq.addFacet(core='coreA', facet='F0')
        cq.addFacet(core='coreA', facet='F1')
        cq.setCoreQuery(core='coreB', query='Q3')
        cq.addMatch(dict(core='coreA', uniqueKey='keyA'), dict(core='coreB', key='keyB'))
        cq.addUnite(dict(core='coreA', query='AQuery'), dict(core='coreB', query='anotherQuery'))
        cq.start = 0
        cq.sortKeys = [dict(sortBy='field', sortDescending=True)]

        d = cq.asDict()
        cq2 = ComposedQuery.fromDict(d)
        self.assertEquals('coreA', cq2.resultsFrom)
        self.assertEquals(0, cq2.start)
        self.assertEquals(None, cq2.stop)
        self.assertEquals(['Q0', 'Q1', 'Q2'], cq2.queriesFor('coreA'))
        self.assertEquals(['F0', 'F1'], cq2.facetsFor('coreA'))
        self.assertEquals('keyA', cq2.keyName('coreA'))
        self.assertEquals('keyB', cq2.keyName('coreB'))