Remove redundant methods & add is-enabled checks
This commit is contained in:
parent
7574d3e2a8
commit
86bc945666
@ -576,9 +576,7 @@ class DbAccessor final {
|
||||
|
||||
void TextIndexAddVertex(const VertexAccessor &vertex) { accessor_->TextIndexAddVertex(vertex.impl_); }
|
||||
|
||||
void TextIndexUpdateVertex(const VertexAccessor &vertex) { accessor_->TextIndexUpdateVertex(vertex.impl_); }
|
||||
|
||||
void TextIndexUpdateVertex(const VertexAccessor &vertex, const std::vector<storage::LabelId> &removed_labels) {
|
||||
void TextIndexUpdateVertex(const VertexAccessor &vertex, const std::vector<storage::LabelId> &removed_labels = {}) {
|
||||
accessor_->TextIndexUpdateVertex(vertex.impl_, removed_labels);
|
||||
}
|
||||
|
||||
|
@ -94,6 +94,10 @@ std::vector<mgcxx::text_search::Context *> TextIndex::GetApplicableTextIndices(c
|
||||
|
||||
void TextIndex::LoadNodeToTextIndices(const std::int64_t gid, const nlohmann::json &properties,
|
||||
const std::vector<mgcxx::text_search::Context *> &applicable_text_indices) {
|
||||
if (applicable_text_indices.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: Text indexes are presently all-property indices. If we allow text indexes restricted to specific properties,
|
||||
// an indexable document should be created for each applicable index.
|
||||
nlohmann::json document = {};
|
||||
@ -128,24 +132,14 @@ void TextIndex::CommitLoadedNodes(mgcxx::text_search::Context &index_context) {
|
||||
}
|
||||
|
||||
void TextIndex::AddNode(Vertex *vertex_after_update, NameIdMapper *name_id_mapper,
|
||||
const std::vector<mgcxx::text_search::Context *> &applicable_text_indices) {
|
||||
std::optional<std::vector<mgcxx::text_search::Context *>> applicable_text_indices) {
|
||||
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
|
||||
throw query::TextSearchDisabledException();
|
||||
}
|
||||
|
||||
auto vertex_properties = vertex_after_update->properties.Properties();
|
||||
LoadNodeToTextIndices(vertex_after_update->gid.AsInt(), SerializeProperties(vertex_properties, name_id_mapper),
|
||||
applicable_text_indices);
|
||||
}
|
||||
|
||||
void TextIndex::AddNode(Vertex *vertex_after_update, NameIdMapper *name_id_mapper) {
|
||||
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
|
||||
throw query::TextSearchDisabledException();
|
||||
}
|
||||
|
||||
auto applicable_text_indices = GetApplicableTextIndices(vertex_after_update->labels);
|
||||
if (applicable_text_indices.empty()) return;
|
||||
AddNode(vertex_after_update, name_id_mapper, applicable_text_indices);
|
||||
applicable_text_indices.value_or(GetApplicableTextIndices(vertex_after_update->labels)));
|
||||
}
|
||||
|
||||
void TextIndex::UpdateNode(Vertex *vertex_after_update, NameIdMapper *name_id_mapper,
|
||||
@ -166,7 +160,7 @@ void TextIndex::UpdateNode(Vertex *vertex_after_update, NameIdMapper *name_id_ma
|
||||
}
|
||||
|
||||
void TextIndex::RemoveNode(Vertex *vertex_after_update,
|
||||
const std::vector<mgcxx::text_search::Context *> &applicable_text_indices) {
|
||||
std::optional<std::vector<mgcxx::text_search::Context *>> applicable_text_indices) {
|
||||
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
|
||||
throw query::TextSearchDisabledException();
|
||||
}
|
||||
@ -174,7 +168,7 @@ void TextIndex::RemoveNode(Vertex *vertex_after_update,
|
||||
auto search_node_to_be_deleted =
|
||||
mgcxx::text_search::SearchInput{.search_query = fmt::format("metadata.gid:{}", vertex_after_update->gid.AsInt())};
|
||||
|
||||
for (auto *index_context : applicable_text_indices) {
|
||||
for (auto *index_context : applicable_text_indices.value_or(GetApplicableTextIndices(vertex_after_update->labels))) {
|
||||
try {
|
||||
mgcxx::text_search::delete_document(*index_context, search_node_to_be_deleted, kDoSkipCommit);
|
||||
} catch (const std::exception &e) {
|
||||
@ -183,17 +177,11 @@ void TextIndex::RemoveNode(Vertex *vertex_after_update,
|
||||
}
|
||||
}
|
||||
|
||||
void TextIndex::RemoveNode(Vertex *vertex_after_update) {
|
||||
void TextIndex::CreateIndex(const std::string &index_name, LabelId label, memgraph::query::DbAccessor *db) {
|
||||
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
|
||||
throw query::TextSearchDisabledException();
|
||||
}
|
||||
|
||||
auto applicable_text_indices = GetApplicableTextIndices(vertex_after_update->labels);
|
||||
if (applicable_text_indices.empty()) return;
|
||||
RemoveNode(vertex_after_update, applicable_text_indices);
|
||||
}
|
||||
|
||||
void TextIndex::CreateIndex(const std::string &index_name, LabelId label, memgraph::query::DbAccessor *db) {
|
||||
CreateEmptyIndex(index_name, label);
|
||||
|
||||
for (const auto &v : db->Vertices(View::NEW)) {
|
||||
@ -211,6 +199,10 @@ void TextIndex::CreateIndex(const std::string &index_name, LabelId label, memgra
|
||||
|
||||
void TextIndex::RecoverIndex(const std::string &index_name, LabelId label,
|
||||
memgraph::utils::SkipList<Vertex>::Accessor vertices, NameIdMapper *name_id_mapper) {
|
||||
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
|
||||
throw query::TextSearchDisabledException();
|
||||
}
|
||||
|
||||
CreateEmptyIndex(index_name, label);
|
||||
|
||||
for (const auto &v : vertices) {
|
||||
@ -218,7 +210,6 @@ void TextIndex::RecoverIndex(const std::string &index_name, LabelId label,
|
||||
continue;
|
||||
}
|
||||
|
||||
nlohmann::json document = {};
|
||||
auto vertex_properties = v.properties.Properties();
|
||||
LoadNodeToTextIndices(v.gid.AsInt(), SerializeProperties(vertex_properties, name_id_mapper),
|
||||
{&index_.at(index_name).context_});
|
||||
@ -286,12 +277,20 @@ std::vector<Gid> TextIndex::Search(const std::string &index_name, const std::str
|
||||
}
|
||||
|
||||
void TextIndex::Commit() {
|
||||
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
|
||||
throw query::TextSearchDisabledException();
|
||||
}
|
||||
|
||||
for (auto &[_, index_data] : index_) {
|
||||
mgcxx::text_search::commit(index_data.context_);
|
||||
}
|
||||
}
|
||||
|
||||
void TextIndex::Rollback() {
|
||||
if (!flags::AreExperimentsEnabled(flags::Experiments::TEXT_SEARCH)) {
|
||||
throw query::TextSearchDisabledException();
|
||||
}
|
||||
|
||||
for (auto &[_, index_data] : index_) {
|
||||
mgcxx::text_search::rollback(index_data.context_);
|
||||
}
|
||||
|
@ -43,11 +43,6 @@ class TextIndex {
|
||||
|
||||
void CommitLoadedNodes(mgcxx::text_search::Context &index_context);
|
||||
|
||||
void AddNode(Vertex *vertex, NameIdMapper *name_id_mapper,
|
||||
const std::vector<mgcxx::text_search::Context *> &applicable_text_indices);
|
||||
|
||||
void RemoveNode(Vertex *vertex, const std::vector<mgcxx::text_search::Context *> &applicable_text_indices);
|
||||
|
||||
public:
|
||||
TextIndex() = default;
|
||||
|
||||
@ -61,11 +56,13 @@ class TextIndex {
|
||||
std::map<std::string, TextIndexData> index_;
|
||||
std::map<LabelId, std::string> label_to_index_;
|
||||
|
||||
void AddNode(Vertex *vertex, NameIdMapper *name_id_mapper);
|
||||
void AddNode(Vertex *vertex, NameIdMapper *name_id_mapper,
|
||||
std::optional<std::vector<mgcxx::text_search::Context *>> applicable_text_indices = std::nullopt);
|
||||
|
||||
void UpdateNode(Vertex *vertex, NameIdMapper *name_id_mapper, const std::vector<LabelId> &removed_labels = {});
|
||||
|
||||
void RemoveNode(Vertex *vertex);
|
||||
void RemoveNode(Vertex *vertex,
|
||||
std::optional<std::vector<mgcxx::text_search::Context *>> applicable_text_indices = std::nullopt);
|
||||
|
||||
void CreateIndex(const std::string &index_name, LabelId label, memgraph::query::DbAccessor *db);
|
||||
|
||||
|
@ -236,11 +236,7 @@ class Storage {
|
||||
storage_->indices_.text_index_.AddNode(vertex.vertex_, storage_->name_id_mapper_.get());
|
||||
}
|
||||
|
||||
void TextIndexUpdateVertex(const VertexAccessor &vertex) {
|
||||
storage_->indices_.text_index_.UpdateNode(vertex.vertex_, storage_->name_id_mapper_.get());
|
||||
}
|
||||
|
||||
void TextIndexUpdateVertex(const VertexAccessor &vertex, std::vector<LabelId> removed_labels) {
|
||||
void TextIndexUpdateVertex(const VertexAccessor &vertex, const std::vector<LabelId> &removed_labels = {}) {
|
||||
storage_->indices_.text_index_.UpdateNode(vertex.vertex_, storage_->name_id_mapper_.get(), removed_labels);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user