This is an automated email from the ASF dual-hosted git repository.

twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 34083189 feat(search): allow to omit `ON HASH|JSON` in FT.CREATE 
(#2484)
34083189 is described below

commit 3408318934cb68c0c1f2ffa937f19f02346d0672
Author: Twice <[email protected]>
AuthorDate: Sat Aug 10 17:53:44 2024 +0800

    feat(search): allow to omit `ON HASH|JSON` in FT.CREATE (#2484)
---
 src/commands/cmd_search.cc              | 12 +++---------
 tests/gocase/unit/search/search_test.go |  3 +++
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/commands/cmd_search.cc b/src/commands/cmd_search.cc
index 615c81a6..1710e673 100644
--- a/src/commands/cmd_search.cc
+++ b/src/commands/cmd_search.cc
@@ -49,14 +49,14 @@ class CommandFTCreate : public Commander {
     }
 
     index_info_ = std::make_unique<kqir::IndexInfo>(index_name, 
redis::IndexMetadata{}, "");
-    auto data_type = IndexOnDataType(0);
+    index_info_->metadata.on_data_type = IndexOnDataType::HASH;
 
     while (parser.Good()) {
       if (parser.EatEqICase("ON")) {
         if (parser.EatEqICase("HASH")) {
-          data_type = IndexOnDataType::HASH;
+          index_info_->metadata.on_data_type = IndexOnDataType::HASH;
         } else if (parser.EatEqICase("JSON")) {
-          data_type = IndexOnDataType::JSON;
+          index_info_->metadata.on_data_type = IndexOnDataType::JSON;
         } else {
           return {Status::RedisParseErr, "expect HASH or JSON after ON"};
         }
@@ -71,12 +71,6 @@ class CommandFTCreate : public Commander {
       }
     }
 
-    if (int(data_type) == 0) {
-      return {Status::RedisParseErr, "expect ON HASH | JSON"};
-    } else {
-      index_info_->metadata.on_data_type = data_type;
-    }
-
     if (parser.EatEqICase("SCHEMA")) {
       while (parser.Good()) {
         auto field_name = GET_OR_RET(parser.TakeStr());
diff --git a/tests/gocase/unit/search/search_test.go 
b/tests/gocase/unit/search/search_test.go
index ef9a554c..01445994 100644
--- a/tests/gocase/unit/search/search_test.go
+++ b/tests/gocase/unit/search/search_test.go
@@ -74,6 +74,9 @@ func TestSearch(t *testing.T) {
 
                srv.Restart()
                verify(t)
+
+               require.NoError(t, rdb.Do(ctx, "FT.CREATE", "testidx2", 
"SCHEMA", "x", "NUMERIC").Err())
+               require.NoError(t, rdb.Do(ctx, "FT.DROPINDEX", 
"testidx2").Err())
        })
 
        t.Run("FT.SEARCH", func(t *testing.T) {

Reply via email to