zzzxl1993 commented on code in PR #29771: URL: https://github.com/apache/doris/pull/29771#discussion_r1452887907
########## 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: change to unique_ptr ########## be/src/olap/rowset/segment_v2/inverted_index/query/query_factory.h: ########## @@ -0,0 +1,51 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include "olap/rowset/segment_v2/inverted_index_query_type.h" + +namespace doris::segment_v2 { + +class Query; +class DisjunctionQuery; +class ConjunctionQuery; +class PhraseQuery; +class PhrasePrefixQuery; +class RegexpQuery; + +class QueryFactory { +public: + template <typename... Args> + static std::unique_ptr<Query> create(InvertedIndexQueryType query_type, Args&&... args) { + if (query_type == InvertedIndexQueryType::MATCH_ANY_QUERY || + query_type == InvertedIndexQueryType::EQUAL_QUERY) { + return std::make_unique<DisjunctionQuery>(std::forward<Args>(args)...); Review Comment: change to switch -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org