Skip to content

Commit bdde929

Browse files
airborne12claude
andcommitted
[fix](be) Score regexp and wildcard patterns with a constant like Elasticsearch
### What problem does this PR solve? Issue Number: None Related PR: #69052 Problem Summary: score() of pattern queries disagrees with Elasticsearch and with itself: -- 'Inverted indexes are suitable for full text search', -- 'The parser splits text into multiple terms', ... SELECT score() FROM document WHERE SEARCH('content:/.*ext/'); -- BM25 sum SELECT score() FROM document WHERE SEARCH('content:*ext'); -- BM25 sum SELECT score() FROM document WHERE SEARCH('content:te*'); -- 1 SELECT score() FROM document WHERE content MATCH_REGEXP 'ext'; -- 0 Elasticsearch scores a query_string /regexp/, wildcard or prefix, and a regexp, wildcard or prefix query, with a constant 1 per matching row (default rewrite constant_score_blended); measured on 9.5.5 with the rows above: 1.0 for both matching rows. Only an explicit "rewrite": "scoring_boolean" sums the BM25 of the expanded terms. Next to a scored clause in a bool must, a regexp adds exactly 1. #69052 made SEARCH regexp and wildcard sum the BM25 of every expanded term, i.e. scoring_boolean always on, while prefix stayed constant. That sum also takes idf and avgdl from the current segment, not from the tablet statistics MATCH uses: two inserts of the same text scored 0.2876821 and 1.3862942 for identical 'apple' rows, while MATCH 'apple' scored 0.6931471 for both. MATCH_REGEXP never requested a scoring context, so it scored 0 like a filter. Fix: 1. Revert the scoring part of #69052: ExpandWeight scores every pattern with the constant scorer again. The test fixture extensions that #69051 built on are kept. 2. MATCH_REGEXP requests scoring on every index; the regexp expansion then publishes the constant 1. The MATCH statistics collector skips it, since a constant reads no statistics and the pattern is not text to analyze. ### Release note score() of SEARCH regexp and wildcard clauses is a constant 1 per matching row again, like prefix clauses and Elasticsearch's default. score() of MATCH_REGEXP is 1 instead of 0. ### Check List (For Author) - Test: Regression test / Unit Test / Manual test - Regression test: new search/test_search_score_pattern_constant (V2/V3/SNII, two segments, keyword and analyzed fields; identical on all three formats); 24 existing score suites in inverted_index_p0, search and variant_p0 pass unchanged - Unit Test: 477 tests (IndexReaderHelperTest, CollectionStatistics*, regexp/wildcard/prefix engine tests restored by the revert, FunctionSearchTest, SNII query tests). Mutation checks: the gate test fails without the gate change, the collector test fails without the regexp skip - Manual test: Elasticsearch 9.5.5 on the same rows for every query shape above; two-segment table now scores 1 for every pattern hit - Built and run on master 62e3d81 plus this change: the current master tip does not compile (function_datasketches_hll.cpp after #69679), and none of the files touched here changed in between - Behavior changed: Yes. SEARCH regexp/wildcard scores and MATCH_REGEXP scores change as described in the release note. - Does this need documentation: No Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c285974 commit bdde929

13 files changed

Lines changed: 325 additions & 197 deletions

File tree

