This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new 43f4cb862a4 branch-4.0: [fix](inverted index) fix incorrect variable
usage in phrase query building #58952 (#58992)
43f4cb862a4 is described below
commit 43f4cb862a4a5a6ecb467a5afbd8005ef1efa10d
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Dec 16 11:32:29 2025 +0800
branch-4.0: [fix](inverted index) fix incorrect variable usage in phrase
query building #58952 (#58992)
Cherry-picked from #58952
Co-authored-by: zzzxl <[email protected]>
---
.../rowset/segment_v2/inverted_index_writer.cpp | 2 +-
be/src/vec/functions/function_search.cpp | 9 +--
.../data/inverted_index_p0/test_pinyin_phrase.out | 18 ++++++
.../inverted_index_p0/test_pinyin_phrase.groovy | 73 ++++++++++++++++++++++
4 files changed, 97 insertions(+), 5 deletions(-)
diff --git a/be/src/olap/rowset/segment_v2/inverted_index_writer.cpp
b/be/src/olap/rowset/segment_v2/inverted_index_writer.cpp
index 1f5d8ab561d..38c465fadb8 100644
--- a/be/src/olap/rowset/segment_v2/inverted_index_writer.cpp
+++ b/be/src/olap/rowset/segment_v2/inverted_index_writer.cpp
@@ -72,7 +72,7 @@ Status InvertedIndexColumnWriter<field_type>::init() {
} catch (const CLuceneError& e) {
LOG(WARNING) << "Inverted index writer init error occurred: " <<
e.what();
return Status::Error<doris::ErrorCode::INVERTED_INDEX_CLUCENE_ERROR>(
- "Inverted index writer init error occurred");
+ "Inverted index writer init error occurred: {}", e.what());
}
}
diff --git a/be/src/vec/functions/function_search.cpp
b/be/src/vec/functions/function_search.cpp
index f9c0b5b010a..7774ed80e25 100644
--- a/be/src/vec/functions/function_search.cpp
+++ b/be/src/vec/functions/function_search.cpp
@@ -571,7 +571,7 @@ Status FunctionSearch::build_leaf_query(const
TSearchClause& clause,
std::vector<TermInfo> phrase_term_infos =
QueryHelper::build_phrase_term_infos(term_infos);
if (phrase_term_infos.size() == 1) {
- const auto& term_info = term_infos[0];
+ const auto& term_info = phrase_term_infos[0];
if (term_info.is_single_term()) {
std::wstring term_wstr =
StringHelper::to_wstring(term_info.get_single_term());
*out = std::make_shared<query_v2::TermQuery>(context,
field_wstr, term_wstr);
@@ -584,11 +584,12 @@ Status FunctionSearch::build_leaf_query(const
TSearchClause& clause,
*out = builder.build();
}
} else {
- if (QueryHelper::is_simple_phrase(term_infos)) {
- *out = std::make_shared<query_v2::PhraseQuery>(context,
field_wstr, term_infos);
+ if (QueryHelper::is_simple_phrase(phrase_term_infos)) {
+ *out = std::make_shared<query_v2::PhraseQuery>(context,
field_wstr,
+
phrase_term_infos);
} else {
*out =
std::make_shared<query_v2::MultiPhraseQuery>(context, field_wstr,
-
term_infos);
+
phrase_term_infos);
}
}
diff --git a/regression-test/data/inverted_index_p0/test_pinyin_phrase.out
b/regression-test/data/inverted_index_p0/test_pinyin_phrase.out
new file mode 100644
index 00000000000..fb46d776bf4
--- /dev/null
+++ b/regression-test/data/inverted_index_p0/test_pinyin_phrase.out
@@ -0,0 +1,18 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sql_1 --
+1 合作高峰论坛
+2 合作伙伴关系
+4 合作
+
+-- !sql_2 --
+1 合作高峰论坛
+3 高峰论坛会议
+
+-- !sql_3 --
+1 合作高峰论坛
+
+-- !sql_4 --
+2 合作伙伴关系
+
+-- !sql_5 --
+
diff --git a/regression-test/suites/inverted_index_p0/test_pinyin_phrase.groovy
b/regression-test/suites/inverted_index_p0/test_pinyin_phrase.groovy
new file mode 100644
index 00000000000..a766c1e5512
--- /dev/null
+++ b/regression-test/suites/inverted_index_p0/test_pinyin_phrase.groovy
@@ -0,0 +1,73 @@
+// 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.
+
+suite("test_pinyin_phrase", "p0") {
+ def indexTbName = "test_pinyin_phrase_table"
+
+ sql """ set enable_match_without_inverted_index = false """
+
+ // Create pinyin analyzer
+ sql """
+ CREATE INVERTED INDEX ANALYZER IF NOT EXISTS cp_test
+ PROPERTIES (
+ "tokenizer" = "pinyin"
+ );
+ """
+
+ sql """ select sleep(10) """
+
+ // Drop table if exists
+ sql "DROP TABLE IF EXISTS ${indexTbName}"
+
+ // Create table with inverted index using pinyin analyzer
+ sql """
+ CREATE TABLE ${indexTbName} (
+ `a` bigint NOT NULL AUTO_INCREMENT(1),
+ `ch` text NULL,
+ INDEX idx_ch (`ch`) USING INVERTED PROPERTIES(
+ "analyzer" = "cp_test",
+ "support_phrase" = "true"
+ )
+ ) ENGINE=OLAP
+ DUPLICATE KEY(`a`)
+ DISTRIBUTED BY RANDOM BUCKETS 1
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1"
+ );
+ """
+
+ // Insert test data
+ sql """ INSERT INTO ${indexTbName} VALUES (1, "合作高峰论坛"); """
+ sql """ INSERT INTO ${indexTbName} VALUES (2, "合作伙伴关系"); """
+ sql """ INSERT INTO ${indexTbName} VALUES (3, "高峰论坛会议"); """
+ sql """ INSERT INTO ${indexTbName} VALUES (4, "合作"); """
+
+ try {
+ sql "sync"
+ sql """ set enable_common_expr_pushdown = true; """
+
+ qt_sql_1 """ SELECT a, ch FROM ${indexTbName} WHERE search('ch:"合作"')
ORDER BY a; """
+ qt_sql_2 """ SELECT a, ch FROM ${indexTbName} WHERE
search('ch:"高峰论坛"') ORDER BY a; """
+ qt_sql_3 """ SELECT a, ch FROM ${indexTbName} WHERE
search('ch:"合作高峰"') ORDER BY a; """
+ qt_sql_4 """ SELECT a, ch FROM ${indexTbName} WHERE search('ch:"伙伴"')
ORDER BY a; """
+ qt_sql_5 """ SELECT a, ch FROM ${indexTbName} WHERE search('ch:"不存在"')
ORDER BY a; """
+
+ } finally {
+ // Cleanup
+ sql "DROP TABLE IF EXISTS ${indexTbName}"
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]