Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FindQuery.resolve_value can't resolve for Operations.IN and RedisSearchFieldTypes.NUMERIC #499

Open
landeholt opened this issue Apr 15, 2023 · 0 comments

Comments

@landeholt
Copy link

landeholt commented Apr 15, 2023

I believe I've found a miss in the resolver.

Currently, I can't seem to do the following when a field is numeric:

class MyModel(JSONModel):
    my_field: int = Field(index=True)

MyModel(my_field=1).save()

assert MyModel.find(MyModel.my_field << [1,2,3,4]).all() == []

It does work when my_field is a string, but I expect it to work for numerics as well.

I've experimented and added the following code:

elif op is Operators.IN:
    result += "|".join(map(lambda v: f"(@{field_name}: [{v} {v}])", value))

to

elif field_type is RediSearchFieldTypes.NUMERIC:
if op is Operators.EQ:
result += f"@{field_name}:[{value} {value}]"
elif op is Operators.NE:
result += f"-(@{field_name}:[{value} {value}])"
elif op is Operators.GT:
result += f"@{field_name}:[({value} +inf]"
elif op is Operators.LT:
result += f"@{field_name}:[-inf ({value}]"
elif op is Operators.GE:
result += f"@{field_name}:[{value} +inf]"
elif op is Operators.LE:
result += f"@{field_name}:[-inf {value}]"

I'm quite concerned about the performance of chaining multiple OR expressions, but this is the only way I've found and seen others doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant