diff --git a/query_modules/text_search_module.cpp b/query_modules/text_search_module.cpp index 8a79b33b7..71dd6510e 100644 --- a/query_modules/text_search_module.cpp +++ b/query_modules/text_search_module.cpp @@ -31,8 +31,8 @@ void TextSearch::Search(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *r auto arguments = mgp::List(args); try { - auto index_name = arguments[0].ValueString().data(); - auto search_query = arguments[1].ValueString().data(); + const auto *index_name = arguments[0].ValueString().data(); + const auto *search_query = arguments[1].ValueString().data(); // 1. See if the given index_name is text-indexed if (!mgp::graph_has_text_index(memgraph_graph, index_name)) { diff --git a/src/query/db_accessor.hpp b/src/query/db_accessor.hpp index 9c0293721..7a4e20922 100644 --- a/src/query/db_accessor.hpp +++ b/src/query/db_accessor.hpp @@ -570,7 +570,7 @@ class DbAccessor final { return accessor_->LabelPropertyIndexExists(label, prop); } - bool TextIndexExists(std::string index_name) const { return accessor_->TextIndexExists(index_name); } + bool TextIndexExists(const std::string &index_name) const { return accessor_->TextIndexExists(index_name); } void TextIndexAddVertex(VertexAccessor *vertex) { accessor_->TextIndexAddVertex(&vertex->impl_); } @@ -580,7 +580,7 @@ class DbAccessor final { accessor_->TextIndexUpdateVertex(&vertex->impl_, removed_labels); } - std::vector TextIndexSearch(std::string index_name, std::string search_query) const { + std::vector TextIndexSearch(const std::string &index_name, const std::string &search_query) const { return accessor_->TextIndexSearch(index_name, search_query); } @@ -659,12 +659,12 @@ class DbAccessor final { return accessor_->DropIndex(label, property); } - utils::BasicResult CreateTextIndex(std::string index_name, + utils::BasicResult CreateTextIndex(const std::string &index_name, storage::LabelId label) { return accessor_->CreateTextIndex(index_name, label, this); } - utils::BasicResult DropTextIndex(std::string index_name) { + utils::BasicResult DropTextIndex(const std::string &index_name) { return accessor_->DropTextIndex(index_name); } diff --git a/src/query/dump.cpp b/src/query/dump.cpp index f274703b0..75164755f 100644 --- a/src/query/dump.cpp +++ b/src/query/dump.cpp @@ -248,7 +248,7 @@ void DumpLabelPropertyIndex(std::ostream *os, query::DbAccessor *dba, storage::L << ");"; } -void DumpTextIndex(std::ostream *os, query::DbAccessor *dba, std::string index_name, storage::LabelId label) { +void DumpTextIndex(std::ostream *os, query::DbAccessor *dba, const std::string &index_name, storage::LabelId label) { *os << "CREATE TEXT INDEX " << EscapeName(index_name) << " ON :" << EscapeName(dba->LabelToName(label)) << ";"; } diff --git a/src/query/procedure/mg_procedure_impl.cpp b/src/query/procedure/mg_procedure_impl.cpp index 1d25c51f6..d4df39ba7 100644 --- a/src/query/procedure/mg_procedure_impl.cpp +++ b/src/query/procedure/mg_procedure_impl.cpp @@ -2601,7 +2601,7 @@ mgp_error mgp_edge_iter_properties(mgp_edge *e, mgp_memory *memory, mgp_properti mgp_error mgp_graph_get_vertex_by_id(mgp_graph *graph, mgp_vertex_id id, mgp_memory *memory, mgp_vertex **result) { return WrapExceptions( [graph, id, memory]() -> mgp_vertex * { - std::optional maybe_vertex = std::visit( + auto maybe_vertex = std::visit( [graph, id](auto *impl) { return impl->FindVertex(memgraph::storage::Gid::FromInt(id.as_int), graph->view); }, diff --git a/src/storage/v2/disk/durable_metadata.cpp b/src/storage/v2/disk/durable_metadata.cpp index bce8344c5..eb9743269 100644 --- a/src/storage/v2/disk/durable_metadata.cpp +++ b/src/storage/v2/disk/durable_metadata.cpp @@ -26,7 +26,7 @@ constexpr const char *kVertexCountDescr = "vertex_count"; constexpr const char *kEdgeDountDescr = "edge_count"; constexpr const char *kLabelIndexStr = "label_index"; constexpr const char *kLabelPropertyIndexStr = "label_property_index"; -constexpr const char *kTextIndexStr = "label_property_index"; +constexpr const char *kTextIndexStr = "text_index"; constexpr const char *kExistenceConstraintsStr = "existence_constraints"; constexpr const char *kUniqueConstraintsStr = "unique_constraints"; } // namespace @@ -145,7 +145,7 @@ bool DurableMetadata::PersistLabelPropertyIndexAndExistenceConstraintDeletion(La return true; } -bool DurableMetadata::PersistTextIndexCreation(std::string index_name) { +bool DurableMetadata::PersistTextIndexCreation(const std::string &index_name) { if (auto text_index_store = durability_kvstore_.Get(kTextIndexStr); text_index_store.has_value()) { std::string &value = text_index_store.value(); value += "|"; @@ -155,7 +155,7 @@ bool DurableMetadata::PersistTextIndexCreation(std::string index_name) { return durability_kvstore_.Put(kTextIndexStr, index_name); } -bool DurableMetadata::PersistTextIndexDeletion(std::string index_name) { +bool DurableMetadata::PersistTextIndexDeletion(const std::string &index_name) { if (auto text_index_store = durability_kvstore_.Get(kTextIndexStr); text_index_store.has_value()) { const std::string &value = text_index_store.value(); std::vector text_indices = utils::Split(value, "|"); diff --git a/src/storage/v2/disk/durable_metadata.hpp b/src/storage/v2/disk/durable_metadata.hpp index 6f2350c3c..175aa944c 100644 --- a/src/storage/v2/disk/durable_metadata.hpp +++ b/src/storage/v2/disk/durable_metadata.hpp @@ -53,9 +53,9 @@ class DurableMetadata { bool PersistLabelPropertyIndexAndExistenceConstraintDeletion(LabelId label, PropertyId property, const std::string &key); - bool PersistTextIndexCreation(std::string index_name); + bool PersistTextIndexCreation(const std::string &index_name); - bool PersistTextIndexDeletion(std::string index_name); + bool PersistTextIndexDeletion(const std::string &index_name); bool PersistUniqueConstraintCreation(LabelId label, const std::set &properties); diff --git a/src/storage/v2/indices/text_index.cpp b/src/storage/v2/indices/text_index.cpp index 2cad78b49..17abdbb2e 100644 --- a/src/storage/v2/indices/text_index.cpp +++ b/src/storage/v2/indices/text_index.cpp @@ -199,7 +199,7 @@ std::vector TextIndex::GetApplicableTextIndices(V return applicable_text_indices; } -bool TextIndex::CreateIndex(std::string index_name, LabelId label, memgraph::query::DbAccessor *db) { +bool TextIndex::CreateIndex(const std::string &index_name, LabelId label, memgraph::query::DbAccessor *db) { if (!flags::run_time::GetExperimentalTextSearchEnabled()) { throw query::QueryException("To use text indices, enable the text search feature."); } @@ -292,7 +292,7 @@ bool TextIndex::CreateIndex(std::string index_name, LabelId label, memgraph::que return true; } -bool TextIndex::RecoverIndex(std::string index_name, LabelId label, +bool TextIndex::RecoverIndex(const std::string &index_name, LabelId label, memgraph::utils::SkipList::Accessor vertices, NameIdMapper *name_id_mapper) { if (!flags::run_time::GetExperimentalTextSearchEnabled()) { throw query::QueryException("To use text indices, enable the text search feature."); @@ -391,7 +391,7 @@ bool TextIndex::RecoverIndex(std::string index_name, LabelId label, return true; } -bool TextIndex::DropIndex(std::string index_name) { +bool TextIndex::DropIndex(const std::string &index_name) { if (!flags::run_time::GetExperimentalTextSearchEnabled()) { throw query::QueryException("To use text indices, enable the text search feature."); } @@ -406,9 +406,9 @@ bool TextIndex::DropIndex(std::string index_name) { return true; } -bool TextIndex::IndexExists(std::string index_name) const { return index_.contains(index_name); } +bool TextIndex::IndexExists(const std::string &index_name) const { return index_.contains(index_name); } -std::vector TextIndex::Search(std::string index_name, std::string search_query) { +std::vector TextIndex::Search(const std::string &index_name, const std::string &search_query) { if (!flags::run_time::GetExperimentalTextSearchEnabled()) { throw query::QueryException("To use text indices, enable the text search feature."); } @@ -465,6 +465,6 @@ std::vector> TextIndex::ListIndices() const { return ret; } -std::uint64_t TextIndex::ApproximateVertexCount(std::string index_name) const { return 10; } +std::uint64_t TextIndex::ApproximateVertexCount(const std::string &index_name) const { return 10; } } // namespace memgraph::storage diff --git a/src/storage/v2/indices/text_index.hpp b/src/storage/v2/indices/text_index.hpp index 70a4ebc87..ce1c194fe 100644 --- a/src/storage/v2/indices/text_index.hpp +++ b/src/storage/v2/indices/text_index.hpp @@ -74,16 +74,16 @@ class TextIndex { void UpdateOnSetProperty(Vertex *vertex_after_update, Storage *storage, const std::uint64_t transaction_start_timestamp); - bool CreateIndex(std::string index_name, LabelId label, memgraph::query::DbAccessor *db); + bool CreateIndex(const std::string &index_name, LabelId label, memgraph::query::DbAccessor *db); - bool RecoverIndex(std::string index_name, LabelId label, memgraph::utils::SkipList::Accessor vertices, + bool RecoverIndex(const std::string &index_name, LabelId label, memgraph::utils::SkipList::Accessor vertices, NameIdMapper *name_id_mapper); - bool DropIndex(std::string index_name); + bool DropIndex(const std::string &index_name); - bool IndexExists(std::string index_name) const; + bool IndexExists(const std::string &index_name) const; - std::vector Search(std::string index_name, std::string search_query); + std::vector Search(const std::string &index_name, const std::string &search_query); void Commit(); @@ -91,7 +91,7 @@ class TextIndex { std::vector> ListIndices() const; - std::uint64_t ApproximateVertexCount(std::string index_name) const; + std::uint64_t ApproximateVertexCount(const std::string &index_name) const; }; } // namespace memgraph::storage diff --git a/src/storage/v2/storage.hpp b/src/storage/v2/storage.hpp index 3fcfff2b4..5202a4194 100644 --- a/src/storage/v2/storage.hpp +++ b/src/storage/v2/storage.hpp @@ -227,7 +227,7 @@ class Storage { virtual bool LabelPropertyIndexExists(LabelId label, PropertyId property) const = 0; - bool TextIndexExists(std::string index_name) const { + bool TextIndexExists(const std::string &index_name) const { return storage_->indices_.text_index_->IndexExists(index_name); } @@ -243,7 +243,7 @@ class Storage { storage_->indices_.text_index_->UpdateNode(vertex->vertex_, storage_, storage_->timestamp_, removed_labels); } - std::vector TextIndexSearch(std::string index_name, std::string search_query) const { + std::vector TextIndexSearch(const std::string &index_name, const std::string &search_query) const { return storage_->indices_.text_index_->Search(index_name, search_query); } @@ -291,13 +291,14 @@ class Storage { virtual utils::BasicResult DropIndex(LabelId label, PropertyId property) = 0; - virtual utils::BasicResult CreateTextIndex(std::string index_name, LabelId label, + virtual utils::BasicResult CreateTextIndex(const std::string &index_name, + LabelId label, query::DbAccessor *db) { storage_->indices_.text_index_->CreateIndex(index_name, label, db); return {}; } - virtual utils::BasicResult DropTextIndex(std::string index_name) { + virtual utils::BasicResult DropTextIndex(const std::string &index_name) { storage_->indices_.text_index_->DropIndex(index_name); return {}; }