From da8a8bd1ef16d081d1bebeb300f53c394aeb4b73 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Sat, 13 Feb 2021 02:16:49 -0300 Subject: [PATCH] filter+fts and tests for edge cases --- lbry/wallet/server/db/elastic_search.py | 6 +++--- tests/integration/blockchain/test_claim_commands.py | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lbry/wallet/server/db/elastic_search.py b/lbry/wallet/server/db/elastic_search.py index c0d6783f2..8798ef61c 100644 --- a/lbry/wallet/server/db/elastic_search.py +++ b/lbry/wallet/server/db/elastic_search.py @@ -405,12 +405,12 @@ def expand_query(**kwargs): query["minimum_should_match"] = 1 query['should'].append({"bool": {"must_not": {"exists": {"field": "signature_digest"}}}}) query['should'].append({"term": {"signature_valid": bool(kwargs["signature_valid"])}}) - if 'text' in kwargs: - return {"query": + if kwargs.get('text'): + query['must'].append( {"simple_query_string": {"query": kwargs["text"], "fields": [ "claim_name^4", "channel_name^8", "title^1", "description^.5", "author^1", "tags^.5" - ]}}} + ]}}) query = { "_source": {"excludes": ["description", "title"]}, 'query': {'bool': query}, diff --git a/tests/integration/blockchain/test_claim_commands.py b/tests/integration/blockchain/test_claim_commands.py index 98d6a298d..93ffbfe79 100644 --- a/tests/integration/blockchain/test_claim_commands.py +++ b/tests/integration/blockchain/test_claim_commands.py @@ -175,6 +175,8 @@ class ClaimSearchCommand(ClaimTestCase): await self.assertFindsClaims([], channel_ids=[channel_id2]) # resolve by claim ids await self.assertFindsClaims([three, two], claim_ids=[self.get_claim_id(three), self.get_claim_id(two)]) + await self.assertFindsClaims([three], claim_id=self.get_claim_id(three)) + await self.assertFindsClaims([three], claim_id=self.get_claim_id(three), text='*') async def test_source_filter(self): no_source = await self.stream_create('no_source', data=None) @@ -451,9 +453,9 @@ class ClaimSearchCommand(ClaimTestCase): await self.assertFindsClaims([claim4], text='conspiracy') await self.assertFindsClaims([], text='conspiracy+history') await self.assertFindsClaims([claim4, claim3], text='conspiracy|history') - await self.assertFindsClaims([claim1, claim4, claim2, claim3], text='documentary') + await self.assertFindsClaims([claim1, claim4, claim2, claim3], text='documentary', order_by=[]) # todo: check why claim1 and claim2 order changed. used to be ...claim1, claim2... - await self.assertFindsClaims([claim4, claim2, claim1, claim3], text='satoshi') + await self.assertFindsClaims([claim4, claim2, claim1, claim3], text='satoshi', order_by=[]) claim2 = await self.stream_update( self.get_claim_id(claim2), clear_tags=True, tags=['cloud'],