Skip lockfilealreadyopen1 under __CYGWIN__ &__WIN32__
[xapian.git] / xapian-core / api / msetinternal.h
blob20b46e60883ed678b8af81c754f9db6af87ebb4a
1 /** @file msetinternal.h
2 * @brief Xapian::MSet internals
3 */
4 /* Copyright 2016,2017 Olly Betts
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef XAPIAN_INCLUDED_MSETINTERNAL_H
22 #define XAPIAN_INCLUDED_MSETINTERNAL_H
24 #include "enquireinternal.h"
25 #include "net/serialise.h"
26 #include "result.h"
27 #include "weight/weightinternal.h"
29 #include "xapian/intrusive_ptr.h"
30 #include "xapian/mset.h"
31 #include "xapian/types.h"
33 #include <memory>
34 #include <string>
35 #include <unordered_map>
36 #include <vector>
38 class Matcher;
40 namespace Xapian {
42 /// Xapian::MSet internals.
43 class MSet::Internal : public Xapian::Internal::intrusive_base {
44 friend class MSet;
45 friend class MSetIterator;
46 friend class ::Matcher;
48 /// Don't allow assignment.
49 void operator=(const Internal &) = delete;
51 /// Don't allow copying.
52 Internal(const Internal &) = delete;
54 /// Relevance weights for non-query terms for generating snippets.
55 mutable std::unordered_map<std::string, double> snippet_bg_relevance;
57 /// The items in the MSet.
58 std::vector<Result> items;
60 /// For looking up query term frequencies and weights.
61 std::unique_ptr<Xapian::Weight::Internal> stats;
63 Xapian::Internal::intrusive_ptr<const Enquire::Internal> enquire;
65 Xapian::doccount matches_lower_bound = 0;
67 Xapian::doccount matches_estimated = 0;
69 Xapian::doccount matches_upper_bound = 0;
71 Xapian::doccount uncollapsed_lower_bound = 0;
73 Xapian::doccount uncollapsed_estimated = 0;
75 Xapian::doccount uncollapsed_upper_bound = 0;
77 Xapian::doccount first = 0;
79 double max_possible = 0;
81 double max_attained = 0;
83 /// Scale factor to convert weights to percentages.
84 double percent_scale_factor = 0;
86 public:
87 Internal() {}
89 Internal(Xapian::doccount first_,
90 Xapian::doccount matches_upper_bound_,
91 Xapian::doccount matches_lower_bound_,
92 Xapian::doccount matches_estimated_,
93 Xapian::doccount uncollapsed_upper_bound_,
94 Xapian::doccount uncollapsed_lower_bound_,
95 Xapian::doccount uncollapsed_estimated_,
96 double max_possible_,
97 double max_attained_,
98 std::vector<Result>&& items_,
99 double percent_scale_factor_)
100 : items(std::move(items_)),
101 matches_lower_bound(matches_lower_bound_),
102 matches_estimated(matches_estimated_),
103 matches_upper_bound(matches_upper_bound_),
104 uncollapsed_lower_bound(uncollapsed_lower_bound_),
105 uncollapsed_estimated(uncollapsed_estimated_),
106 uncollapsed_upper_bound(uncollapsed_upper_bound_),
107 first(first_),
108 max_possible(max_possible_),
109 max_attained(max_attained_),
110 percent_scale_factor(percent_scale_factor_) {}
112 void set_first(Xapian::doccount first_) { first = first_; }
114 void set_enquire(const Xapian::Enquire::Internal* enquire_) {
115 enquire = enquire_;
118 Xapian::Weight::Internal* get_stats() const { return stats.get(); }
120 void set_stats(Xapian::Weight::Internal* stats_) { stats.reset(stats_); }
122 double get_percent_scale_factor() const { return percent_scale_factor; }
124 Xapian::Document get_document(Xapian::doccount index) const;
126 void fetch(Xapian::doccount first, Xapian::doccount last) const;
128 void set_item_weight(Xapian::doccount i, double weight);
130 int convert_to_percent(double weight) const;
132 void unshard_docids(Xapian::doccount shard, Xapian::doccount n_shards);
134 void merge_stats(const Internal* o);
136 std::string snippet(const std::string & text, size_t length,
137 const Xapian::Stem & stemmer,
138 unsigned flags,
139 const std::string & hi_start,
140 const std::string & hi_end,
141 const std::string & omit) const;
143 /** Serialise this object.
145 * @return The serialisation of this object.
147 std::string serialise() const;
149 /** Unserialise a serialised Xapian::MSet::Internal object.
151 * @param p Pointer to the start of the string to unserialise.
152 * @param p_end Pointer to the end of the string to unserialise.
154 * This object is updated with the unserialised data.
156 void unserialise(const char * p, const char * p_end);
158 /// Return a string describing this object.
159 std::string get_description() const;
164 #endif // XAPIAN_INCLUDED_MSETINTERNAL_H