Skip to content

Commit

Permalink
feat(search): allow to omit ON HASH|JSON in FT.CREATE (#2484)
Browse files Browse the repository at this point in the history
  • Loading branch information
PragmaTwice authored Aug 10, 2024
1 parent a63d48e commit 3408318
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/commands/cmd_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
}
Expand All @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions tests/gocase/unit/search/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3408318

Please sign in to comment.