本文整理汇总了Python中cqlparser.cqltoexpression.QueryExpression.nested方法的典型用法代码示例。如果您正苦于以下问题:Python QueryExpression.nested方法的具体用法?Python QueryExpression.nested怎么用?Python QueryExpression.nested使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cqlparser.cqltoexpression.QueryExpression
的用法示例。
在下文中一共展示了QueryExpression.nested方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testBooleanNotQueryNested
# 需要导入模块: from cqlparser.cqltoexpression import QueryExpression [as 别名]
# 或者: from cqlparser.cqltoexpression.QueryExpression import nested [as 别名]
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))
示例2: convert
# 需要导入模块: from cqlparser.cqltoexpression import QueryExpression [as 别名]
# 或者: from cqlparser.cqltoexpression.QueryExpression import nested [as 别名]
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))
示例3: testQueryExpressionWithOperands
# 需要导入模块: from cqlparser.cqltoexpression import QueryExpression [as 别名]
# 或者: from cqlparser.cqltoexpression.QueryExpression import nested [as 别名]
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)
示例4: convert
# 需要导入模块: from cqlparser.cqltoexpression import QueryExpression [as 别名]
# 或者: from cqlparser.cqltoexpression.QueryExpression import nested [as 别名]
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))
示例5: testUnqualifiedTermFieldsWithNestedExpression
# 需要导入模块: from cqlparser.cqltoexpression import QueryExpression [as 别名]
# 或者: from cqlparser.cqltoexpression.QueryExpression import nested [as 别名]
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))
示例6: testBooleanOrQuery
# 需要导入模块: from cqlparser.cqltoexpression import QueryExpression [as 别名]
# 或者: from cqlparser.cqltoexpression.QueryExpression import nested [as 别名]
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)
示例7: testBooleanAndQuery
# 需要导入模块: from cqlparser.cqltoexpression import QueryExpression [as 别名]
# 或者: from cqlparser.cqltoexpression.QueryExpression import nested [as 别名]
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))
示例8: testBooleanNotQuery
# 需要导入模块: from cqlparser.cqltoexpression import QueryExpression [as 别名]
# 或者: from cqlparser.cqltoexpression.QueryExpression import nested [as 别名]
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)
示例9: convert
# 需要导入模块: from cqlparser.cqltoexpression import QueryExpression [as 别名]
# 或者: from cqlparser.cqltoexpression.QueryExpression import nested [as 别名]
def convert(self, expression, core):
filterQueries = {}
if expression.operator is None or expression.operator == 'OR':
e = QueryExpression.nested('AND')
e.operands.append(expression)
expression = e
if expression.operator == 'AND':
oldOperands = expression.operands
expression.operands = []
for operand in oldOperands:
operandCores = list(self.coresInExpression(expression=operand, core=core))
if len(operandCores) == 1 and operandCores[0] != core:
removeCoreFromFieldname(operandCores[0], operand)
filterQueries.setdefault(operandCores[0], []).append(operand)
else:
expression.operands.append(operand)
if len(expression.operands) == 1:
expression = expression.operands[0]
elif len(expression.operands) == 0:
expression = None
if expression and self.coresInExpression(expression=expression, core=core) != set([core]):
raise TooComplexQueryExpression('Multiple core query detected, but unable to convert to a correct composed query')
return expression, filterQueries