airborne12 commented on code in PR #29771:
URL: https://github.com/apache/doris/pull/29771#discussion_r1452875905
##########
be/src/olap/rowset/segment_v2/inverted_index/query/phrase_prefix_query.cpp:
##########
@@ -17,47 +17,56 @@
#include "phrase_prefix_query.h"
+#include <memory>
+
+#include "CLucene/search/MultiPhraseQuery.h"
#include "olap/rowset//segment_v2/inverted_index/query/prefix_query.h"
-namespace doris {
+namespace doris::segment_v2 {
-namespace segment_v2 {
+PhrasePrefixQuery::PhrasePrefixQuery(const
std::shared_ptr<lucene::search::IndexSearcher>& searcher,
+ const TQueryOptions& query_options)
+ : _searcher(searcher),
+ _query(new CL_NS(search)::MultiPhraseQuery()),
+ _max_expansions(query_options.inverted_index_max_expansions) {}
-PhrasePrefixQuery::PhrasePrefixQuery(const
std::shared_ptr<lucene::search::IndexSearcher>& searcher)
- : _searcher(searcher) {}
+PhrasePrefixQuery::~PhrasePrefixQuery() {
+ if (_query) {
+ delete _query;
+ _query = nullptr;
+ }
+}
void PhrasePrefixQuery::add(const std::wstring& field_name, const
std::vector<std::string>& terms) {
if (terms.empty()) {
- return;
+ _CLTHROWA(CL_ERR_IllegalArgument, "PhrasePrefixQuery::add: terms
empty");
}
for (size_t i = 0; i < terms.size(); i++) {
if (i < terms.size() - 1) {
std::wstring ws = StringUtil::string_to_wstring(terms[i]);
Term* t = _CLNEW Term(field_name.c_str(), ws.c_str());
- _query.add(t);
- _CLDECDELETE(t);
+ _query->add(t);
+ _CLLDECDELETE(t);
} else {
std::vector<CL_NS(index)::Term*> prefix_terms;
PrefixQuery::get_prefix_terms(_searcher->getReader(), field_name,
terms[i],
prefix_terms, _max_expansions);
if (prefix_terms.empty()) {
continue;
}
- _query.add(prefix_terms);
+ _query->add(prefix_terms);
for (auto& t : prefix_terms) {
- _CLDECDELETE(t);
+ _CLLDECDELETE(t);
}
}
}
}
void PhrasePrefixQuery::search(roaring::Roaring& roaring) {
- _searcher->_search(&_query, [&roaring](const int32_t docid, const float_t
/*score*/) {
+ _searcher->_search(_query, [&roaring](const int32_t docid, const float_t
/*score*/) {
Review Comment:
we can use std::unique_ptr for query, then here we can pass _query.get() to
search params
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]