Skip to content

Commit

Permalink
Merge eb2b919 into 5eb95d7
Browse files Browse the repository at this point in the history
  • Loading branch information
shyba committed Dec 22, 2021
2 parents 5eb95d7 + eb2b919 commit 1516e96
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
4 changes: 3 additions & 1 deletion lbry/extras/daemon/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2440,7 +2440,7 @@ async def jsonrpc_claim_search(self, **kwargs):
[--not_locations=<not_locations>...]
[--order_by=<order_by>...] [--no_totals] [--page=<page>] [--page_size=<page_size>]
[--wallet_id=<wallet_id>] [--include_purchase_receipt] [--include_is_my_output]
[--remove_duplicates] [--has_source | --has_no_source]
[--remove_duplicates] [--has_source | --has_no_source] [--sd_hash=<sd_hash>]
[--new_sdk_server=<new_sdk_server>]
Options:
Expand Down Expand Up @@ -2538,6 +2538,8 @@ async def jsonrpc_claim_search(self, **kwargs):
--remove_duplicates : (bool) removes duplicated content from search by picking either the
original claim or the oldest matching repost
--has_source : (bool) find claims containing a source field
--sd_hash=<sd_hash> : (str) find claims where the source stream descriptor hash matches
(partially or completely) the given hexadecimal string
--has_no_source : (bool) find claims not containing a source field
--new_sdk_server=<new_sdk_server> : (str) URL of the new SDK server (EXPERIMENTAL)
Expand Down
15 changes: 11 additions & 4 deletions lbry/schema/types/v2/hub_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lbry/wallet/orchstr8/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__hub_url__ = (
"https://github.com/lbryio/hub/releases/download/range-queries/hub"
"https://github.com/lbryio/hub/releases/download/v0.2021.12.18.1/hub"
)
from .node import Conductor
from .service import ConductorService
17 changes: 15 additions & 2 deletions lbry/wallet/server/db/elasticsearch/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@
"max_chars": 10
}
},
"sd_hash": {
"fields": {
"keyword": {
"ignore_above": 96,
"type": "keyword"
}
},
"type": "text",
"index_prefixes": {
"min_chars": 1,
"max_chars": 4
}
},
"height": {"type": "integer"},
"claim_type": {"type": "byte"},
"censor_type": {"type": "byte"},
Expand All @@ -52,14 +65,14 @@
'timestamp', 'creation_timestamp',
'duration', 'release_time',
'tags', 'languages', 'has_source', 'reposted_claim_type',
'reposted_claim_id', 'repost_count',
'reposted_claim_id', 'repost_count', 'sd_hash',
'trending_score', 'tx_num'
}

TEXT_FIELDS = {'author', 'canonical_url', 'channel_id', 'description', 'claim_id', 'censoring_channel_id',
'media_type', 'normalized_name', 'public_key_bytes', 'public_key_id', 'short_url', 'signature',
'claim_name', 'signature_digest', 'title', 'tx_id', 'fee_currency', 'reposted_claim_id',
'tags'}
'tags', 'sd_hash'}

RANGE_FIELDS = {
'height', 'creation_height', 'activation_height', 'expiration_height',
Expand Down
4 changes: 2 additions & 2 deletions lbry/wallet/server/db/elasticsearch/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,15 +559,15 @@ 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
if key in TEXT_FIELDS:
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:]
Expand Down
1 change: 1 addition & 0 deletions lbry/wallet/server/leveldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ def _prepare_claim_metadata(self, claim_hash: bytes, claim: ResolveResult):
'claim_type': CLAIM_TYPES[metadata.claim_type],
'has_source': reposted_has_source if metadata.is_repost else (
False if not metadata.is_stream else metadata.stream.has_source),
'sd_hash': metadata.stream.source.sd_hash if metadata.is_stream and metadata.stream.has_source else None,
'stream_type': STREAM_TYPES[guess_stream_type(metadata.stream.source.media_type)]
if metadata.is_stream and metadata.stream.has_source
else reposted_stream_type if metadata.is_repost else 0,
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/claims/test_claim_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ async def test_basic_claim_search(self):
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='*')
# 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')
Expand Down

0 comments on commit 1516e96

Please sign in to comment.