Refactor types
This commit is contained in:
parent
971dd5c4cc
commit
35532254a9
@ -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)) {
|
||||
|
@ -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<storage::Gid> TextIndexSearch(std::string index_name, std::string search_query) const {
|
||||
std::vector<storage::Gid> 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<storage::StorageIndexDefinitionError, void> CreateTextIndex(std::string index_name,
|
||||
utils::BasicResult<storage::StorageIndexDefinitionError, void> CreateTextIndex(const std::string &index_name,
|
||||
storage::LabelId label) {
|
||||
return accessor_->CreateTextIndex(index_name, label, this);
|
||||
}
|
||||
|
||||
utils::BasicResult<storage::StorageIndexDefinitionError, void> DropTextIndex(std::string index_name) {
|
||||
utils::BasicResult<storage::StorageIndexDefinitionError, void> DropTextIndex(const std::string &index_name) {
|
||||
return accessor_->DropTextIndex(index_name);
|
||||
}
|
||||
|
||||
|
@ -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)) << ";";
|
||||
}
|
||||
|
||||
|
@ -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<memgraph::query::VertexAccessor> 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);
|
||||
},
|
||||
|
@ -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<std::string> text_indices = utils::Split(value, "|");
|
||||
|
@ -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<PropertyId> &properties);
|
||||
|
||||
|
@ -199,7 +199,7 @@ std::vector<mgcxx::text_search::Context *> 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<Vertex>::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<Gid> TextIndex::Search(std::string index_name, std::string search_query) {
|
||||
std::vector<Gid> 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<std::pair<std::string, LabelId>> 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
|
||||
|
@ -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<Vertex>::Accessor vertices,
|
||||
bool RecoverIndex(const std::string &index_name, LabelId label, memgraph::utils::SkipList<Vertex>::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<Gid> Search(std::string index_name, std::string search_query);
|
||||
std::vector<Gid> Search(const std::string &index_name, const std::string &search_query);
|
||||
|
||||
void Commit();
|
||||
|
||||
@ -91,7 +91,7 @@ class TextIndex {
|
||||
|
||||
std::vector<std::pair<std::string, LabelId>> ListIndices() const;
|
||||
|
||||
std::uint64_t ApproximateVertexCount(std::string index_name) const;
|
||||
std::uint64_t ApproximateVertexCount(const std::string &index_name) const;
|
||||
};
|
||||
|
||||
} // namespace memgraph::storage
|
||||
|
@ -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<Gid> TextIndexSearch(std::string index_name, std::string search_query) const {
|
||||
std::vector<Gid> 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<StorageIndexDefinitionError, void> DropIndex(LabelId label, PropertyId property) = 0;
|
||||
|
||||
virtual utils::BasicResult<StorageIndexDefinitionError, void> CreateTextIndex(std::string index_name, LabelId label,
|
||||
virtual utils::BasicResult<StorageIndexDefinitionError, void> CreateTextIndex(const std::string &index_name,
|
||||
LabelId label,
|
||||
query::DbAccessor *db) {
|
||||
storage_->indices_.text_index_->CreateIndex(index_name, label, db);
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual utils::BasicResult<StorageIndexDefinitionError, void> DropTextIndex(std::string index_name) {
|
||||
virtual utils::BasicResult<StorageIndexDefinitionError, void> DropTextIndex(const std::string &index_name) {
|
||||
storage_->indices_.text_index_->DropIndex(index_name);
|
||||
return {};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user