new_subdb(int) -> new_shard(size_t)
[xapian.git] / xapian-core / matcher / valuestreamdocument.h
blob37d9bd9f60fc028087d82f2d2faee17492557467
1 /** @file valuestreamdocument.h
2 * @brief A document which gets its values from a ValueStreamManager.
3 */
4 /* Copyright (C) 2009,2011,2014,2017 Olly Betts
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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_VALUESTREAMDOCUMENT_H
22 #define XAPIAN_INCLUDED_VALUESTREAMDOCUMENT_H
24 #include "backends/documentinternal.h"
25 #include "backends/multi.h"
26 #include "backends/multi/multi_database.h"
27 #include "backends/valuelist.h"
28 #include "omassert.h"
29 #include "xapian/database.h"
30 #include "xapian/types.h"
32 #include <map>
34 /// A document which gets its values from a ValueStreamManager.
35 class ValueStreamDocument : public Xapian::Document::Internal {
36 /// Don't allow assignment.
37 void operator=(const ValueStreamDocument &);
39 /// Don't allow copying.
40 ValueStreamDocument(const ValueStreamDocument &);
42 mutable std::map<Xapian::valueno, ValueList *> valuelists;
44 Xapian::Database db;
46 size_t current = 0;
48 size_t n_shards;
50 mutable Xapian::Document::Internal * doc = NULL;
52 /** Private constructor.
54 * This is an implementation detail - the public constructor forwards to
55 * this constructor so we can use n_shards_ to init our parent class.
57 ValueStreamDocument(const Xapian::Database& db_, size_t n_shards_)
58 : Internal(n_shards_ == 1 ?
59 db_.internal.get() :
60 static_cast<MultiDatabase*>(db_.internal.get())->shards[0],
61 0),
62 db(db_),
63 n_shards(n_shards_) {}
65 public:
66 explicit ValueStreamDocument(const Xapian::Database& db_)
67 : ValueStreamDocument(db_, db_.internal->size()) {}
69 void new_shard(size_t n);
71 ~ValueStreamDocument();
73 void set_shard_document(Xapian::docid shard_did) {
74 if (did != shard_did) {
75 did = shard_did;
76 delete doc;
77 doc = NULL;
81 void set_document(Xapian::docid did_) {
82 AssertEq(current, shard_number(did_, n_shards));
83 set_shard_document(shard_docid(did_, n_shards));
86 // Optimise away the virtual call when the matcher wants to know a value.
87 std::string get_value(Xapian::valueno slot) const {
88 return ValueStreamDocument::fetch_value(slot);
91 protected:
92 /** Implementation of virtual methods @{ */
93 std::string fetch_value(Xapian::valueno slot) const;
94 void fetch_all_values(std::map<Xapian::valueno, std::string> & values_) const;
95 std::string fetch_data() const;
96 /** @} */
99 #endif // XAPIAN_INCLUDED_VALUESTREAMDOCUMENT_H