1 /** @file postlisttree.h
2 * @brief Class for managing a tree of PostList objects
4 /* Copyright 2017 Olly Betts
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef XAPIAN_INCLUDED_POSTLISTTREE_H
22 #define XAPIAN_INCLUDED_POSTLISTTREE_H
24 #include "api/postlist.h"
29 bool use_cached_max_weight
= false;
40 void set_postlist(PostList
* pl_
) {
44 double recalc_maxweight() {
45 if (!use_cached_max_weight
) {
46 use_cached_max_weight
= true;
47 max_weight
= pl
->recalc_maxweight();
53 use_cached_max_weight
= false;
56 Xapian::doccount
get_termfreq_min() const {
57 return pl
->get_termfreq_min();
60 Xapian::doccount
get_termfreq_max() const {
61 return pl
->get_termfreq_max();
64 Xapian::doccount
get_termfreq_est() const {
65 return pl
->get_termfreq_est();
68 Xapian::docid
get_docid() const {
69 return pl
->get_docid();
72 double get_weight() const {
73 return pl
->get_weight();
76 const std::string
* get_sort_key() const {
77 return pl
->get_sort_key();
80 const std::string
* get_collapse_key() const {
81 return pl
->get_collapse_key();
84 /// Return false if we're done.
85 bool next(double w_min
) {
86 if (rare(!use_cached_max_weight
) && w_min
> 0.0) {
87 if (recalc_maxweight() < w_min
) {
88 // We can't now achieve w_min so we're done.
93 PostList
* result
= pl
->next(w_min
);
98 if (rare(pl
->at_end()))
101 if (rare(result
) && w_min
> 0.0) {
102 use_cached_max_weight
= false;
103 if (recalc_maxweight() < w_min
) {
104 // We can't now achieve w_min so we're done.
112 Xapian::termcount
count_matching_subqs() const {
113 return pl
->count_matching_subqs();
116 std::string
get_description() const {
117 return pl
->get_description();
121 #endif // XAPIAN_INCLUDED_POSTLISTTREE_H