xapian-core  1.4.25
decvalwtsource.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2009 Lemur Consulting Ltd
5  * Copyright (C) 2011,2012,2015,2016 Olly Betts
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <config.h>
23 
24 #include "xapian/postingsource.h"
25 #include "xapian/error.h"
26 #include "net/length.h"
27 
28 using namespace Xapian;
29 
31  Xapian::valueno slot_,
32  Xapian::docid range_start_,
33  Xapian::docid range_end_)
35  range_start(range_start_),
36  range_end(range_end_)
37 {
38 }
39 
40 double
42  return curr_weight;
43 }
44 
48  range_end);
49 }
50 
51 std::string
53  return "Xapian::DecreasingValueWeightPostingSource";
54 }
55 
56 std::string
58  std::string result;
59  result += encode_length(get_slot());
60  result += encode_length(range_start);
61  result += encode_length(range_end);
62  return result;
63 }
64 
67  const char * pos = s.data();
68  const char * end = pos + s.size();
69  Xapian::valueno new_slot;
70  Xapian::docid new_range_start, new_range_end;
71  decode_length(&pos, end, new_slot);
72  decode_length(&pos, end, new_range_start);
73  decode_length(&pos, end, new_range_end);
74  if (pos != end)
75  throw Xapian::NetworkError("Junk at end of serialised "
76  "DecreasingValueWeightPostingSource");
77  return new DecreasingValueWeightPostingSource(new_slot, new_range_start,
78  new_range_end);
79 }
80 
81 void
84  if (range_end == 0 || get_database().get_doccount() <= range_end)
85  items_at_end = false;
86  else
87  items_at_end = true;
88 }
89 
90 void
92 {
96  if (docid >= range_start && (range_end == 0 || docid <= range_end)) {
97  if (items_at_end) {
98  if (curr_weight < min_wt) {
99  // skip to end of range.
103  }
104  } else {
105  if (curr_weight < min_wt) {
106  // terminate early.
107  done();
108  } else {
109  // Update max_weight.
111  }
112  }
113  }
114 }
115 
116 void
118  if (get_maxweight() < min_wt) {
119  done();
120  return;
121  }
123  skip_if_in_range(min_wt);
124 }
125 
126 void
128  double min_wt) {
129  if (get_maxweight() < min_wt) {
130  done();
131  return;
132  }
134  skip_if_in_range(min_wt);
135 }
136 
137 bool
139  double min_wt) {
140  if (get_maxweight() < min_wt) {
141  done();
142  return true;
143  }
144  bool valid = Xapian::ValueWeightPostingSource::check(min_docid, min_wt);
145  if (valid) {
146  skip_if_in_range(min_wt);
147  }
148  return valid;
149 }
150 
151 std::string
153  return "DecreasingValueWeightPostingSource()";
154 }
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
std::string serialise() const
Serialise object parameters into a string.
void skip_if_in_range(double min_wt)
Skip the iterator forward if in the decreasing range, and weight is low.
length encoded as a string
This class is used to access a database, or a group of databases.
Definition: database.h:68
void set_maxweight(double max_weight)
Specify an upper bound on what get_weight() will return from now on.
void done()
End the iteration.
std::string get_description() const
Return a string describing this object.
Xapian::docid get_docid() const
Return the current docid.
bool check(Xapian::docid min_docid, double min_wt)
Check if the specified docid occurs.
void skip_to(Xapian::docid min_docid, double min_wt)
Advance to the specified docid.
std::string name() const
Name of the posting source class.
bool at_end() const
Return true if the current position is past the last entry in this list.
External sources of posting information.
DecreasingValueWeightPostingSource * unserialise(const std::string &serialised) const
Create object given string serialisation returned by serialise().
std::string encode_length(T len)
Encode a length as a variable-length string.
Definition: length.h:36
Read weights from a value which is known to decrease as docid increases.
Hierarchy of classes which Xapian can throw as exceptions.
bool check(Xapian::docid min_docid, double min_wt)
Check if the specified docid occurs.
DecreasingValueWeightPostingSource * clone() const
Clone the posting source.
bool items_at_end
Flag, set to true if there are docs after the end of the range.
Xapian::docid range_end
End of range of docids for which weights are known to be decreasing.
void skip_to(Xapian::docid min_docid, double min_wt)
Advance to the specified docid.
double get_weight() const
Return the weight contribution for the current document.
void init(const Database &db_)
Set this PostingSource to the start of the list of postings.
A posting source which reads weights from a value slot.
double get_weight() const
Return the weight contribution for the current document.
void init(const Xapian::Database &db_)
Set this PostingSource to the start of the list of postings.
Indicates a problem communicating with a remote database.
Definition: error.h:803
unsigned valueno
The number for a value slot in a document.
Definition: types.h:108
double get_maxweight() const
Return the currently set upper bound on what get_weight() can return.
void next(double min_wt)
Advance the current position to the next matching document.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
DecreasingValueWeightPostingSource(Xapian::valueno slot_, Xapian::docid range_start_=0, Xapian::docid range_end_=0)
Construct a DecreasingValueWeightPostingSource.
void decode_length(const char **p, const char *end, unsigned &out)
Decode a length encoded by encode_length.
Definition: length.cc:94
Xapian::docid range_start
Start of range of docids for which weights are known to be decreasing.
double curr_weight
Weight at current position.
Xapian::valueno get_slot() const
The slot we&#39;re reading values from.
Xapian::Database get_database() const
The database we&#39;re reading values from.
void next(double min_wt)
Advance the current position to the next matching document.