1 /** @file slowvaluelist.cc
2 * @brief Slow implementation for backends which don't streamed values.
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
23 #include "slowvaluelist.h"
25 #include "documentinternal.h"
27 #include "unicode/description_append.h"
29 #include "xapian/error.h"
36 SlowValueList::get_docid() const
42 SlowValueList::get_value() const
48 SlowValueList::get_valueno() const
54 SlowValueList::at_end() const
56 return last_docid
== 0;
62 // Compare before incrementing, since last_docid could be the largest
63 // representable value in which case current_did will wrap to zero before
65 while (current_did
++ < last_docid
) {
67 // Open document lazily so that we don't waste time checking for
69 void * d
= db
->open_document(current_did
, true);
72 unique_ptr
<Xapian::Document::Internal
>
73 doc(static_cast<Xapian::Document::Internal
*>(d
));
74 string value
= doc
->get_value(slot
);
76 swap(current_value
, value
);
79 } catch (const Xapian::DocNotFoundError
&) {
83 // Indicate that we're at_end().
88 SlowValueList::skip_to(Xapian::docid did
)
90 if (did
<= current_did
) return;
91 current_did
= did
- 1;
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().
110 void * d
= db
->open_document(current_did
, true);
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();
124 SlowValueList::get_description() const
126 string desc
= "SlowValueList(slot=";
128 if (last_docid
!= 0) {
130 desc
+= str(current_did
);
131 desc
+= ", value=\"";
132 description_append(desc
, current_value
);