xapian-core  2.0.0
valuerangepostlist.cc
Go to the documentation of this file.
1 
4 /* Copyright 2007,2008,2009,2010,2011,2013,2016,2017,2022,2025,2026 Olly Betts
5  * Copyright 2009 Lemur Consulting Ltd
6  * Copyright 2010 Richard Boulton
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, see
20  * <https://www.gnu.org/licenses/>.
21  */
22 
23 #include <config.h>
24 
25 #include "valuerangepostlist.h"
26 
27 #include "estimateop.h"
28 #include "omassert.h"
29 #include "str.h"
31 
32 using namespace std;
33 
35 {
36  delete valuelist;
37  if (estimate_op && (accepted || rejected)) {
38  // Only call report_range_ratio() if there are counts. During the
39  // building of the PostList tree we sometimes need to delete PostList
40  // objects and their associated EstimateOp and it's hard to arrange
41  // that they are always deleted in the correct order.
42  estimate_op->report_range_ratio(accepted, rejected);
43  }
44 }
45 
48 {
49  Assert(valuelist);
50  Assert(db);
51  return valuelist->get_docid();
52 }
53 
54 double
57  Xapian::termcount) const
58 {
59  Assert(db);
60  return 0;
61 }
62 
65 {
66  Assert(db);
67  return 0;
68 }
69 
70 double
72 {
73  Assert(db);
74  return 0;
75 }
76 
79 {
80  Assert(db);
81  return NULL;
82 }
83 
84 PostList *
86 {
87  Assert(db);
88  if (!valuelist) {
89  valuelist = db->open_value_list(slot);
90  valuelist->next();
91  if (estimate_op) estimate_op->report_first(valuelist->get_docid());
92  } else {
93  valuelist->next();
94  }
95  while (!valuelist->at_end()) {
96  const string & v = valuelist->get_value();
97  if (v >= begin && v <= end) {
98  ++accepted;
99  return NULL;
100  }
101  ++rejected;
102  valuelist->next();
103  }
104  db = NULL;
105  return NULL;
106 }
107 
108 PostList *
110 {
111  Assert(db);
112  if (!valuelist) valuelist = db->open_value_list(slot);
113  valuelist->skip_to(did);
114  while (!valuelist->at_end()) {
115  const string & v = valuelist->get_value();
116  if (v >= begin && v <= end) {
117  ++accepted;
118  return NULL;
119  }
120  ++rejected;
121  valuelist->next();
122  }
123  db = NULL;
124  return NULL;
125 }
126 
127 PostList *
128 ValueRangePostList::check(Xapian::docid did, double, bool &valid)
129 {
130  Assert(db);
131  AssertRelParanoid(did, <=, db->get_lastdocid());
132  if (!valuelist) valuelist = db->open_value_list(slot);
133  valid = valuelist->check(did);
134  if (!valid) {
135  return NULL;
136  }
137  const string & v = valuelist->get_value();
138  valid = (v >= begin && v <= end);
139  if (valid)
140  ++accepted;
141  else
142  ++rejected;
143  return NULL;
144 }
145 
146 bool
148 {
149  return (db == NULL);
150 }
151 
154 {
155  return 1;
156 }
157 
158 string
160 {
161  string desc = "ValueRangePostList(";
162  desc += str(slot);
163  desc += ", ";
164  description_append(desc, begin);
165  desc += ", ";
166  description_append(desc, end);
167  desc += ")";
168  return desc;
169 }
double recalc_maxweight()
Recalculate the upper bound on what get_weight() can return.
Xapian::termcount get_wdfdocmax() const
std::string get_description() const
Return a string description of this object.
PositionList * read_position_list()
Read the position list for the term in the current document and return a pointer to it (owned by the ...
Xapian::termcount count_matching_subqs() const
Count the number of leaf subqueries which match at the current position.
PostList * skip_to(Xapian::docid, double w_min)
Skip forward to the specified docid.
double get_weight(Xapian::termcount doclen, Xapian::termcount unique_terms, Xapian::termcount wdfdocmax) const
Return the weight contribution for the current position.
PostList * check(Xapian::docid did, double w_min, bool &valid)
Check if the specified docid occurs in this postlist.
bool at_end() const
Return true if the current position is past the last entry in this list.
Xapian::docid get_docid() const
Return the current docid.
Abstract base class for postlists.
Definition: postlist.h:40
PostList * next()
Advance the current position to the next document in the postlist.
Definition: postlist.h:168
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:32
Append a string to an object description, escaping invalid UTF-8.
Calculated bounds on and estimate of number of matches.
string str(int value)
Convert int to std::string.
Definition: str.cc:91
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
Various assertion macros.
#define AssertRelParanoid(A, REL, B)
Definition: omassert.h:130
#define Assert(COND)
Definition: omassert.h:122
Convert types to std::string.
void description_append(std::string &desc, std::string_view s)
Definition: unittest.cc:105
Return document ids matching a range test on a specified doc value.