Add more CRUD operations
This commit is contained in:
parent
809a990cd5
commit
2df3b09019
@ -253,7 +253,7 @@ VertexAccessor &CreateLocalVertex(const NodeCreationInfo &node_info, Frame *fram
|
||||
|
||||
// TODO antepusic check if text search is turned on
|
||||
if (flags::run_time::GetTextSearchEnabled()) {
|
||||
// new_node.AddToTextSearch()
|
||||
new_node.impl_.storage_->indices_.text_index_->AddNode(new_node.impl_.vertex_, new_node.impl_.storage_);
|
||||
}
|
||||
|
||||
(*frame)[node_info.symbol] = new_node;
|
||||
@ -2825,8 +2825,9 @@ bool SetProperty::SetPropertyCursor::Pull(Frame &frame, ExecutionContext &contex
|
||||
TypedValue{std::move(old_value)}, TypedValue{rhs});
|
||||
}
|
||||
// TODO antepusic: update text index
|
||||
// new_node.UpdateInTextSearch()
|
||||
if (flags::run_time::GetTextSearchEnabled()) {
|
||||
auto new_node = lhs.ValueVertex();
|
||||
new_node.impl_.storage_->indices_.text_index_->UpdateNode(new_node.impl_.vertex_, new_node.impl_.storage_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -2985,8 +2986,9 @@ void SetPropertiesOnRecord(TRecordAccessor *record, const TypedValue &rhs, SetPr
|
||||
PropertiesMap new_properties = get_props(rhs.ValueVertex());
|
||||
update_props(new_properties);
|
||||
// TODO antepusic: update text index
|
||||
// new_node.UpdateInTextSearch()
|
||||
if (flags::run_time::GetTextSearchEnabled()) {
|
||||
auto new_node = rhs.ValueVertex();
|
||||
new_node.impl_.storage_->indices_.text_index_->UpdateNode(new_node.impl_.vertex_, new_node.impl_.storage_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -3136,7 +3138,7 @@ bool SetLabels::SetLabelsCursor::Pull(Frame &frame, ExecutionContext &context) {
|
||||
|
||||
// TODO antepusic check if text search is turned on
|
||||
if (flags::run_time::GetTextSearchEnabled()) {
|
||||
// new_node.UpdateInTextSearch()
|
||||
vertex.impl_.storage_->indices_.text_index_->UpdateNode(vertex.impl_.vertex_, vertex.impl_.storage_);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -3302,7 +3304,7 @@ bool RemoveLabels::RemoveLabelsCursor::Pull(Frame &frame, ExecutionContext &cont
|
||||
|
||||
// TODO antepusic check if text search is turned on
|
||||
if (flags::run_time::GetTextSearchEnabled()) {
|
||||
// new_node.UpdateInTextSearch()
|
||||
vertex.impl_.storage_->indices_.text_index_->UpdateNode(vertex.impl_.vertex_, vertex.impl_.storage_, self_.labels_);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -53,6 +53,16 @@ void TextIndex::UpdateNode(Vertex *vertex_after_update, Storage *storage) {
|
||||
AddNode(vertex_after_update, storage, applicable_text_indices);
|
||||
}
|
||||
|
||||
void TextIndex::UpdateNode(Vertex *vertex_after_update, Storage *storage, const std::vector<LabelId> &removed_labels) {
|
||||
auto indexes_to_remove_node_from = GetApplicableTextIndices(removed_labels);
|
||||
RemoveNode(vertex_after_update, indexes_to_remove_node_from);
|
||||
|
||||
auto indexes_to_update_node = GetApplicableTextIndices(vertex_after_update);
|
||||
if (indexes_to_update_node.empty()) return;
|
||||
RemoveNode(vertex_after_update, indexes_to_update_node);
|
||||
AddNode(vertex_after_update, storage, indexes_to_update_node);
|
||||
}
|
||||
|
||||
void TextIndex::RemoveNode(Vertex *vertex_after_update,
|
||||
const std::vector<memcxx::text_search::Context *> &applicable_text_indices) {
|
||||
auto search_node_to_be_deleted = memcxx::text_search::SearchInput{
|
||||
@ -88,6 +98,16 @@ void TextIndex::UpdateOnSetProperty(Vertex *vertex_after_update, Storage *storag
|
||||
UpdateNode(vertex_after_update, storage);
|
||||
}
|
||||
|
||||
std::vector<memcxx::text_search::Context *> TextIndex::GetApplicableTextIndices(const std::vector<LabelId> &labels) {
|
||||
std::vector<memcxx::text_search::Context *> applicable_text_indices;
|
||||
for (const auto &label : labels) {
|
||||
if (label_to_index_.contains(label)) {
|
||||
applicable_text_indices.push_back(&index_.at(label_to_index_.at(label)));
|
||||
}
|
||||
}
|
||||
return applicable_text_indices;
|
||||
}
|
||||
|
||||
std::vector<memcxx::text_search::Context *> TextIndex::GetApplicableTextIndices(Vertex *vertex) {
|
||||
std::vector<memcxx::text_search::Context *> applicable_text_indices;
|
||||
for (const auto &label : vertex->labels) {
|
||||
@ -111,6 +131,10 @@ bool TextIndex::CreateIndex(std::string index_name, LabelId label, memgraph::que
|
||||
bool has_schema = false;
|
||||
std::vector<std::pair<PropertyId, std::string>> indexed_properties{};
|
||||
for (const auto &v : db->Vertices(View::OLD)) {
|
||||
if (!v.HasLabel(View::OLD, label).GetValue()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!has_schema) [[unlikely]] {
|
||||
for (const auto &[prop_id, prop_val] : v.Properties(View::OLD).GetValue()) {
|
||||
if (prop_val.IsString()) {
|
||||
|
@ -29,6 +29,8 @@ class TextIndex {
|
||||
void AddNode(Vertex *vertex, Storage *storage,
|
||||
const std::vector<memcxx::text_search::Context *> &applicable_text_indices);
|
||||
|
||||
std::vector<memcxx::text_search::Context *> GetApplicableTextIndices(const std::vector<LabelId> &labels);
|
||||
|
||||
void RemoveNode(Vertex *vertex, const std::vector<memcxx::text_search::Context *> &applicable_text_indices);
|
||||
|
||||
public:
|
||||
@ -48,6 +50,8 @@ class TextIndex {
|
||||
|
||||
void UpdateNode(Vertex *vertex, Storage *storage);
|
||||
|
||||
void UpdateNode(Vertex *vertex, Storage *storage, const std::vector<LabelId> &removed_labels);
|
||||
|
||||
void RemoveNode(Vertex *vertex);
|
||||
|
||||
void UpdateOnAddLabel(LabelId added_label, Vertex *vertex_after_update, Storage *storage, const Transaction &tx);
|
||||
|
@ -147,13 +147,13 @@ Result<std::optional<VertexAccessor>> Storage::Accessor::DeleteVertex(VertexAcce
|
||||
return res.GetError();
|
||||
}
|
||||
|
||||
// TODO antepusic remove from text index
|
||||
|
||||
const auto &value = res.GetValue();
|
||||
if (!value) {
|
||||
return std::optional<VertexAccessor>{};
|
||||
}
|
||||
|
||||
// TODO antepusic remove from text index
|
||||
|
||||
const auto &[vertices, edges] = *value;
|
||||
|
||||
MG_ASSERT(vertices.size() <= 1, "The number of deleted vertices is not less or equal to 1!");
|
||||
|
Loading…
Reference in New Issue
Block a user