enable and test prefix search for sd hash

This commit is contained in:
Victor Shyba 2021-12-08 04:27:57 -03:00
parent 6ad2e31976
commit ebe351c67e
2 changed files with 3 additions and 2 deletions

View file

@ -559,7 +559,7 @@ def expand_query(**kwargs):
value = [item[::-1].hex() for item in value]
else:
value = value[::-1].hex()
if not many and key in ('_id', 'claim_id') and len(value) < 20:
if not many and key in ('_id', 'claim_id', 'sd_hash') and len(value) < 20:
partial_id = True
if key in ('signature_valid', 'has_source'):
continue # handled later
@ -567,7 +567,7 @@ def expand_query(**kwargs):
key += '.keyword'
ops = {'<=': 'lte', '>=': 'gte', '<': 'lt', '>': 'gt'}
if partial_id:
query['must'].append({"prefix": {"claim_id": value}})
query['must'].append({"prefix": {key: value}})
elif key in RANGE_FIELDS and isinstance(value, str) and value[0] in ops:
operator_length = 2 if value[:2] in ops else 1
operator, value = value[:operator_length], value[operator_length:]

View file

@ -217,6 +217,7 @@ class ClaimSearchCommand(ClaimTestCase):
# resolve by sd hash
two_sd_hash = two['outputs'][0]['value']['source']['sd_hash']
await self.assertFindsClaims([two], sd_hash=two_sd_hash)
await self.assertFindsClaims([two], sd_hash=two_sd_hash[:2])
async def test_source_filter(self):
channel = await self.channel_create('@abc')