tags dynamic filters #2
This commit is contained in:
parent
c00075feec
commit
013cd864c2
|
|
@ -149,25 +149,23 @@ class CustomFacetedSearchFilterBackend(FacetedSearchFilterBackend):
|
||||||
result_bucket = buckets[0]
|
result_bucket = buckets[0]
|
||||||
for bucket in buckets[1:]:
|
for bucket in buckets[1:]:
|
||||||
for tag in bucket.tag.buckets._l_:
|
for tag in bucket.tag.buckets._l_:
|
||||||
if tag not in result_bucket.tag.buckets._l_:
|
result_bucket.tag.buckets.append(tag)
|
||||||
result_bucket.tag.buckets._l_.append(tag)
|
|
||||||
def reducer(prev, cur):
|
def reducer(prev, cur):
|
||||||
try:
|
"""Unique by key"""
|
||||||
index = list(map(lambda x: x['key'], prev)).index(cur['key'])
|
if not len(list(filter(lambda x: x['key'] == cur['key'], prev))):
|
||||||
if cur['doc_count'] < prev[index]['doc_count']:
|
|
||||||
prev[index]['doc_count'] = cur['doc_count']
|
|
||||||
except ValueError:
|
|
||||||
prev.append(cur)
|
prev.append(cur)
|
||||||
return prev
|
return prev
|
||||||
|
|
||||||
result_bucket.tag.buckets._l_ = list(reduce(
|
buckets_count = len(buckets)
|
||||||
reducer, result_bucket.tag.buckets._l_, []
|
result_bucket.tag.buckets = list(filter(lambda t: t is not None, [
|
||||||
))
|
tag if len(list(filter(lambda t: t['key'] == tag['key'], result_bucket.tag.buckets._l_))) == buckets_count else None
|
||||||
result_bucket.doc_count = reduce(
|
for tag in result_bucket.tag.buckets._l_])) # here we remove tags which don't present in any bucket
|
||||||
lambda prev, cur: prev + cur['doc_count'],
|
result_bucket.tag.buckets = list(reduce(
|
||||||
|
reducer,
|
||||||
result_bucket.tag.buckets._l_,
|
result_bucket.tag.buckets._l_,
|
||||||
0
|
[]
|
||||||
)
|
))
|
||||||
return result_bucket
|
return result_bucket
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user