Branch data Line data Source code
1 : : /* branchpostlist.h: virtual base class for branched types of postlist
2 : : *
3 : : * Copyright 1999,2000,2001 BrightStation PLC
4 : : * Copyright 2002 Ananova Ltd
5 : : * Copyright 2003,2004,2007 Olly Betts
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
20 : : * USA
21 : : */
22 : :
23 : : #ifndef OM_HGUARD_BRANCHPOSTLIST_H
24 : : #define OM_HGUARD_BRANCHPOSTLIST_H
25 : :
26 : : #include "multimatch.h"
27 : : #include "postlist.h"
28 : :
29 : : /** Base class for postlists which are generated by merging two
30 : : * sub-postlists.
31 : : *
32 : : * These postlists form a tree which is used to perform a sum over all the
33 : : * terms in the query for each document, in order to calculate the score
34 : : * for that document.
35 : : */
36 : : class BranchPostList : public PostList {
37 : : private:
38 : : // Prevent copying
39 : : BranchPostList(const BranchPostList &);
40 : : BranchPostList & operator=(const BranchPostList &);
41 : :
42 : : protected:
43 : : /// Left sub-postlist
44 : : PostList *l;
45 : :
46 : : /// Right sub-postlist
47 : : PostList *r;
48 : :
49 : : /** The object which is using this postlist to perform
50 : : * a match. This object needs to be notified when the
51 : : * tree changes such that the maximum weights need to be
52 : : * recalculated.
53 : : */
54 : : MultiMatch *matcher;
55 : :
56 : : /** Utility method, to call recalc_maxweight() and do the pruning
57 : : * if a next() or skip_to() returns non-NULL result.
58 : : */
59 : 1901 : void handle_prune(PostList *&kid, PostList *ret) {
60 [ + + ]: 1901 : if (ret) {
61 [ + - ]: 96 : delete kid;
62 : 96 : kid = ret;
63 : :
64 : : // now tell matcher that maximum weights need recalculation.
65 : 96 : matcher->recalc_maxweight();
66 : : }
67 : 1901 : }
68 : :
69 : : public:
70 : 234454 : BranchPostList(PostList *l_, PostList *r_, MultiMatch *matcher_)
71 : 234454 : : l(l_), r(r_), matcher(matcher_) {}
72 : :
73 : : virtual ~BranchPostList();
74 : : };
75 : :
76 : : // Helper functions - call next/skip_to on a postlist and handle any
77 : : // resulting prune
78 : : //
79 : : // Returns true iff a prune was handled, so the caller can recalculate
80 : : // weights etc if necessary
81 : : inline bool
82 : 137867966 : next_handling_prune(PostList * & pl, Xapian::weight w_min,
83 : : MultiMatch *matcher)
84 : : {
85 : 137867966 : PostList *p = pl->next(w_min);
86 [ + + ]: 137867966 : if (!p) return false;
87 [ + - ]: 231922 : delete pl;
88 : 231922 : pl = p;
89 : : // now tell matcher that maximum weights need recalculation.
90 [ + - ]: 231922 : if (matcher) matcher->recalc_maxweight();
91 : 137867966 : return true;
92 : : }
93 : :
94 : : inline bool
95 : 504 : skip_to_handling_prune(PostList * & pl, Xapian::docid did, Xapian::weight w_min,
96 : : MultiMatch *matcher)
97 : : {
98 : 504 : PostList *p = pl->skip_to(did, w_min);
99 [ + + ]: 504 : if (!p) return false;
100 [ + - ]: 13 : delete pl;
101 : 13 : pl = p;
102 : : // now tell matcher that maximum weights need recalculation.
103 [ + - ]: 13 : if (matcher) matcher->recalc_maxweight();
104 : 504 : return true;
105 : : }
106 : :
107 : : inline bool
108 : 808 : check_handling_prune(PostList * & pl, Xapian::docid did, Xapian::weight w_min,
109 : : MultiMatch *matcher, bool & valid)
110 : : {
111 : 808 : PostList *p = pl->check(did, w_min, valid);
112 [ + - ]: 808 : if (!p) return false;
113 [ # # ]: 0 : delete pl;
114 : 0 : pl = p;
115 : : // now tell matcher that maximum weights need recalculation.
116 [ # # ]: 0 : if (matcher) matcher->recalc_maxweight();
117 : 808 : return true;
118 : : }
119 : :
120 : : #endif /* OM_HGUARD_BRANCHPOSTLIST_H */
|