Compare commits

...

3 commits

Author SHA1 Message Date
zeppi b21c71a420 cleanup 2022-03-24 19:05:24 -04:00
zeppi c8aa73a5d6 wip 2022-03-24 18:41:29 -04:00
zeppi a24fbf81d7 es should fix 2022-03-24 18:07:22 -04:00
2 changed files with 47 additions and 11 deletions

View file

@ -620,18 +620,43 @@ def expand_query(**kwargs):
if 'signature_valid' in kwargs:
query['must'].append({"term": {"is_signature_valid": bool(kwargs["signature_valid"])}})
elif 'signature_valid' in kwargs:
query.setdefault('should', [])
query["minimum_should_match"] = 1
query['should'].append({"bool": {"must_not": {"exists": {"field": "signature"}}}})
query['should'].append({"term": {"is_signature_valid": bool(kwargs["signature_valid"])}})
query['must'].append(
{"bool":
{"should": [
{"bool": {"must_not": {"exists": {"field": "signature"}}}},
{"bool" : {"must" : {"term": {"is_signature_valid": bool(kwargs["signature_valid"])}}}}
]}
}
)
if 'has_source' in kwargs:
query.setdefault('should', [])
query["minimum_should_match"] = 1
is_stream_or_repost = {"terms": {"claim_type": [CLAIM_TYPES['stream'], CLAIM_TYPES['repost']]}}
query['should'].append(
{"bool": {"must": [{"match": {"has_source": kwargs['has_source']}}, is_stream_or_repost]}})
query['should'].append({"bool": {"must_not": [is_stream_or_repost]}})
query['should'].append({"bool": {"must": [{"term": {"reposted_claim_type": CLAIM_TYPES['channel']}}]}})
is_stream_or_repost_terms = {"terms": {"claim_type": [CLAIM_TYPES['stream'], CLAIM_TYPES['repost']]}}
query['must'].append(
{"bool":
{"should": [
{"bool": # when is_stream_or_repost AND has_source
{"must": [
{"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'):
query['must'].append(
{"simple_query_string":

View file

@ -405,6 +405,17 @@ class ClaimSearchCommand(ClaimTestCase):
not_channel_ids=[chan2_id], has_channel_signature=True, valid_channel_signature=True)
await match([], not_channel_ids=[chan1_id, chan2_id], has_channel_signature=True, valid_channel_signature=True)
async def test_no_source_and_valid_channel_signature_and_media_type(self):
await self.channel_create('@spam2', '1.0')
await self.stream_create('barrrrrr', '1.0', channel_name='@spam2', file_path=self.video_file_name)
paradox_no_source_claims = await self.claim_search(has_no_source=True, valid_channel_signature=True,
media_type="video/mp4")
mp4_claims = await self.claim_search(media_type="video/mp4")
no_source_claims = await self.claim_search(has_no_source=True, valid_channel_signature=True)
self.assertEqual(0, len(paradox_no_source_claims))
self.assertEqual(1, len(no_source_claims))
self.assertEqual(1, len(mp4_claims))
async def test_limit_claims_per_channel(self):
match = self.assertFindsClaims
chan1_id = self.get_claim_id(await self.channel_create('@chan1'))