Make PostList subclasses return PostList* not Internal*
[xapian.git] / xapian-core / matcher / maxpostlist.h
blob8d05527390db2de5343460c57717cdc78d9707ba
1 /** @file maxpostlist.h
2 * @brief N-way OR postlist with wt=max(wt_i)
3 */
4 /* Copyright (C) 2007,2009,2010,2011,2012,2013 Olly Betts
5 * Copyright (C) 2009 Lemur Consulting Ltd
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 USA
22 #ifndef XAPIAN_INCLUDED_MAXPOSTLIST_H
23 #define XAPIAN_INCLUDED_MAXPOSTLIST_H
25 #include "api/postlist.h"
26 #include "postlisttree.h"
28 #include <algorithm>
30 /// N-way OR postlist with wt=max(wt_i).
31 class MaxPostList : public PostList {
32 /// Don't allow assignment.
33 void operator=(const MaxPostList &);
35 /// Don't allow copying.
36 MaxPostList(const MaxPostList &);
38 /// The current docid, or zero if we haven't started or are at_end.
39 Xapian::docid did;
41 /// The number of sub-postlists.
42 size_t n_kids;
44 /// Array of pointers to sub-postlists.
45 PostList ** plist;
47 /// The number of documents in the database.
48 Xapian::doccount db_size;
50 /// Pointer to the matcher object, so we can report pruning.
51 PostListTree *matcher;
53 /// Erase a sub-postlist.
54 void erase_sublist(size_t i) {
55 delete plist[i];
56 --n_kids;
57 for (size_t j = i; j < n_kids; ++j) {
58 plist[j] = plist[j + 1];
60 matcher->force_recalc();
63 public:
64 /** Construct from 2 random-access iterators to a container of PostList*,
65 * a pointer to the matcher, and the document collection size.
67 template <class RandomItor>
68 MaxPostList(RandomItor pl_begin, RandomItor pl_end,
69 PostListTree * matcher_, Xapian::doccount db_size_)
70 : did(0), n_kids(pl_end - pl_begin), plist(NULL),
71 db_size(db_size_), matcher(matcher_)
73 plist = new PostList * [n_kids];
74 std::copy(pl_begin, pl_end, plist);
77 ~MaxPostList();
79 Xapian::doccount get_termfreq_min() const;
81 Xapian::doccount get_termfreq_max() const;
83 Xapian::doccount get_termfreq_est() const;
85 TermFreqs get_termfreq_est_using_stats(
86 const Xapian::Weight::Internal & stats) const;
88 Xapian::docid get_docid() const;
90 double get_weight() const;
92 bool at_end() const;
94 double recalc_maxweight();
96 PositionList * read_position_list() {
97 return NULL;
100 PostList* next(double w_min);
102 PostList* skip_to(Xapian::docid, double w_min);
104 std::string get_description() const;
106 /** get_wdf() for MaxPostlist returns the sum of the wdfs of the
107 * sub postlists which match the current docid.
109 * The wdf isn't really meaningful in many situations, but if the lists
110 * are being combined as a synonym we want the sum of the wdfs, so we do
111 * that in general.
113 Xapian::termcount get_wdf() const;
115 Xapian::termcount count_matching_subqs() const;
118 #endif // XAPIAN_INCLUDED_MAXPOSTLIST_H