Reputation: 31
Good afternoon,
I got a problem with redisearch this afternoon at work. I would like to search a record with a specific value in its keys but this key has a special character in it.
Example: Record_1: name: toto job: product manager town: lolo-baba
in redis-cli when I execute 'ft.search "lolo-baba"' which gives me the query executed by redisearch. -> Its doing lolo OR -baba.
After some research i saw that its due to how redisearch divides words into tokens. The solution to it is to use a '\' or two before a 'special character' to escape it but it is not working in my case.
I already tried: ft.search "lolo-baba" -> does "lolo OR -baba" not what i want
ft.search "lolo-baba" -> this one gives me what i want "lolo-baba instead of lolo OR -baba" but i don't know why it returns me nothing.
ft.search "lolo\-baba" -> does something weird with a multiple times the same word, i don't know weird.
I would like to have a query that does "lolo-baba" as a single string and not 2 tokens.
Upvotes: 3
Views: 4130
Reputation: 524
If you use redis-cli you gone need double escaping, the first escaping is for the cli to tell it to escape the next char and the second escaping is so that the escape char will actually be sent to the redis:
ft.search lolo\\-baba
This will create the exact query you are looking for but notice that it will still not return any results because you also have to escape at index time (otherwise those two words will also be tokenize at index time and will not be indexed as a single term).
Another possibility is to index this field as TAG field. TAGS are only tokenize by SEPERATOR (',' by default). Then your query will look something like this:
ft.search @field_name:{lolo\\-baba}
Upvotes: 6