Reduce overheads of PostList positional data support
[xapian.git] / xapian-core / matcher / queryoptimiser.h
blob0f0795c60e41972896d5953004d75fc83446cc7f
1 /** @file queryoptimiser.h
2 * @brief Details passed around while building PostList tree from Query tree
3 */
4 /* Copyright (C) 2007,2008,2009,2010,2011,2013,2014,2015,2016 Olly Betts
5 * Copyright (C) 2008 Lemur Consulting Ltd
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.
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.
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 USA
22 #ifndef XAPIAN_INCLUDED_QUERYOPTIMISER_H
23 #define XAPIAN_INCLUDED_QUERYOPTIMISER_H
25 #include "backends/databaseinternal.h"
26 #include "localsubmatch.h"
27 #include "api/postlist.h"
29 class LeafPostList;
30 class PostListTree;
32 namespace Xapian {
33 namespace Internal {
35 class QueryOptimiser {
36 /// Prevent assignment.
37 void operator=(const QueryOptimiser &);
39 /// Prevent copying.
40 QueryOptimiser(const QueryOptimiser &);
42 LocalSubMatch & localsubmatch;
44 /** How many weighted leaf subqueries there are.
46 * Used for scaling percentages when the highest weighted document doesn't
47 * "match all terms".
49 Xapian::termcount total_subqs;
51 LeafPostList * hint;
53 bool hint_owned;
55 public:
56 bool need_positions;
58 bool in_synonym;
60 bool full_db_has_positions;
62 const Xapian::Database::Internal & db;
64 Xapian::doccount db_size;
66 PostListTree * matcher;
68 QueryOptimiser(const Xapian::Database::Internal & db_,
69 LocalSubMatch & localsubmatch_,
70 PostListTree * matcher_,
71 bool full_db_has_positions_)
72 : localsubmatch(localsubmatch_), total_subqs(0),
73 hint(0), hint_owned(false),
74 need_positions(false), in_synonym(false),
75 full_db_has_positions(full_db_has_positions_),
76 db(db_), db_size(db.get_doccount()),
77 matcher(matcher_) { }
79 ~QueryOptimiser() {
80 if (hint_owned) delete hint;
83 void inc_total_subqs() { ++total_subqs; }
85 Xapian::termcount get_total_subqs() const { return total_subqs; }
87 void set_total_subqs(Xapian::termcount n) { total_subqs = n; }
89 PostList * open_post_list(const std::string& term,
90 Xapian::termcount wqf,
91 double factor) {
92 return localsubmatch.open_post_list(term, wqf, factor, need_positions,
93 in_synonym, this, false);
96 PostList * open_lazy_post_list(const std::string& term,
97 Xapian::termcount wqf,
98 double factor) {
99 return localsubmatch.open_post_list(term, wqf, factor, need_positions,
100 in_synonym, this, true);
103 PostList * make_synonym_postlist(PostList * pl, double factor) {
104 return localsubmatch.make_synonym_postlist(matcher, pl, factor);
107 const LeafPostList * get_hint_postlist() const { return hint; }
109 void set_hint_postlist(LeafPostList * new_hint) {
110 if (hint_owned) {
111 hint_owned = false;
112 delete hint;
114 hint = new_hint;
117 void take_hint_ownership() { hint_owned = true; }
123 using Xapian::Internal::QueryOptimiser;
125 #endif // XAPIAN_INCLUDED_QUERYOPTIMISER_H