claim_search --not_tags feature + integration tests

This commit is contained in:
Lex Berezhny 2019-05-06 16:37:17 -04:00
parent 75211b7e84
commit 4702bea9f0
3 changed files with 31 additions and 4 deletions

View file

@ -1674,9 +1674,11 @@ class Daemon(metaclass=JSONRPCServerType):
Usage:
claim_search [<name> | --name=<name>] [--claim_id=<claim_id>] [--txid=<txid> --nout=<nout>]
[--channel_id=<channel_id>] [--channel_name=<channel_name>] [--is_controlling]
[--any_tags=<any_tags>...] [--all_tags=<all_tags>...]
[--any_tags=<any_tags>...] [--all_tags=<all_tags>...] [--not_tags=<not_tags>...]
[--any_languages=<any_languages>...] [--all_languages=<all_languages>...]
[--not_languages=<not_languages>...]
[--any_locations=<any_locations>...] [--all_locations=<all_locations>...]
[--not_locations=<not_locations>...]
[--page=<page>] [--page_size=<page_size>]
Options:
@ -1689,10 +1691,13 @@ class Daemon(metaclass=JSONRPCServerType):
--is_controlling : (bool) limit to controlling claims for their respective name
--any_tags=<any_tags> : (list) find claims containing any of the tags
--all_tags=<all_tags> : (list) find claims containing every tag
--not_tags=<not_tags> : (list) find claims not containing any of these tags
--any_languages=<any_languages> : (list) find claims containing any of the languages
--all_languages=<all_languages> : (list) find claims containing every language
--not_languages=<not_languages> : (list) find claims not containing any of these languages
--any_locations=<any_locations> : (list) find claims containing any of the locations
--all_locations=<all_locations> : (list) find claims containing every location
--not_locations=<not_locations> : (list) find claims not containing any of these locations
--page=<page> : (int) page to return during paginating
--page_size=<page_size> : (int) number of items on page during pagination

View file

@ -378,6 +378,15 @@ class SQLDB:
SELECT txo_hash FROM tag WHERE tag IN ({}) GROUP BY txo_hash HAVING COUNT(tag) = :$all_tags_count
""".format(', '.join(f':$all_tags{i}' for i in range(len(all_tags))))
not_tags = constraints.pop('not_tags', [])[:100]
if not_tags:
constraints.update({
f'$not_tags{i}': tag for i, tag in enumerate(not_tags)
})
constraints['claim.txo_hash__not_in'] = """
SELECT DISTINCT txo_hash FROM tag WHERE tag IN ({})
""".format(', '.join(f':$not_tags{i}' for i in range(len(not_tags))))
return self.db.execute(*query(
f"""
SELECT {cols} FROM claim
@ -413,9 +422,9 @@ class SQLDB:
SEARCH_PARAMS = {
'name', 'claim_id', 'txid', 'nout',
'channel', 'channel_id', 'channel_name',
'any_tags', 'all_tags',
'any_locations', 'all_locations',
'any_languages', 'all_languages',
'any_tags', 'all_tags', 'not_tags',
'any_locations', 'all_locations', 'not_locations',
'any_languages', 'all_languages', 'not_languages',
'is_controlling', 'limit', 'offset'
}

View file

@ -135,6 +135,19 @@ class ClaimSearchCommand(CommandTestCase):
await self.assertFindsClaims([], all_tags=['ghi', 'xyz'])
await self.assertFindsClaims([], all_tags=['xyz'])
# not_tags
await self.assertFindsClaims([], not_tags=['abc', 'pqr'])
await self.assertFindsClaims([claim5], not_tags=['abc'])
await self.assertFindsClaims([claim5], not_tags=['abc', 'ghi'])
await self.assertFindsClaims([claim5, claim2, claim1], not_tags=['ghi'])
await self.assertFindsClaims([claim5, claim2, claim1], not_tags=['ghi', 'xyz'])
await self.assertFindsClaims([claim5, claim4, claim3, claim2, claim1], not_tags=['xyz'])
# combinations
await self.assertFindsClaims([claim3], all_tags=['abc', 'ghi'], not_tags=['mno'])
await self.assertFindsClaims([claim3], all_tags=['abc', 'ghi'], any_tags=['jkl'], not_tags=['mno'])
await self.assertFindsClaims([claim4, claim3, claim2], all_tags=['abc'], any_tags=['def', 'ghi'])
class ChannelCommands(CommandTestCase):