xapian-core  1.4.21
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 #include "serialise-double.h"
28 #include <cmath>
29 
30 using namespace Xapian;
31 
33  Xapian::valueno slot_,
34  Xapian::docid range_start_,
35  Xapian::docid range_end_)
37  range_start(range_start_),
38  range_end(range_end_)
39 {
40 }
41 
42 double
44  return curr_weight;
45 }
46 
50  range_end);
51 }
52 
53 std::string
55  return "Xapian::DecreasingValueWeightPostingSource";
56 }
57 
58 std::string
60  std::string result;
61  result += encode_length(get_slot());
62  result += encode_length(range_start);
63  result += encode_length(range_end);
64  return result;
65 }
66 
69  const char * pos = s.data();
70  const char * end = pos + s.size();
71  Xapian::valueno new_slot;
72  Xapian::docid new_range_start, new_range_end;
73  decode_length(&pos, end, new_slot);
74  decode_length(&pos, end, new_range_start);
75  decode_length(&pos, end, new_range_end);
76  if (pos != end)
77  throw Xapian::NetworkError("Junk at end of serialised "
78  "DecreasingValueWeightPostingSource");
79  return new DecreasingValueWeightPostingSource(new_slot, new_range_start,
80  new_range_end);
81 }
82 
83 void
86  if (range_end == 0 || get_database().get_doccount() <= range_end)
87  items_at_end = false;
88  else
89  items_at_end = true;
90 }
91 
92 void
94 {
98  if (docid >= range_start && (range_end == 0 || docid <= range_end)) {
99  if (items_at_end) {
100  if (curr_weight < min_wt) {
101  // skip to end of range.
105  }
106  } else {
107  if (curr_weight < min_wt) {
108  // terminate early.
109  done();
110  } else {
111  // Update max_weight.
113  }
114  }
115  }
116 }
117 
118 void
120  if (get_maxweight() < min_wt) {
121  done();
122  return;
123  }
125  skip_if_in_range(min_wt);
126 }
127 
128 void
130  double min_wt) {
131  if (get_maxweight() < min_wt) {
132  done();
133  return;
134  }
136  skip_if_in_range(min_wt);
137 }
138 
139 bool
141  double min_wt) {
142  if (get_maxweight() < min_wt) {
143  done();
144  return true;
145  }
146  bool valid = Xapian::ValueWeightPostingSource::check(min_docid, min_wt);
147  if (valid) {
148  skip_if_in_range(min_wt);
149  }
150  return valid;
151 }
152 
153 std::string
155  return "DecreasingValueWeightPostingSource()";
156 }
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.
functions to serialise and unserialise a double
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.