dragonflydb / dragonfly

A modern replacement for Redis and Memcached
https://www.dragonflydb.io/
Other
25.96k stars 954 forks source link

fix(search_family): Process wrong field types in indexes for the FT.SEARCH and FT.AGGREGATE commands #4070

Closed BagritsevichStepan closed 1 week ago

BagritsevichStepan commented 2 weeks ago

fixes dragonflydb#3986

BagritsevichStepan commented 2 weeks ago

@romange I've added more tests. After adding support for nullable values, a more tests will be added. Please take a look at the PR.

BagritsevichStepan commented 1 week ago

I found several new bugs and fixed them in the latest commit:

  1. Bug:

    JSON.SET j1 . '{"data":1}'
    JSON.SET j2 . '{"data":"1"}'
    FT.CREATE i1 ON JSON SCHEMA $.data AS data NUMERIC
    FT.CREATE i2 ON JSON SCHEMA $.data AS data TEXT

    FT.SEARCH i1 "*" and FT.SEARCH i2 "*" both return j1 and j2. However, it should return j1 for i1 and j2 for i2. This happens because we are parsing string and numeric fields in the same way in the DocumentAccessor.

  2. Bug related to how we parse FtVector in the GetVector function in DocumentAccessor.

  3. Bug was crash during JsonAccessor::GetVectorwhen the field type is not an array

I’ve also added more tests

BagritsevichStepan commented 1 week ago

Found and fixed another bug:

We should support queries like this:

JSON.SET j1 . '{"data":["first value", "second_value"]}'
FT.CREATE index ON JSON SCHEMA $.data AS data TEXT

FT.SEARCH index "*" should return j1