From 75b4df80c18815433c92ee91bf68231276400ae7 Mon Sep 17 00:00:00 2001 From: Stepan Bagritsevich Date: Mon, 25 Nov 2024 13:08:52 +0400 Subject: [PATCH] refactor(search_family): address comments 5 Signed-off-by: Stepan Bagritsevich --- src/core/search/search.cc | 1 + src/server/search/search_family.cc | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/core/search/search.cc b/src/core/search/search.cc index a2bd9f56e573..c62be8096334 100644 --- a/src/core/search/search.cc +++ b/src/core/search/search.cc @@ -654,6 +654,7 @@ const Schema& FieldIndices::GetSchema() const { SortableValue FieldIndices::GetSortIndexValue(DocId doc, std::string_view field_identifier) const { auto it = sort_indices_.find(field_identifier); + DCHECK(it != sort_indices_.end()); return it->second->Lookup(doc); } diff --git a/src/server/search/search_family.cc b/src/server/search/search_family.cc index 65c9665256aa..c7c12176a45c 100644 --- a/src/server/search/search_family.cc +++ b/src/server/search/search_family.cc @@ -183,13 +183,9 @@ optional ParseSchemaOrReply(DocIndex::DataType type, CmdArgParse #pragma GCC diagnostic pop #endif -bool StartsWithAtSign(std::string_view field) { - return !field.empty() && field.front() == '@'; -} - std::string_view ParseField(CmdArgParser* parser) { std::string_view field = parser->Next(); - if (StartsWithAtSign(field)) { + if (absl::StartsWith(field, "@"sv)) { field.remove_prefix(1); // remove leading @ if exists } return field; @@ -197,7 +193,7 @@ std::string_view ParseField(CmdArgParser* parser) { std::string_view ParseFieldWithAtSign(CmdArgParser* parser) { std::string_view field = parser->Next(); - if (StartsWithAtSign(field)) { + if (absl::StartsWith(field, "@"sv)) { field.remove_prefix(1); // remove leading @ } else { // Temporary warning until we can throw an error @@ -217,7 +213,7 @@ void ParseLoadFields(CmdArgParser* parser, std::optional* load while (num_fields--) { string_view str = parser->Next(); - if (StartsWithAtSign(str)) { + if (absl::StartsWith(str, "@"sv)) { str.remove_prefix(1); // remove leading @ }