def testXTermDrilldown(self): self.response = LuceneResponse(drilldownData=[ dict(fieldname='prefix:field1', terms=[dict(term='term1', count=1)]), dict(fieldname='unknownJoinName.field', terms=[]), dict(fieldname='normal:drilldown', terms=[]), dict(fieldname='prefix:field2', terms=[dict(term='term2', count=1)]), ]) response = retval(self.tree.any.executeQuery( cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={}, facets=[ dict(fieldname='otherCore.prefix:field2', maxTerms=7), dict(fieldname='normal:drilldown', maxTerms=11), dict(fieldname='otherCore.prefix:field1', maxTerms=9), dict(fieldname='unknownJoinName.field', maxTerms=12) ], someKwarg='someValue')) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] cq.validate() self.assertEquals(set(['defaultCore', 'otherCore']), cq.cores) self.assertEquals('keyDefault', cq.keyName('defaultCore', 'otherCore')) self.assertEquals('keyOther', cq.keyName('otherCore', 'defaultCore')) self.assertEquals([dict(fieldname='prefix:field2', path=[], maxTerms=7), dict(fieldname='prefix:field1', path=[], maxTerms=9)], cq.facetsFor('otherCore')) self.assertEquals([dict(fieldname='normal:drilldown', path=[], maxTerms=11), dict(fieldname='unknownJoinName.field', path=[], maxTerms=12)], cq.facetsFor('defaultCore')) self.assertEquals([ dict(fieldname='otherCore.prefix:field2', terms=[dict(term='term2', count=1)]), dict(fieldname='normal:drilldown', terms=[]), dict(fieldname='otherCore.prefix:field1', terms=[dict(term='term1', count=1)]), dict(fieldname='unknownJoinName.field', terms=[]) ], response.drilldownData)
def testDrilldownQueriesWithTranslate(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={}, drilldownQueries=[('toBePrefixed', ['path1', 'path2']), ('otherCore.toBePrefixed', ['path3'])])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] cq.validate() self.assertEquals([('prefix.toBePrefixed', ['path1', 'path2'])], cq.drilldownQueriesFor('defaultCore')) self.assertEquals([('prefix.toBePrefixed', ['path3'])], cq.drilldownQueriesFor('otherCore'))
def testXFilterCommonKeysFieldOverridesXFilterCommonKeys(self): self.setupDna(dedupByDefault=False) consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={'x-filter-common-keys-field': ['dcterms:isFormatOf.uri'], 'x-filter-common-keys': ['true']}, facets=[])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEquals("__key__.dcterms:isFormatOf.uri", cq.dedupField) self.assertEquals("__key__.date", cq.dedupSortField)
def testDedupExplicitlyOn(self): self.setupDna(dedupByDefault=False) consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={'x-filter-common-keys': ['true']}, facets=[])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEquals("__key__.dedup", cq.dedupField) self.assertEquals("__key__.date", cq.dedupSortField)
def testDedupExplicitlyOn(self): self.setupDna(dedupByDefault=False) consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={'x-filter-common-keys': ['true']}, facets=[])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEquals("__key__", cq.dedupField) self.assertEquals("__key__.date", cq.dedupSortField)
def testNoDedupWhenDedupByDefaultSetToFalse(self): self.setupDna(dedupByDefault=False) consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={}, facets=[])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEquals(None, cq.dedupField) self.assertEquals(None, cq.dedupSortField)
def testNormalQueryWithoutAnyJoin(self): ast = parseCQL("prefixfield=value") consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=ast, extraArguments={})) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] cq.validate() self.assertEquals('defaultCore', cq.resultsFrom) self.assertEquals([cqlToExpression("prefixfield=value")], cq.queriesFor('defaultCore'))
def testXFilterWhichIsNoJoinQuery(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={'x-filter': ['prefix:field=value']}, facets=[], someKwarg='someValue')) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] cq.validate() self.assertEquals('defaultCore', cq.resultsFrom) self.assertEquals([cqlToExpression("*"), cqlToExpression("prefix:field=value")], cq.queriesFor('defaultCore')) self.assertEquals(1, cq.numberOfUsedCores)
def testXFilterCommonKeysIgnoredWhenNoDedupFieldSpecified(self): self.setupDna(dedupFieldName=None) consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={'x-filter-common-keys': []}, facets=[])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEquals(None, cq.dedupField) self.assertEquals(None, cq.dedupSortField)
def testTwoXFiltersForSameCore(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={'x-filter': ['otherCore.prefix:field=value', 'otherCore.field2=value2']}, facets=[])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] cq.validate() self.assertEquals('defaultCore', cq.resultsFrom) self.assertEquals(set(['defaultCore', 'otherCore']), cq.cores) self.assertEquals('keyDefault', cq.keyName('defaultCore', 'otherCore')) self.assertEquals('keyOther', cq.keyName('otherCore', 'defaultCore')) self.assertEquals([cqlToExpression("prefix:field=value"), cqlToExpression('field2=value2')], cq.queriesFor('otherCore'))
def testFilterQuery(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), filterQueries=[('otherCore', 'prefix:field=value')], facets=[], start=1)) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] cq.validate() self.assertEquals(1, cq.start) self.assertEquals(set(['defaultCore', 'otherCore']), cq.cores) self.assertEquals('keyDefault', cq.keyName('defaultCore', 'otherCore')) self.assertEquals('keyOther', cq.keyName('otherCore', 'defaultCore')) self.assertEquals([cqlToExpression("prefix:field=value")], cq.queriesFor('otherCore')) self.assertEquals([cqlToExpression('*')], cq.queriesFor('defaultCore'))
def testSortKeys(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), sortKeys=[dict(sortBy='field', sortDescending=True), dict(sortBy='otherCore.field', sortDescending=False)])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] cq.validate() self.assertEquals(set(['defaultCore', 'otherCore']), cq.cores) self.assertEquals('keyDefault', cq.keyName('defaultCore', 'otherCore')) self.assertEquals('keyOther', cq.keyName('otherCore', 'defaultCore')) self.assertEquals([ dict(sortBy='field', sortDescending=True, core='defaultCore'), dict(sortBy='field', sortDescending=False, core='otherCore') ], cq.sortKeys)
def testXRankQuery(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={'x-rank-query': ['otherCore.prefix:field=value', 'otherCore.otherprefix:otherfield=othervalue', 'field=value']})) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] cq.validate() self.assertEquals(set(['defaultCore', 'otherCore']), cq.cores) self.assertEquals('keyDefault', cq.keyName('defaultCore', 'otherCore')) self.assertEquals('keyOther', cq.keyName('otherCore', 'defaultCore')) self.assertEquals(cqlToExpression("prefix:field=value OR otherprefix:otherfield=othervalue"), cq.rankQueryFor('otherCore')) self.assertEquals(cqlToExpression("field=value"), cq.rankQueryFor('defaultCore')) self.assertEquals([], cq.queriesFor('otherCore')) self.assertEquals([cqlToExpression('*')], cq.queriesFor('defaultCore'))
def testMatchesOptional(self): self.tree = be( (Observable(), (ConvertToComposedQuery(resultsFrom='defaultCore'), (self.observer,) ) ) ) consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={'x-filter': ['prefix:field=value']}, facets=[], start=1)) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] cq.validate() self.assertEquals(1, cq.start) self.assertEquals(set(['defaultCore']), cq.cores) self.assertRaises(KeyError, lambda: cq.keyName('defaultCore', 'otherCore')) self.assertEquals([cqlToExpression("*"), cqlToExpression("prefix:field=value")], cq.queriesFor('defaultCore'))
def testHierarchicalXTermDrilldown(self): self.response = LuceneResponse(drilldownData=[ dict(fieldname='field1', path=['field2'], terms=[dict(term='term1', count=1)]), ]) response = retval(self.tree.any.executeQuery( cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={}, facets=[ dict(fieldname='otherCore.field1>field2', maxTerms=10), ], someKwarg='someValue')) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] cq.validate() self.assertEquals([{'fieldname': 'field1', 'path': ['field2'], 'maxTerms': 10}], cq.facetsFor('otherCore')) self.assertEquals([ dict(fieldname='otherCore.field1', path=['field2'], terms=[dict(term='term1', count=1)]), ], response.drilldownData)
def testConvertJoinQueryToFilters(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('field=value AND otherCore.field=value2'))) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEqual(QueryExpression.searchterm('field', '=', 'value'), cq.queryFor('defaultCore')) self.assertEqual([QueryExpression.searchterm('field', '=', 'value2')], cq.filterQueriesFor('otherCore'))
def testDedup(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={}, facets=[])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEquals("__key__.dedup", cq.dedupField) self.assertEquals("__key__.date", cq.dedupSortField)
def testIgnoreCorePrefixForResultCore(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('defaultCore.field=value'))) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEqual([cqlToExpression('defaultCore.field=value')], cq.queriesFor('defaultCore'))
def testClustering(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={'x-clustering': ['true']})) cq = self.observer.calledMethods[0].kwargs['query'] self.assertTrue(cq.clustering)
def testDedupTurnedOff(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={'x-filter-common-keys': ['false']}, facets=[])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEquals(None, cq.dedupField) self.assertEquals(None, cq.dedupSortField)
def testClusteringNotEnabledIfTurnedOffInConfig(self): consume(self.tree.any.updateConfig(config=dict(features_disabled=['clustering']), indexConfig={})) consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('fiets'), extraArguments={'x-clustering': ['true']}, facets=[])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEquals(None, cq.clusteringConfig)
def testGroupingTurnedOn(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('fiets'), extraArguments={'x-grouping': ['true']}, facets=[])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEquals("__key__", cq.otherKwargs().get("groupingField"))
def testNoGroupingForMatchAllQuery(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={'x-grouping': ['true']})) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEqual(None, cq.groupingField)
def testGroupingDefaultTurnedOff(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={}, facets=[])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEquals(None, cq.otherKwargs().get("groupingField"))
def testDedup(self): consume(self.tree.any.executeQuery(cqlAbstractSyntaxTree=parseCQL('*'), extraArguments={}, facets=[])) self.assertEquals(['executeComposedQuery'], self.observer.calledMethodNames()) cq = self.observer.calledMethods[0].kwargs['query'] self.assertEquals("__key__", cq.dedupField) self.assertEquals("__key__.date", cq.dedupSortField)