Redisearch 2.0 Queries

Since Redisearch 2.0 works on existing data, what is the proper way to handle queries where data isn’t escaped at insertion?

For example, I have many text values such as item-1, item-2, s-1, s-2 where I want to be able to find that exact phrase, but other times I may just search for what’s before the dash.

When I attempt FT.SEARCH for s-2 or s-2 to find the exact phrase match I get no results.

@u66NH9MJQ1dv you need to define the field on ft.create with the proper type. For example if you want exact match you probably need to define the field as a TAG field (https://oss.redislabs.com/redisearch/Tags/). Also notice that you need to escape the ‘-’ in the query, i.e, on redis-cli the query need to look like: ft.search s\\-1

1 Like

Yeah I thought about TAG but I wanted to maintay ability to do partial matches via the split it’s already doing on the dash.

This could be an issue specific to 2.0, but my query for s\-1 doesn’t return any results.

I am only able to get results if I remove the dash and search for s\1.

Is this expected?

1 Like

Yes this is because ‘-’ is a token that we split in our tokenizer so if you indexed as TEXT you will not be able to find it. We are planing to allow to customize to tokenizer and give your own tokenizations chars, but its only will be available in future versions.

2 Likes

Thanks @meirsh , this makes sense and I’ve switched to use TAG.

The following is giving an error when I try to search two TAGs, even though both work separately. My example appears to match the documentation. Has something changed here for 2.0 or am I missing something more obvious?

127.0.0.1:6379> FT.SEARCH tasks @movefrom:{s\-2} LIMIT 0 0
1) (integer) 128450
127.0.0.1:6379> FT.SEARCH tasks @moveto:{s\-1} LIMIT 0 0
1) (integer) 134750
127.0.0.1:6379> FT.SEARCH tasks @movefrom:{s\-2} @moveto:{s\-1}
(error) Unknown argument `@moveto:{s\-1}` at position 1 for <main>

@u66NH9MJQ1dv on the redis-cli you need to wrap the query with ‘"’ so it will not be spitted to two argument:
127.0.0.1:6379> FT.SEARCH tasks “@movefrom:{s\-2} @moveto:{s\-1}”
1) (integer) 0

2 Likes

@meirsh Thanks again for the quick help and sorry for the newb questions. I’m getting better at this!

127.0.0.1:6379> FT.EXPLAINCLI tasks "@moveto:{saw\\-1} @movefrom:{s\\-2}"
1) INTERSECT {
2)   TAG:@moveto {
3)     saw-1
4)   }
5)   TAG:@movefrom {
6)     s-2
7)   }
8) }
1 Like