1

I'm starting with Redis (v7) and the lettucemod (v3.1.6), and trying to simulate an index/search sample found in redis docs. But I'm not able to get the right result. Below the sequence of actions taken in redis-cli:

root@redis01:~# redis-server --version
Redis server v=7.0.7 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=2260280010e18db8

root@redis01:~# redis-cli
127.0.0.1:6379> info modules
# Modules
module:name=ReJSON,ver=20008,api=1,filters=0,usedby=[search],using=[],options=[handle-io-errors]
module:name=search,ver=20405,api=1,filters=0,usedby=[],using=[ReJSON],options=[]

127.0.0.1:6379> FT.CREATE itemIdx ON JSON PREFIX 1 36: SCHEMA $.encoding AS encoding TEXT
OK

127.0.0.1:6379> FT._LIST
1) "itemIdx"

127.0.0.1:6379> JSON.SET 36:1 $ '{"encoding":"utf-8"}'
OK

127.0.0.1:6379> JSON.GET 36:1
"{\"encoding\":\"utf-8\"}"

127.0.0.1:6379> FT.SEARCH itemIdx '*'
1) (integer) 1
2) "36:1"
3) 1) "$"
   2) "{\"encoding\":\"utf-8\"}"

127.0.0.1:6379> FT.SEARCH itemIdx '@encoding:utf-8'
1) (integer) 0

127.0.0.1:6379> FT.SEARCH itemIdx '@encoding:(tf)'
1) (integer) 0

Any help would be very appreciated.

Joan.

JBalaguero
  • 181
  • 2
  • 13

1 Answers1

0

Let's start from the second query,

127.0.0.1:6379> FT.SEARCH itemIdx '@encoding:(tf)'
1) (integer) 0

It's missing a * to indicate it's a suffix query see: Infix/Suffix matching

127.0.0.1:6379> FT.SEARCH itemIdx '@encoding:*tf'
1) (integer) 1
2) "36:1"
3) 1) "$"
   2) "{\"encoding\":\"utf-8\"}"

As for the first query,

127.0.0.1:6379> FT.SEARCH itemIdx '@encoding:utf-8'
1) (integer) 0

By default RediSearch escape some of the characters ,.<>{}[]"':;!@#$%^&*()-+=~ to read more about it see: Tokenization

This is why the following works:

127.0.0.1:6379> FT.SEARCH itemIdx '@encoding:utf'
1) (integer) 1
2) "36:1"
3) 1) "$"
   2) "{\"encoding\":\"utf-8\"}"

The simple way to work around this default escaping is to "escape it":

127.0.0.1:6379> JSON.SET 36:1 $ '{"encoding":"utf\\-8"}'
OK
127.0.0.1:6379> FT.SEARCH itemIdx '@encoding:utf\-8'
1) (integer) 1
2) "36:1"
3) 1) "$"
   2) "{\"encoding\":\"utf\\\\-8\"}"

Other ways can include setting the slop between the words, or changing the default escaping.

Guy Korland
  • 9,139
  • 14
  • 59
  • 106