redis / redis-om-python

Object mapping, and more, for Redis and Python
MIT License
1.11k stars 112 forks source link

[Enhancement] Allow Full Text Search using '%' to query with empty string #521

Closed XChikuX closed 5 months ago

XChikuX commented 1 year ago

The current working of string matching returns an error for search_term=""

Person.find(Person.personal_statement % search_term).all()

"message": "Syntax error at offset 140 near personal_statement_fts",

This behaviour should be enhanced to allow for an empty string as the default search

Why, I suggest this is because in my code I am attempting to use multiple parameters before sending to redis. In which I would like to include the search_term, like so:

users += await RedisUser.find(
    (RedisUser.age >= beg_age) & 
    (RedisUser.age <= end_age) &
    (RedisUser.height >= beg_height) & 
    (RedisUser.height <= end_height) &
    (RedisUser.gender == gender) &
    (RedisUser.bio % search_term)
    ).all()

I have strong defaults for my query to ensure that if no arguments are passed to the function, the query will try to get the defaults. In case no seach_term is provided I want to use an empty string.

slorello89 commented 5 months ago

I'm afraid this just isn't valid syntax for RediSearch so I don't think there's going to much we can do for this issue at this juncture.

XChikuX commented 5 months ago

@slorello89 Please close it as won't fix

closing as completed is a bit misleading.

XChikuX commented 5 months ago

I'm afraid this just isn't valid syntax for RediSearch so I don't think there's going to much we can do for this issue at this juncture.

Can't redis-om abstract this behaviour?

If empty-string; Remove RediSearch query from the stack?

Really helps with keeping the code clean. I'd have to copy paste the code in multiple locations and remove the '%' call at each instance.

Please think about it.