本文整理匯總了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