hub changes for stream/repost with extensions #113

Open
moodyjon wants to merge 13 commits from moodyjon/limited_repost into master
2 changed files with 18 additions and 7 deletions
Showing only changes of commit a09d49f8df - Show all commits

View file

@ -765,7 +765,15 @@ INDEX_DEFAULT_SETTINGS = {
"censor_type": {"type": "byte"}, "censor_type": {"type": "byte"},
"trending_score": {"type": "double"}, "trending_score": {"type": "double"},
"release_time": {"type": "long"}, "release_time": {"type": "long"},
"extensions": {"type": "object"}, # top-level keys of extensions dict indexed as keywords
"extensions": {
"type": "keyword"
},
# full contents of extensions dict available as "runtime" fields
"extensions_obj": {
"type": "object",
"dynamic": "runtime"
},
} }
} }
} }
@ -789,7 +797,7 @@ FIELDS = {
'reposted_claim_id', 'repost_count', 'sd_hash', 'reposted_claim_id', 'repost_count', 'sd_hash',
'trending_score', 'tx_num', 'trending_score', 'tx_num',
'channel_tx_id', 'channel_tx_position', 'channel_height', 'reposted_tx_id', 'channel_tx_id', 'channel_tx_position', 'channel_height', 'reposted_tx_id',
'reposted_tx_position', 'reposted_height', 'extensions', 'reposted_tx_position', 'reposted_height', 'extensions', 'extensions_obj'
} }
TEXT_FIELDS = { TEXT_FIELDS = {
@ -854,6 +862,8 @@ def expand_query(**kwargs):
value = list(filter(None, value)) value = list(filter(None, value))
if value is None or isinstance(value, list) and len(value) == 0: if value is None or isinstance(value, list) and len(value) == 0:
continue continue
if key in OBJECT_FIELDS and not isinstance(value, dict):
continue
key = REPLACEMENTS.get(key, key) key = REPLACEMENTS.get(key, key)
#print(f'expand_query: *** {key} = {value}') #print(f'expand_query: *** {key} = {value}')
if key in FIELDS: if key in FIELDS:
@ -934,10 +944,10 @@ def expand_query(**kwargs):
# require <field> match value <d> # require <field> match value <d>
yield {"match": {field: {"query": d}}} yield {"match": {field: {"query": d}}}
#yield {"term": {field: {"value": d}}} #yield {"term": {field: {"value": d}}}
query['must'].append( # query field <key> for list of top-level dictionary keys
{"exists": {"field": key}}, query['must'].append({"terms": {key: list(value.keys())}})
) # query field <key>_obj for nested properties
query['must'].extend(flatten(key, value)) query['must'].extend(flatten(f'{key}_obj', value))
elif many: elif many:
query['must'].append({"terms": {key: value}}) query['must'].append({"terms": {key: value}})
else: else:

View file

@ -191,7 +191,8 @@ class ElasticSyncDB(SecondaryDB):
'channel_tx_id': None if not claim.channel_tx_hash else claim.channel_tx_hash[::-1].hex(), 'channel_tx_id': None if not claim.channel_tx_hash else claim.channel_tx_hash[::-1].hex(),
'channel_tx_position': claim.channel_tx_position, 'channel_tx_position': claim.channel_tx_position,
'channel_height': claim.channel_height, 'channel_height': claim.channel_height,
'extensions': extensions 'extensions': list(extensions.keys()) if extensions else None,
'extensions_obj': extensions,
} }
if metadata.is_repost and reposted_duration is not None: if metadata.is_repost and reposted_duration is not None: