xapian-core  2.0.0
valuestreamdocument.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2009,2011,2014,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 #include <config.h>
22 
23 #include "valuestreamdocument.h"
24 
26 #include "omassert.h"
27 
28 using namespace std;
29 
30 static void
31 clear_valuelists(map<Xapian::valueno, ValueList *> & valuelists)
32 {
33  map<Xapian::valueno, ValueList *>::const_iterator i;
34  for (i = valuelists.begin(); i != valuelists.end(); ++i) {
35  delete i->second;
36  }
37  valuelists.clear();
38 }
39 
41 {
42  delete doc;
43  clear_valuelists(valuelists);
44 }
45 
46 void
48 {
49  AssertRel(n,>,0);
50  AssertRel(n,<,n_shards);
51  current = unsigned(n);
52  // This method should only be called for a MultiDatabase.
53  auto multidb = static_cast<MultiDatabase*>(db.internal.get());
54  database = multidb->shards[n];
55  // Ensure set_document()'s "same docid" check doesn't misfire.
56  did = 0;
57  clear_valuelists(valuelists);
58 }
59 
60 string
62 {
63  pair<map<Xapian::valueno, ValueList *>::iterator, bool> ret;
64  ret = valuelists.insert(make_pair(slot, static_cast<ValueList*>(NULL)));
65  ValueList * vl;
66  if (ret.second) {
67  // Entry didn't already exist, so open a value list for slot.
68  vl = database->open_value_list(slot);
69  ret.first->second = vl;
70  } else {
71  vl = ret.first->second;
72  if (!vl) {
73  return string();
74  }
75  }
76 
77  if (vl->check(did)) {
78  if (vl->at_end()) {
79  delete vl;
80  ret.first->second = NULL;
81  } else if (vl->get_docid() == did) {
82  return vl->get_value();
83  }
84  }
85 
86  return string();
87 }
88 
89 void
90 ValueStreamDocument::fetch_all_values(map<Xapian::valueno, string> & v) const
91 {
92  if (!doc) {
93  doc = database->open_document(did, true);
94  }
95  doc->fetch_all_values(v);
96 }
97 
98 string
100 {
101  if (!doc) {
102  doc = database->open_document(did, true);
103  }
104  return doc->fetch_data();
105 }
Sharded database backend.
Xapian::SmallVectorI< Xapian::Database::Internal > shards
void fetch_all_values(std::map< Xapian::valueno, std::string > &values_) const
Implementation of virtual methods.
std::string fetch_value(Xapian::valueno slot) const
Implementation of virtual methods.
std::string fetch_data() const
Implementation of virtual methods.
void new_shard(Xapian::doccount n)
Abstract base class for value streams.
Definition: valuelist.h:31
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 bool check(Xapian::docid did)
Check if the specified docid occurs in this valuestream.
Definition: valuelist.cc:30
virtual std::string get_value() const =0
Return the value at the current position.
Sharded database backend.
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
Various assertion macros.
#define AssertRel(A, REL, B)
Definition: omassert.h:123
static void clear_valuelists(map< Xapian::valueno, ValueList * > &valuelists)
A document which gets its values from a ValueStreamManager.