xapian-core  1.4.26
selectpostlist.h
Go to the documentation of this file.
1 
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2003,2004,2009,2010,2011,2012,2013 Olly Betts
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, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20  * USA
21  */
22 
23 #ifndef OM_HGUARD_SELECTPOSTLIST_H
24 #define OM_HGUARD_SELECTPOSTLIST_H
25 
26 #include "api/postlist.h"
27 
31 class SelectPostList : public PostList {
32  private:
33  // Prevent copying
36 
37  inline bool check_weight(double w_min) {
38  return w_min == 0.0 || SelectPostList::get_weight() >= w_min;
39  }
40 
41  protected:
43  mutable double wt;
44 
48  virtual bool test_doc() = 0;
49  public:
50  PostList *next(double w_min);
51  PostList *skip_to(Xapian::docid did, double w_min);
52  PostList *check(Xapian::docid did, double w_min, bool &valid);
53 
54  // pass all these through to the underlying source PostList
55  Xapian::doccount get_termfreq_max() const { return source->get_termfreq_max(); }
56  Xapian::doccount get_termfreq_min() const { return 0; }
57  double get_maxweight() const { return source->get_maxweight(); }
58  Xapian::docid get_docid() const { return source->get_docid(); }
59  double get_weight() const {
60  if (wt < 0.0)
61  wt = source->get_weight();
62  return wt;
63  }
64  Xapian::termcount get_doclength() const { return source->get_doclength(); }
65  Xapian::termcount get_unique_terms() const { return source->get_unique_terms(); }
66  double recalc_maxweight() { return source->recalc_maxweight(); }
68  PositionList * open_position_list() const { return source->open_position_list(); }
69  bool at_end() const { return source->at_end(); }
70 
72  return source->count_matching_subqs();
73  }
74 
75  std::string get_description() const;
76 
77  explicit SelectPostList(PostList *source_) : source(source_), wt(-1) { }
78  ~SelectPostList() { delete source; }
79 };
80 
81 inline std::string
83 {
84  return "(Select " + source->get_description() + ")";
85 }
86 
87 #endif /* OM_HGUARD_SELECTPOSTLIST_H */
PostList * source
Xapian::termcount get_unique_terms() const
Return the number of unique terms in the current document.
Xapian::termcount count_matching_subqs() const
Count the number of leaf subqueries which match at the current position.
Abstract base class for postlists.
Definition: postlist.h:37
SelectPostList(PostList *source_)
double get_maxweight() const
Return an upper bound on what get_weight() can return.
virtual Xapian::docid get_docid() const =0
Return the current docid.
PositionList * read_position_list()
Read the position list for the term in the current document and return a pointer to it (owned by the ...
virtual double recalc_maxweight()=0
Recalculate the upper bound on what get_weight() can return.
PositionList * open_position_list() const
Read the position list for the term in the current document and return a pointer to it (not owned by ...
SelectPostList & operator=(const SelectPostList &)
virtual Xapian::termcount get_unique_terms() const =0
Return the number of unique terms in the current document.
Abstract base class for postlists.
Xapian::termcount get_doclength() const
Return the length of current document.
Xapian::docid get_docid() const
Return the current docid.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
virtual bool test_doc()=0
Subclasses should override test_doc() with a method which returns true if a document meets the approp...
virtual Xapian::doccount get_termfreq_max() const =0
Get an upper bound on the number of documents indexed by this term.
Internal * next()
Advance the current position to the next document in the postlist.
Definition: postlist.h:194
virtual PositionList * read_position_list()
Read the position list for the term in the current document and return a pointer to it (owned by the ...
bool at_end() const
Return true if the current position is past the last entry in this list.
Xapian::doccount get_termfreq_max() const
Get an upper bound on the number of documents indexed by this term.
virtual PositionList * open_position_list() const
Read the position list for the term in the current document and return a pointer to it (not owned by ...
virtual double get_maxweight() const =0
Return an upper bound on what get_weight() can return.
PostList * check(Xapian::docid did, double w_min, bool &valid)
Check if the specified docid occurs in this postlist.
A postlist parent class for classes which only return selected docs from a source postlist (e...
PostList * skip_to(Xapian::docid did, double w_min)
Skip forward to the specified docid.
virtual Xapian::termcount get_doclength() const =0
Return the length of current document.
virtual std::string get_description() const =0
Return a string description of this object.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
std::string get_description() const
Return a string description of this object.
virtual Xapian::termcount count_matching_subqs() const
Count the number of leaf subqueries which match at the current position.
Xapian::doccount get_termfreq_min() const
Get a lower bound on the number of documents indexed by this term.
bool check_weight(double w_min)
virtual bool at_end() const =0
Return true if the current position is past the last entry in this list.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:31
SelectPostList(const SelectPostList &)
double recalc_maxweight()
Recalculate the upper bound on what get_weight() can return.
double get_weight() const
Return the weight contribution for the current position.
virtual double get_weight() const =0
Return the weight contribution for the current position.