@@ -49,19 +49,23 @@ class SegmentPostings : public Postings {
4949public:
5050 using IterVariant = std::variant<std::monostate, TermDocsPtr, TermPositionsPtr>;
5151
52- explicit SegmentPostings (TermDocsPtr iter, bool enable_scoring, SimilarityPtr similarity)
52+ explicit SegmentPostings (TermDocsPtr iter, bool enable_scoring, SimilarityPtr similarity,
53+ bool has_norms = true )
5354 : _iter(std::move(iter)),
5455 _enable_scoring(enable_scoring),
56+ _has_norms(has_norms),
5557 _similarity(std::move(similarity)) {
5658 if (auto * p = std::get_if<TermDocsPtr>(&_iter)) {
5759 _raw_iter = p->get ();
5860 }
5961 _init_doc ();
6062 }
6163
62- explicit SegmentPostings (TermPositionsPtr iter, bool enable_scoring, SimilarityPtr similarity)
64+ explicit SegmentPostings (TermPositionsPtr iter, bool enable_scoring, SimilarityPtr similarity,
65+ bool has_norms = true )
6366 : _iter(std::move(iter)),
6467 _enable_scoring(enable_scoring),
68+ _has_norms(has_norms),
6569 _has_positions(true ),
6670 _similarity(std::move(similarity)) {
6771 if (auto * p = std::get_if<TermPositionsPtr>(&_iter)) {
@@ -120,7 +124,7 @@ class SegmentPostings : public Postings {
120124 }
121125
122126 uint32_t norm () const override {
123- if (!_enable_scoring || !_block.norm_many || _cursor == 0 ) {
127+ if (!_enable_scoring || !_has_norms || ! _block.norm_many || _cursor == 0 ) {
124128 return 1 ;
125129 }
126130 return (*_block.norm_many )[_cursor - 1 ];
@@ -194,24 +198,28 @@ class SegmentPostings : public Postings {
194198 return _block_max_score_cache;
195199 }
196200 int32_t max_block_freq = _raw_iter->getMaxBlockFreq ();
197- int32_t max_block_norm = _raw_iter->getMaxBlockNorm ();
201+ int32_t max_block_norm = _has_norms ? _raw_iter->getMaxBlockNorm () : 1 ;
198202 if (max_block_freq >= 0 && max_block_norm >= 0 ) {
199203 _block_max_score_cache = _similarity->score (static_cast <float >(max_block_freq),
200204 static_cast <int64_t >(max_block_norm));
201205 return _block_max_score_cache;
202206 }
203- return _similarity-> max_score ();
207+ return max_score ();
204208 }
205209
206210 float max_score () const {
207211 if (!_enable_scoring || !_similarity) {
208212 return std::numeric_limits<float >::max ();
209213 }
214+ // Missing norms have a fixed length of one, including for WAND bounds.
215+ if (!_has_norms) {
216+ return _similarity->score (std::numeric_limits<float >::max (), 1 );
217+ }
210218 return _similarity->max_score ();
211219 }
212220
213221 int32_t max_block_freq () const { return _raw_iter->getMaxBlockFreq (); }
214- int32_t max_block_norm () const { return _raw_iter->getMaxBlockNorm (); }
222+ int32_t max_block_norm () const { return _has_norms ? _raw_iter->getMaxBlockNorm () : 1 ; }
215223
216224private:
217225 bool _refill () {
@@ -241,6 +249,7 @@ class SegmentPostings : public Postings {
241249 lucene::index::TermDocs* _raw_iter = nullptr ;
242250 uint32_t _doc = TERMINATED ;
243251 bool _enable_scoring = false ;
252+ bool _has_norms = true ;
244253 bool _has_positions = false ;
245254
246255 DocRange _block;
@@ -253,13 +262,15 @@ class SegmentPostings : public Postings {
253262using SegmentPostingsPtr = std::shared_ptr<SegmentPostings>;
254263
255264inline SegmentPostingsPtr make_segment_postings (TermDocsPtr iter, bool enable_scoring,
256- SimilarityPtr similarity) {
257- return std::make_shared<SegmentPostings>(std::move (iter), enable_scoring, similarity);
265+ SimilarityPtr similarity, bool has_norms = true ) {
266+ return std::make_shared<SegmentPostings>(std::move (iter), enable_scoring, similarity,
267+ has_norms);
258268}
259269
260270inline SegmentPostingsPtr make_segment_postings (TermPositionsPtr iter, bool enable_scoring,
261- SimilarityPtr similarity) {
262- return std::make_shared<SegmentPostings>(std::move (iter), enable_scoring, similarity);
271+ SimilarityPtr similarity, bool has_norms = true ) {
272+ return std::make_shared<SegmentPostings>(std::move (iter), enable_scoring, similarity,
273+ has_norms);
263274}
264275
265276} // namespace doris::segment_v2::inverted_index::query_v2
0 commit comments