xapian-check-patch: Check for lines > 80 columns
[xapian.git] / xapian-core / matcher / mergepostlist.cc
blobcd54dc204bcd53ea8c9ad112dee2ec2ab64ad034
1 /** @file mergepostlist.cc
2 * @brief PostList class implementing Query::OP_AND_NOT
3 */
4 /* Copyright 2017 Olly Betts
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <config.h>
23 #include "mergepostlist.h"
25 #include "backends/multi.h"
26 #include "valuestreamdocument.h"
28 using namespace std;
30 MergePostList::~MergePostList()
32 pl = NULL;
33 for (Xapian::doccount i = 0; i != n_shards; ++i)
34 delete shard_pls[i];
37 Xapian::doccount
38 MergePostList::get_termfreq_min() const
40 Xapian::doccount result = 0;
41 for (Xapian::doccount i = 0; i != n_shards; ++i)
42 result += shard_pls[i]->get_termfreq_min();
43 return result;
46 Xapian::doccount
47 MergePostList::get_termfreq_max() const
49 Xapian::doccount result = 0;
50 for (Xapian::doccount i = 0; i != n_shards; ++i)
51 result += shard_pls[i]->get_termfreq_max();
52 return result;
55 Xapian::doccount
56 MergePostList::get_termfreq_est() const
58 Xapian::doccount result = 0;
59 for (Xapian::doccount i = 0; i != n_shards; ++i)
60 result += shard_pls[i]->get_termfreq_est();
61 return result;
64 Xapian::docid
65 MergePostList::get_docid() const
67 return unshard(WrapperPostList::get_docid(), shard, n_shards);
70 const string*
71 MergePostList::get_sort_key() const
73 return pl->get_sort_key();
76 const string*
77 MergePostList::get_collapse_key() const
79 return pl->get_collapse_key();
82 bool
83 MergePostList::at_end() const
85 return shard == n_shards;
88 double
89 MergePostList::recalc_maxweight()
91 double result = 0;
92 for (Xapian::doccount i = 0; i != n_shards; ++i) {
93 result = max(result, shard_pls[i]->recalc_maxweight());
95 return result;
98 TermFreqs
99 MergePostList::get_termfreq_est_using_stats(const Xapian::Weight::Internal&) const
101 // We're only called by PostListTree which never calls this method.
102 Assert(false);
103 return TermFreqs();
106 PostList*
107 MergePostList::next(double w_min)
109 while (true) {
110 PostList* result = pl->next(w_min);
111 if (result) {
112 delete pl;
113 pl = result;
114 shard_pls[shard] = pl;
116 if (!pl->at_end() || ++shard == n_shards) {
117 break;
119 // Move on to the next shard.
120 vsdoc.new_shard(shard);
121 pl = shard_pls[shard];
123 return NULL;
126 PostList*
127 MergePostList::skip_to(Xapian::docid, double)
129 // We're only called by PostListTree which never calls this method.
130 Assert(false);
131 return NULL;
134 string
135 MergePostList::get_description() const
137 string desc = "MergePostList(";
138 for (Xapian::doccount i = 0; i != n_shards; ++i) {
139 desc += shard_pls[i]->get_description();
140 desc += ',';
142 desc.back() = ')';
143 return desc;