xapian-core  1.4.27
queryoptimiser.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2008,2009,2010,2011,2013,2014,2015,2016,2018 Olly Betts
5  * Copyright (C) 2008 Lemur Consulting Ltd
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 USA
20  */
21 
22 #ifndef XAPIAN_INCLUDED_QUERYOPTIMISER_H
23 #define XAPIAN_INCLUDED_QUERYOPTIMISER_H
24 
25 #include "backends/database.h"
26 #include "localsubmatch.h"
27 #include "api/postlist.h"
28 
29 class LeafPostList;
30 class MultiMatch;
31 
34  void operator=(const QueryOptimiser &);
35 
38 
40 
47 
49 
50  bool hint_owned;
51 
52  public:
54 
55  bool in_synonym;
56 
58 
60 
62 
64 
66  LocalSubMatch & localsubmatch_,
67  MultiMatch* matcher_,
68  Xapian::doccount shard_index_)
69  : localsubmatch(localsubmatch_), total_subqs(0),
70  hint(0), hint_owned(false),
71  need_positions(false), in_synonym(false),
72  shard_index(shard_index_),
73  db(db_), db_size(db.get_doccount()),
74  matcher(matcher_) { }
75 
77  if (hint_owned) delete hint;
78  }
79 
80  bool full_db_has_positions() const {
81  return matcher->full_db_has_positions();
82  }
83 
85 
87 
88  void set_total_subqs(Xapian::termcount n) { total_subqs = n; }
89 
90  LeafPostList * open_post_list(const std::string& term,
92  double factor) {
93  return localsubmatch.open_post_list(term, wqf, factor, need_positions,
94  in_synonym, this, false);
95  }
96 
97  LeafPostList * open_lazy_post_list(const std::string& term,
99  double factor) {
100  return localsubmatch.open_post_list(term, wqf, factor, false,
101  in_synonym, this, true);
102  }
103 
105  double factor,
106  bool wdf_disjoint) {
107  return localsubmatch.make_synonym_postlist(pl, matcher, factor,
108  wdf_disjoint);
109  }
110 
111  const LeafPostList * get_hint_postlist() const { return hint; }
112 
113  void set_hint_postlist(LeafPostList * new_hint) {
114  if (hint_owned) {
115  hint_owned = false;
116  delete hint;
117  }
118  hint = new_hint;
119  }
120 
122  if (pl == static_cast<PostList*>(hint)) {
123  hint_owned = true;
124  } else {
125  if (!hint_owned) {
126  // The hint could be a subpostlist of pl, but we can't easily
127  // tell so we have to do the safe thing and reset it.
128  //
129  // This isn't ideal, but it's much better than use-after-free
130  // bugs.
131  hint = nullptr;
132  }
133  delete pl;
134  }
135  }
136 };
137 
138 #endif // XAPIAN_INCLUDED_QUERYOPTIMISER_H
Xapian::doccount db_size
bool full_db_has_positions() const
Definition: multimatch.h:140
Abstract base class for postlists.
Definition: postlist.h:37
void set_total_subqs(Xapian::termcount n)
QueryOptimiser(const Xapian::Database::Internal &db_, LocalSubMatch &localsubmatch_, MultiMatch *matcher_, Xapian::doccount shard_index_)
const LeafPostList * get_hint_postlist() const
Base class for databases.
Definition: database.h:57
void inc_total_subqs()
void set_hint_postlist(LeafPostList *new_hint)
Abstract base class for leaf postlists.
Definition: leafpostlist.h:39
#define false
Definition: header.h:9
LocalSubMatch & localsubmatch
void destroy_postlist(PostList *pl)
Abstract base class for postlists.
MultiMatch * matcher
void operator=(const QueryOptimiser &)
Prevent assignment.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
Xapian::termcount get_total_subqs() const
PostList * make_synonym_postlist(PostList *pl, double factor, bool wdf_disjoint)
LeafPostList * open_lazy_post_list(const std::string &term, Xapian::termcount wqf, double factor)
SubMatch class for a local database.
LeafPostList * hint
LeafPostList * open_post_list(const std::string &term, Xapian::termcount wqf, double factor)
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
const Xapian::Database::Internal & db
bool full_db_has_positions() const
LeafPostList * open_post_list(const std::string &term, Xapian::termcount wqf, double factor, bool need_positions, bool in_synonym, QueryOptimiser *qopt, bool lazy_weight)
PostList * make_synonym_postlist(PostList *or_pl, MultiMatch *matcher, double factor, bool wdf_disjoint)
Convert a postlist into a synonym postlist.
Xapian::termcount total_subqs
How many weighted leaf subqueries there are.
Xapian::doccount shard_index
QueryOptimiser(const QueryOptimiser &)
Prevent copying.