1 /** @file andmaybepostlist.h
2 * @brief PostList class implementing Query::OP_AND_MAYBE
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 #ifndef XAPIAN_INCLUDED_ANDMAYBEPOSTLIST_H
22 #define XAPIAN_INCLUDED_ANDMAYBEPOSTLIST_H
24 #include "postlisttree.h"
25 #include "wrapperpostlist.h"
27 /// PostList class implementing Query::OP_AND_MAYBE
28 class AndMaybePostList
: public WrapperPostList
{
29 /// Right-hand side of OP_MAYBE.
32 /// Current docid from WrapperPostList's pl.
33 Xapian::docid pl_did
= 0;
35 /// Current docid from @a r (or 0).
36 Xapian::docid r_did
= 0;
38 /// Current max weight from WrapperPostList's pl.
41 /// Current max weight from @a r.
44 /** Total number of documents in the database.
46 * Only used if we decay to AND.
48 Xapian::doccount db_size
;
52 /// Does @a r match at the current position?
53 bool maybe_matches() const { return pl_did
== r_did
; }
55 PostList
* decay_to_and(Xapian::docid did
,
57 bool* valid_ptr
= NULL
);
60 AndMaybePostList(PostList
* left
, PostList
* right
,
61 PostListTree
* pltree_
, Xapian::doccount db_size_
)
62 : WrapperPostList(left
), r(right
), db_size(db_size_
), pltree(pltree_
)
65 /** Construct as decay product from OrPostList.
67 * The first operation after such construction must be check() or
70 AndMaybePostList(PostList
* left
,
74 PostListTree
* pltree_
,
75 Xapian::doccount db_size_
)
76 : WrapperPostList(left
), r(right
), pl_max(lmax
), r_max(rmax
),
77 db_size(db_size_
), pltree(pltree_
)
81 ~AndMaybePostList() { delete r
; }
83 Xapian::docid
get_docid() const;
85 double get_weight(Xapian::termcount doclen
,
86 Xapian::termcount unique_terms
) const;
88 double recalc_maxweight();
90 PostList
* next(double w_min
);
92 PostList
* skip_to(Xapian::docid did
, double w_min
);
94 PostList
* check(Xapian::docid did
, double w_min
, bool& valid
);
96 std::string
get_description() const;
98 Xapian::termcount
get_wdf() const;
100 Xapian::termcount
count_matching_subqs() const;
102 void gather_position_lists(OrPositionList
* orposlist
);
105 #endif // XAPIAN_INCLUDED_ANDMAYBEPOSTLIST_H