diff --git a/src/common/expression/TextSearchExpression.cpp b/src/common/expression/TextSearchExpression.cpp index 1ee06c027f6..f88112a0466 100644 --- a/src/common/expression/TextSearchExpression.cpp +++ b/src/common/expression/TextSearchExpression.cpp @@ -10,26 +10,14 @@ namespace nebula { bool TextSearchArgument::operator==(const TextSearchArgument& rhs) const { - return index_ == rhs.index_ && query_ == rhs.query_ && props_ == rhs.props_; + return index_ == rhs.index_ && query_ == rhs.query_; } std::string TextSearchArgument::toString() const { std::string buf; buf.reserve(64); - if (!index_.empty()) { - buf += "\"" + index_ + "\", "; - } + buf += index_ + ", "; buf += "\"" + query_ + "\""; - if (!props_.empty()) { - buf += ", ["; - for (size_t i = 0; i < props_.size(); i++) { - buf += props_[i]; - if (i != props_.size() - 1) { - buf += ", "; - } - } - buf += "]"; - } return buf; } diff --git a/src/common/expression/TextSearchExpression.h b/src/common/expression/TextSearchExpression.h index 02f820051a7..08156dd9075 100644 --- a/src/common/expression/TextSearchExpression.h +++ b/src/common/expression/TextSearchExpression.h @@ -15,9 +15,8 @@ class TextSearchArgument final { public: static TextSearchArgument* make(ObjectPool* pool, const std::string& index, - const std::string& query, - const std::vector& props) { - return pool->makeAndAdd(index, query, props); + const std::string& query) { + return pool->makeAndAdd(index, query); } ~TextSearchArgument() = default; @@ -30,35 +29,18 @@ class TextSearchArgument final { return query_; } - std::vector& props() { - return props_; - } - - int64_t& offset() { - return offset_; - } - - int64_t& count() { - return count_; - } - bool operator==(const TextSearchArgument& rhs) const; std::string toString() const; private: friend ObjectPool; - TextSearchArgument(const std::string& index, - const std::string& query, - const std::vector& props) - : index_(index), query_(query), props_(props) {} + TextSearchArgument(const std::string& index, const std::string& query) + : index_(index), query_(query) {} private: std::string index_; std::string query_; - std::vector props_; - int64_t count_ = 0; - int64_t offset_ = 0; }; class TextSearchExpression : public Expression { @@ -85,9 +67,7 @@ class TextSearchExpression : public Expression { std::string toString() const override; Expression* clone() const override { - auto arg = TextSearchArgument::make(pool_, arg_->index(), arg_->query(), arg_->props()); - arg->count() = arg_->count(); - arg->offset() = arg_->offset(); + auto arg = TextSearchArgument::make(pool_, arg_->index(), arg_->query()); return TextSearchExpression::make(pool_, kind_, arg); } diff --git a/src/common/plugin/fulltext/elasticsearch/ESAdapter.cpp b/src/common/plugin/fulltext/elasticsearch/ESAdapter.cpp index a7dd540c298..d582b43e90f 100644 --- a/src/common/plugin/fulltext/elasticsearch/ESAdapter.cpp +++ b/src/common/plugin/fulltext/elasticsearch/ESAdapter.cpp @@ -189,17 +189,12 @@ Status ESAdapter::bulk(const ESBulk& bulk, bool refresh) { StatusOr ESAdapter::queryString(const std::string& index, const std::string& query, - const std::vector& fields, int64_t from, int64_t size) { folly::dynamic body = folly::dynamic::object(); body["query"] = folly::dynamic::object(); body["query"]["query_string"] = folly::dynamic::object(); body["query"]["query_string"]["query"] = query; - body["query"]["query_string"]["fields"] = folly::dynamic::array(); - for (auto& field : fields) { - body["query"]["query_string"]["fields"].push_back(field); - } if (size > 0) { body["size"] = size; body["from"] = from; diff --git a/src/common/plugin/fulltext/elasticsearch/ESAdapter.h b/src/common/plugin/fulltext/elasticsearch/ESAdapter.h index 4ad974b0543..a4488b9060d 100644 --- a/src/common/plugin/fulltext/elasticsearch/ESAdapter.h +++ b/src/common/plugin/fulltext/elasticsearch/ESAdapter.h @@ -80,7 +80,6 @@ class ESAdapter { virtual StatusOr queryString(const std::string& index, const std::string& query, - const std::vector& fields, int64_t from, int64_t size); diff --git a/src/graph/executor/query/FulltextIndexScanExecutor.cpp b/src/graph/executor/query/FulltextIndexScanExecutor.cpp index e950901a2be..8c2627c2e21 100644 --- a/src/graph/executor/query/FulltextIndexScanExecutor.cpp +++ b/src/graph/executor/query/FulltextIndexScanExecutor.cpp @@ -33,20 +33,18 @@ folly::Future FulltextIndexScanExecutor::execute() { if (ftIndexScan->isEdge()) { DataSet edges({"edge"}); for (auto& item : esResultValue.items) { - // TODO(hs.zhang): return item.score Edge edge; edge.src = item.src; edge.dst = item.dst; edge.ranking = item.rank; edge.type = ftIndexScan->schemaId(); - edges.emplace_back(Row({std::move(edge)})); + edges.emplace_back(Row({std::move(edge), item.score})); } finish(ResultBuilder().value(Value(std::move(edges))).iter(Iterator::Kind::kProp).build()); } else { DataSet vertices({kVid}); for (auto& item : esResultValue.items) { - // TODO(hs.zhang): return item.score - vertices.emplace_back(Row({item.vid})); + vertices.emplace_back(Row({item.vid, item.score})); } finish(ResultBuilder().value(Value(std::move(vertices))).iter(Iterator::Kind::kProp).build()); } @@ -78,17 +76,15 @@ StatusOr FulltextIndexScanExecutor::accessFulltextIndex( TextSearchExpression* tsExpr) { std::function()> execFunc; plugin::ESAdapter& esAdapter = esAdapter_; + auto* ftIndexScan = asNode(node()); switch (tsExpr->kind()) { case Expression::Kind::kESQUERY: { auto arg = tsExpr->arg(); auto index = arg->index(); auto query = arg->query(); - auto props = arg->props(); - auto count = arg->count(); - auto offset = arg->offset(); - execFunc = [=, &esAdapter]() { - return esAdapter.queryString(index, query, props, offset, count); - }; + int64_t offset = ftIndexScan->offset(); + int64_t count = ftIndexScan->limit(); + execFunc = [=, &esAdapter]() { return esAdapter.queryString(index, query, offset, count); }; break; } default: { diff --git a/src/graph/validator/LookupValidator.cpp b/src/graph/validator/LookupValidator.cpp index 853952316c8..545180320db 100644 --- a/src/graph/validator/LookupValidator.cpp +++ b/src/graph/validator/LookupValidator.cpp @@ -164,42 +164,14 @@ Status LookupValidator::validateWhere() { std::string& index = arg->index(); auto metaClient = qctx_->getMetaClient(); meta::cpp2::FTIndex ftIndex; - if (index.empty()) { - auto result = metaClient->getFTIndexFromCache(spaceId(), schemaId()); - NG_RETURN_IF_ERROR(result); - auto indexes = std::move(result).value(); - if (indexes.size() == 0) { - return Status::Error("There is no ft index of schema"); - } else if (indexes.size() > 1) { - return Status::Error("There is more than one schema, one must be specified"); - } - index = indexes.begin()->first; - ftIndex = indexes.begin()->second; - } else { - // TODO(hs.zhang): Directly get `ftIndex` by `index` - auto result = metaClient->getFTIndexFromCache(spaceId(), schemaId()); - NG_RETURN_IF_ERROR(result); - auto indexes = std::move(result).value(); - auto iter = indexes.find(index); - if (iter == indexes.end()) { - return Status::Error("Index %s is not found", index.c_str()); - } - ftIndex = iter->second; - } - auto& props = arg->props(); - if (props.empty()) { - for (auto& f : *ftIndex.fields()) { - props.push_back(f); - } - } else { - std::set fields(ftIndex.fields()->begin(), ftIndex.fields()->end()); - for (auto& p : props) { - if (fields.count(p)) { - continue; - } - return Status::Error("Index %s does not include %s", index.c_str(), p.c_str()); - } + auto result = metaClient->getFTIndexFromCache(spaceId(), schemaId()); + NG_RETURN_IF_ERROR(result); + auto indexes = std::move(result).value(); + auto iter = indexes.find(index); + if (iter == indexes.end()) { + return Status::Error("Index %s is not found", index.c_str()); } + ftIndex = iter->second; } else { if (filter != nullptr) { auto vars = graph::ExpressionUtils::ExtractInnerVars(filter, qctx_); diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 33a4cb30348..5cd6a5c87bf 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -2066,38 +2066,12 @@ sign_out_service_sentence text_search_argument - : STRING COMMA STRING COMMA L_BRACKET name_label_list R_BRACKET{ - std::vector props; - for(auto& p:$6->labels()){ - props.push_back(*p); - } - delete $6; - auto args = TextSearchArgument::make(qctx->objPool(), *$1, *$3, props); - delete $1; - delete $3; - $$ = args; - } - | STRING COMMA STRING { - auto args = TextSearchArgument::make(qctx->objPool(), *$1, *$3, {}); + : name_label COMMA STRING { + auto args = TextSearchArgument::make(qctx->objPool(), *$1, *$3); delete $1; delete $3; $$ = args; } - | STRING COMMA L_BRACKET name_label_list R_BRACKET { - std::vector props; - for(auto& p:$4->labels()){ - props.push_back(*p); - } - delete $4; - auto args = TextSearchArgument::make(qctx->objPool(), "", *$1, props); - delete $1; - $$ = args; - } - | STRING { - auto args = TextSearchArgument::make(qctx->objPool(), "", *$1, {}); - delete $1; - $$ = args; - } ; text_search_expression @@ -2637,8 +2611,8 @@ opt_analyzer : %empty { $$ = nullptr; } - | KW_USE KW_ANALYZER ASSIGN STRING { - $$ = $4; + | KW_ANALYZER ASSIGN STRING { + $$ = $3; } ; diff --git a/src/parser/test/ParserTest.cpp b/src/parser/test/ParserTest.cpp index bc2df895f6d..acbb5bf75f7 100644 --- a/src/parser/test/ParserTest.cpp +++ b/src/parser/test/ParserTest.cpp @@ -2929,22 +2929,7 @@ TEST_F(ParserTest, Zone) { TEST_F(ParserTest, FullText) { { - std::string query = "LOOKUP ON t1 WHERE ES_QUERY(\"abc\", \"qwerty\", [a,b,c,d])"; - auto result = parse(query); - EXPECT_TRUE(result.ok()) << result.status(); - } - { - std::string query = "LOOKUP ON t1 WHERE ES_QUERY(\"qwerty\", [a,b,c,d])"; - auto result = parse(query); - EXPECT_TRUE(result.ok()) << result.status(); - } - { - std::string query = "LOOKUP ON t1 WHERE ES_QUERY(\"index1\", \"qwerty\")"; - auto result = parse(query); - EXPECT_TRUE(result.ok()) << result.status(); - } - { - std::string query = "LOOKUP ON t1 WHERE ES_QUERY(\"qwerty\")"; + std::string query = "LOOKUP ON t1 WHERE ES_QUERY(abc, \"qwerty\")"; auto result = parse(query); EXPECT_TRUE(result.ok()) << result.status(); }