xapian-core  2.0.0
andpostlist.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2009,2011,2012,2015,2017 Olly Betts
5  * Copyright (C) 2009 Lemur Consulting Ltd
6  *
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.
11  *
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.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see
19  * <https://www.gnu.org/licenses/>.
20  */
21 
22 #include <config.h>
23 
24 #include "andpostlist.h"
25 
26 #include "omassert.h"
27 #include "debuglog.h"
28 
29 using namespace std;
30 
31 void
33 {
34  plist = new PostList * [n_kids];
35  try {
36  max_wt = new double [n_kids]();
37  } catch (...) {
38  delete [] plist;
39  plist = NULL;
40  throw;
41  }
42 }
43 
45 {
46  if (plist) {
47  for (size_t i = 0; i < n_kids; ++i) {
48  delete plist[i];
49  }
50  delete [] plist;
51  }
52  delete [] max_wt;
53 }
54 
57 {
58  return did;
59 }
60 
61 double
63  Xapian::termcount unique_terms,
64  Xapian::termcount wdfdocmax) const
65 {
66  Assert(did);
67  double result = 0;
68  for (size_t i = 0; i < n_kids; ++i) {
69  result += plist[i]->get_weight(doclen, unique_terms, wdfdocmax);
70  }
71  return result;
72 }
73 
74 bool
76 {
77  return (did == 0);
78 }
79 
80 double
82 {
83  max_total = 0.0;
84  for (size_t i = 0; i < n_kids; ++i) {
85  double new_max = plist[i]->recalc_maxweight();
86  max_wt[i] = new_max;
87  max_total += new_max;
88  }
89  return max_total;
90 }
91 
92 PostList *
94 {
95 advanced_plist0:
96  if (plist[0]->at_end()) {
97  did = 0;
98  return NULL;
99  }
100  did = plist[0]->get_docid();
101  for (size_t i = 1; i < n_kids; ++i) {
102  bool valid;
103  check_helper(i, did, w_min, valid);
104  if (!valid) {
105  next_helper(0, w_min);
106  goto advanced_plist0;
107  }
108  if (plist[i]->at_end()) {
109  did = 0;
110  return NULL;
111  }
112  Xapian::docid new_did = plist[i]->get_docid();
113  if (new_did != did) {
114  skip_to_helper(0, new_did, w_min);
115  goto advanced_plist0;
116  }
117  }
118  return NULL;
119 }
120 
121 PostList *
122 AndPostList::next(double w_min)
123 {
124  next_helper(0, w_min);
125  return find_next_match(w_min);
126 }
127 
128 PostList *
129 AndPostList::skip_to(Xapian::docid did_min, double w_min)
130 {
131  skip_to_helper(0, did_min, w_min);
132  return find_next_match(w_min);
133 }
134 
135 void
137 {
138  plist[0]->get_docid_range(first, last);
139  for (size_t i = 1; i != n_kids; ++i) {
140  Xapian::docid f = first, l = last;
141  plist[i]->get_docid_range(f, l);
142  first = max(first, f);
143  last = min(last, l);
144  if (last < first) break;
145  }
146 }
147 
148 std::string
150 {
151  string desc("(");
152  desc += plist[0]->get_description();
153  for (size_t i = 1; i < n_kids; ++i) {
154  desc += " AND ";
155  desc += plist[i]->get_description();
156  }
157  desc += ')';
158  return desc;
159 }
160 
163 {
164  Xapian::termcount totwdf = 0;
165  for (size_t i = 0; i < n_kids; ++i) {
166  totwdf += plist[i]->get_wdf();
167  }
168  return totwdf;
169 }
170 
173 {
174  Xapian::termcount total = 0;
175  for (size_t i = 0; i < n_kids; ++i) {
176  total += plist[i]->count_matching_subqs();
177  }
178  return total;
179 }
180 
181 void
183 {
184  for (size_t i = 0; i < n_kids; ++i) {
185  plist[i]->gather_position_lists(orposlist);
186  }
187 }
N-way AND postlist.
Xapian::termcount count_matching_subqs() const
Count the number of leaf subqueries which match at the current position.
Definition: andpostlist.cc:172
double get_weight(Xapian::termcount doclen, Xapian::termcount unique_terms, Xapian::termcount wdfdocmax) const
Return the weight contribution for the current position.
Definition: andpostlist.cc:62
PostList * find_next_match(double w_min)
Advance the sublists to the next match.
Definition: andpostlist.cc:93
Xapian::docid get_docid() const
Return the current docid.
Definition: andpostlist.cc:56
PostList * skip_to(Xapian::docid, double w_min)
Skip forward to the specified docid.
Definition: andpostlist.cc:129
void get_docid_range(Xapian::docid &first, Xapian::docid &last) const
Get the bounds on the range of docids this PostList can return.
Definition: andpostlist.cc:136
void gather_position_lists(OrPositionList *orposlist)
Gather PositionList* objects for a subtree.
Definition: andpostlist.cc:182
double recalc_maxweight()
Recalculate the upper bound on what get_weight() can return.
Definition: andpostlist.cc:81
Xapian::termcount get_wdf() const
Get the within-document frequency.
Definition: andpostlist.cc:162
bool at_end() const
Return true if the current position is past the last entry in this list.
Definition: andpostlist.cc:75
void allocate_plist_and_max_wt()
Allocate plist and max_wt arrays of n_kids each.
Definition: andpostlist.cc:32
std::string get_description() const
Return a string description of this object.
Definition: andpostlist.cc:149
Abstract base class for postlists.
Definition: postlist.h:40
virtual Xapian::docid get_docid() const =0
Return the current docid.
PostList * next()
Advance the current position to the next document in the postlist.
Definition: postlist.h:168
Debug logging macros.
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 Assert(COND)
Definition: omassert.h:122