xapian-core  2.0.0
msetinternal.h
Go to the documentation of this file.
1 
4 /* Copyright 2016,2017,2024 Olly Betts
5  *
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.
10  *
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.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef XAPIAN_INCLUDED_MSETINTERNAL_H
22 #define XAPIAN_INCLUDED_MSETINTERNAL_H
23 
24 #include "enquireinternal.h"
25 #include "net/serialise.h"
26 #include "result.h"
27 #include "weight/weightinternal.h"
28 
29 #include "xapian/intrusive_ptr.h"
30 #include "xapian/mset.h"
31 #include "xapian/types.h"
32 
33 #include <memory>
34 #include <string>
35 #include <string_view>
36 #include <unordered_map>
37 #include <vector>
38 
39 class Matcher;
40 
41 namespace Xapian {
42 
45  friend class MSet;
46  friend class MSetIterator;
47  friend class ::Matcher;
48 
50  void operator=(const Internal &) = delete;
51 
53  Internal(const Internal &) = delete;
54 
56  mutable std::unordered_map<std::string, double> snippet_bg_relevance;
57 
59  std::vector<Result> items;
60 
62  std::unique_ptr<Xapian::Weight::Internal> stats;
63 
65 
67 
69 
71 
73 
75 
77 
79 
80  double max_possible = 0;
81 
82  double max_attained = 0;
83 
86 
87  public:
88  Internal() {}
89 
91  Xapian::doccount matches_upper_bound_,
92  Xapian::doccount matches_lower_bound_,
93  Xapian::doccount matches_estimated_,
94  Xapian::doccount uncollapsed_upper_bound_,
95  Xapian::doccount uncollapsed_lower_bound_,
96  Xapian::doccount uncollapsed_estimated_,
97  double max_possible_,
98  double max_attained_,
99  std::vector<Result>&& items_,
100  double percent_scale_factor_)
101  : items(std::move(items_)),
102  matches_lower_bound(matches_lower_bound_),
103  matches_estimated(matches_estimated_),
104  matches_upper_bound(matches_upper_bound_),
105  uncollapsed_lower_bound(uncollapsed_lower_bound_),
106  uncollapsed_estimated(uncollapsed_estimated_),
107  uncollapsed_upper_bound(uncollapsed_upper_bound_),
108  first(first_),
109  max_possible(max_possible_),
110  max_attained(max_attained_),
111  percent_scale_factor(percent_scale_factor_) {}
112 
113  void set_first(Xapian::doccount first_) { first = first_; }
114 
115  void set_enquire(const Xapian::Enquire::Internal* enquire_) {
116  enquire = enquire_;
117  }
118 
119  Xapian::Weight::Internal* get_stats() const { return stats.get(); }
120 
121  void set_stats(Xapian::Weight::Internal* stats_) { stats.reset(stats_); }
122 
124 
126 
127  void fetch(Xapian::doccount first, Xapian::doccount last) const;
128 
129  void set_item_weight(Xapian::doccount i, double weight);
130 
131  int convert_to_percent(double weight) const;
132 
133  void unshard_docids(Xapian::doccount shard, Xapian::doccount n_shards);
134 
135  void merge_stats(const Internal* o, bool collapsing);
136 
137  std::string snippet(std::string_view text,
138  size_t length,
139  const Xapian::Stem & stemmer,
140  unsigned flags,
141  std::string_view hi_start,
142  std::string_view hi_end,
143  std::string_view omit) const;
144 
149  std::string serialise() const;
150 
158  void unserialise(const char * p, const char * p_end);
159 
161  std::string get_description() const;
162 };
163 
164 }
165 
166 #endif // XAPIAN_INCLUDED_MSETINTERNAL_H
Class representing a document.
Definition: document.h:64
Base class for objects managed by intrusive_ptr.
Definition: intrusive_ptr.h:50
A smart pointer that uses intrusive reference counting.
Definition: intrusive_ptr.h:83
Iterator over a Xapian::MSet.
Definition: mset.h:535
Xapian::MSet internals.
Definition: msetinternal.h:44
Xapian::doccount uncollapsed_upper_bound
Definition: msetinternal.h:76
std::string serialise() const
Serialise this object.
Definition: mset.cc:517
void operator=(const Internal &)=delete
Don't allow assignment.
Xapian::Weight::Internal * get_stats() const
Definition: msetinternal.h:119
void set_first(Xapian::doccount first_)
Definition: msetinternal.h:113
int convert_to_percent(double weight) const
Definition: mset.cc:449
Xapian::Internal::intrusive_ptr< const Enquire::Internal > enquire
Definition: msetinternal.h:64
std::unordered_map< std::string, double > snippet_bg_relevance
Relevance weights for non-query terms for generating snippets.
Definition: msetinternal.h:56
std::string get_description() const
Return a string describing this object.
Definition: mset.cc:598
std::unique_ptr< Xapian::Weight::Internal > stats
For looking up query term frequencies and weights.
Definition: msetinternal.h:62
std::vector< Result > items
The items in the MSet.
Definition: msetinternal.h:59
Xapian::doccount uncollapsed_lower_bound
Definition: msetinternal.h:72
Internal(const Internal &)=delete
Don't allow copying.
Xapian::doccount matches_estimated
Definition: msetinternal.h:68
void unshard_docids(Xapian::doccount shard, Xapian::doccount n_shards)
Definition: mset.cc:482
void unserialise(const char *p, const char *p_end)
Unserialise a serialised Xapian::MSet::Internal object.
Definition: mset.cc:556
Xapian::Document get_document(Xapian::doccount index) const
Definition: mset.cc:400
void merge_stats(const Internal *o, bool collapsing)
Definition: mset.cc:491
Xapian::doccount first
Definition: msetinternal.h:78
void fetch(Xapian::doccount first, Xapian::doccount last) const
Definition: mset.cc:414
double get_percent_scale_factor() const
Definition: msetinternal.h:123
void set_item_weight(Xapian::doccount i, double weight)
Definition: mset.cc:431
Xapian::doccount matches_lower_bound
Definition: msetinternal.h:66
std::string snippet(std::string_view text, size_t length, const Xapian::Stem &stemmer, unsigned flags, std::string_view hi_start, std::string_view hi_end, std::string_view omit) const
double percent_scale_factor
Scale factor to convert weights to percentages.
Definition: msetinternal.h:85
Internal(Xapian::doccount first_, Xapian::doccount matches_upper_bound_, Xapian::doccount matches_lower_bound_, Xapian::doccount matches_estimated_, Xapian::doccount uncollapsed_upper_bound_, Xapian::doccount uncollapsed_lower_bound_, Xapian::doccount uncollapsed_estimated_, double max_possible_, double max_attained_, std::vector< Result > &&items_, double percent_scale_factor_)
Definition: msetinternal.h:90
void set_stats(Xapian::Weight::Internal *stats_)
Definition: msetinternal.h:121
Xapian::doccount matches_upper_bound
Definition: msetinternal.h:70
void set_enquire(const Xapian::Enquire::Internal *enquire_)
Definition: msetinternal.h:115
Xapian::doccount uncollapsed_estimated
Definition: msetinternal.h:74
Class representing a list of search results.
Definition: mset.h:46
Class representing a stemming algorithm.
Definition: stem.h:74
Class to hold statistics for a given collection.
PositionList * p
Xapian::Enquire internals.
Class representing a list of search results.
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:37
A result in an MSet.
functions to convert classes to strings and back
static Xapian::Stem stemmer
Definition: stemtest.cc:42
typedefs for Xapian
Xapian::Weight::Internal class, holding database and term statistics.