-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
be/src/olap/rowset/segment_v2/inverted_index/query/phrase_prefix_query.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
54 changes: 54 additions & 0 deletions
54
be/src/olap/rowset/segment_v2/inverted_index/query/phrase_prefix_query.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
80 changes: 80 additions & 0 deletions
80
be/src/olap/rowset/segment_v2/inverted_index/query/prefix_query.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
40 changes: 40 additions & 0 deletions
40
be/src/olap/rowset/segment_v2/inverted_index/query/prefix_query.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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]