redis / redis-om-python

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

find query cannot search for string that contains forward slash "/" #312

Closed mrkprdo closed 2 years ago

mrkprdo commented 2 years ago

I have a string value which is a unix path that has slash, i can set it in db, but cannot query it. I have set Field(index=True, full_text_search=True).

Afaik, in sql, we can use the keyword LIKE or % escape to query it, how to do it with redis om in FindQuery?

ninoseki commented 2 years ago

Hello, I also have the same problem with redis-om v0.0.27.

Here is a code to reproduce the issue.

from aredis_om import JsonModel, Migrator, Field
import asyncio

class Test(JsonModel):
    name: str = Field(index=True)

async def main():
    await Migrator().run()

    foo = Test(name="/tmp/foo/bar")
    await foo.save()

    results = await Test.find(Test.name == "/tmp/foo/bar").all()
    # this will raise AssertionError
    assert len(results) > 0

asyncio.run(main())

I checked args in execute.

['ft.search', ':__main__.Test:index', '@name:{/tmp/foo/bar}', 'LIMIT', 0, 10]

I guess TokenEscaper should also escape /.

localhost:6379> ft.search :__main__.Test:index @name:{/tmp/foo/bar}
1) (integer) 0

localhost:6379> ft.search :__main__.Test:index @name:{\/tmp\/foo\/bar}
1) (integer) 1
mrkprdo commented 2 years ago

Thanks @ninoseki @dvora-h