Skip to content

Commit

Permalink
fix resolve partial id
Browse files Browse the repository at this point in the history
  • Loading branch information
shyba committed Jan 27, 2021
1 parent 4bc479a commit e314d32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions lbry/wallet/server/db/elastic_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def start(self):
"default": {"tokenizer": "whitespace", "filter": ["lowercase", "porter_stem"]}}},
"index":
{"refresh_interval": -1,
"number_of_shards": 3}
"number_of_shards": 1}
},

}
Expand Down Expand Up @@ -222,11 +222,10 @@ def extract_doc(doc, index):
TEXT_FIELDS = ['author', 'canonical_url', 'channel_id', 'claim_id', 'claim_name', 'description',
'media_type', 'normalized', 'public_key_bytes', 'public_key_hash', 'short_url', 'signature',
'signature_digest', 'stream_type', 'title', 'tx_id', 'fee_currency', 'reposted_claim_id', 'tags']
RANGE_FIELDS = ['height', 'fee_amount', 'duration', 'reposted']
RANGE_FIELDS = ['height', 'fee_amount', 'duration', 'reposted', 'release_time']
REPLACEMENTS = {
'name': 'normalized',
'txid': 'tx_id',
'claim_hash': '_id',
}


Expand All @@ -236,11 +235,14 @@ def expand_query(**kwargs):
query = {'must': [], 'must_not': []}
collapse = None
for key, value in kwargs.items():
if not value:
continue
key = key.replace('claim.', '')
many = key.endswith('__in') or isinstance(value, list)
if many:
key = key.replace('__in', '')
key = REPLACEMENTS.get(key, key)
partial_id = False
if key in FIELDS:
if key == 'claim_type':
if isinstance(value, str):
Expand All @@ -252,6 +254,8 @@ def expand_query(**kwargs):
value = [hexlify(item[::-1]).decode() for item in value]
else:
value = hexlify(value[::-1]).decode()
if key in ('_id', 'claim_id') and len(value) < 20:
partial_id = True
if key == 'public_key_id':
key = 'public_key_hash'
value = hexlify(Base58.decode(value)[1:21]).decode()
Expand All @@ -260,7 +264,9 @@ def expand_query(**kwargs):
if key in TEXT_FIELDS:
key += '.keyword'
ops = {'<=': 'lte', '>=': 'gte', '<': 'lt', '>': 'gt'}
if key in RANGE_FIELDS and isinstance(value, str) and value[0] in ops:
if partial_id:
query['must'].append({"prefix": {key: {"value": 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:]
if key == 'fee_amount':
Expand Down
3 changes: 2 additions & 1 deletion scripts/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def exec_factory(cursor, statement, bindings):
claim['censoring_channel_hash'] = None
claim['tags'] = claim['tags'].split(' ') if claim['tags'] else []
claim['languages'] = claim['languages'].split(' ') if claim['languages'] else []
print(num, total)
if num % 10_000 == 0:
print(num, total)
yield extract_doc(claim, INDEX)


Expand Down

0 comments on commit e314d32

Please sign in to comment.