Branch data Line data Source code
1 : : /** @file multixorpostlist.h
2 : : * @brief N-way XOR postlist
3 : : */
4 : : /* Copyright (C) 2007,2009,2010 Olly Betts
5 : : * Copyright (C) 2009 Lemur Consulting Ltd
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 USA
20 : : */
21 : :
22 : : #ifndef XAPIAN_INCLUDED_MULTIXORPOSTLIST_H
23 : : #define XAPIAN_INCLUDED_MULTIXORPOSTLIST_H
24 : :
25 : : #include "multimatch.h"
26 : : #include "postlist.h"
27 : : #include <algorithm>
28 : :
29 : : using namespace std;
30 : :
31 : : class MultiMatch;
32 : :
33 : : /// N-way XOR postlist.
34 : : class MultiXorPostList : public PostList {
35 : : /// Don't allow assignment.
36 : : void operator=(const MultiXorPostList &);
37 : :
38 : : /// Don't allow copying.
39 : : MultiXorPostList(const MultiXorPostList &);
40 : :
41 : : /// The current docid, or zero if we haven't started or are at_end.
42 : : Xapian::docid did;
43 : :
44 : : /// The number of sub-postlists.
45 : : size_t n_kids;
46 : :
47 : : /// Array of pointers to sub-postlists.
48 : : PostList ** plist;
49 : :
50 : : /// Total maximum weight the XOR could possibly return.
51 : : Xapian::weight max_total;
52 : :
53 : : /// The number of documents in the database.
54 : : Xapian::doccount db_size;
55 : :
56 : : /// Pointer to the matcher object, so we can report pruning.
57 : : MultiMatch *matcher;
58 : :
59 : : /// Erase a sub-postlist.
60 : 166 : void erase_sublist(size_t i) {
61 [ + - ]: 166 : delete plist[i];
62 : 166 : --n_kids;
63 [ + + ]: 232 : for (size_t j = i; j < n_kids; ++j) {
64 : 66 : plist[j] = plist[j + 1];
65 : : }
66 : 166 : matcher->recalc_maxweight();
67 : 166 : }
68 : :
69 : : public:
70 : : /** Construct from 2 random-access iterators to a container of PostList*,
71 : : * a pointer to the matcher, and the document collection size.
72 : : */
73 : : template <class RandomItor>
74 : 134 : MultiXorPostList(RandomItor pl_begin, RandomItor pl_end,
75 : : MultiMatch * matcher_, Xapian::doccount db_size_)
76 : : : did(0), n_kids(pl_end - pl_begin), plist(NULL),
77 : 134 : max_total(0), db_size(db_size_), matcher(matcher_)
78 : : {
79 : 134 : plist = new PostList * [n_kids];
80 : 134 : std::copy(pl_begin, pl_end, plist);
81 : 134 : }
82 : :
83 : : ~MultiXorPostList();
84 : :
85 : : Xapian::doccount get_termfreq_min() const;
86 : :
87 : : Xapian::doccount get_termfreq_max() const;
88 : :
89 : : Xapian::doccount get_termfreq_est() const;
90 : :
91 : : TermFreqs get_termfreq_est_using_stats(
92 : : const Xapian::Weight::Internal & stats) const;
93 : :
94 : : Xapian::weight get_maxweight() const;
95 : :
96 : : Xapian::docid get_docid() const;
97 : :
98 : : Xapian::termcount get_doclength() const;
99 : :
100 : : Xapian::weight get_weight() const;
101 : :
102 : : bool at_end() const;
103 : :
104 : : Xapian::weight recalc_maxweight();
105 : :
106 : : Internal *next(Xapian::weight w_min);
107 : :
108 : : Internal *skip_to(Xapian::docid, Xapian::weight w_min);
109 : :
110 : : std::string get_description() const;
111 : :
112 : : /** get_wdf() for MultiXorPostlists returns the sum of the wdfs of the
113 : : * sub postlists which match the current docid.
114 : : *
115 : : * The wdf isn't really meaningful in many situations, but if the lists
116 : : * are being combined as a synonym we want the sum of the wdfs, so we do
117 : : * that in general.
118 : : */
119 : : Xapian::termcount get_wdf() const;
120 : :
121 : : Xapian::termcount count_matching_subqs() const;
122 : : };
123 : :
124 : : #endif // XAPIAN_INCLUDED_MULTIXORPOSTLIST_H
|