From ebe351c67e4fe9975ba95ce5c020c425de9d7658 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Wed, 8 Dec 2021 04:27:57 -0300 Subject: [PATCH] enable and test prefix search for sd hash --- lbry/wallet/server/db/elasticsearch/search.py | 4 ++-- tests/integration/claims/test_claim_commands.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lbry/wallet/server/db/elasticsearch/search.py b/lbry/wallet/server/db/elasticsearch/search.py index 521a7cdf2..3111155a9 100644 --- a/lbry/wallet/server/db/elasticsearch/search.py +++ b/lbry/wallet/server/db/elasticsearch/search.py @@ -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:] diff --git a/tests/integration/claims/test_claim_commands.py b/tests/integration/claims/test_claim_commands.py index 0f9c67e2d..06c005ff7 100644 --- a/tests/integration/claims/test_claim_commands.py +++ b/tests/integration/claims/test_claim_commands.py @@ -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')