Redisearch: Is there a way to escape reserved characters in a quoted query?

Created on 2 Sep 2017  路  6Comments  路  Source: RediSearch/RediSearch

For instance, if I have this index:

FT.CREATE BookIndex SCHEMA name TEXT
FT.ADD BookIndex bcda 1 FIELDS name "Hamlet: Act 1"

I get a syntax error when my search query includes a ":"...

(error) Syntax error at offset 0 near ''

For example, these all return a syntax error complaining about the ":"...

FT.SEARCH BookIndex :
FT.SEARCH BookIndex ":"
FT.SEARCH BookIndex '":"'
FT.SEARCH BookIndex '"\:"'
question

Most helpful comment

No, I actually don't want to relax or complicate the parser too much to allow for non structured queries. Just sanitize the input I guess if you want.

All 6 comments

Currently there is no way and there is no point since they are removed in tokenization.

If I search for "Hamlet: Act 1" I get a syntax error though. Is that a bug?

127.0.0.1:6379> FT.SEARCH BookIndex "Hamlet: Act 1"
(error) Syntax error at offset 6 near 'Hamlet'

No, I actually don't want to relax or complicate the parser too much to allow for non structured queries. Just sanitize the input I guess if you want.

I was thinking actually about supporting two parsers or two search commands - simple search and structured search (with all the filters and advanced syntax). What do you think?

From a client package perspective, having two search commands would allow me to expose two search methods in my package's query builder class. But that would trickle down to the package user where they have to decide which to use. They also probably don't want to worry about the low level advanced query syntax. I think the better option is to add methods to my query builder class that enable advanced queries (e.g. where(), notWhere()). In this scenario, having a simple search command in RediSearch wouldn't help much because it is fairly trivial to strip all the advanced query separators out of the query in my package's existing search method. That's my take.

This has been added a couple of versions ago and I forgot to close this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yansuihehe picture yansuihehe  路  5Comments

zhangkyou picture zhangkyou  路  4Comments

ethan-tr picture ethan-tr  路  8Comments

mnunberg picture mnunberg  路  5Comments

tw-bert picture tw-bert  路  7Comments