2 * @brief Class representing a document
4 /* Copyright 2008,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 "xapian/document.h"
27 #include "backends/documentinternal.h"
28 #include "net/serialise.h"
31 #include "xapian/error.h"
37 throw_invalid_arg_empty_term()
39 throw Xapian::InvalidArgumentError("Empty termnames are invalid");
44 Document::Document(Document::Internal
* internal_
)
49 Document::Document(const Document
& o
)
50 : internal(o
.internal
)
55 Document::operator=(const Document
& o
)
57 internal
= o
.internal
;
61 Document::Document() : internal(new Xapian::Document::Internal
)
70 Document::get_docid() const
72 return internal
->get_docid();
76 Document::get_data() const
78 return internal
->get_data();
82 Document::set_data(const string
& data
)
84 internal
->set_data(data
);
88 Document::add_term(const string
& term
, Xapian::termcount wdf_inc
)
91 throw_invalid_arg_empty_term();
93 internal
->add_term(term
, wdf_inc
);
97 Document::remove_term(const string
& term
)
100 throw_invalid_arg_empty_term();
102 if (!internal
->remove_term(term
)) {
104 m
= "Document::remove_term() failed - term '";
107 throw Xapian::InvalidArgumentError(m
);
112 Document::add_posting(const string
& term
,
113 Xapian::termpos term_pos
,
114 Xapian::termcount wdf_inc
)
117 throw_invalid_arg_empty_term();
119 internal
->add_posting(term
, term_pos
, wdf_inc
);
123 Document::remove_posting(const string
& term
,
124 Xapian::termpos term_pos
,
125 Xapian::termcount wdf_dec
)
128 throw_invalid_arg_empty_term();
130 auto res
= internal
->remove_posting(term
, term_pos
, wdf_dec
);
131 if (res
!= Document::Internal::OK
) {
132 string m
= "Document::remove_posting() failed - term '";
134 if (res
== Document::Internal::NO_TERM
) {
135 m
+= "' not present";
137 m
+= "' not present at position ";
140 throw Xapian::InvalidArgumentError(m
);
145 Document::clear_terms()
147 internal
->clear_terms();
151 Document::termlist_count() const {
152 return internal
->termlist_count();
156 Document::termlist_begin() const
158 return TermIterator(internal
->open_term_list());
162 Document::get_value(Xapian::valueno slot
) const
164 return internal
->get_value(slot
);
168 Document::add_value(Xapian::valueno slot
, const string
& value
)
170 internal
->add_value(slot
, value
);
174 Document::clear_values()
176 internal
->clear_values();
180 Document::values_count() const {
181 return internal
->values_count();
185 Document::values_begin() const
187 return internal
->values_begin();
191 Document::serialise() const
193 return serialise_document(*this);
197 Document::unserialise(const string
& serialised
)
199 return unserialise_document(serialised
);
203 Document::get_description() const
205 return internal
->get_description();