Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(search): allow to omit ON HASH|JSON in FT.CREATE #2484

Merged
merged 4 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading