2 * @brief Merged postlist: items from one list, weights from both
4 * AND MAYBE of two posting lists
5 * A AND MAYBE B is logically just A, but we keep B around for weight purposes
7 /* Copyright 1999,2000,2001 BrightStation PLC
8 * Copyright 2002 Ananova Ltd
9 * Copyright 2003,2004,2009,2011,2017 Olly Betts
10 * Copyright 2009 Lemur Consulting Ltd
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
29 #ifndef OM_HGUARD_ANDMAYBEPOSTLIST_H
30 #define OM_HGUARD_ANDMAYBEPOSTLIST_H
32 #include "branchpostlist.h"
34 /** A postlist with weights modified by another postlist.
36 * This postlist returns a posting if and only if it is in the left
39 * If the posting does not occur in the right postlist, the weight for the
40 * posting is simply that in the left postlist. If the posting occurs in
41 * both postlists, the weight for the posting is the sum of the weights in
44 * This type of postlist is useful for specifying a set of terms which
45 * must appear in the query result: these terms can be specified as the
46 * left hand argument, with the rest of the query being on the right hand
47 * side, and having the effect of modifying the weights.
49 * The postlist is also used as a "decay product" of other postlist types
50 * during the match process: when a postlist can no longer cause a
51 * document to enter the mset on its own, but can influence relative
52 * rankings, it may be combined using one of these.
54 class AndMaybePostList
: public BranchPostList
{
56 Xapian::doccount dbsize
; // only need in case we decay to an AndPostList
57 Xapian::docid lhead
, rhead
;
60 PostList
* process_next_or_skip_to(double w_min
, PostList
*ret
);
62 Xapian::doccount
get_termfreq_max() const;
63 Xapian::doccount
get_termfreq_min() const;
64 Xapian::doccount
get_termfreq_est() const;
66 TermFreqs
get_termfreq_est_using_stats(
67 const Xapian::Weight::Internal
& stats
) const;
69 Xapian::docid
get_docid() const;
70 double get_weight() const;
71 double get_maxweight() const;
73 double recalc_maxweight();
75 PostList
*next(double w_min
);
76 PostList
*skip_to(Xapian::docid did
, double w_min
);
79 std::string
get_description() const;
81 /** Return the document length of the document the current term
84 virtual Xapian::termcount
get_doclength() const;
86 virtual Xapian::termcount
get_unique_terms() const;
88 AndMaybePostList(PostList
*left_
,
91 Xapian::doccount dbsize_
)
92 : BranchPostList(left_
, right_
, matcher_
),
93 dbsize(dbsize_
), lhead(0), rhead(0)
95 // lmax and rmax will get initialised by a recalc_maxweight
98 /// Constructor for use by decomposing OrPostList
99 AndMaybePostList(PostList
*left_
,
101 MultiMatch
*matcher_
,
102 Xapian::doccount dbsize_
,
103 Xapian::docid lhead_
,
104 Xapian::docid rhead_
)
105 : BranchPostList(left_
, right_
, matcher_
),
106 dbsize(dbsize_
), lhead(lhead_
), rhead(rhead_
)
108 // Initialise the maxweights from the kids so we can avoid forcing
109 // a full maxweight recalc
110 lmax
= l
->get_maxweight();
111 rmax
= r
->get_maxweight();
114 /** Synchronise the RHS to the LHS after construction.
115 * Used after constructing from a decomposing OrPostList
117 PostList
* sync_rhs(double w_min
);
119 /** get_wdf() for ANDMAYBE postlists returns the sum of the wdfs of the
120 * sub postlists which are at the current document - this is desirable
121 * when the ANDMAYBE is part of a synonym.
123 Xapian::termcount
get_wdf() const;
125 Xapian::termcount
count_matching_subqs() const;
127 void gather_position_lists(OrPositionList
* orposlist
);
130 #endif /* OM_HGUARD_ANDMAYBEPOSTLIST_H */