1 /** @file documentinternal.cc
2 * @brief Abstract base class for a document
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
23 #include "backends/documentinternal.h"
25 #include "api/documenttermlist.h"
26 #include "api/documentvaluelist.h"
28 #include "unicode/description_append.h"
30 #include "xapian/valueiterator.h"
39 Document::Internal::ensure_terms_fetched() const
44 terms
.reset(new map
<string
, TermInfo
>());
49 unique_ptr
<TermList
> t(database
->open_term_list(did
));
50 while (t
->next(), !t
->at_end()) {
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());
57 term
.append_position(p
->get_position());
63 Document::Internal::ensure_values_fetched() const
68 values
.reset(new map
<Xapian::valueno
, string
>());
70 fetch_all_values(*values
);
75 Document::Internal::fetch_data() const
81 Document::Internal::fetch_all_values(map
<Xapian::valueno
,
82 string
>& values_
) const
88 Document::Internal::fetch_value(Xapian::valueno
) const
93 Document::Internal::~Internal()
96 database
->invalidate_doc_object(this);
100 Document::Internal::open_term_list() const
103 return new DocumentTermList(this);
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));
126 Document::Internal::get_description() const
128 string desc
= "Document(docid=";
133 description_append(desc
, *data
);
138 desc
+= str(terms
->size());
144 desc
+= str(values
->size());
148 if (database
.get()) {
150 desc
+= database
->get_description();