本文整理汇总了Python中haystack.inputs.Exact方法的典型用法代码示例。如果您正苦于以下问题:Python inputs.Exact方法的具体用法?Python inputs.Exact怎么用?Python inputs.Exact使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类haystack.inputs
的用法示例。
在下文中一共展示了inputs.Exact方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_query
# 需要导入模块: from haystack import inputs [as 别名]
# 或者: from haystack.inputs import Exact [as 别名]
def build_query(self, **filters):
inclusions = {}
exclusions = None
SQ = self.view.query_object
exact_fields = getattr(self.view.serializer_class.Meta, "exact_fields", [])
for qname, qvals in filters.items():
if qname not in exact_fields:
continue
for qval in qvals:
if qval:
filt = SQ(**{qname: Exact(qval)})
inclusions[qname] = (
(filt | inclusions[qname]) if qname in inclusions else filt
)
inclusions = (
functools.reduce(operator.and_, inclusions.values()) if inclusions else None
)
return inclusions, exclusions
示例2: build_query
# 需要导入模块: from haystack import inputs [as 别名]
# 或者: from haystack.inputs import Exact [as 别名]
def build_query(self, **filters):
inclusions = {}
exclusions = None
SQ = self.view.query_object
status_fields = getattr(self.view.serializer_class.Meta, 'status_fields', {})
for qname, qval in status_fields.items():
if qval and qval != 'any':
inclusions[qname] = SQ(**{qname: Exact(qval)})
for qname, qvals in filters.items():
if qname not in status_fields:
continue
for qval in qvals:
if qval and qval != 'any':
inclusions[qname] = SQ(**{qname: Exact(qval)})
elif qname in inclusions:
del inclusions[qname]
inclusions = functools.reduce(operator.and_, inclusions.values()) if inclusions else None
return inclusions, exclusions
示例3: build_name_query
# 需要导入模块: from haystack import inputs [as 别名]
# 或者: from haystack.inputs import Exact [as 别名]
def build_name_query(self, term):
SQ = self.view.query_object
filter = super(CredNameFilterBuilder, self).build_name_query(term)
if term and " " not in term:
filter = filter | (SQ(source_id=Exact(term)) & SQ(name=Raw("*")))
return filter
示例4: build_query
# 需要导入模块: from haystack import inputs [as 别名]
# 或者: from haystack.inputs import Exact [as 别名]
def build_query(self, **filters):
inclusions = {}
exclusions = None
SQ = self.view.query_object
filter_fields_map = getattr(
self.view.serializer_class.Meta, "filter_fields_map", ()
)
# For every parameter passed in the request
for qname, qvals in filters.items():
for qval in qvals:
# Check if we track this filter type in the serializer
# in `filter_fields_map` tuple
if qname in filter_fields_map:
mapped_index_attributes = filter_fields_map[qname]
attr_inclusions = {}
# Construct an OR clause for this filter across all of the
# mapped index attributes
for mapped_attr in mapped_index_attributes:
attr_inclusions[mapped_attr] = SQ(**{mapped_attr: Exact(qval)})
attr_inclusions = (
functools.reduce(operator.or_, attr_inclusions.values())
if attr_inclusions
else None
)
# Add this sub OR clause to the top-level set of AND clauses
inclusions[mapped_attr] = attr_inclusions
inclusions = (
functools.reduce(operator.and_, inclusions.values()) if inclusions else None
)
return inclusions, exclusions
示例5: build_name_query
# 需要导入模块: from haystack import inputs [as 别名]
# 或者: from haystack.inputs import Exact [as 别名]
def build_name_query(self, term):
SQ = self.view.query_object
filter = super(CredNameFilterBuilder, self).build_name_query(term)
if term and ' ' not in term:
filter = filter | (SQ(source_id=Exact(term)) & SQ(name=Raw('*')))
return filter