[honey] Clean up unused values
[xapian.git] / xapian-core / backends / documentinternal.cc
blobc71943328698fa20fe5a4452cb16d7be4260c20d
1 /** @file documentinternal.cc
2 * @brief Abstract base class for a document
3 */
4 /* Copyright 2017 Olly Betts
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (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 #include <config.h>
23 #include "backends/documentinternal.h"
25 #include "api/documenttermlist.h"
26 #include "api/documentvaluelist.h"
27 #include "str.h"
28 #include "unicode/description_append.h"
30 #include "xapian/valueiterator.h"
32 #include <memory>
34 using namespace std;
36 namespace Xapian {
38 void
39 Document::Internal::ensure_terms_fetched() const
41 if (terms)
42 return;
44 terms.reset(new map<string, TermInfo>());
45 termlist_size = 0;
46 if (!database.get())
47 return;
49 unique_ptr<TermList> t(database->open_term_list(did));
50 while (t->next(), !t->at_end()) {
51 ++termlist_size;
52 auto&& r = terms->emplace(make_pair(t->get_termname(),
53 TermInfo(t->get_wdf())));
54 TermInfo& term = r.first->second;
55 unique_ptr<PositionList> p(t->positionlist_begin());
56 while (p->next()) {
57 term.append_position(p->get_position());
62 void
63 Document::Internal::ensure_values_fetched() const
65 if (values)
66 return;
68 values.reset(new map<Xapian::valueno, string>());
69 if (database.get()) {
70 fetch_all_values(*values);
74 string
75 Document::Internal::fetch_data() const
77 return string();
80 void
81 Document::Internal::fetch_all_values(map<Xapian::valueno,
82 string>& values_) const
84 values_.clear();
87 string
88 Document::Internal::fetch_value(Xapian::valueno) const
90 return string();
93 Document::Internal::~Internal()
95 if (database.get())
96 database->invalidate_doc_object(this);
99 TermList*
100 Document::Internal::open_term_list() const
102 if (terms)
103 return new DocumentTermList(this);
105 if (!database.get())
106 return NULL;
108 return database->open_term_list(did);
111 Xapian::ValueIterator
112 Document::Internal::values_begin() const
114 if (!values && database.get()) {
115 values.reset(new map<Xapian::valueno, string>());
116 fetch_all_values(*values);
119 if (!values || values->empty())
120 return Xapian::ValueIterator();
122 return Xapian::ValueIterator(new DocumentValueList(this));
125 string
126 Document::Internal::get_description() const
128 string desc = "Document(docid=";
129 desc += str(did);
131 if (data) {
132 desc += ", data=";
133 description_append(desc, *data);
136 if (terms) {
137 desc += ", terms[";
138 desc += str(terms->size());
139 desc += ']';
142 if (values) {
143 desc += ", values[";
144 desc += str(values->size());
145 desc += ']';
148 if (database.get()) {
149 desc += ", db=";
150 desc += database->get_description();
153 desc += ')';
155 return desc;