xapian-core  2.0.0
rsetinternal.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2017 Olly Betts
5  *
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.
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  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, see
16  * <https://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef XAPIAN_INCLUDED_RSETINTERNAL_H
20 #define XAPIAN_INCLUDED_RSETINTERNAL_H
21 
22 #include <xapian/rset.h>
23 
24 #include "backends/multi.h"
25 
26 #include <set>
27 #include <vector>
28 
29 namespace Xapian {
30 
32  public:
33  // We want to be able to iterate the contents in docid order, and we don't
34  // expect people to mark vast numbers of documents as relevant, so use
35  // std::set rather than std::unordered_set.
36  std::set<Xapian::docid> docs;
37 
38  void shard(Xapian::doccount n_shards, std::vector<Xapian::RSet>& rsets) {
39  if (n_shards == 1 || docs.empty()) {
40  // Either there's a single database (in which case we just need
41  // to return ourself as the sharded RSet), or there are no relevance
42  // judgements (in which case we can use ourself as the internals for
43  // all the empty sharded RSets).
44  rsets.resize(n_shards, RSet(this));
45  return;
46  }
47 
48  // Using resize() here would result in all the entries having the same
49  // internals.
50  rsets.reserve(n_shards);
51  for (Xapian::doccount i = 0; i < n_shards; ++i) {
52  rsets.emplace_back(RSet());
53  }
54 
55  for (auto&& did : docs) {
56  Xapian::docid shard_did = shard_docid(did, n_shards);
57  rsets[shard_number(did, n_shards)].add_document(shard_did);
58  }
59  }
60 };
61 
62 }
63 
64 #endif // XAPIAN_INCLUDED_RSETINTERNAL_H
Base class for objects managed by intrusive_ptr.
Definition: intrusive_ptr.h:50
std::set< Xapian::docid > docs
Definition: rsetinternal.h:36
void shard(Xapian::doccount n_shards, std::vector< Xapian::RSet > &rsets)
Definition: rsetinternal.h:38
RSet()
Default constructor.
Definition: rset.cc:42
Multi-database support functions.
Xapian::doccount shard_number(Xapian::docid did, Xapian::doccount n_shards)
Convert docid in the multi-db to shard number.
Definition: multi.h:49
Xapian::docid shard_docid(Xapian::docid did, Xapian::doccount n_shards)
Convert docid in the multi-db to the docid in the shard.
Definition: multi.h:35
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
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
Set of documents judged as relevant.