redis / redis-om-python

Object mapping, and more, for Redis and Python
MIT License
1.06k stars 108 forks source link

how can I search by condition #579

Closed saifullah-repliq closed 3 months ago

saifullah-repliq commented 8 months ago
results = []

if name:
  results = BaseProductPy.find(BaseProductPy.name % f"{name}*")

if tags:
  results = results.find(BaseProductPy.tag.value == tags)

if city:
  results = results.find(BaseProductPy.address.city == city)

return results

how can i search by condition where if name is there, find by name. if tag is there, find by name and tag. If city is there, find by name, tag and city.

how can i do that?

slorello89 commented 3 months ago

If you're ok with OR semantics then you can just or the predicates together. Otherwise there really isn't a good way in Redis OM Python at the moment of conditionally searching fields (you can do it via aggregations using redis-py.

slorello89 commented 3 months ago

Or you could of course just pull back the OR case and filter it down further in your app