Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[feature](invert index) match_phrase_prefix feature added#27404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // 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. | ||
| #include "phrase_prefix_query.h" | ||
| #include "olap/rowset//segment_v2/inverted_index/query/prefix_query.h" | ||
| namespace doris { | ||
| namespace segment_v2 { | ||
| PhrasePrefixQuery::PhrasePrefixQuery(const std::shared_ptr<lucene::search::IndexSearcher>& searcher) | ||
| : _searcher(searcher) {} | ||
| void PhrasePrefixQuery::add(const std::wstring& field_name, const std::vector<std::string>& terms) { | ||
| if (terms.empty()) { | ||
| return; | ||
| } | ||
| 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); | ||
| } 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); | ||
| for (auto& t : prefix_terms) { | ||
| _CLDECDELETE(t); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| void PhrasePrefixQuery::search(roaring::Roaring& roaring) { | ||
| _searcher->_search(&_query, [&roaring](const int32_t docid, const float_t /*score*/) { | ||
| roaring.add(docid); | ||
| }); | ||
| } | ||
| } // namespace segment_v2 | ||
| } // namespace doris |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // 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 <CLucene.h> | ||
| #include <CLucene/index/IndexReader.h> | ||
| #include <memory> | ||
| #include "CLucene/search/MultiPhraseQuery.h" | ||
| #include "roaring/roaring.hh" | ||
| CL_NS_USE(index) | ||
| CL_NS_USE(search) | ||
| namespace doris { | ||
| namespace segment_v2 { | ||
| class PhrasePrefixQuery { | ||
| public: | ||
| PhrasePrefixQuery(const std::shared_ptr<lucene::search::IndexSearcher>& searcher); | ||
| ~PhrasePrefixQuery() = default; | ||
| void set_max_expansions(int32_t max_expansions) { _max_expansions = max_expansions; } | ||
| void add(const std::wstring& field_name, const std::vector<std::string>& terms); | ||
| void search(roaring::Roaring& roaring); | ||
| private: | ||
| std::shared_ptr<lucene::search::IndexSearcher> _searcher; | ||
| MultiPhraseQuery _query; | ||
| int32_t _max_expansions = 50; | ||
| }; | ||
| } // namespace segment_v2 | ||
| } // namespace doris | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // 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. | ||
| #include "prefix_query.h" | ||
| namespace doris { | ||
| void PrefixQuery::get_prefix_terms(IndexReader* reader, const std::wstring& field_name, | ||
| const std::string& prefix, | ||
| std::vector<CL_NS(index)::Term*>& prefix_terms, | ||
| int32_t max_expansions) { | ||
| std::wstring ws_prefix = StringUtil::string_to_wstring(prefix); | ||
| Term* prefix_term = _CLNEW Term(field_name.c_str(), ws_prefix.c_str()); | ||
| TermEnum* enumerator = reader->terms(prefix_term); | ||
| int32_t count = 0; | ||
| Term* lastTerm = nullptr; | ||
| try { | ||
| const TCHAR* prefixText = prefix_term->text(); | ||
| const TCHAR* prefixField = prefix_term->field(); | ||
| const TCHAR* tmp = nullptr; | ||
| size_t i = 0; | ||
| size_t prefixLen = prefix_term->textLength(); | ||
| do { | ||
| lastTerm = enumerator->term(); | ||
| if (lastTerm != nullptr && lastTerm->field() == prefixField) { | ||
| size_t termLen = lastTerm->textLength(); | ||
| if (prefixLen > termLen) { | ||
| break; | ||
| } | ||
| tmp = lastTerm->text(); | ||
| for (i = prefixLen - 1; i != -1; --i) { | ||
| if (tmp[i] != prefixText[i]) { | ||
| tmp = nullptr; | ||
| break; | ||
| } | ||
| } | ||
| if (tmp == nullptr) { | ||
| break; | ||
| } | ||
| if (max_expansions > 0 && count >= max_expansions) { | ||
| break; | ||
| } | ||
| Term* t = _CLNEW Term(field_name.c_str(), tmp); | ||
| prefix_terms.push_back(t); | ||
| count++; | ||
| } else { | ||
| break; | ||
| } | ||
| _CLDECDELETE(lastTerm); | ||
| } while (enumerator->next()); | ||
| } | ||
| _CLFINALLY({ | ||
| enumerator->close(); | ||
| _CLDELETE(enumerator); | ||
| _CLDECDELETE(lastTerm); | ||
| _CLDECDELETE(prefix_term); | ||
| }); | ||
| } | ||
| } // namespace doris |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // 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 <CLucene.h> | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 'CLucene.h' file not found [clang-diagnostic-error] #include<CLucene.h>
^Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 'CLucene.h' file not found [clang-diagnostic-error] #include<CLucene.h>
^ | ||
| #include <CLucene/index/IndexReader.h> | ||
| #include <cstdint> | ||
| CL_NS_USE(index) | ||
| namespace doris { | ||
| class PrefixQuery { | ||
| public: | ||
| PrefixQuery() = default; | ||
| ~PrefixQuery() = default; | ||
| static void get_prefix_terms(IndexReader* reader, const std::wstring& field_name, | ||
| const std::string& prefix, | ||
| std::vector<CL_NS(index)::Term*>& prefix_terms, | ||
| int32_t max_expansions = 50); | ||
| }; | ||
| } // namespace doris | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: 'CLucene.h' file not found [clang-diagnostic-error]