xapian-core  2.0.0
document.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2010,2015,2016,2017,2018,2019,2023,2024 Olly Betts
5  * Copyright 2009 Lemur Consulting Ltd
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see
19  * <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef XAPIAN_INCLUDED_DOCUMENT_H
23 #define XAPIAN_INCLUDED_DOCUMENT_H
24 
25 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
26 # error Never use <xapian/document.h> directly; include <xapian.h> instead.
27 #endif
28 
29 #include <string>
30 #include <string_view>
31 
32 #include <xapian/attributes.h>
33 #include <xapian/intrusive_ptr.h>
34 #include <xapian/termiterator.h>
35 #include <xapian/types.h>
36 #include <xapian/valueiterator.h>
37 #include <xapian/visibility.h>
38 
39 namespace Xapian {
40 
65  public:
67  class Internal;
70 
73  explicit Document(Internal*);
74 
79  Document(const Document& o);
80 
86 
89 
92 
97  Document();
98 
100  ~Document();
101 
111  Xapian::docid get_docid() const;
112 
114  std::string get_data() const;
115 
122  void set_data(std::string_view data);
123 
125  void add_term(std::string_view term, Xapian::termcount wdf_inc = 1);
126 
145  void add_boolean_term(std::string_view term) { add_term(term, 0); }
146 
148  void remove_term(std::string_view term);
149 
151  void add_posting(std::string_view term,
152  Xapian::termpos term_pos,
153  Xapian::termcount wdf_inc = 1);
154 
170  void remove_posting(std::string_view term,
171  Xapian::termpos term_pos,
172  Xapian::termcount wdf_dec = 1);
173 
195  Xapian::termpos remove_postings(std::string_view term,
196  Xapian::termpos term_pos_first,
197  Xapian::termpos term_pos_last,
198  Xapian::termcount wdf_dec = 1);
199 
201  void clear_terms();
202 
204  Xapian::termcount termlist_count() const;
205 
216  TermIterator termlist_begin() const;
217 
219  TermIterator termlist_end() const noexcept {
220  return TermIterator();
221  }
222 
229  std::string get_value(Xapian::valueno slot) const;
230 
236  void add_value(Xapian::valueno slot, std::string_view value);
237 
243  add_value(slot, {});
244  }
245 
247  void clear_values();
248 
250  Xapian::valueno values_count() const;
251 
256  ValueIterator values_begin() const;
257 
259  ValueIterator values_end() const noexcept {
260  return ValueIterator();
261  }
262 
267  void swap(Document& o) { internal.swap(o.internal); }
268 
275  std::string serialise() const;
276 
278  static Document unserialise(std::string_view serialised);
279 
281  std::string get_description() const;
282 };
283 
284 }
285 
286 #endif // XAPIAN_INCLUDED_DOCUMENT_H
Compiler attribute macros.
Abstract base class for a document.
Class representing a document.
Definition: document.h:64
Document(const Document &o)
Copy constructor.
Document(Document &&o)
Move constructor.
Document & operator=(const Document &o)
Assignment operator.
void add_boolean_term(std::string_view term)
Add a boolean filter term to the document.
Definition: document.h:145
void swap(Document &o)
Efficiently swap this Document object with another.
Definition: document.h:267
Xapian::Internal::intrusive_ptr_nonnull< Internal > internal
Definition: document.h:67
void remove_value(Xapian::valueno slot)
Remove any value from the specified slot.
Definition: document.h:242
TermIterator termlist_end() const noexcept
End iterator corresponding to termlist_begin().
Definition: document.h:219
Document & operator=(Document &&o)
Move assignment operator.
ValueIterator values_end() const noexcept
End iterator corresponding to values_begin().
Definition: document.h:259
Class for iterating over a list of terms.
Definition: termiterator.h:41
Class for iterating over document values.
Definition: valueiterator.h:39
string term
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned valueno
The number for a value slot in a document.
Definition: types.h:90
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Definition: types.h:75
Class for iterating over a list of terms.
typedefs for Xapian
Class for iterating over document values.
Define XAPIAN_VISIBILITY_* macros.
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28
#define XAPIAN_VISIBILITY_INTERNAL
Definition: visibility.h:29