2 * @brief N-way OR postlist with wt=max(wt_i)
4 /* Copyright (C) 2007,2009,2010,2011,2012,2013,2014,2017 Olly Betts
5 * Copyright (C) 2009 Lemur Consulting Ltd
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "maxpostlist.h"
31 MaxPostList::~MaxPostList()
34 for (size_t i
= 0; i
< n_kids
; ++i
) {
42 MaxPostList::get_docid() const
48 MaxPostList::get_weight(Xapian::termcount doclen
,
49 Xapian::termcount unique_terms
,
50 Xapian::termcount wdfdocmax
) const
54 for (size_t i
= 0; i
< n_kids
; ++i
) {
55 if (plist
[i
]->get_docid() == did
)
56 res
= max(res
, plist
[i
]->get_weight(doclen
,
64 MaxPostList::at_end() const
70 MaxPostList::recalc_maxweight()
72 double result
= plist
[0]->recalc_maxweight();
73 for (size_t i
= 1; i
< n_kids
; ++i
) {
74 result
= max(result
, plist
[i
]->recalc_maxweight());
80 MaxPostList::next(double w_min
)
82 Xapian::docid old_did
= did
;
84 for (size_t i
= 0; i
< n_kids
; UNSIGNED_OVERFLOW_OK(++i
)) {
85 Xapian::docid cur_did
= 0;
87 cur_did
= plist
[i
]->get_docid();
88 if (cur_did
<= old_did
) {
90 if (old_did
== 0 || cur_did
== old_did
) {
91 res
= plist
[i
]->next(w_min
);
93 res
= plist
[i
]->skip_to(old_did
+ 1, w_min
);
100 if (plist
[i
]->at_end()) {
101 // erase_sublist(i) shuffles down i+1, etc down one index, so
102 // the next sublist to deal with is also at index i, unless
103 // this was the last index. We deal with this by decrementing
104 // i here and it'll be incremented by the loop, but this may
105 // underflow (which is OK because i is an unsigned type).
106 erase_sublist(UNSIGNED_OVERFLOW_OK(i
--));
111 matcher
->force_recalc();
113 cur_did
= plist
[i
]->get_docid();
116 if (did
== 0 || cur_did
< did
) {
130 MaxPostList::skip_to(Xapian::docid did_min
, double w_min
)
132 Xapian::docid old_did
= did
;
134 for (size_t i
= 0; i
< n_kids
; ++i
) {
135 Xapian::docid cur_did
= 0;
137 cur_did
= plist
[i
]->get_docid();
138 if (cur_did
< did_min
) {
139 PostList
* res
= plist
[i
]->skip_to(did_min
, w_min
);
145 if (plist
[i
]->at_end()) {
151 matcher
->force_recalc();
153 cur_did
= plist
[i
]->get_docid();
156 if (did
== 0 || cur_did
< did
) {
170 MaxPostList::get_docid_range(Xapian::docid
& first
, Xapian::docid
& last
) const
172 plist
[0]->get_docid_range(first
, last
);
173 for (size_t i
= 1; i
!= n_kids
; ++i
) {
174 Xapian::docid f
= 1, l
= Xapian::docid(-1);
175 plist
[i
]->get_docid_range(f
, l
);
176 first
= min(first
, f
);
182 MaxPostList::get_description() const
185 desc
+= plist
[0]->get_description();
186 for (size_t i
= 1; i
< n_kids
; ++i
) {
188 desc
+= plist
[i
]->get_description();
195 MaxPostList::get_wdf() const
197 Xapian::termcount totwdf
= 0;
198 for (size_t i
= 0; i
< n_kids
; ++i
) {
199 if (plist
[i
]->get_docid() == did
)
200 totwdf
+= plist
[i
]->get_wdf();
206 MaxPostList::count_matching_subqs() const