[honey] Clean up unused values
[xapian.git] / xapian-core / backends / slowvaluelist.cc
blob7d258098ce9a63d1ad04993d208a9541ea920ec1
1 /** @file slowvaluelist.cc
2 * @brief Slow implementation for backends which don't streamed values.
3 */
4 /* Copyright (C) 2008,2011,2013,2014,2018 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 "slowvaluelist.h"
25 #include "documentinternal.h"
26 #include "str.h"
27 #include "unicode/description_append.h"
29 #include "xapian/error.h"
31 #include <memory>
33 using namespace std;
35 Xapian::docid
36 SlowValueList::get_docid() const
38 return current_did;
41 string
42 SlowValueList::get_value() const
44 return current_value;
47 Xapian::valueno
48 SlowValueList::get_valueno() const
50 return slot;
53 bool
54 SlowValueList::at_end() const
56 return last_docid == 0;
59 void
60 SlowValueList::next()
62 // Compare before incrementing, since last_docid could be the largest
63 // representable value in which case current_did will wrap to zero before
64 // exceeding it.
65 while (current_did++ < last_docid) {
66 try {
67 // Open document lazily so that we don't waste time checking for
68 // its existence.
69 void * d = db->open_document(current_did, true);
70 if (!d)
71 continue;
72 unique_ptr<Xapian::Document::Internal>
73 doc(static_cast<Xapian::Document::Internal*>(d));
74 string value = doc->get_value(slot);
75 if (!value.empty()) {
76 swap(current_value, value);
77 return;
79 } catch (const Xapian::DocNotFoundError &) {
83 // Indicate that we're at_end().
84 last_docid = 0;
87 void
88 SlowValueList::skip_to(Xapian::docid did)
90 if (did <= current_did) return;
91 current_did = did - 1;
92 next();
95 bool
96 SlowValueList::check(Xapian::docid did)
98 if (did <= current_did) {
99 return !current_value.empty();
102 if (did > last_docid) {
103 // Indicate that we're at_end().
104 last_docid = 0;
105 return true;
108 current_did = did;
109 try {
110 void * d = db->open_document(current_did, true);
111 if (d) {
112 unique_ptr<Xapian::Document::Internal>
113 doc(static_cast<Xapian::Document::Internal*>(d));
114 current_value = doc->get_value(slot);
115 if (!current_value.empty()) return true;
117 } catch (const Xapian::DocNotFoundError &) {
119 current_value = string();
120 return false;
123 string
124 SlowValueList::get_description() const
126 string desc = "SlowValueList(slot=";
127 desc += str(slot);
128 if (last_docid != 0) {
129 desc += ", docid=";
130 desc += str(current_did);
131 desc += ", value=\"";
132 description_append(desc, current_value);
133 desc += "\")";
134 } else {
135 desc += ", atend)";
137 return desc;