scriptindex: Fix weird error cases
[xapian.git] / xapian-core / matcher / selectpostlist.h
blob4a70e9851b9635993645ea71d69413352d9feaf5
1 /** @file
2 * @brief Parent class for classes which only return selected docs
3 */
4 /* Copyright 1999,2000,2001 BrightStation PLC
5 * Copyright 2003,2004,2009,2010,2011,2012,2013 Olly Betts
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.
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.
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
23 #ifndef OM_HGUARD_SELECTPOSTLIST_H
24 #define OM_HGUARD_SELECTPOSTLIST_H
26 #include "api/postlist.h"
28 /** A postlist parent class for classes which only return selected docs
29 * from a source postlist (e.g. NEAR and PHRASE)
31 class SelectPostList : public PostList {
32 private:
33 // Prevent copying
34 SelectPostList(const SelectPostList &);
35 SelectPostList & operator=(const SelectPostList &);
37 inline bool check_weight(double w_min) {
38 return w_min == 0.0 || SelectPostList::get_weight() >= w_min;
41 protected:
42 PostList *source;
43 mutable double wt;
45 /** Subclasses should override test_doc() with a method which returns
46 * true if a document meets the appropriate criterion, false in not
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);
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;
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(); }
67 PositionList * read_position_list() { return source->read_position_list(); }
68 PositionList * open_position_list() const { return source->open_position_list(); }
69 bool at_end() const { return source->at_end(); }
71 Xapian::termcount count_matching_subqs() const {
72 return source->count_matching_subqs();
75 std::string get_description() const;
77 explicit SelectPostList(PostList *source_) : source(source_), wt(-1) { }
78 ~SelectPostList() { delete source; }
81 inline std::string
82 SelectPostList::get_description() const
84 return "(Select " + source->get_description() + ")";
87 #endif /* OM_HGUARD_SELECTPOSTLIST_H */