Skip to content

Commit

Permalink
refactor(search_family): address comments 5
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Bagritsevich <[email protected]>
  • Loading branch information
BagritsevichStepan committed Nov 25, 2024
1 parent c74d4a3 commit 75b4df8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/core/search/search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
10 changes: 3 additions & 7 deletions src/server/search/search_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,17 @@ optional<search::Schema> 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;
}

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
Expand All @@ -217,7 +213,7 @@ void ParseLoadFields(CmdArgParser* parser, std::optional<SearchFieldsList>* load
while (num_fields--) {
string_view str = parser->Next();

if (StartsWithAtSign(str)) {
if (absl::StartsWith(str, "@"sv)) {
str.remove_prefix(1); // remove leading @
}

Expand Down

0 comments on commit 75b4df8

Please sign in to comment.