1 /** @file rsetinternal.h
2 * @brief Set of documents judged as relevant
4 /* Copyright (C) 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
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef XAPIAN_INCLUDED_RSETINTERNAL_H
20 #define XAPIAN_INCLUDED_RSETINTERNAL_H
22 #include <xapian/rset.h>
24 #include "backends/multi.h"
31 class RSet::Internal
: public Xapian::Internal::intrusive_base
{
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
;
38 void shard(size_t 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));
48 // Using resize() here would result in all the entries having the same
50 rsets
.reserve(n_shards
);
51 for (size_t i
= 0; i
< n_shards
; ++i
) {
52 rsets
.emplace_back(RSet());
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
);
64 #endif // XAPIAN_INCLUDED_RSETINTERNAL_H