xapian-core  2.0.0
multi_valuelist.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2008,2009,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  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef XAPIAN_INCLUDED_MULTI_VALUELIST_H
22 #define XAPIAN_INCLUDED_MULTI_VALUELIST_H
23 
24 #include "backends/valuelist.h"
25 
27 #include "backends/multi.h"
28 
29 #include <string>
30 
31 struct SubValueList {
33  unsigned shard;
34 
35  SubValueList(ValueList * vl, unsigned shard_)
36  : valuelist(vl), shard(shard_) { }
37 
39  delete valuelist;
40  }
41 
42  void skip_to(Xapian::docid did, Xapian::doccount n_shards) {
43  // Calculate the docid in this shard which is the same or later than
44  // did (which may be in a different shard).
45  Xapian::docid shard_did = shard_docid(did, n_shards);
46  if (shard_number(did, n_shards) > shard)
47  ++shard_did;
48  valuelist->skip_to(shard_did);
49  }
50 
52  return valuelist->get_docid();
53  }
54 
55  Xapian::docid get_merged_docid(unsigned n_shards) const {
56  return unshard(valuelist->get_docid(), shard, n_shards);
57  }
58 
59  std::string get_value() const { return valuelist->get_value(); }
60 
61  void next() {
62  valuelist->next();
63  }
64 
65  bool at_end() const { return valuelist->at_end(); }
66 };
67 
69 class MultiValueList : public ValueList {
71  void operator=(const MultiValueList &);
72 
75 
78 
81 
84 
87 
89 
90  public:
93  SubValueList** valuelists_,
94  Xapian::valueno slot_)
95  : count(n_shards_),
96  valuelists(valuelists_),
97  slot(slot_),
98  n_shards(n_shards_)
99  {
100  }
101 
103  ~MultiValueList();
104 
106  Xapian::docid get_docid() const;
107 
109  std::string get_value() const;
110 
113 
115  bool at_end() const;
116 
123  void next();
124 
130  void skip_to(Xapian::docid);
131 
150  bool check(Xapian::docid did);
151 
153  std::string get_description() const;
154 };
155 
156 #endif // XAPIAN_INCLUDED_MULTIVALUELIST_H
Class for merging ValueList objects from subdatabases.
bool check(Xapian::docid did)
Check if the specified docid occurs in this valuestream.
Xapian::valueno get_valueno() const
Return the value slot for the current position/this iterator.
std::string get_value() const
Return the value at the current position.
std::string get_description() const
Return a string description of this object.
Xapian::docid current_docid
Current docid (or 0 if we haven't started yet).
Xapian::valueno slot
The value slot we're iterating over.
MultiValueList(Xapian::doccount n_shards_, SubValueList **valuelists_, Xapian::valueno slot_)
Constructor.
Xapian::doccount count
Number of SubValueList* entries in valuelists.
Xapian::doccount n_shards
void next()
Advance the current position to the next document in the value stream.
void operator=(const MultiValueList &)
Don't allow assignment.
~MultiValueList()
Destructor.
SubValueList ** valuelists
Array of sub-valuelists which we use as a heap.
MultiValueList(const MultiValueList &)
Don't allow copying.
bool at_end() const
Return true if the current position is past the last entry in this list.
Xapian::docid get_docid() const
Return the docid at the current position.
void skip_to(Xapian::docid)
Skip forward to the specified docid.
Abstract base class for value streams.
Definition: valuelist.h:31
virtual void next()=0
Advance the current position to the next document in the value stream.
virtual Xapian::docid get_docid() const =0
Return the docid at the current position.
virtual bool at_end() const =0
Return true if the current position is past the last entry in this list.
virtual void skip_to(Xapian::docid)=0
Skip forward to the specified docid.
virtual std::string get_value() const =0
Return the value at the current position.
Virtual base class for Database internals.
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
Xapian::docid unshard(Xapian::docid shard_did, Xapian::doccount shard, Xapian::doccount n_shards)
Convert shard number and shard docid to docid in multi-db.
Definition: multi.h:64
unsigned valueno
The number for a value slot in a document.
Definition: types.h:90
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
Xapian::docid get_docid() const
SubValueList(ValueList *vl, unsigned shard_)
bool at_end() const
unsigned shard
Xapian::docid get_merged_docid(unsigned n_shards) const
void skip_to(Xapian::docid did, Xapian::doccount n_shards)
ValueList * valuelist
std::string get_value() const
Abstract base class for value streams.