Reimplement Xapian::MSet
[xapian.git] / xapian-core / api / result.h
blob97397aaa6de7ef04f193de83b2290c88bdc8e3c9
1 /** @file result.h
2 * @brief A result in an MSet
3 */
4 /* Copyright 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_RESULT_H
22 #define XAPIAN_INCLUDED_RESULT_H
24 #include "xapian/types.h"
26 #include <string>
28 /** A result in an MSet. */
29 class Result {
30 double weight;
32 Xapian::docid did;
34 Xapian::doccount collapse_count = 0;
36 std::string collapse_key;
38 std::string sort_key;
40 public:
41 /// FIXME: Try to eliminate non-move assignment.
42 Result& operator=(const Result&) = default;
44 /// FIXME: Try to eliminate copying.
45 Result(const Result&) = default;
47 /// Move constructor.
48 Result(Result&& o) = default;
50 /// Move assignment.
51 Result& operator=(Result&& o) = default;
53 /// Constructor.
54 Result(double weight_, Xapian::docid did_)
55 : weight(weight_), did(did_) {}
57 /// Constructor used by MSet::Internal::unserialise().
58 Result(double weight_, Xapian::docid did_,
59 std::string&& collapse_key_,
60 Xapian::doccount collapse_count_,
61 std::string&& sort_key_)
62 : weight(weight_), did(did_),
63 collapse_count(collapse_count_),
64 collapse_key(std::move(collapse_key_)),
65 sort_key(std::move(sort_key_)) {}
67 void swap(Result& o);
69 Xapian::docid get_docid() const { return did; }
71 double get_weight() const { return weight; }
73 Xapian::doccount get_collapse_count() const { return collapse_count; }
75 const std::string& get_collapse_key() const { return collapse_key; }
77 const std::string& get_sort_key() const { return sort_key; }
79 void set_weight(double weight_) { weight = weight_; }
81 void set_collapse_count(Xapian::doccount c) { collapse_count = c; }
83 void set_collapse_key(const std::string& k) { collapse_key = k; }
85 void set_sort_key(const std::string& k) { sort_key = k; }
87 std::string get_description() const;
90 #endif // XAPIAN_INCLUDED_RESULT_H