fix shoulds in es
This commit is contained in:
parent
3dfea9974d
commit
879869cb31
1 changed files with 36 additions and 11 deletions
|
@ -396,18 +396,43 @@ def expand_query(**kwargs):
|
||||||
if 'signature_valid' in kwargs:
|
if 'signature_valid' in kwargs:
|
||||||
query['must'].append({"term": {"is_signature_valid": bool(kwargs["signature_valid"])}})
|
query['must'].append({"term": {"is_signature_valid": bool(kwargs["signature_valid"])}})
|
||||||
elif 'signature_valid' in kwargs:
|
elif 'signature_valid' in kwargs:
|
||||||
query.setdefault('should', [])
|
query['must'].append(
|
||||||
query["minimum_should_match"] = 1
|
{"bool":
|
||||||
query['should'].append({"bool": {"must_not": {"exists": {"field": "signature"}}}})
|
{"should": [
|
||||||
query['should'].append({"term": {"is_signature_valid": bool(kwargs["signature_valid"])}})
|
{"bool": {"must_not": {"exists": {"field": "signature"}}}},
|
||||||
|
{"bool" : {"must" : {"term": {"is_signature_valid": bool(kwargs["signature_valid"])}}}}
|
||||||
|
]}
|
||||||
|
}
|
||||||
|
)
|
||||||
if 'has_source' in kwargs:
|
if 'has_source' in kwargs:
|
||||||
query.setdefault('should', [])
|
is_stream_or_repost_terms = {"terms": {"claim_type": [CLAIM_TYPES['stream'], CLAIM_TYPES['repost']]}}
|
||||||
query["minimum_should_match"] = 1
|
query['must'].append(
|
||||||
is_stream_or_repost = {"terms": {"claim_type": [CLAIM_TYPES['stream'], CLAIM_TYPES['repost']]}}
|
{"bool":
|
||||||
query['should'].append(
|
{"should": [
|
||||||
{"bool": {"must": [{"match": {"has_source": kwargs['has_source']}}, is_stream_or_repost]}})
|
{"bool": # when is_stream_or_repost AND has_source
|
||||||
query['should'].append({"bool": {"must_not": [is_stream_or_repost]}})
|
{"must": [
|
||||||
query['should'].append({"bool": {"must": [{"term": {"reposted_claim_type": CLAIM_TYPES['channel']}}]}})
|
{"match": {"has_source": kwargs['has_source']}},
|
||||||
|
is_stream_or_repost_terms,
|
||||||
|
]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{"bool": # when not is_stream_or_repost
|
||||||
|
{"must_not": is_stream_or_repost_terms}
|
||||||
|
},
|
||||||
|
{"bool": # when reposted_claim_type wouldn't have source
|
||||||
|
{"must_not":
|
||||||
|
[
|
||||||
|
{"term": {"reposted_claim_type": CLAIM_TYPES['stream']}}
|
||||||
|
],
|
||||||
|
"must":
|
||||||
|
[
|
||||||
|
{"term": {"claim_type": CLAIM_TYPES['repost']}}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
}
|
||||||
|
)
|
||||||
if kwargs.get('text'):
|
if kwargs.get('text'):
|
||||||
query['must'].append(
|
query['must'].append(
|
||||||
{"simple_query_string":
|
{"simple_query_string":
|
||||||
|
|
Loading…
Reference in a new issue