‎be/src/storage/index/index_reader_helper.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ bool can_score_match(const TabletIndex* index_meta) {
3636

3737
bool IndexReaderHelper::is_need_similarity_score(InvertedIndexQueryType query_type,
3838
const TabletIndex* index_meta) {
39+
// A regexp scores a constant 1 per matching row, as an Elasticsearch regexp query does in
40+
// query context. The constant reads no statistics, norms or positions, so every index can
41+
// score it: body MATCH 'apple' AND body MATCH_REGEXP 'ap.*' adds 1 to the apple score.
42+
if (query_type == InvertedIndexQueryType::MATCH_REGEXP_QUERY) {
43+
return true;
44+
}
3945
return (query_type == InvertedIndexQueryType::MATCH_ANY_QUERY ||
4046
query_type == InvertedIndexQueryType::MATCH_ALL_QUERY ||
4147
query_type == InvertedIndexQueryType::MATCH_PHRASE_QUERY ||
@@ -45,6 +51,10 @@ bool IndexReaderHelper::is_need_similarity_score(InvertedIndexQueryType query_ty
4551

4652
bool IndexReaderHelper::is_need_similarity_score(TExprOpcode::type query_type,
4753
const TabletIndex* index_meta) {
54+
// See the InvertedIndexQueryType overload: a regexp scores a constant on every index.
55+
if (query_type == TExprOpcode::MATCH_REGEXP) {
56+
return true;
57+
}
4858
return (query_type == TExprOpcode::MATCH_ANY || query_type == TExprOpcode::MATCH_ALL ||
4959
query_type == TExprOpcode::MATCH_PHRASE ||
5060
query_type == TExprOpcode::MATCH_PHRASE_PREFIX) &&

‎be/src/storage/index/inverted/query/engine/expand_query/expand_query.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ class ExpandQuery : public Query {
3838
_pattern(std::move(pattern)) {}
3939
~ExpandQuery() override = default;
4040

41-
WeightPtr weight(bool enable_scoring) override {
42-
return std::make_shared<ExpandWeight>(_context, _field, _kind, _pattern, enable_scoring);
41+
// Scores are constant, so scoring changes nothing.
42+
WeightPtr weight(bool /*enable_scoring*/) override {
43+
return std::make_shared<ExpandWeight>(_context, _field, _kind, _pattern);
4344
}
4445

4546
private:

‎be/src/storage/index/inverted/query/engine/expand_query/expand_weight.cpp‎

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "storage/index/inverted/query/engine/expand_query/expand_weight.h"
1919

20-
#include <cmath>
2120
#include <memory>
2221
#include <roaring/roaring.hh>
2322
#include <vector>
@@ -26,14 +25,10 @@
2625
#include "storage/index/inverted/query/engine/bit_set_query/bit_set_scorer.h"
2726
#include "storage/index/inverted/query/engine/const_score_query/const_score_scorer.h"
2827
#include "storage/index/inverted/query/engine/nullable_scorer.h"
29-
#include "storage/index/inverted/query/engine/score_combiner.h"
30-
#include "storage/index/inverted/query/engine/term_query/term_scorer.h"
31-
#include "storage/index/inverted/query/engine/union/buffered_union.h"
3228
#include "storage/index/inverted/query/exec/block_doc_set.h"
3329
#include "storage/index/inverted/query/exec/collect_postings.h"
3430
#include "storage/index/inverted/query/exec/roaring_docid_sink.h"
3531
#include "storage/index/inverted/query/exec/term_waves.h"
36-
#include "storage/index/inverted/query/scoring/bm25_similarity.h"
3732
#include "storage/index/inverted/query/spi/postings_cursor.h"
3833

3934
namespace doris::segment_v2::inverted_index::query_v2 {
@@ -63,15 +58,11 @@ Status collect_expanded_rows(index_query::IndexSource& source, index_query::Term
6358
}
6459

6560
ExpandWeight::ExpandWeight(IndexQueryContextPtr context, std::wstring field,
66-
index_query::TermPatternKind kind, std::string pattern,
67-
bool enable_scoring)
61+
index_query::TermPatternKind kind, std::string pattern)
6862
: _context(std::move(context)),
6963
_field(std::move(field)),
7064
_kind(kind),
71-
_pattern(std::move(pattern)),
72-
// Prefix and phrase-edge expansions retain their constant-score behavior.
73-
_enable_scoring(enable_scoring && (kind == index_query::TermPatternKind::kRegexp ||
74-
kind == index_query::TermPatternKind::kWildcard)) {}
65+
_pattern(std::move(pattern)) {}
7566

7667
std::shared_ptr<roaring::Roaring> ExpandWeight::_rows(const QueryExecutionContext& context,
7768
const std::string& binding_key,
@@ -94,68 +85,12 @@ std::shared_ptr<roaring::Roaring> ExpandWeight::_rows(const QueryExecutionContex
9485

9586
ScorerPtr ExpandWeight::scorer(const QueryExecutionContext& context,
9687
const std::string& binding_key) {
97-
// The listing fast path discards term frequencies, so scored patterns need term scorers.
98-
if (_enable_scoring) {
99-
return make_nullable_scorer(_scored_terms(context, binding_key),
100-
logical_field_or_fallback(context, binding_key, _field),
101-
context.null_resolver);
102-
}
10388
auto scorer = std::make_shared<ConstScoreScorer<BitSetScorerPtr>>(
10489
std::make_shared<BitSetScorer>(_rows(context, binding_key, nullptr)));
10590
return make_nullable_scorer(scorer, logical_field_or_fallback(context, binding_key, _field),
10691
context.null_resolver);
10792
}
10893

109-
ScorerPtr ExpandWeight::_scored_terms(const QueryExecutionContext& context,
110-
const std::string& binding_key) {
111-
index_query::TermPattern pattern;
112-
THROW_IF_ERROR(index_query::TermPattern::create(_kind, _pattern, &pattern));
113-
auto source = lookup_source(_field, context, binding_key);
114-
// An unbound field has no postings and contributes no matches.
115-
if (source == nullptr) {
116-
return std::make_shared<EmptyScorer>();
117-
}
118-
std::vector<std::string> terms;
119-
THROW_IF_ERROR(source->expand_terms(
120-
pattern, index_query::expansion_limit(_kind, index_query::max_expansions(*_context)),
121-
&terms));
122-
// A valid pattern may match no dictionary terms.
123-
if (terms.empty()) {
124-
return std::make_shared<EmptyScorer>();
125-
}
126-
// Expansion terms are absent from collection statistics; use the bound source's statistics.
127-
index_query::IndexScoringStats stats;
128-
THROW_IF_ERROR(source->scoring_stats(&stats));
129-
DORIS_CHECK_GT(stats.doc_count, 0);
130-
// Docs-only SNII still reports its physical token count. Only legacy sources without
131-
// that metadata report zero, so use unit average length only for those sources.
132-
const uint64_t token_count = stats.token_count != 0 ? stats.token_count : stats.doc_count;
133-
const float avgdl = static_cast<float>(token_count) / stats.doc_count;
134-
DORIS_CHECK_GT(avgdl, 0.0F);
135-
std::vector<ScorerPtr> scorers;
136-
scorers.reserve(terms.size());
137-
auto logical_field = logical_field_or_fallback(context, binding_key, _field);
138-
for (const auto& term : terms) {
139-
uint64_t doc_freq = 0;
140-
THROW_IF_ERROR(source->doc_freq(term, &doc_freq));
141-
// The immutable source just enumerated this term and must have its postings.
142-
DCHECK_GT(doc_freq, 0);
143-
const auto idf = static_cast<float>(std::log1p(
144-
(static_cast<double>(stats.doc_count) - doc_freq + 0.5) / (doc_freq + 0.5)));
145-
auto similarity = std::make_shared<BM25Similarity>(idf, avgdl);
146-
auto postings = open_postings(*source, term, /*positions=*/false, /*enable_scoring=*/true,
147-
similarity);
148-
DCHECK(postings != nullptr);
149-
scorers.emplace_back(std::make_shared<TermScorer>(std::move(postings),
150-
std::move(similarity), logical_field));
151-
}
152-
// One expanded term needs no union; multiple terms add their per-document BM25 scores.
153-
if (scorers.size() == 1) {
154-
return std::move(scorers.front());
155-
}
156-
return make_buffered_union(scorers, std::make_shared<SumCombiner>());
157-
}
158-
15994
index_query::TruthSet ExpandWeight::listed_rows(const QueryExecutionContext& context,
16095
const std::string& binding_key,
16196
const roaring::Roaring* candidates) {

‎be/src/storage/index/inverted/query/engine/expand_query/expand_weight.h‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,30 @@ Status collect_expanded_rows(index_query::IndexSource& source, index_query::Term
2929
int32_t max_expansions, const roaring::Roaring* candidates,
3030
roaring::Roaring* rows);
3131

32-
// Every document that holds an expanded term; scored regexp and wildcard clauses sum BM25.
32+
// Every document that holds a term the pattern expands to, with a constant score.
3333
class ExpandWeight : public Weight {
3434
public:
3535
ExpandWeight(IndexQueryContextPtr context, std::wstring field,
36-
index_query::TermPatternKind kind, std::string pattern,
37-
bool enable_scoring = false);
36+
index_query::TermPatternKind kind, std::string pattern);
3837
~ExpandWeight() override = default;
3938

4039
ScorerPtr scorer(const QueryExecutionContext& context, const std::string& binding_key) override;
4140

4241
bool lists_rows(const QueryExecutionContext&, const std::string&) const override {
43-
return !_enable_scoring;
42+
return true;
4443
}
4544
index_query::TruthSet listed_rows(const QueryExecutionContext& context,
4645
const std::string& binding_key,
4746
const roaring::Roaring* candidates) override;
4847

4948
private:
50-
ScorerPtr _scored_terms(const QueryExecutionContext& context, const std::string& binding_key);
5149
std::shared_ptr<roaring::Roaring> _rows(const QueryExecutionContext& context,
5250
const std::string& binding_key,
5351
const roaring::Roaring* candidates);
5452
IndexQueryContextPtr _context;
5553
std::wstring _field;
5654
index_query::TermPatternKind _kind;
5755
std::string _pattern;
58-
bool _enable_scoring;
5956
};
6057

6158
} // namespace doris::segment_v2::inverted_index::query_v2

‎be/src/storage/index/inverted/reader/predicate_collector.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ Status MatchPredicateCollector::collect(RuntimeState* state, const TabletSchemaS
369369
!IndexReaderHelper::is_need_similarity_score(expr->op(), index_meta)) {
370370
return Status::OK();
371371
}
372+
// A regexp scores a constant and reads no statistics. Its value is a pattern, not text, so
373+
// analyzing it would collect statistics for made-up terms: 'ap.*' would become "ap".
374+
if (expr->op() == TExprOpcode::MATCH_REGEXP) {
375+
return Status::OK();
376+
}
372377

373378
DORIS_CHECK(analyzer_ctx->analyzer_provider != nullptr);
374379
auto options = DataTypeSerDe::get_default_format_options();

‎be/test/exprs/function/search/function_search_test.cpp‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include <gtest/gtest.h>
4141

4242
#include <chrono>
43-
#include <cmath>
4443
#include <initializer_list>
4544
#include <map>
4645
#include <memory>
@@ -1881,8 +1880,6 @@ TEST_F(FunctionSearchTest, TestBuildLeafQueryExecutesSelectedSniiWildcardReader)
18811880
std::make_shared<RecordingNativeInvertedIndexReader>(&decoy_meta, decoy_file_reader);
18821881
auto selected_reader = std::make_shared<RecordingNativeInvertedIndexReader>(
18831882
&selected_meta, selected_file_reader);
1884-
selected_reader->fake_source->set_doc_count(4);
1885-
selected_reader->fake_source->set_scoring_stats({.doc_count = 4, .token_count = 3});
18861883
selected_reader->fake_source->add("alpha", {0, 2});
18871884
selected_reader->fake_source->add("gamma", {1});
18881885
decoy_reader->fake_source->add("alpha", {1});
@@ -1931,8 +1928,7 @@ TEST_F(FunctionSearchTest, TestBuildLeafQueryExecutesSelectedSniiWildcardReader)
19311928
binding_key);
19321929
ASSERT_NE(nullptr, scorer);
19331930
EXPECT_EQ(0U, scorer->doc());
1934-
// The source has three tokens over four rows, even without stored norms.
1935-
EXPECT_NEAR(0.88F * std::log(2.0F), scorer->score(), 1e-6F);
1931+
EXPECT_FLOAT_EQ(1.0F, scorer->score());
19361932
expect_bitmap_eq(collect_docs(scorer), {0, 2});
19371933
// The pattern was lowercased by the selected analyzer and enumerated on the selected
19381934
// index only; a leading wildcard has no prefix to enumerate from.
@@ -2526,8 +2522,7 @@ static void search_snii_pattern(const std::map<std::string, std::string>& proper
25262522
ASSERT_TRUE(status.ok()) << status.to_string();
25272523
EXPECT_EQ(0, reader->query_calls) << value;
25282524
// The scorer enumerates the stem on the source; the reader itself is never asked.
2529-
// This helper checks normalization and routing, without requesting scoring statistics.
2530-
auto weight = query->weight(false);
2525+
auto weight = query->weight(true);
25312526
ASSERT_NE(nullptr, weight);
25322527
auto scorer = weight->scorer(build_variant_search_query_execution_context(4, resolver, nullptr),
25332528
binding_key);
@@ -2760,12 +2755,13 @@ TEST_F(FunctionSearchTest, TestSniiScoredLeafRanksByTheEngineBm25) {
27602755
}
27612756
}
27622757

2763-
// Scored wildcard leaves read frequencies and statistics through the unified source,
2764-
// even when the old reader query API publishes no per-document scores.
2765-
TEST_F(FunctionSearchTest, TestSniiNativeWildcardUsesSourceScoringStatistics) {
2758+
// A leaf for which the reader publishes no per-document score must keep the constant that the
2759+
// CLucene path also gives its own constant-score leaves, so that routing scored clauses through a
2760+
// new scorer does not quietly re-rank the unscored ones. The fake reader is what withholds the
2761+
// scores here, so this pins the "nothing published -> BitSetQuery -> 1.0" behaviour; it does not
2762+
// pin which query types the production is_need_similarity_score gate rejects.
2763+
TEST_F(FunctionSearchTest, TestSniiNativeLeafWithoutPublishedScoresKeepsConstantScore) {
27662764
SniiScoringFixture fixture(43, 4);
2767-
fixture.reader->fake_source->set_doc_count(4);
2768-
fixture.reader->fake_source->set_scoring_stats({.doc_count = 4, .token_count = 2});
27692765
fixture.reader->fake_source->add("alpha", {0, 2});
27702766

27712767
inverted_index::query_v2::QueryPtr query;
@@ -2782,8 +2778,7 @@ TEST_F(FunctionSearchTest, TestSniiNativeWildcardUsesSourceScoringStatistics) {
27822778
auto scorer = weight->scorer(exec_ctx, binding_key);
27832779
ASSERT_NE(nullptr, scorer);
27842780
EXPECT_EQ(0U, scorer->doc());
2785-
// avgdl = 2/4 and implicit length = 1: BM25 is idf * 2.2 / 3.1.
2786-
EXPECT_NEAR((2.2F / 3.1F) * std::log(2.0F), scorer->score(), 1e-6F);
2781+
EXPECT_FLOAT_EQ(1.0F, scorer->score());
27872782
expect_bitmap_eq(collect_docs(scorer), {0, 2});
27882783
}
27892784

‎be/test/storage/index/inverted/query/engine/prefix_query_test.cpp‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <CLucene.h>
1919
#include <gtest/gtest.h>
2020

21-
#include <cmath>
2221
#include <memory>
2322
#include <roaring/roaring.hh>
2423
#include <string>
@@ -33,8 +32,6 @@
3332
#include "storage/index/inverted/inverted_index_reader.h"
3433
#include "storage/index/inverted/query/engine/expand_query/expand_query.h"
3534
#include "storage/index/inverted/query/logical/node.h"
36-
#include "storage/index/inverted/query/scoring/bm25_similarity.h"
37-
#include "storage/index/inverted/query/scoring/collection_similarity.h"
3835
#include "storage/index/inverted/query/spi/fake_index_source.h"
3936
#include "storage/olap_common.h"
4037

@@ -495,8 +492,6 @@ TEST(ExpansionLeafTest, KeepsPatternLimitsAndLeavesRootCandidatesToTheCaller) {
495492
auto source = std::make_shared<index_query::testing::FakeIndexSource>();
496493
source->batches = batches;
497494
source->set_doc_count(10);
498-
// Scored regexp and wildcard leaves need statistics from their bound source.
499-
source->set_scoring_stats({.doc_count = 10, .token_count = 10});
500495
source->add("apple", {0, 4});
501496
source->add("application", {1});
502497
source->add("apply", {2, 4});
@@ -514,30 +509,12 @@ TEST(ExpansionLeafTest, KeepsPatternLimitsAndLeavesRootCandidatesToTheCaller) {
514509
expected.add(2);
515510
}
516511
for (const bool scoring : {false, true}) {
517-
context->collection_similarity =
518-
scoring ? std::make_shared<CollectionSimilarity>() : nullptr;
519512
auto result = std::make_shared<roaring::Roaring>();
520513
result->add(9);
521514
const auto status = run_leaf(context, L"content", leaf, &candidates, scoring,
522515
source, source->doc_count(), result);
523516
ASSERT_TRUE(status.ok()) << status;
524517
EXPECT_EQ(*result, expected) << pattern << " scoring=" << scoring;
525-
if (scoring) {
526-
const auto& scores = context->collection_similarity->_bm25_scores;
527-
EXPECT_EQ(scores.size(), expected.cardinality() - 1);
528-
const bool bm25 = kind == logical::ExpandKind::kWildcard ||
529-
kind == logical::ExpandKind::kRegexp;
530-
for (const auto& [doc, score] : scores) {
531-
// Row 9 predates this leaf and must not acquire a score from it.
532-
EXPECT_NE(doc, 9U);
533-
EXPECT_TRUE(expected.contains(doc));
534-
const float df = doc == 1 ? 1.0F : 2.0F;
535-
const float idf = std::log1p((10.0F - df + 0.5F) / (df + 0.5F));
536-
const float expected_score =
537-
bm25 ? BM25Similarity(idf, 1.0F).score(1.0F, 1) : 1.0F;
538-
EXPECT_FLOAT_EQ(score, expected_score) << pattern << " doc=" << doc;
539-
}
540-
}
541518
}
542519
}
543520
}

‎be/test/storage/index/inverted/query/engine/regexp_query_test.cpp‎

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,13 @@ class RegexpQueryV2Test : public testing::Test {
5050
st = io::global_local_filesystem()->create_directory(kTestDir);
5151
ASSERT_TRUE(st.ok()) << st;
5252
std::string field_name = "content";
53-
create_test_index(field_name, kTestDir,
54-
{"apple123", "apple456", "banana789",
55-
"test123abc", "pattern456", "regex999",
56-
"match123", "search456", "prefix123",
57-
"suffix789", "apple_test", "banana_data",
58-
"test_pattern", "data_regex", "apple_banana",
59-
"test_match", "pattern_test", "prefix_suffix",
60-
"abc123xyz", "def456ghi", "apple789 apple789 apple456"},
61-
"standard");
53+
create_test_index(
54+
field_name, kTestDir,
55+
{"apple123", "apple456", "banana789", "test123abc", "pattern456",
56+
"regex999", "match123", "search456", "prefix123", "suffix789",
57+
"apple_test", "banana_data", "test_pattern", "data_regex", "apple_banana",
58+
"test_match", "pattern_test", "prefix_suffix", "abc123xyz", "def456ghi"},
59+
"standard");
6260
}
6361

6462
void TearDown() override {
@@ -182,36 +180,6 @@ TEST_F(RegexpQueryV2Test, test_regexp_query_with_scoring) {
182180
ASSERT_NE(regexp_weight, nullptr);
183181
}
184182

185-
TEST_F(RegexpQueryV2Test, test_regexp_query_scores_matching_terms) {
186-
auto context = std::make_shared<IndexQueryContext>();
187-
context->collection_statistics = std::make_shared<CollectionStatistics>();
188-
context->collection_similarity = std::make_shared<CollectionSimilarity>();
189-
190-
auto* dir = FSDirectory::getDirectory(kTestDir.c_str());
191-
auto reader_holder = make_shared_reader(lucene::index::IndexReader::open(dir, true));
192-
ASSERT_NE(reader_holder, nullptr);
193-
194-
std::wstring field = StringHelper::to_wstring("content");
195-
auto query = std::make_shared<query_v2::ExpandQuery>(
196-
context, field, index_query::TermPatternKind::kRegexp, anchored("apple.*"));
197-
auto weight = query->weight(true);
198-
199-
query_v2::QueryExecutionContext exec_ctx;
200-
exec_ctx.segment_num_rows = reader_holder->maxDoc();
201-
exec_ctx.sources = {clucene_index_source(reader_holder, field, nullptr)};
202-
exec_ctx.field_sources.emplace(field, exec_ctx.sources.front());
203-
204-
auto scorer = weight->scorer(exec_ctx);
205-
ASSERT_EQ(scorer->seek(0), 0);
206-
float single_term_score = scorer->score();
207-
EXPECT_NE(single_term_score, 1.0F);
208-
uint32_t last_doc = reader_holder->maxDoc() - 1;
209-
ASSERT_EQ(scorer->seek(last_doc), last_doc);
210-
EXPECT_GT(scorer->score(), single_term_score);
211-
212-
_CLDECDELETE(dir);
213-
}
214-
215183
// Test regexp query execution
216184
TEST_F(RegexpQueryV2Test, test_regexp_query_execution) {
217185
auto context = std::make_shared<IndexQueryContext>();
@@ -660,7 +628,7 @@ TEST_F(RegexpQueryV2Test, test_whole_term_match_any_term) {
660628
doc = scorer->advance();
661629
}
662630

663-
EXPECT_EQ(result.cardinality(), 21);
631+
EXPECT_EQ(result.cardinality(), 20);
664632

665633
_CLDECDELETE(dir);
666634
}

0 commit comments

Comments
 (0)