-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'branch-2.0' into branch-2.0-fix-publish-failed-return-ok
- Loading branch information
Showing
53 changed files
with
1,308 additions
and
249 deletions.
There are no files selected for viewing
Submodule clucene
updated
10 files
This file contains 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 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 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 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 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 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 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 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 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 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> | ||
#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 |
Oops, something went wrong.