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

Search: Escape sequences #3145

Open
dranikpg opened this issue Jun 6, 2024 · 2 comments
Open

Search: Escape sequences #3145

dranikpg opened this issue Jun 6, 2024 · 2 comments
Assignees

Comments

@dranikpg
Copy link
Contributor

dranikpg commented Jun 6, 2024

Test escaping and direct qutoes to be on the safe side

@CodeToFreedom
Copy link

@dranikpg
Unfortunately just escaping the sequences works only in dragonflydb but not in redis.
As this syntax difference causes major query problems/crashes in our efforts to migrate to this otherwhise really awesome dragonfly library, I added the solution here as well hoping it gets seen by one of the contributors: #3258 (comment)

The problem:

This works in redis (but fails in dragonflydb):
"FT.SEARCH" ":Language:index" "(@code:{ZH\\-CN})" "LIMIT" "0" "1"

This works in dragonflydb (but fails in redis):
"FT.SEARCH" ":Language:index" "(@code:{'ZH-CN'})" "LIMIT" "0" "1"

Here is the fix:

To fix that and make dragonflydb behave like the redis tokenizer please escape the following regex matches with two backslashes.
DEFAULT_ESCAPED_CHARS = r"[,.<>{}\[\]\\\"\':;!@#$%^&*()\-+=~\/ ]"

The matching regex groups need to be ESCAPED like that:
f"\\{value}"

References:
Here is a completely working token escaper from a redis client library:
Source: https://github.com/redis/redis-om-python/blob/main/aredis_om/model/token_escaper.py

Many thanks for your efforts.

@CodeToFreedom
Copy link

@dranikpg I added more detailed test script and syntax examples: #3258 (comment)

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

3 participants