本文整理汇总了Python中cqlparser.cqltoexpression.QueryExpression类的典型用法代码示例。如果您正苦于以下问题:Python QueryExpression类的具体用法?Python QueryExpression怎么用?Python QueryExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QueryExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert
def convert(self, expression):
if expression.must_not:
r = QueryExpression.nested('AND')
r.operands.append(QueryExpression.searchterm(term='*'))
r.operands.append(expression)
expression = r
return JsonDict(self._expression(expression))
示例2: testQueryExpression
def testQueryExpression(self):
conversion = Conversion()
kwargs = {'q': QueryExpression.searchterm(term='term')}
dump = conversion.jsonDumpMessage(message='aMessage', **kwargs)
loadedMessage, loadedKwargs = conversion.jsonLoadMessage(dump)
self.assertEquals('aMessage', loadedMessage)
self.assertEquals({'q': QueryExpression.searchterm(term='term')}, loadedKwargs)
示例3: testBooleanNotQueryNested
def testBooleanNotQueryNested(self):
expr = QueryExpression.nested(operator='AND')
nestedNotExpr = QueryExpression.nested(operator='AND')
nestedNotExpr.must_not = True
nestedNotExpr.operands = [
QueryExpression.searchterm("field2", "=", "value2"),
QueryExpression.searchterm("field3", "=", "value3")
]
expr.operands = [QueryExpression.searchterm("field1", "=", "value1"), nestedNotExpr]
self.assertEquals(
{
"type": "BooleanQuery",
"clauses": [
{
"type": "TermQuery",
"term": {"field": "field1", "value": "value1"},
"occur": "MUST"
}, {
"type": "BooleanQuery",
"occur": "MUST_NOT",
"clauses": [
{
"type": "TermQuery",
"term": {"field": "field2", "value": "value2"},
"occur": "MUST"
},
{
"type": "TermQuery",
"term": {"field": "field3", "value": "value3"},
"occur": "MUST"
}
]
}
]
}, self._convert(expr))
示例4: testQueryExpressionWithOperands
def testQueryExpressionWithOperands(self):
conversion = Conversion()
qe = QueryExpression.nested(operator='AND')
qe.operands = [QueryExpression.searchterm(term='term'), QueryExpression.searchterm(term='term1')]
kwargs = {'q': qe}
dump = conversion.jsonDumpMessage(message='aMessage', **kwargs)
loadedMessage, loadedKwargs = conversion.jsonLoadMessage(dump)
self.assertEquals('aMessage', loadedMessage)
self.assertEquals({'q': qe}, loadedKwargs)
示例5: convert
def convert(self, expression, unqualifiedTermFields=None, composedQuery=None):
if expression.must_not:
r = QueryExpression.nested('AND')
r.operands.append(QueryExpression.searchterm(term='*'))
r.operands.append(expression)
expression = r
return JsonDict(_Converter(
analyzer=self._analyzer,
fieldRegistry=self._fieldRegistry,
ignoreStemmingForWords=self._ignoreStemmingForWords,
unqualifiedTermFields=unqualifiedTermFields or self._unqualifiedTermFields,
composedQuery=composedQuery).convert(expression))
示例6: testIntRangeQuery
def testIntRangeQuery(self):
# (field, lowerTerm, upperTerm, includeLower, includeUpper)
q = dict(type="RangeQuery", rangeType="Int", field='intField', lowerTerm=1, upperTerm=None, includeLower=False, includeUpper=True)
self.assertEquals(q, self._convert('intField > 1'))
q = dict(type="RangeQuery", rangeType="Int", field='intField', lowerTerm=1, upperTerm=None, includeLower=True, includeUpper=True)
self.assertEquals(q, self._convert('intField >= 1'))
q = dict(type="RangeQuery", rangeType="Int", field='intField', lowerTerm=None, upperTerm=3, includeLower=True, includeUpper=False)
self.assertEquals(q, self._convert('intField < 3'))
q = dict(type="RangeQuery", rangeType="Int", field='intField', lowerTerm=None, upperTerm=3, includeLower=True, includeUpper=True)
self.assertEquals(q, self._convert('intField <= 3'))
q = dict(type="RangeQuery", rangeType="Int", field='intField', lowerTerm=3, upperTerm=3, includeLower=True, includeUpper=True)
self.assertEquals(q, self._convert('intField = 3'))
self.assertEquals(q, self._convert(QueryExpression.searchterm(index='intField', relation='exact', term=3)))
self.assertEquals(q, self._convert(QueryExpression.searchterm(index='intField', relation='=', term=3)))
示例7: testEquals
def testEquals(self):
self.assertEquals(QueryExpression(index='field', relation='=', term='term'), QueryExpression(index='field', relation='=', term='term'))
self.assertEquals(cqlToExpression('field=value AND otherfield=othervalue'), QueryExpression(operator='AND', operands=[QE('field=value'), QE('otherfield=othervalue')]))
self.assertTrue(QueryExpression.searchterm('a') == QueryExpression.searchterm('a'))
self.assertFalse(QueryExpression.searchterm('a') != QueryExpression.searchterm('a'))
self.assertFalse(QueryExpression.searchterm('a') == QueryExpression.searchterm('b'))
self.assertTrue(QueryExpression.searchterm('a') != QueryExpression.searchterm('b'))
示例8: testUnqualifiedTermFieldsWithNestedExpression
def testUnqualifiedTermFieldsWithNestedExpression(self):
self.unqualifiedFields = [('aField', 1.0)]
expr = QueryExpression.nested(operator='AND')
expr.operands = [
QueryExpression.searchterm(term="value1"),
QueryExpression.searchterm(term="value2")
]
self.assertEquals({
'type': 'BooleanQuery',
'clauses': [
{'type': 'TermQuery', 'occur': 'MUST', 'term': {'field': 'aField', 'value': u'value1'}, 'boost': 1.0},
{'type': 'TermQuery', 'occur': 'MUST', 'term': {'field': 'aField', 'value': u'value2'}, 'boost': 1.0}
],
},
self._convert(expr))
示例9: testTermQuery
def testTermQuery(self):
self.assertConversion({
"type": "TermQuery",
"term": {
"field":"field",
"value": "value",
}
}, QueryExpression.searchterm("field", "=", "value"))
self.assertConversion({"term": {"field": "field", "value": "value"}, "type": "TermQuery"}, QueryExpression.searchterm("field", "=", "value"))
示例10: testPhraseOutput
def testPhraseOutput(self):
self.assertConversion({
"type": "PhraseQuery",
"boost": 1.0,
"terms": [
{"field": "unqualified", "value": "cats"},
{"field": "unqualified", "value": "dogs"}
]
}, QueryExpression.searchterm(term='"cats dogs"'))
示例11: testBooleanOrQuery
def testBooleanOrQuery(self):
expr = QueryExpression.nested(operator='OR')
expr.operands=[
QueryExpression.searchterm("field1", "=", "value1"),
QueryExpression.searchterm("field2", "=", "value2")
]
self.assertConversion({
"type": "BooleanQuery",
"clauses": [
{
"type": "TermQuery",
"term": {"field": "field1", "value": "value1"},
"occur": "SHOULD"
}, {
"type": "TermQuery",
"term": {"field": "field2", "value": "value2"},
"occur": "SHOULD"
}
]
}, expr)
示例12: testTermQuery
def testTermQuery(self):
self.assertEquals(
{
"type": "TermQuery",
"term": {
"field":"field",
"value": "value",
}
}, self._convert(QueryExpression.searchterm("field", "=", "value")))
self.assertEquals(
{"term": {"field": "field", "value": "value"}, "type": "TermQuery"}, self._convert(QueryExpression.searchterm("field", "=", "value")))
示例13: testBooleanNotQuery
def testBooleanNotQuery(self):
expr = QueryExpression.nested(operator='AND')
expr.operands=[
QueryExpression.searchterm("field1", "=", "value1"),
QueryExpression.searchterm("field2", "=", "value2")
]
expr.operands[1].must_not = True
self.assertConversion({
"type": "BooleanQuery",
"clauses": [
{
"type": "TermQuery",
"term": {"field": "field1", "value": "value1"},
"occur": "MUST"
}, {
"type": "TermQuery",
"term": {"field": "field2", "value": "value2"},
"occur": "MUST_NOT"
}
]
}, expr)
示例14: testBooleanAndQuery
def testBooleanAndQuery(self):
expr = QueryExpression.nested(operator='AND')
expr.operands = [
QueryExpression.searchterm("field1", "=", "value1"),
QueryExpression.searchterm("field2", "=", "value2")
]
self.assertEquals(
{
"type": "BooleanQuery",
"clauses": [
{
"type": "TermQuery",
"term": {"field": "field1", "value": "value1"},
"occur": "MUST"
}, {
"type": "TermQuery",
"term": {"field": "field2", "value": "value2"},
"occur": "MUST"
}
]
}, self._convert(expr))
示例15: testOtherCoreAndQuery
def testOtherCoreAndQuery(self):
self.assertEquals({
'type': 'JoinAndQuery',
'first': {
"type": "RelationalLuceneQuery", # should this not be 'joined' to own core somehow?
"core": "thisCore",
"collectKeyName": "A", # where does this keyName come from?
"filterKeyName": "A",
"query": {
"type": "TermQuery",
"term": {
"field":"field0",
"value": "value",
}
}
},
'second': {
"type": "RelationalLuceneQuery", # should this not be 'joined' to own core somehow?
"core": "otherCore",
"collectKeyName": "A", # where does this keyName come from?
"filterKeyName": "A",
"query": {
"type": "TermQuery",
"term": {
"field":"field",
"value": "value",
}
}
}
}, self._convert(
QueryExpression(operator='AND', operands=[
QueryExpression.searchterm('field0', '=', 'value'),
QueryExpression.searchterm("otherCore.field", "=", "value")
])
)
)