diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index da2363186..07980efcb 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -205,12 +205,15 @@ def fix_kwargs_for_hub(**kwargs): elif key == "not_channel_ids": kwargs["channel_id"] = {"invert": True, "value": kwargs.pop("not_channel_ids")} elif key in MY_RANGE_FIELDS: - operator = '=' - if isinstance(value, str) and value[0] in opcodes: - operator_length = 2 if value[:2] in opcodes else 1 - operator, value = value[:operator_length], value[operator_length:] - value = [str(value if key != 'fee_amount' else Decimal(value)*1000)] - kwargs[key] = {"op": opcodes[operator], "value": value} + constraints = [] + for v in value if isinstance(value, list) else [value]: + operator = '=' + if isinstance(v, str) and v[0] in opcodes: + operator_length = 2 if v[:2] in opcodes else 1 + operator, v = v[:operator_length], v[operator_length:] + v = [str(v if key != 'fee_amount' else Decimal(v)*1000)] + constraints.append({"op": opcodes[operator], "value": v}) + kwargs[key] = constraints elif key == 'order_by': # TODO: remove this after removing support for old trending args from the api value = value if isinstance(value, list) else [value] new_value = [] @@ -2408,6 +2411,9 @@ class Daemon(metaclass=JSONRPCServerType): value with an equality constraint such as '>', '>=', '<' and '<=' eg. --height=">400000" would limit results to only claims above 400k block height. + They also support multiple constraints passed as a list of the args described above. + eg. --release_time=[">1000000", "<2000000"] + Usage: claim_search [ | --name=] [--text=] [--txid=] [--nout=] [--claim_id= | --claim_ids=...] diff --git a/lbry/wallet/server/db/elasticsearch/search.py b/lbry/wallet/server/db/elasticsearch/search.py index 68383959a..521a7cdf2 100644 --- a/lbry/wallet/server/db/elasticsearch/search.py +++ b/lbry/wallet/server/db/elasticsearch/search.py @@ -574,6 +574,15 @@ def expand_query(**kwargs): if key == 'fee_amount': value = str(Decimal(value)*1000) query['must'].append({"range": {key: {ops[operator]: value}}}) + elif key in RANGE_FIELDS and isinstance(value, list) and all(v[0] in ops for v in value): + range_constraints = [] + for v in value: + operator_length = 2 if v[:2] in ops else 1 + operator, stripped_op_v = v[:operator_length], v[operator_length:] + if key == 'fee_amount': + stripped_op_v = str(Decimal(stripped_op_v)*1000) + range_constraints.append((operator, stripped_op_v)) + query['must'].append({"range": {key: {ops[operator]: v for operator, v in range_constraints}}}) elif many: query['must'].append({"terms": {key: value}}) else: diff --git a/lbry/wallet/server/session.py b/lbry/wallet/server/session.py index 473a8f2fa..6218b3992 100644 --- a/lbry/wallet/server/session.py +++ b/lbry/wallet/server/session.py @@ -981,8 +981,9 @@ class LBRYElectrumX(SessionBase): start = time.perf_counter() if 'release_time' in kwargs: release_time = kwargs.pop('release_time') + release_times = release_time if isinstance(release_time, list) else [release_time] try: - kwargs['release_time'] = format_release_time(release_time) + kwargs['release_time'] = [format_release_time(release_time) for release_time in release_times] except ValueError: pass try: diff --git a/tests/integration/claims/test_claim_commands.py b/tests/integration/claims/test_claim_commands.py index 6bcd27d1d..dc48a557c 100644 --- a/tests/integration/claims/test_claim_commands.py +++ b/tests/integration/claims/test_claim_commands.py @@ -1796,6 +1796,12 @@ class StreamCommands(ClaimTestCase): self.assertEqual(1, len(await self.claim_search(release_time='>123456', order_by=['release_time']))) self.assertEqual(2, len(await self.claim_search(release_time='<123457', order_by=['release_time']))) + self.assertEqual(2, len(await self.claim_search(release_time=['<123457'], order_by=['release_time']))) + self.assertEqual(2, len(await self.claim_search(release_time=['>0', '<123457'], order_by=['release_time']))) + self.assertEqual( + 2, len(await self.claim_search(release_time=['>=123097', '<123457'], order_by=['release_time'])) + ) + async def test_setting_fee_fields(self): tx = await self.out(self.stream_create('paid-stream')) txo = tx['outputs'][0]