Implement review suggestions (on smarter naming, types and calls)

This commit is contained in:
Ante Pušić 2024-02-09 20:55:25 +01:00
parent 3e20423050
commit fc0a71f3d5
18 changed files with 81 additions and 80 deletions

View File

@ -4340,7 +4340,7 @@ inline List ListAllLabelPropertyIndices(mgp_graph *memgraph_graph) {
return List(label_property_indices);
}
inline List SearchTextIndex(mgp_graph *memgraph_graph, std::string_view index_name, std::string_view search_query) {
inline List RunTextSearchQuery(mgp_graph *memgraph_graph, std::string_view index_name, std::string_view search_query) {
auto results_or_error =
Map(mgp::MemHandlerCallback(graph_search_text_index, memgraph_graph, index_name.data(), search_query.data()));
auto maybe_error = results_or_error["error_msg"].ValueString();

View File

@ -41,7 +41,7 @@ void TextSearch::Search(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *r
}
// 2. Run a text search of that index and return the search results
for (const auto &node : mgp::SearchTextIndex(memgraph_graph, index_name, search_query)) {
for (const auto &node : mgp::RunTextSearchQuery(memgraph_graph, index_name, search_query)) {
auto record = record_factory.NewRecord();
record.Insert(TextSearch::kReturnNode.data(), node.ValueNode());
}

View File

@ -576,7 +576,7 @@ class DbAccessor final {
void TextIndexUpdateVertex(VertexAccessor *vertex) { accessor_->TextIndexUpdateVertex(&vertex->impl_); }
void TextIndexUpdateVertex(VertexAccessor *vertex, std::vector<storage::LabelId> removed_labels) {
void TextIndexUpdateVertex(VertexAccessor *vertex, const std::vector<storage::LabelId> &removed_labels) {
accessor_->TextIndexUpdateVertex(&vertex->impl_, removed_labels);
}

View File

@ -392,7 +392,7 @@ PullPlanDump::PullChunk PullPlanDump::CreateTextIndicesPullChunk() {
if (!indices_info_) {
indices_info_.emplace(dba_->ListAllIndices());
}
const auto &text = indices_info_->text;
const auto &text = indices_info_->text_indices;
size_t local_counter = 0;
while (global_index < text.size() && (!n || local_counter < *n)) {

View File

@ -3431,7 +3431,7 @@ PreparedQuery PrepareDatabaseInfoQuery(ParsedQuery parsed_query, bool in_explici
auto info = dba->ListAllIndices();
auto storage_acc = database->Access();
std::vector<std::vector<TypedValue>> results;
results.reserve(info.label.size() + info.label_property.size() + info.text.size());
results.reserve(info.label.size() + info.label_property.size() + info.text_indices.size());
for (const auto &item : info.label) {
results.push_back({TypedValue(label_index_mark), TypedValue(storage->LabelToName(item)), TypedValue(),
TypedValue(static_cast<int>(storage_acc->ApproximateVertexCount(item)))});
@ -3442,7 +3442,7 @@ PreparedQuery PrepareDatabaseInfoQuery(ParsedQuery parsed_query, bool in_explici
TypedValue(storage->PropertyToName(item.second)),
TypedValue(static_cast<int>(storage_acc->ApproximateVertexCount(item.first, item.second)))});
}
for (const auto &item : info.text) {
for (const auto &item : info.text_indices) {
results.push_back({TypedValue(text_index_mark), TypedValue(item.first), TypedValue(), TypedValue()});
}
std::sort(results.begin(), results.end(), [&label_index_mark](const auto &record_1, const auto &record_2) {

View File

@ -847,7 +847,7 @@ StorageInfo DiskStorage::GetInfo(bool force_dir,
const auto &lbl = access->ListAllIndices();
info.label_indices = lbl.label.size();
info.label_property_indices = lbl.label_property.size();
info.text_indices = lbl.text.size();
info.text_indices = lbl.text_indices.size();
const auto &con = access->ListAllConstraints();
info.existence_constraints = con.existence.size();
info.unique_constraints = con.unique.size();
@ -1657,12 +1657,12 @@ utils::BasicResult<StorageManipulationError, void> DiskStorage::DiskAccessor::Co
throw utils::NotYetImplemented("ClearIndexStats(stats) is not implemented for DiskStorage.");
} break;
case MetadataDelta::Action::TEXT_INDEX_CREATE: {
if (!disk_storage->durable_metadata_.PersistTextIndexCreation(md_delta.text.index_name)) {
if (!disk_storage->durable_metadata_.PersistTextIndexCreation(md_delta.text_indices.index_name)) {
return StorageManipulationError{PersistenceError{}};
}
} break;
case MetadataDelta::Action::TEXT_INDEX_DROP: {
if (!disk_storage->durable_metadata_.PersistTextIndexDeletion(md_delta.text.index_name)) {
if (!disk_storage->durable_metadata_.PersistTextIndexDeletion(md_delta.text_indices.index_name)) {
return StorageManipulationError{PersistenceError{}};
}
} break;
@ -1765,7 +1765,7 @@ utils::BasicResult<StorageManipulationError, void> DiskStorage::DiskAccessor::Co
}
spdlog::trace("rocksdb: Commit successful");
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
disk_storage->indices_.text_index_->Commit();
disk_storage->indices_.text_index_.Commit();
}
is_transaction_active_ = false;
@ -1886,7 +1886,7 @@ void DiskStorage::DiskAccessor::Abort() {
transaction_.disk_transaction_->Rollback();
transaction_.disk_transaction_->ClearSnapshot();
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
storage_->indices_.text_index_->Rollback();
storage_->indices_.text_index_.Rollback();
}
delete transaction_.disk_transaction_;
transaction_.disk_transaction_ = nullptr;
@ -2077,8 +2077,8 @@ IndicesInfo DiskStorage::DiskAccessor::ListAllIndices() const {
auto *disk_label_index = static_cast<DiskLabelIndex *>(on_disk->indices_.label_index_.get());
auto *disk_label_property_index =
static_cast<DiskLabelPropertyIndex *>(on_disk->indices_.label_property_index_.get());
auto *text_index = storage_->indices_.text_index_.get();
return {disk_label_index->ListIndices(), disk_label_property_index->ListIndices(), text_index->ListIndices()};
auto &text_index = storage_->indices_.text_index_;
return {disk_label_index->ListIndices(), disk_label_property_index->ListIndices(), text_index.ListIndices()};
}
ConstraintsInfo DiskStorage::DiskAccessor::ListAllConstraints() const {
auto *disk_storage = static_cast<DiskStorage *>(storage_);

View File

@ -199,10 +199,10 @@ void RecoverIndicesAndStats(const RecoveredIndicesAndConstraints::IndicesMetadat
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
// Recover text indices.
spdlog::info("Recreating {} text indices from metadata.", indices_metadata.text.size());
auto *mem_text_index = static_cast<TextIndex *>(indices->text_index_.get());
for (const auto &item : indices_metadata.text) {
if (!mem_text_index->RecoverIndex(item.first, item.second, vertices->access(), name_id_mapper))
spdlog::info("Recreating {} text indices from metadata.", indices_metadata.text_indices.size());
auto &mem_text_index = indices->text_index_;
for (const auto &item : indices_metadata.text_indices) {
if (!mem_text_index.RecoverIndex(item.first, item.second, vertices->access(), name_id_mapper))
throw RecoveryFailure("The text index must be created here!");
spdlog::info("Text index {} on :{} is recreated from metadata", item.first,
name_id_mapper->IdToName(item.second.AsUint()));

View File

@ -43,7 +43,7 @@ struct RecoveredIndicesAndConstraints {
std::vector<std::pair<LabelId, PropertyId>> label_property;
std::vector<std::pair<LabelId, LabelIndexStats>> label_stats;
std::vector<std::pair<LabelId, std::pair<PropertyId, LabelPropertyIndexStats>>> label_property_stats;
std::vector<std::pair<std::string, LabelId>> text;
std::vector<std::pair<std::string, LabelId>> text_indices;
} indices;
struct ConstraintsMetadata {

View File

@ -1640,8 +1640,8 @@ RecoveredSnapshot LoadSnapshot(const std::filesystem::path &path, utils::SkipLis
if (!index_name.has_value()) throw RecoveryFailure("Couldn't read text index name!");
auto label = snapshot.ReadUint();
if (!label) throw RecoveryFailure("Couldn't read text index label!");
AddRecoveredIndexConstraint(&indices_constraints.indices.text, {index_name.value(), get_label_from_id(*label)},
"The text index already exists!");
AddRecoveredIndexConstraint(&indices_constraints.indices.text_indices,
{index_name.value(), get_label_from_id(*label)}, "The text index already exists!");
SPDLOG_TRACE("Recovered metadata of text index {} for :{}", index_name.value(),
name_id_mapper->IdToName(snapshot_id_map.at(*label)));
}
@ -2127,7 +2127,7 @@ void CreateSnapshot(Storage *storage, Transaction *transaction, const std::files
// Write text indices.
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
auto text = storage->indices_.text_index_->ListIndices();
auto text = storage->indices_.text_index_.ListIndices();
snapshot.WriteUint(text.size());
for (const auto &item : text) {
snapshot.WriteString(item.first);

View File

@ -950,14 +950,14 @@ RecoveryInfo LoadWal(const std::filesystem::path &path, RecoveredIndicesAndConst
case WalDeltaData::Type::TEXT_INDEX_CREATE: {
auto index_name = delta.operation_text.index_name;
auto label = LabelId::FromUint(name_id_mapper->NameToId(delta.operation_text.label));
AddRecoveredIndexConstraint(&indices_constraints->indices.text, {index_name, label},
AddRecoveredIndexConstraint(&indices_constraints->indices.text_indices, {index_name, label},
"The text index already exists!");
break;
}
case WalDeltaData::Type::TEXT_INDEX_DROP: {
auto index_name = delta.operation_text.index_name;
auto label = LabelId::FromUint(name_id_mapper->NameToId(delta.operation_text.label));
RemoveRecoveredIndexConstraint(&indices_constraints->indices.text, {index_name, label},
RemoveRecoveredIndexConstraint(&indices_constraints->indices.text_indices, {index_name, label},
"The text index doesn't exist!");
break;
}

View File

@ -14,6 +14,7 @@
#include "storage/v2/disk/label_property_index.hpp"
#include "storage/v2/inmemory/label_index.hpp"
#include "storage/v2/inmemory/label_property_index.hpp"
#include "storage/v2/storage.hpp"
namespace memgraph::storage {
@ -43,7 +44,7 @@ void Indices::UpdateOnAddLabel(LabelId label, Vertex *vertex, const Transaction
label_index_->UpdateOnAddLabel(label, vertex, tx);
label_property_index_->UpdateOnAddLabel(label, vertex, tx);
if (update_text_index) {
text_index_->UpdateOnAddLabel(label, vertex, storage, tx.start_timestamp);
text_index_.UpdateOnAddLabel(label, vertex, storage->name_id_mapper_.get(), tx.start_timestamp);
}
}
@ -51,7 +52,7 @@ void Indices::UpdateOnRemoveLabel(LabelId label, Vertex *vertex, const Transacti
label_index_->UpdateOnRemoveLabel(label, vertex, tx);
label_property_index_->UpdateOnRemoveLabel(label, vertex, tx);
if (update_text_index) {
text_index_->UpdateOnRemoveLabel(label, vertex, tx.start_timestamp);
text_index_.UpdateOnRemoveLabel(label, vertex, tx.start_timestamp);
}
}
@ -59,13 +60,12 @@ void Indices::UpdateOnSetProperty(PropertyId property, const PropertyValue &valu
const Transaction &tx, Storage *storage, bool update_text_index) const {
label_property_index_->UpdateOnSetProperty(property, value, vertex, tx);
if (update_text_index) {
text_index_->UpdateOnSetProperty(vertex, storage, tx.start_timestamp);
text_index_.UpdateOnSetProperty(vertex, storage->name_id_mapper_.get(), tx.start_timestamp);
}
}
Indices::Indices(const Config &config, StorageMode storage_mode) {
std::invoke([this, config, storage_mode]() {
text_index_ = std::make_unique<TextIndex>();
if (storage_mode == StorageMode::IN_MEMORY_TRANSACTIONAL || storage_mode == StorageMode::IN_MEMORY_ANALYTICAL) {
label_index_ = std::make_unique<InMemoryLabelIndex>();
label_property_index_ = std::make_unique<InMemoryLabelPropertyIndex>();

View File

@ -68,7 +68,7 @@ struct Indices {
std::unique_ptr<LabelIndex> label_index_;
std::unique_ptr<LabelPropertyIndex> label_property_index_;
std::unique_ptr<TextIndex> text_index_;
mutable TextIndex text_index_;
};
} // namespace memgraph::storage

View File

@ -17,8 +17,9 @@
namespace memgraph::storage {
void TextIndex::AddNode(Vertex *vertex_after_update, Storage *storage, const std::uint64_t transaction_start_timestamp,
const std::vector<mgcxx::text_search::Context *> &applicable_text_indices, bool skip_commit) {
void TextIndex::AddNode(Vertex *vertex_after_update, NameIdMapper *name_id_mapper,
const std::uint64_t transaction_start_timestamp,
const std::vector<mgcxx::text_search::Context *> &applicable_text_indices) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
throw query::QueryException("To use text indices, enable the text search feature.");
}
@ -30,16 +31,16 @@ void TextIndex::AddNode(Vertex *vertex_after_update, Storage *storage, const std
for (const auto &[prop_id, prop_value] : vertex_after_update->properties.Properties()) {
switch (prop_value.type()) {
case PropertyValue::Type::Bool:
properties[storage->PropertyToName(prop_id)] = prop_value.ValueBool();
properties[name_id_mapper->IdToName(prop_id.AsUint())] = prop_value.ValueBool();
break;
case PropertyValue::Type::Int:
properties[storage->PropertyToName(prop_id)] = prop_value.ValueInt();
properties[name_id_mapper->IdToName(prop_id.AsUint())] = prop_value.ValueInt();
break;
case PropertyValue::Type::Double:
properties[storage->PropertyToName(prop_id)] = prop_value.ValueDouble();
properties[name_id_mapper->IdToName(prop_id.AsUint())] = prop_value.ValueDouble();
break;
case PropertyValue::Type::String:
properties[storage->PropertyToName(prop_id)] = prop_value.ValueString();
properties[name_id_mapper->IdToName(prop_id.AsUint())] = prop_value.ValueString();
break;
case PropertyValue::Type::Null:
case PropertyValue::Type::List:
@ -63,14 +64,14 @@ void TextIndex::AddNode(Vertex *vertex_after_update, Storage *storage, const std
*index_context,
mgcxx::text_search::DocumentInput{
.data = document.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace)},
skip_commit);
kDoSkipCommit);
} catch (const std::exception &e) {
throw query::QueryException(fmt::format("Tantivy error: {}", e.what()));
}
}
}
void TextIndex::AddNode(Vertex *vertex_after_update, Storage *storage,
void TextIndex::AddNode(Vertex *vertex_after_update, NameIdMapper *name_id_mapper,
const std::uint64_t transaction_start_timestamp) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
throw query::QueryException("To use text indices, enable the text search feature.");
@ -78,10 +79,10 @@ void TextIndex::AddNode(Vertex *vertex_after_update, Storage *storage,
auto applicable_text_indices = GetApplicableTextIndices(vertex_after_update);
if (applicable_text_indices.empty()) return;
AddNode(vertex_after_update, storage, transaction_start_timestamp, applicable_text_indices);
AddNode(vertex_after_update, std::move(name_id_mapper), transaction_start_timestamp, applicable_text_indices);
}
void TextIndex::UpdateNode(Vertex *vertex_after_update, Storage *storage,
void TextIndex::UpdateNode(Vertex *vertex_after_update, NameIdMapper *name_id_mapper,
const std::uint64_t transaction_start_timestamp) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
throw query::QueryException("To use text indices, enable the text search feature.");
@ -90,10 +91,10 @@ void TextIndex::UpdateNode(Vertex *vertex_after_update, Storage *storage,
auto applicable_text_indices = GetApplicableTextIndices(vertex_after_update);
if (applicable_text_indices.empty()) return;
RemoveNode(vertex_after_update, applicable_text_indices);
AddNode(vertex_after_update, storage, transaction_start_timestamp, applicable_text_indices);
AddNode(vertex_after_update, std::move(name_id_mapper), transaction_start_timestamp, applicable_text_indices);
}
void TextIndex::UpdateNode(Vertex *vertex_after_update, Storage *storage,
void TextIndex::UpdateNode(Vertex *vertex_after_update, NameIdMapper *name_id_mapper,
const std::uint64_t transaction_start_timestamp,
const std::vector<LabelId> &removed_labels) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
@ -106,7 +107,7 @@ void TextIndex::UpdateNode(Vertex *vertex_after_update, Storage *storage,
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, transaction_start_timestamp, indexes_to_update_node);
AddNode(vertex_after_update, std::move(name_id_mapper), transaction_start_timestamp, indexes_to_update_node);
}
void TextIndex::RemoveNode(Vertex *vertex_after_update,
@ -137,7 +138,7 @@ void TextIndex::RemoveNode(Vertex *vertex_after_update) {
RemoveNode(vertex_after_update, applicable_text_indices);
}
void TextIndex::UpdateOnAddLabel(LabelId added_label, Vertex *vertex_after_update, Storage *storage,
void TextIndex::UpdateOnAddLabel(LabelId added_label, Vertex *vertex_after_update, NameIdMapper *name_id_mapper,
const std::uint64_t transaction_start_timestamp) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
throw query::QueryException("To use text indices, enable the text search feature.");
@ -146,7 +147,7 @@ void TextIndex::UpdateOnAddLabel(LabelId added_label, Vertex *vertex_after_updat
if (!label_to_index_.contains(added_label)) {
return;
}
AddNode(vertex_after_update, storage, transaction_start_timestamp,
AddNode(vertex_after_update, std::move(name_id_mapper), transaction_start_timestamp,
std::vector<mgcxx::text_search::Context *>{&index_.at(label_to_index_.at(added_label)).context_});
}
@ -162,13 +163,13 @@ void TextIndex::UpdateOnRemoveLabel(LabelId removed_label, Vertex *vertex_after_
RemoveNode(vertex_after_update, {&index_.at(label_to_index_.at(removed_label)).context_});
}
void TextIndex::UpdateOnSetProperty(Vertex *vertex_after_update, Storage *storage,
void TextIndex::UpdateOnSetProperty(Vertex *vertex_after_update, NameIdMapper *name_id_mapper,
std::uint64_t transaction_start_timestamp) {
if (!flags::run_time::GetExperimentalTextSearchEnabled()) {
throw query::QueryException("To use text indices, enable the text search feature.");
}
UpdateNode(vertex_after_update, storage, transaction_start_timestamp);
UpdateNode(vertex_after_update, std::move(name_id_mapper), transaction_start_timestamp);
}
std::vector<mgcxx::text_search::Context *> TextIndex::GetApplicableTextIndices(const std::vector<LabelId> &labels) {
@ -222,6 +223,8 @@ bool TextIndex::CreateIndex(const std::string &index_name, LabelId label, memgra
bool has_schema = false;
std::vector<std::pair<PropertyId, std::string>> indexed_properties{};
auto &index_context = index_.at(index_name).context_;
// TODO antepusic get nodes with label if there's an adequate label index
for (const auto &v : db->Vertices(View::NEW)) {
if (!v.HasLabel(View::NEW, label).GetValue()) {
continue;
@ -431,13 +434,11 @@ std::vector<Gid> TextIndex::Search(const std::string &index_name, const std::str
} catch (const std::exception &e) {
throw query::QueryException(fmt::format("Tantivy error: {}", e.what()));
}
auto docs = search_results.docs;
for (const auto &doc : docs) {
for (const auto &doc : search_results.docs) {
// The CXX .data() method (https://cxx.rs/binding/string.html) may overestimate string length, causing JSON parsing
// errors downstream. We prevent this by resizing the converted string with the correctly-working .length() method.
auto doc_data = doc.data;
std::string doc_string = doc_data.data();
doc_string.resize(doc_data.length());
std::string doc_string = doc.data.data();
doc_string.resize(doc.data.length());
auto doc_json = nlohmann::json::parse(doc_string);
found_nodes.push_back(storage::Gid::FromString(doc_json["metadata"]["gid"].dump()));
}
@ -460,7 +461,7 @@ std::vector<std::pair<std::string, LabelId>> TextIndex::ListIndices() const {
std::vector<std::pair<std::string, LabelId>> ret;
ret.reserve(index_.size());
for (const auto &[index_name, index_data] : index_) {
ret.push_back({index_name, index_data.scope_});
ret.emplace_back(index_name, index_data.scope_);
}
return ret;
}

View File

@ -33,9 +33,8 @@ struct TextIndexData {
class TextIndex {
private:
void AddNode(Vertex *vertex, Storage *storage, const std::uint64_t transaction_start_timestamp,
const std::vector<mgcxx::text_search::Context *> &applicable_text_indices,
bool skip_commit = kDoSkipCommit);
void AddNode(Vertex *vertex, NameIdMapper *name_id_mapper, const std::uint64_t transaction_start_timestamp,
const std::vector<mgcxx::text_search::Context *> &applicable_text_indices);
std::vector<mgcxx::text_search::Context *> GetApplicableTextIndices(const std::vector<LabelId> &labels);
@ -56,22 +55,22 @@ class TextIndex {
std::map<std::string, TextIndexData> index_;
std::map<LabelId, std::string> label_to_index_;
void AddNode(Vertex *vertex, Storage *storage, const std::uint64_t transaction_start_timestamp);
void AddNode(Vertex *vertex, NameIdMapper *name_id_mapper, const std::uint64_t transaction_start_timestamp);
void UpdateNode(Vertex *vertex, Storage *storage, const std::uint64_t transaction_start_timestamp);
void UpdateNode(Vertex *vertex, NameIdMapper *name_id_mapper, const std::uint64_t transaction_start_timestamp);
void UpdateNode(Vertex *vertex, Storage *storage, const std::uint64_t transaction_start_timestamp,
void UpdateNode(Vertex *vertex, NameIdMapper *name_id_mapper, const std::uint64_t transaction_start_timestamp,
const std::vector<LabelId> &removed_labels);
void RemoveNode(Vertex *vertex);
void UpdateOnAddLabel(LabelId added_label, Vertex *vertex_after_update, Storage *storage,
void UpdateOnAddLabel(LabelId added_label, Vertex *vertex_after_update, NameIdMapper *name_id_mapper,
const std::uint64_t transaction_start_timestamp);
void UpdateOnRemoveLabel(LabelId removed_label, Vertex *vertex_after_update,
const std::uint64_t transaction_start_timestamp);
void UpdateOnSetProperty(Vertex *vertex_after_update, Storage *storage,
void UpdateOnSetProperty(Vertex *vertex_after_update, NameIdMapper *name_id_mapper,
const std::uint64_t transaction_start_timestamp);
bool CreateIndex(const std::string &index_name, LabelId label, memgraph::query::DbAccessor *db);

View File

@ -877,7 +877,7 @@ utils::BasicResult<StorageManipulationError, void> InMemoryStorage::InMemoryAcce
}
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
mem_storage->indices_.text_index_->Commit();
mem_storage->indices_.text_index_.Commit();
}
}
@ -1202,7 +1202,7 @@ void InMemoryStorage::InMemoryAccessor::Abort() {
storage_->indices_.AbortEntries(property, prop_vertices, transaction_.start_timestamp);
}
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
storage_->indices_.text_index_->Rollback();
storage_->indices_.text_index_.Rollback();
}
// VERTICES
@ -1803,7 +1803,7 @@ StorageInfo InMemoryStorage::GetInfo(bool force_directory,
const auto &lbl = access->ListAllIndices();
info.label_indices = lbl.label.size();
info.label_property_indices = lbl.label_property.size();
info.text_indices = lbl.text.size();
info.text_indices = lbl.text_indices.size();
const auto &con = access->ListAllConstraints();
info.existence_constraints = con.existence.size();
info.unique_constraints = con.unique.size();
@ -2058,12 +2058,12 @@ bool InMemoryStorage::AppendToWal(const Transaction &transaction, uint64_t final
final_commit_timestamp);
} break;
case MetadataDelta::Action::TEXT_INDEX_CREATE: {
const auto &info = md_delta.text;
const auto &info = md_delta.text_indices;
AppendToWalDataDefinition(durability::StorageMetadataOperation::TEXT_INDEX_CREATE, info.index_name, info.label,
final_commit_timestamp);
} break;
case MetadataDelta::Action::TEXT_INDEX_DROP: {
const auto &info = md_delta.text;
const auto &info = md_delta.text_indices;
AppendToWalDataDefinition(durability::StorageMetadataOperation::TEXT_INDEX_DROP, info.index_name, info.label,
final_commit_timestamp);
} break;
@ -2274,8 +2274,8 @@ IndicesInfo InMemoryStorage::InMemoryAccessor::ListAllIndices() const {
auto *mem_label_index = static_cast<InMemoryLabelIndex *>(in_memory->indices_.label_index_.get());
auto *mem_label_property_index =
static_cast<InMemoryLabelPropertyIndex *>(in_memory->indices_.label_property_index_.get());
auto *text_index = storage_->indices_.text_index_.get();
return {mem_label_index->ListIndices(), mem_label_property_index->ListIndices(), text_index->ListIndices()};
auto &text_index = storage_->indices_.text_index_;
return {mem_label_index->ListIndices(), mem_label_property_index->ListIndices(), text_index.ListIndices()};
}
ConstraintsInfo InMemoryStorage::InMemoryAccessor::ListAllConstraints() const {
const auto *mem_storage = static_cast<InMemoryStorage *>(storage_);

View File

@ -94,10 +94,10 @@ struct MetadataDelta {
: action(Action::LABEL_PROPERTY_INDEX_STATS_CLEAR), label{label} {}
MetadataDelta(TextIndexCreate /*tag*/, std::string index_name, LabelId label)
: action(Action::TEXT_INDEX_CREATE), text{index_name, label} {}
: action(Action::TEXT_INDEX_CREATE), text_indices{index_name, label} {}
MetadataDelta(TextIndexDrop /*tag*/, std::string index_name, LabelId label)
: action(Action::TEXT_INDEX_DROP), text{index_name, label} {}
: action(Action::TEXT_INDEX_DROP), text_indices{index_name, label} {}
MetadataDelta(ExistenceConstraintCreate /*tag*/, LabelId label, PropertyId property)
: action(Action::EXISTENCE_CONSTRAINT_CREATE), label_property{label, property} {}
@ -167,7 +167,7 @@ struct MetadataDelta {
struct {
std::string index_name;
LabelId label;
} text;
} text_indices;
};
};

View File

@ -150,7 +150,7 @@ Result<std::optional<VertexAccessor>> Storage::Accessor::DeleteVertex(VertexAcce
}
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
storage_->indices_.text_index_->RemoveNode(vertex->vertex_);
storage_->indices_.text_index_.RemoveNode(vertex->vertex_);
}
const auto &value = res.GetValue();
@ -191,7 +191,7 @@ Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> Stor
}
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
storage_->indices_.text_index_->RemoveNode(vertex->vertex_);
storage_->indices_.text_index_.RemoveNode(vertex->vertex_);
}
auto &value = res.GetValue();
@ -284,7 +284,7 @@ Storage::Accessor::DetachDelete(std::vector<VertexAccessor *> nodes, std::vector
if (flags::run_time::GetExperimentalTextSearchEnabled()) {
for (auto *node : nodes_to_delete) {
storage_->indices_.text_index_->RemoveNode(node);
storage_->indices_.text_index_.RemoveNode(node);
}
}

View File

@ -61,7 +61,7 @@ class EdgeAccessor;
struct IndicesInfo {
std::vector<LabelId> label;
std::vector<std::pair<LabelId, PropertyId>> label_property;
std::vector<std::pair<std::string, LabelId>> text;
std::vector<std::pair<std::string, LabelId>> text_indices;
};
struct ConstraintsInfo {
@ -228,23 +228,24 @@ class Storage {
virtual bool LabelPropertyIndexExists(LabelId label, PropertyId property) const = 0;
bool TextIndexExists(const std::string &index_name) const {
return storage_->indices_.text_index_->IndexExists(index_name);
return storage_->indices_.text_index_.IndexExists(index_name);
}
void TextIndexAddVertex(VertexAccessor *vertex) {
storage_->indices_.text_index_->AddNode(vertex->vertex_, storage_, storage_->timestamp_);
storage_->indices_.text_index_.AddNode(vertex->vertex_, storage_->name_id_mapper_.get(), storage_->timestamp_);
}
void TextIndexUpdateVertex(VertexAccessor *vertex) {
storage_->indices_.text_index_->UpdateNode(vertex->vertex_, storage_, storage_->timestamp_);
storage_->indices_.text_index_.UpdateNode(vertex->vertex_, storage_->name_id_mapper_.get(), storage_->timestamp_);
}
void TextIndexUpdateVertex(VertexAccessor *vertex, std::vector<LabelId> removed_labels) {
storage_->indices_.text_index_->UpdateNode(vertex->vertex_, storage_, storage_->timestamp_, removed_labels);
storage_->indices_.text_index_.UpdateNode(vertex->vertex_, storage_->name_id_mapper_.get(), storage_->timestamp_,
removed_labels);
}
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);
return storage_->indices_.text_index_.Search(index_name, search_query);
}
virtual IndicesInfo ListAllIndices() const = 0;
@ -294,12 +295,12 @@ class Storage {
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);
storage_->indices_.text_index_.CreateIndex(index_name, label, db);
return {};
}
virtual utils::BasicResult<StorageIndexDefinitionError, void> DropTextIndex(const std::string &index_name) {
storage_->indices_.text_index_->DropIndex(index_name);
storage_->indices_.text_index_.DropIndex(index_name);
return {};
}