Skip to content

Commit e819402

Browse files
Ft search (#5567)
* stash * real ft-search * fmt * fix bug * fix bug * fix memleak --------- Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
1 parent e4f91de commit e819402

34 files changed

+241
-1498
lines changed

src/clients/meta/MetaClient.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ Status MetaClient::handleResponse(const RESP& resp) {
990990
case nebula::cpp2::ErrorCode::E_HOST_CAN_NOT_BE_ADDED:
991991
return Status::Error("Could not add a host, which is not a storage and not expired either");
992992
default:
993-
return Status::Error("Unknown error!");
993+
return Status::Error("Unknown error %d!", static_cast<int>(resp.get_code()));
994994
}
995995
}
996996

src/common/expression/Expression.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,7 @@ Expression* Expression::decode(ObjectPool* pool, Expression::Decoder& decoder) {
512512
exp->resetFrom(decoder);
513513
return exp;
514514
}
515-
case Expression::Kind::kTSPrefix:
516-
case Expression::Kind::kTSWildcard:
517-
case Expression::Kind::kTSRegexp:
518-
case Expression::Kind::kTSFuzzy: {
515+
case Expression::Kind::kESQUERY: {
519516
LOG(FATAL) << "Should not decode text search expression";
520517
return exp;
521518
}
@@ -721,17 +718,8 @@ std::ostream& operator<<(std::ostream& os, Expression::Kind kind) {
721718
case Expression::Kind::kPathBuild:
722719
os << "PathBuild";
723720
break;
724-
case Expression::Kind::kTSPrefix:
725-
os << "Prefix";
726-
break;
727-
case Expression::Kind::kTSWildcard:
728-
os << "Wildcard";
729-
break;
730-
case Expression::Kind::kTSRegexp:
731-
os << "Regexp";
732-
break;
733-
case Expression::Kind::kTSFuzzy:
734-
os << "Fuzzy";
721+
case Expression::Kind::kESQUERY:
722+
os << "ESQuery";
735723
break;
736724
case Expression::Kind::kListComprehension:
737725
os << "ListComprehension";

src/common/expression/Expression.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ class Expression {
9696

9797
kPathBuild,
9898
// text or key word search expression
99-
kTSPrefix,
100-
kTSWildcard,
101-
kTSRegexp,
102-
kTSFuzzy,
99+
kESQUERY,
103100

104101
kAggregate,
105102
kIsNull,

src/common/expression/TextSearchExpression.cpp

+15-30
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,25 @@
1010
namespace nebula {
1111

1212
bool TextSearchArgument::operator==(const TextSearchArgument& rhs) const {
13-
return val_ == rhs.val_ && op_ == rhs.op_ && fuzziness_ == rhs.fuzziness_ &&
14-
limit_ == rhs.limit_ && timeout_ == rhs.timeout_;
13+
return index_ == rhs.index_ && query_ == rhs.query_ && props_ == rhs.props_;
1514
}
1615

1716
std::string TextSearchArgument::toString() const {
1817
std::string buf;
1918
buf.reserve(64);
20-
buf = from_ + "." + prop_ + ", ";
21-
buf += "\"" + val_ + "\"";
22-
if (fuzziness_ == -1) {
23-
buf += ", AUTO, ";
24-
buf += ((op_ == "or") ? "OR" : "AND");
25-
} else if (fuzziness_ > -1) {
26-
buf += ", ";
27-
buf += folly::stringPrintf("%d, ", fuzziness_);
28-
buf += ((op_ == "or") ? "OR" : "AND");
19+
if (!index_.empty()) {
20+
buf += "\"" + index_ + "\", ";
2921
}
30-
if (limit_ != -1) {
31-
buf += folly::stringPrintf(", %d", limit_);
32-
}
33-
if (timeout_ != -1) {
34-
buf += folly::stringPrintf(", %d", timeout_);
22+
buf += "\"" + query_ + "\"";
23+
if (!props_.empty()) {
24+
buf += ", [";
25+
for (size_t i = 0; i < props_.size(); i++) {
26+
buf += props_[i];
27+
if (i != props_.size() - 1) {
28+
buf += ", ";
29+
}
30+
}
31+
buf += "]";
3532
}
3633
return buf;
3734
}
@@ -49,20 +46,8 @@ std::string TextSearchExpression::toString() const {
4946
std::string buf;
5047
buf.reserve(64);
5148
switch (kind_) {
52-
case Kind::kTSWildcard: {
53-
buf = "WILDCARD(";
54-
break;
55-
}
56-
case Kind::kTSPrefix: {
57-
buf = "PREFIX(";
58-
break;
59-
}
60-
case Kind::kTSFuzzy: {
61-
buf = "FUZZY(";
62-
break;
63-
}
64-
case Kind::kTSRegexp: {
65-
buf = "REGEXP(";
49+
case Kind::kESQUERY: {
50+
buf = "ES_QUERY(";
6651
break;
6752
}
6853
default: {

src/common/expression/TextSearchExpression.h

+28-66
Original file line numberDiff line numberDiff line change
@@ -14,60 +14,32 @@ namespace nebula {
1414
class TextSearchArgument final {
1515
public:
1616
static TextSearchArgument* make(ObjectPool* pool,
17-
const std::string& from,
18-
const std::string& prop,
19-
const std::string& val) {
20-
return pool->makeAndAdd<TextSearchArgument>(from, prop, val);
17+
const std::string& index,
18+
const std::string& query,
19+
const std::vector<std::string>& props) {
20+
return pool->makeAndAdd<TextSearchArgument>(index, query, props);
2121
}
2222

2323
~TextSearchArgument() = default;
2424

25-
void setVal(const std::string& val) {
26-
val_ = val;
25+
std::string& index() {
26+
return index_;
2727
}
2828

29-
const std::string& from() {
30-
return from_;
29+
std::string& query() {
30+
return query_;
3131
}
3232

33-
const std::string& prop() {
34-
return prop_;
33+
std::vector<std::string>& props() {
34+
return props_;
3535
}
3636

37-
const std::string& val() const {
38-
return val_;
37+
int64_t& offset() {
38+
return offset_;
3939
}
4040

41-
void setOP(const std::string& op) {
42-
op_ = op;
43-
}
44-
45-
const std::string& op() const {
46-
return op_;
47-
}
48-
49-
void setFuzziness(int32_t fuzz) {
50-
fuzziness_ = fuzz;
51-
}
52-
53-
int32_t fuzziness() {
54-
return fuzziness_;
55-
}
56-
57-
void setLimit(int32_t limit) {
58-
limit_ = limit;
59-
}
60-
61-
int32_t limit() {
62-
return limit_;
63-
}
64-
65-
void setTimeout(int32_t timeout) {
66-
timeout_ = timeout;
67-
}
68-
69-
int32_t timeout() {
70-
return timeout_;
41+
int64_t& count() {
42+
return count_;
7143
}
7244

7345
bool operator==(const TextSearchArgument& rhs) const;
@@ -76,35 +48,23 @@ class TextSearchArgument final {
7648

7749
private:
7850
friend ObjectPool;
79-
TextSearchArgument(const std::string& from, const std::string& prop, const std::string& val)
80-
: from_(from), prop_(prop), val_(val) {}
51+
TextSearchArgument(const std::string& index,
52+
const std::string& query,
53+
const std::vector<std::string>& props)
54+
: index_(index), query_(query), props_(props) {}
8155

8256
private:
83-
std::string from_;
84-
std::string prop_;
85-
std::string val_;
86-
std::string op_;
87-
int32_t fuzziness_{-2};
88-
int32_t limit_{10000};
89-
int32_t timeout_{-1};
57+
std::string index_;
58+
std::string query_;
59+
std::vector<std::string> props_;
60+
int64_t count_ = 0;
61+
int64_t offset_ = 0;
9062
};
9163

9264
class TextSearchExpression : public Expression {
9365
public:
94-
static TextSearchExpression* makePrefix(ObjectPool* pool, TextSearchArgument* arg) {
95-
return pool->makeAndAdd<TextSearchExpression>(pool, Kind::kTSPrefix, arg);
96-
}
97-
98-
static TextSearchExpression* makeWildcard(ObjectPool* pool, TextSearchArgument* arg) {
99-
return pool->makeAndAdd<TextSearchExpression>(pool, Kind::kTSWildcard, arg);
100-
}
101-
102-
static TextSearchExpression* makeRegexp(ObjectPool* pool, TextSearchArgument* arg) {
103-
return pool->makeAndAdd<TextSearchExpression>(pool, Kind::kTSRegexp, arg);
104-
}
105-
106-
static TextSearchExpression* makeFuzzy(ObjectPool* pool, TextSearchArgument* arg) {
107-
return pool->makeAndAdd<TextSearchExpression>(pool, Kind::kTSFuzzy, arg);
66+
static TextSearchExpression* makeQuery(ObjectPool* pool, TextSearchArgument* arg) {
67+
return pool->makeAndAdd<TextSearchExpression>(pool, Kind::kESQUERY, arg);
10868
}
10969

11070
static TextSearchExpression* make(ObjectPool* pool, Kind kind, TextSearchArgument* arg) {
@@ -125,7 +85,9 @@ class TextSearchExpression : public Expression {
12585
std::string toString() const override;
12686

12787
Expression* clone() const override {
128-
auto arg = TextSearchArgument::make(pool_, arg_->from(), arg_->prop(), arg_->val());
88+
auto arg = TextSearchArgument::make(pool_, arg_->index(), arg_->query(), arg_->props());
89+
arg->count() = arg_->count();
90+
arg->offset() = arg_->offset();
12991
return TextSearchExpression::make(pool_, kind_, arg);
13092
}
13193

0 commit comments

Comments
 (0)