xapian-core  2.0.0
queryoptimiser.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007-2026 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, see
19  * <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef XAPIAN_INCLUDED_QUERYOPTIMISER_H
23 #define XAPIAN_INCLUDED_QUERYOPTIMISER_H
24 
26 #include "backends/leafpostlist.h"
27 #include "backends/postlist.h"
28 #include "localsubmatch.h"
29 
30 class LeafPostList;
31 class PostListTree;
32 
33 namespace Xapian {
34 namespace Internal {
35 
38  void operator=(const QueryOptimiser &);
39 
42 
44 
51 
52  LeafPostList* hint = nullptr;
53 
54  bool hint_owned = false;
55 
56  bool no_estimates = false;
57 
58  public:
59  bool need_positions = false;
60 
61  bool compound_weight = false;
62 
64 
66 
68 
70 
72  LocalSubMatch & localsubmatch_,
73  PostListTree * matcher_,
74  Xapian::doccount shard_index_)
75  : localsubmatch(localsubmatch_),
76  shard_index(shard_index_),
77  db(db_), db_size(db.get_doccount()),
78  matcher(matcher_) { }
79 
81  if (hint_owned) delete hint;
82  }
83 
85 
87 
89 
90  bool get_no_estimates() const { return no_estimates; }
91 
92  void set_no_estimates(bool f) { no_estimates = f; }
93 
102  open_post_list(const std::string& term,
103  Xapian::termcount wqf,
104  double factor,
105  TermFreqs* termfreqs) {
106  return localsubmatch.open_post_list(term, wqf, factor, need_positions,
107  compound_weight, this, false,
108  termfreqs);
109  }
110 
112  open_lazy_post_list(const std::string& term,
113  Xapian::termcount wqf,
114  double factor) {
115  return localsubmatch.open_post_list(term, wqf, factor, need_positions,
116  compound_weight, this, true,
117  NULL);
118  }
119 
129  TermFreqs* termfreqs) {
131  }
132 
140  double factor,
141  const TermFreqs& termfreqs) {
142  return localsubmatch.make_synonym_postlist(matcher, std::move(or_pl),
143  factor, termfreqs);
144  }
145 
146  const LeafPostList * get_hint_postlist() const { return hint; }
147 
148  void set_hint_postlist(LeafPostList * new_hint) {
149  if (hint_owned) {
150  hint_owned = false;
151  delete hint;
152  }
153  hint = new_hint;
154  }
155 
156  void own_hint_postlist() { hint_owned = true; }
157 
159  if (!pl) return;
160  if (pl == static_cast<PostList*>(hint)) {
161  hint_owned = true;
162  } else {
163  if (!hint_owned) {
164  // The hint could be a subpostlist of pl, but we can't easily
165  // tell so we have to do the safe thing and reset it.
166  //
167  // This isn't ideal, but it's much better than use-after-free
168  // bugs.
169  hint = nullptr;
170  }
171  delete pl;
172  }
173  }
174 
177  }
178 
180  return localsubmatch.get_stats();
181  }
182 };
183 
184 }
185 }
186 
188 
189 #endif // XAPIAN_INCLUDED_QUERYOPTIMISER_H
Abstract base class for leaf postlists.
Definition: leafpostlist.h:40
bool weight_needs_wdf() const
const Xapian::Weight::Internal * get_stats() const
PostListAndEstimate open_post_list(const std::string &term, Xapian::termcount wqf, double factor, bool need_positions, bool compound_weight, Xapian::Internal::QueryOptimiser *qopt, bool lazy_weight, TermFreqs *termfreqs)
void register_lazy_postlist_for_stats(LeafPostList *pl, TermFreqs *termfreqs)
PostListAndEstimate make_synonym_postlist(PostListTree *pltree, PostListAndEstimate or_pl, double factor, const TermFreqs &termfreqs)
Convert a postlist into a synonym postlist.
Virtual base class for Database internals.
Abstract base class for postlists.
Definition: postlist.h:40
Xapian::termcount get_total_subqs() const
void register_lazy_postlist_for_stats(LeafPostList *pl, TermFreqs *termfreqs)
Register a lazily-created LeafPostList for stats.
QueryOptimiser(const Xapian::Database::Internal &db_, LocalSubMatch &localsubmatch_, PostListTree *matcher_, Xapian::doccount shard_index_)
QueryOptimiser(const QueryOptimiser &)
Prevent copying.
void operator=(const QueryOptimiser &)
Prevent assignment.
void destroy_postlist(PostList *pl)
PostListAndEstimate open_post_list(const std::string &term, Xapian::termcount wqf, double factor, TermFreqs *termfreqs)
Create a PostList object for term.
PostListAndEstimate make_synonym_postlist(PostListAndEstimate or_pl, double factor, const TermFreqs &termfreqs)
Create a SynonymPostList object.
void set_hint_postlist(LeafPostList *new_hint)
const Xapian::Weight::Internal * get_stats() const
const Xapian::Database::Internal & db
const LeafPostList * get_hint_postlist() const
PostListAndEstimate open_lazy_post_list(const std::string &term, Xapian::termcount wqf, double factor)
Xapian::termcount total_subqs
How many weighted leaf subqueries there are.
void set_total_subqs(Xapian::termcount n)
Class to hold statistics for a given collection.
string term
Virtual base class for Database internals.
Abstract base class for leaf postlists.
SubMatch class for a local database.
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:37
Abstract base class for postlists.
The frequencies for a term.