-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(search): persist FT.SYNUPDATE synonyms across server restarts #5988
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
Changes from 1 commit
9ac6e84
2be6db2
46444b2
e555bc4
78df2b8
7122b5b
44eb146
7e12bb5
bf6d0f7
0caee49
e221a14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2825,11 +2825,28 @@ void RdbLoader::LoadSearchIndexDefFromAux(string&& def) { | |
| return; | ||
| } | ||
|
|
||
| // Prepend FT.CREATE to index definiton | ||
| // Determine command type and prepend appropriate prefix | ||
| CmdArgVec arg_vec; | ||
| facade::RespExpr::VecToArgList(resp_vec, &arg_vec); | ||
| string ft_create = "FT.CREATE"; | ||
| arg_vec.insert(arg_vec.begin(), MutableSlice{ft_create.data(), ft_create.size()}); | ||
|
|
||
| // Check if this is a SYNUPDATE command or a CREATE command | ||
| string command_name; | ||
| if (!arg_vec.empty()) { | ||
| string_view first_token = facade::ToSV(arg_vec[0]); | ||
| if (first_token == "SYNUPDATE") { | ||
|
||
| // Replace first token with FT.SYNUPDATE | ||
| command_name = "FT.SYNUPDATE"; | ||
| arg_vec[0] = MutableSlice{command_name.data(), command_name.size()}; | ||
| } else { | ||
| // Prepend FT.CREATE for index definition | ||
| command_name = "FT.CREATE"; | ||
| arg_vec.insert(arg_vec.begin(), MutableSlice{command_name.data(), command_name.size()}); | ||
| } | ||
| } else { | ||
| // Default: prepend FT.CREATE | ||
| command_name = "FT.CREATE"; | ||
| arg_vec.insert(arg_vec.begin(), MutableSlice{command_name.data(), command_name.size()}); | ||
| } | ||
|
|
||
| service_->DispatchCommand(absl::MakeSpan(arg_vec), &crb, &cntx); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1367,9 +1367,27 @@ RdbSaver::GlobalData RdbSaver::GetGlobalData(const Service* service) { | |
| if (shard->shard_id() == 0) { | ||
| auto* indices = shard->search_indices(); | ||
| for (const auto& index_name : indices->GetIndexNames()) { | ||
| auto index_info = indices->GetIndex(index_name)->GetInfo(); | ||
| auto* index = indices->GetIndex(index_name); | ||
| auto index_info = index->GetInfo(); | ||
|
|
||
| // Save index definition | ||
| search_indices.emplace_back( | ||
| absl::StrCat(index_name, " ", index_info.BuildRestoreCommand())); | ||
|
|
||
| // Save synonym groups for this index | ||
| const auto& synonym_groups = index->GetSynonyms().GetGroups(); | ||
| for (const auto& [group_id, terms] : synonym_groups) { | ||
| if (!terms.empty()) { | ||
| // Convert set<string> to vector for joining | ||
| std::vector<std::string_view> terms_vec(terms.begin(), terms.end()); | ||
|
||
|
|
||
| // Format: "SYNUPDATE index_name group_id term1 term2 term3" | ||
| std::string syn_cmd = absl::StrCat("SYNUPDATE ", index_name, " ", group_id, " ", | ||
| absl::StrJoin(terms_vec, " ")); | ||
|
||
|
|
||
| search_indices.emplace_back(std::move(syn_cmd)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the aux format for these definitions?
will it stay compatible with previous snapshots?
will it be extendable with more commands?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Aux format: Two separate fields -
"search-index"for FT.CREATE,"search-synonyms"for FT.SYNUPDATEBackward compatible: Yes. Tested with the main branch.
Extensible: Yes. Can add
search-aliases,search-config, etc., as separate aux fields using the same pattern.