1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/** @file multixorpostlist.h
* @brief N-way XOR postlist
*/
/* Copyright (C) 2007,2009,2010,2011,2012 Olly Betts
* Copyright (C) 2009 Lemur Consulting Ltd
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef XAPIAN_INCLUDED_MULTIXORPOSTLIST_H
#define XAPIAN_INCLUDED_MULTIXORPOSTLIST_H
#include "multimatch.h"
#include "api/postlist.h"
#include <algorithm>
class MultiMatch;
/// N-way XOR postlist.
class MultiXorPostList : public PostList {
/// Don't allow assignment.
void operator=(const MultiXorPostList &);
/// Don't allow copying.
MultiXorPostList(const MultiXorPostList &);
/// The current docid, or zero if we haven't started or are at_end.
Xapian::docid did;
/// The number of sub-postlists.
size_t n_kids;
/// Array of pointers to sub-postlists.
PostList ** plist;
/// Total maximum weight the XOR could possibly return.
double max_total;
/// The number of documents in the database.
Xapian::doccount db_size;
/// Pointer to the matcher object, so we can report pruning.
MultiMatch *matcher;
/// Erase a sub-postlist.
void erase_sublist(size_t i) {
delete plist[i];
--n_kids;
for (size_t j = i; j < n_kids; ++j) {
plist[j] = plist[j + 1];
}
matcher->recalc_maxweight();
}
public:
/** Construct from 2 random-access iterators to a container of PostList*,
* a pointer to the matcher, and the document collection size.
*/
template <class RandomItor>
MultiXorPostList(RandomItor pl_begin, RandomItor pl_end,
MultiMatch * matcher_, Xapian::doccount db_size_)
: did(0), n_kids(pl_end - pl_begin), plist(NULL),
max_total(0), db_size(db_size_), matcher(matcher_)
{
plist = new PostList * [n_kids];
std::copy(pl_begin, pl_end, plist);
}
~MultiXorPostList();
Xapian::doccount get_termfreq_min() const;
Xapian::doccount get_termfreq_max() const;
Xapian::doccount get_termfreq_est() const;
TermFreqs get_termfreq_est_using_stats(
const Xapian::Weight::Internal & stats) const;
double get_maxweight() const;
Xapian::docid get_docid() const;
Xapian::termcount get_doclength() const;
Xapian::termcount get_unique_terms() const;
double get_weight() const;
bool at_end() const;
double recalc_maxweight();
PositionList * read_position_list() {
return NULL;
}
Internal *next(double w_min);
Internal *skip_to(Xapian::docid, double w_min);
std::string get_description() const;
/** get_wdf() for MultiXorPostlists returns the sum of the wdfs of the
* sub postlists which match the current docid.
*
* The wdf isn't really meaningful in many situations, but if the lists
* are being combined as a synonym we want the sum of the wdfs, so we do
* that in general.
*/
Xapian::termcount get_wdf() const;
Xapian::termcount count_matching_subqs() const;
};
#endif // XAPIAN_INCLUDED_MULTIXORPOSTLIST_H
|