mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-10 18:05:44 +02:00
fix: review comments
This commit is contained in:
parent
4000cef7c4
commit
7f1298bf3f
5 changed files with 38 additions and 49 deletions
|
@ -16,18 +16,6 @@ using namespace std;
|
||||||
|
|
||||||
namespace dfly::search {
|
namespace dfly::search {
|
||||||
|
|
||||||
AstTermNode::AstTermNode(string term) : term{std::move(term)} {
|
|
||||||
}
|
|
||||||
|
|
||||||
AstPrefixNode::AstPrefixNode(string prefix) : prefix{std::move(prefix)} {
|
|
||||||
}
|
|
||||||
|
|
||||||
AstSuffixNode::AstSuffixNode(string suffix) : suffix{std::move(suffix)} {
|
|
||||||
}
|
|
||||||
|
|
||||||
AstInfixNode::AstInfixNode(string infix) : infix{std::move(infix)} {
|
|
||||||
}
|
|
||||||
|
|
||||||
AstRangeNode::AstRangeNode(double lo, bool lo_excl, double hi, bool hi_excl)
|
AstRangeNode::AstRangeNode(double lo, bool lo_excl, double hi, bool hi_excl)
|
||||||
: lo{lo_excl ? nextafter(lo, hi) : lo}, hi{hi_excl ? nextafter(hi, lo) : hi} {
|
: lo{lo_excl ? nextafter(lo, hi) : lo}, hi{hi_excl ? nextafter(hi, lo) : hi} {
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "core/search/base.h"
|
#include "core/search/base.h"
|
||||||
|
#include "core/search/tag_types.h"
|
||||||
|
|
||||||
namespace dfly {
|
namespace dfly {
|
||||||
|
|
||||||
|
@ -25,30 +26,17 @@ struct AstStarNode {};
|
||||||
// Matches all documents where this field has a non-null value
|
// Matches all documents where this field has a non-null value
|
||||||
struct AstStarFieldNode {};
|
struct AstStarFieldNode {};
|
||||||
|
|
||||||
// Matches terms in text fields
|
template <TagType T> struct AstAffixNode {
|
||||||
struct AstTermNode {
|
explicit AstAffixNode(std::string affix) : affix{std::move(affix)} {
|
||||||
explicit AstTermNode(std::string term);
|
}
|
||||||
|
|
||||||
std::string term;
|
std::string affix;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AstPrefixNode {
|
using AstTermNode = AstAffixNode<TagType::REGULAR>;
|
||||||
explicit AstPrefixNode(std::string prefix);
|
using AstPrefixNode = AstAffixNode<TagType::PREFIX>;
|
||||||
|
using AstSuffixNode = AstAffixNode<TagType::SUFFIX>;
|
||||||
std::string prefix;
|
using AstInfixNode = AstAffixNode<TagType::INFIX>;
|
||||||
};
|
|
||||||
|
|
||||||
struct AstSuffixNode {
|
|
||||||
explicit AstSuffixNode(std::string suffix);
|
|
||||||
|
|
||||||
std::string suffix;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AstInfixNode {
|
|
||||||
explicit AstInfixNode(std::string infix);
|
|
||||||
|
|
||||||
std::string infix;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Matches numeric range
|
// Matches numeric range
|
||||||
struct AstRangeNode {
|
struct AstRangeNode {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
%top{
|
%top{
|
||||||
// Our lexer need to know about Parser::symbol_type
|
// Our lexer need to know about Parser::symbol_type
|
||||||
#include "core/search/parser.hh"
|
#include "core/search/parser.hh"
|
||||||
|
#include "core/search/tag_types.h" // Include TagType enum
|
||||||
}
|
}
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
@ -25,8 +26,7 @@
|
||||||
// A number symbol corresponding to the value in S.
|
// A number symbol corresponding to the value in S.
|
||||||
using dfly::search::Parser;
|
using dfly::search::Parser;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using dfly::search::TagType;
|
||||||
enum class TagType { PREFIX, SUFFIX, INFIX, REGULAR };
|
|
||||||
|
|
||||||
Parser::symbol_type make_StringLit(string_view src, const Parser::location_type& loc);
|
Parser::symbol_type make_StringLit(string_view src, const Parser::location_type& loc);
|
||||||
Parser::symbol_type make_Tag(string_view src, TagType type, const Parser::location_type& loc);
|
Parser::symbol_type make_Tag(string_view src, TagType type, const Parser::location_type& loc);
|
||||||
|
|
|
@ -118,16 +118,16 @@ struct ProfileBuilder {
|
||||||
string GetNodeInfo(const AstNode& node) {
|
string GetNodeInfo(const AstNode& node) {
|
||||||
struct NodeFormatter {
|
struct NodeFormatter {
|
||||||
void operator()(std::string* out, const AstPrefixNode& node) const {
|
void operator()(std::string* out, const AstPrefixNode& node) const {
|
||||||
out->append(node.prefix);
|
out->append(node.affix);
|
||||||
}
|
}
|
||||||
void operator()(std::string* out, const AstSuffixNode& node) const {
|
void operator()(std::string* out, const AstSuffixNode& node) const {
|
||||||
out->append(node.suffix);
|
out->append(node.affix);
|
||||||
}
|
}
|
||||||
void operator()(std::string* out, const AstInfixNode& node) const {
|
void operator()(std::string* out, const AstInfixNode& node) const {
|
||||||
out->append(node.infix);
|
out->append(node.affix);
|
||||||
}
|
}
|
||||||
void operator()(std::string* out, const AstTermNode& node) const {
|
void operator()(std::string* out, const AstTermNode& node) const {
|
||||||
out->append(node.term);
|
out->append(node.affix);
|
||||||
}
|
}
|
||||||
void operator()(std::string* out, const AstTagsNode::TagValue& value) const {
|
void operator()(std::string* out, const AstTagsNode::TagValue& value) const {
|
||||||
visit([this, out](const auto& n) { this->operator()(out, n); }, value);
|
visit([this, out](const auto& n) { this->operator()(out, n); }, value);
|
||||||
|
@ -135,10 +135,10 @@ struct ProfileBuilder {
|
||||||
};
|
};
|
||||||
Overloaded node_info{
|
Overloaded node_info{
|
||||||
[](monostate) -> string { return ""s; },
|
[](monostate) -> string { return ""s; },
|
||||||
[](const AstTermNode& n) { return absl::StrCat("Term{", n.term, "}"); },
|
[](const AstTermNode& n) { return absl::StrCat("Term{", n.affix, "}"); },
|
||||||
[](const AstPrefixNode& n) { return absl::StrCat("Prefix{", n.prefix, "}"); },
|
[](const AstPrefixNode& n) { return absl::StrCat("Prefix{", n.affix, "}"); },
|
||||||
[](const AstSuffixNode& n) { return absl::StrCat("Suffix{", n.suffix, "}"); },
|
[](const AstSuffixNode& n) { return absl::StrCat("Suffix{", n.affix, "}"); },
|
||||||
[](const AstInfixNode& n) { return absl::StrCat("Infix{", n.infix, "}"); },
|
[](const AstInfixNode& n) { return absl::StrCat("Infix{", n.affix, "}"); },
|
||||||
[](const AstRangeNode& n) { return absl::StrCat("Range{", n.lo, "<>", n.hi, "}"); },
|
[](const AstRangeNode& n) { return absl::StrCat("Range{", n.lo, "<>", n.hi, "}"); },
|
||||||
[](const AstLogicalNode& n) {
|
[](const AstLogicalNode& n) {
|
||||||
auto op = n.op == AstLogicalNode::AND ? "and" : "or";
|
auto op = n.op == AstLogicalNode::AND ? "and" : "or";
|
||||||
|
@ -301,7 +301,7 @@ struct BasicSearch {
|
||||||
|
|
||||||
// "term": access field's text index or unify results from all text indices if no field is set
|
// "term": access field's text index or unify results from all text indices if no field is set
|
||||||
IndexResult Search(const AstTermNode& node, string_view active_field) {
|
IndexResult Search(const AstTermNode& node, string_view active_field) {
|
||||||
std::string term = node.term;
|
std::string term = node.affix;
|
||||||
bool strip_whitespace = true;
|
bool strip_whitespace = true;
|
||||||
|
|
||||||
if (auto synonyms = indices_->GetSynonyms(); synonyms) {
|
if (auto synonyms = indices_->GetSynonyms(); synonyms) {
|
||||||
|
@ -363,7 +363,7 @@ struct BasicSearch {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto mapping = [&node, this](TextIndex* index) {
|
auto mapping = [&node, this](TextIndex* index) {
|
||||||
return CollectPrefixMatches(index, node.prefix);
|
return CollectPrefixMatches(index, node.affix);
|
||||||
};
|
};
|
||||||
return UnifyResults(GetSubResults(indices, mapping), LogicOp::OR);
|
return UnifyResults(GetSubResults(indices, mapping), LogicOp::OR);
|
||||||
}
|
}
|
||||||
|
@ -422,16 +422,16 @@ struct BasicSearch {
|
||||||
return IndexResult{};
|
return IndexResult{};
|
||||||
|
|
||||||
Overloaded ov{[tag_index](const AstTermNode& term) -> IndexResult {
|
Overloaded ov{[tag_index](const AstTermNode& term) -> IndexResult {
|
||||||
return tag_index->Matching(term.term);
|
return tag_index->Matching(term.affix);
|
||||||
},
|
},
|
||||||
[tag_index, this](const AstPrefixNode& prefix) {
|
[tag_index, this](const AstPrefixNode& prefix) {
|
||||||
return CollectPrefixMatches(tag_index, prefix.prefix);
|
return CollectPrefixMatches(tag_index, prefix.affix);
|
||||||
},
|
},
|
||||||
[tag_index, this](const AstSuffixNode& suffix) {
|
[tag_index, this](const AstSuffixNode& suffix) {
|
||||||
return CollectSuffixMatches(tag_index, suffix.suffix);
|
return CollectSuffixMatches(tag_index, suffix.affix);
|
||||||
},
|
},
|
||||||
[tag_index, this](const AstInfixNode& infix) {
|
[tag_index, this](const AstInfixNode& infix) {
|
||||||
return CollectInfixMatches(tag_index, infix.infix);
|
return CollectInfixMatches(tag_index, infix.affix);
|
||||||
}};
|
}};
|
||||||
auto mapping = [ov](const auto& tag) { return visit(ov, tag); };
|
auto mapping = [ov](const auto& tag) { return visit(ov, tag); };
|
||||||
return UnifyResults(GetSubResults(node.tags, mapping), LogicOp::OR);
|
return UnifyResults(GetSubResults(node.tags, mapping), LogicOp::OR);
|
||||||
|
|
13
src/core/search/tag_types.h
Normal file
13
src/core/search/tag_types.h
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// Copyright 2023, DragonflyDB authors. All rights reserved.
|
||||||
|
// See LICENSE for licensing terms.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace dfly {
|
||||||
|
namespace search {
|
||||||
|
|
||||||
|
enum class TagType { PREFIX, SUFFIX, INFIX, REGULAR };
|
||||||
|
|
||||||
|
} // namespace search
|
||||||
|
} // namespace dfly
|
Loading…
Add table
Add a link
Reference in a new issue