Redo text index checking

This commit is contained in:
Ante Pušić 2024-01-09 21:35:57 +01:00
parent 3595a9c3b5
commit b067ded578
2 changed files with 15 additions and 14 deletions

View File

@ -28,6 +28,16 @@ class TextIndex {
void UpdateOnRemoveLabel(LabelId removed_label, Vertex *vertex_after_update, const Transaction &tx) {}
std::vector<mgcxx_mock::text_search::IndexContext *> GetApplicableTextIndices(Vertex *vertex, Storage *storage) {
std::vector<mgcxx_mock::text_search::IndexContext *> applicable_text_indices;
for (const auto &label : vertex->labels) {
if (label_to_index_.contains(label)) {
applicable_text_indices.push_back(&index_.at(label_to_index_.at(label)));
}
}
return applicable_text_indices;
}
/// @throw std::bad_alloc
bool CreateIndex(std::string index_name, LabelId label,
const std::optional<durability::ParallelizedSchemaCreationInfo> &parallel_exec_info) {
@ -64,6 +74,7 @@ class TextIndex {
uint64_t ApproximateVertexCount(std::string index_name) { return 10; }
std::map<std::string, mgcxx_mock::text_search::IndexContext> index_;
std::map<LabelId, std::string> label_to_index_;
};
} // namespace memgraph::storage

View File

@ -275,25 +275,15 @@ Result<PropertyValue> VertexAccessor::SetProperty(PropertyId property, const Pro
[transaction = transaction_, storage = storage_, vertex = vertex_, &value, &property, &current_value]() {
CreateAndLinkDelta(transaction, vertex, Delta::SetPropertyTag(), property, current_value);
if (flags::run_time::GetTextSearchEnabled()) {
// if (!storage->indices_.text_index_->IndexExists(storage->NameToLabel(name))) continue;
// TODO antepusic: check which text indices apply
// for (const auto index : GetApplicableTextIndices(vertex)) {
//
// }
for (auto label : vertex->labels) {
auto &context = storage->indices_.text_index_->index_.at("myIndex");
// Calling the text search tool is done here and not inside a PropertyStore method
// make SearchInput
for (const auto *index_context : storage->indices_.text_index_->GetApplicableTextIndices(vertex, storage)) {
auto search_input = mgcxx_mock::text_search::SearchInput{};
auto search_result = mgcxx_mock::text_search::Mock::search(context, search_input);
mgcxx_mock::text_search::Mock::delete_document(context, search_input, true);
auto search_result = mgcxx_mock::text_search::Mock::search(*index_context, search_input);
mgcxx_mock::text_search::Mock::delete_document(*index_context, search_input, true);
// parse result to JSON, set property in JSON and convert to string
auto new_properties = search_result.docs[0].data;
auto new_properties_document = mgcxx_mock::text_search::DocumentInput{.data = new_properties};
mgcxx_mock::text_search::Mock::add(context, new_properties_document, true);
mgcxx_mock::text_search::Mock::add(*index_context, new_properties_document, true);
}
}
vertex->properties.SetProperty(property, value);