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"
37 Document::Internal::ensure_terms_fetched() const
42 terms
.reset(new map
<string
, TermInfo
>());
47 unique_ptr
<TermList
> t(database
->open_term_list(did
));
48 while (t
->next(), !t
->at_end()) {
50 auto&& r
= terms
->emplace(make_pair(t
->get_termname(),
51 TermInfo(t
->get_wdf())));
52 TermInfo
& term
= r
.first
->second
;
53 for (auto p
= t
->positionlist_begin(); p
!= PositionIterator(); ++p
) {
54 term
.append_position(*p
);
60 Document::Internal::ensure_values_fetched() const
65 values
.reset(new map
<Xapian::valueno
, string
>());
67 fetch_all_values(*values
);
72 Document::Internal::fetch_data() const
78 Document::Internal::fetch_all_values(map
<Xapian::valueno
,
79 string
>& values_
) const
85 Document::Internal::fetch_value(Xapian::valueno
) const
90 Document::Internal::~Internal()
93 database
->invalidate_doc_object(this);
97 Document::Internal::open_term_list() const
100 return new DocumentTermList(this);
105 return database
->open_term_list(did
);
108 Xapian::ValueIterator
109 Document::Internal::values_begin() const
111 if (!values
&& database
.get()) {
112 values
.reset(new map
<Xapian::valueno
, string
>());
113 fetch_all_values(*values
);
116 if (!values
|| values
->empty())
117 return Xapian::ValueIterator();
119 return Xapian::ValueIterator(new DocumentValueList(this));
123 Document::Internal::get_description() const
125 string desc
= "Document(docid=";
130 description_append(desc
, *data
);
135 desc
+= str(terms
->size());
141 desc
+= str(values
->size());
145 if (database
.get()) {
147 desc
+= database
->get_description();