xapian-core  2.1.0
documenttermlist.cc
Go to the documentation of this file.
1 
4 /* Copyright 2017,2024,2026 Olly Betts
5  *
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.
10  *
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.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #include <config.h>
22 
23 #include "documenttermlist.h"
24 
26 #include "clamp_cast.h"
27 #include "omassert.h"
28 
29 #include "xapian/error.h"
30 
31 using namespace std;
32 
35 {
36  // DocumentTermList is only used in a TermIterator wrapper and that never
37  // calls this method.
38  Assert(false);
39  return 0;
40 }
41 
44 {
45  Assert(it != doc->terms->end());
46  return it->second.get_wdf();
47 }
48 
51 {
52  throw Xapian::InvalidOperationError("get_termfreq() not valid for a TermIterator from a Document which is not associated with a database");
53 }
54 
57 {
58  return it->second.get_positions();
59 }
60 
63 {
64  return new InMemoryPositionList(*it->second.get_positions());
65 }
66 
69 {
70  return clamp_cast<Xapian::termcount>(it->second.count_positions());
71 }
72 
73 TermList*
75 {
76  if (it == doc->terms->end()) {
77  it = doc->terms->begin();
78  } else {
79  ++it;
80  }
81  while (it != doc->terms->end() && it->second.is_deleted()) {
82  ++it;
83  }
84  if (it == doc->terms->end()) {
85  return this;
86  }
87  current_term = it->first;
88  return NULL;
89 }
90 
91 TermList*
93 {
94  it = doc->terms->lower_bound(term);
95  while (it != doc->terms->end() && it->second.is_deleted()) {
96  ++it;
97  }
98  if (it == doc->terms->end()) {
99  return this;
100  }
101  current_term = it->first;
102  return NULL;
103 }
Cast a value to a type, clamping out of range values.
const Xapian::VecCOW< Xapian::termpos > * get_vec_termpos() const
Get pointer to VecCOW<termpos> if that's the internal representation.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
TermList * skip_to(std::string_view term)
Skip forward to the specified term.
Xapian::termcount positionlist_count() const
Return the length of the position list for the current position.
PositionList * positionlist_begin() const
Return PositionList for the current position.
TermList * next()
Advance the current position to the next term in the termlist.
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
PositionList from an InMemory DB or a Document object.
InvalidOperationError indicates the API was used in an invalid way.
Definition: error.h:271
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:32
Abstract base class for termlists.
Definition: termlist.h:42
Suitable for "simple" type T.
Definition: smallvector.h:62
string term
Iteration over terms in a document.
Hierarchy of classes which Xapian can throw as exceptions.
PositionList from an InMemory DB or a Document object.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:37
Various assertion macros.
#define Assert(COND)
Definition: omassert.h:122