xapian-core  2.1.0
inmemory_alltermslist.cc
Go to the documentation of this file.
1 
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2003,2004,2007,2008,2009,2017,2024,2026 Olly Betts
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 #include <config.h>
23 #include "inmemory_alltermslist.h"
24 
25 #include "clamp_cast.h"
26 #include "stringutils.h"
27 
28 using namespace std;
29 
32 {
33  // This may be an over-estimate due to deleted entries, and we may be
34  // restricted to a prefix, but we only use this value to build a balanced
35  // or-tree, and it'll do a decent job for that.
36  return clamp_cast<Xapian::termcount>(tmap->size());
37 }
38 
41 {
42  if (database->is_closed()) InMemoryDatabase::throw_database_closed();
43  Assert(it != tmap->end());
44  Assert(!it->first.empty());
45  /* FIXME: this isn't quite right. */
46  return clamp_cast<Xapian::doccount>(it->second.docs.size());
47 }
48 
49 TermList*
51 {
52  if (database->is_closed()) InMemoryDatabase::throw_database_closed();
53  string term(term_);
54  Assert(it != tmap->end());
55  if (!it->first.empty()) {
56  // Don't skip backwards.
57  if (term <= it->first) return NULL;
58  } else {
59  // Don't skip to before where we're supposed to start.
60  if (term < prefix) {
61  term = prefix;
62  } else if (term.empty()) {
63  ++it;
64  while (it != tmap->end() && it->second.term_freq == 0) ++it;
65  if (it == tmap->end())
66  return this;
67  current_term = it->first;
68  return NULL;
69  }
70  }
71  it = tmap->lower_bound(term);
72  while (it != tmap->end() && it->second.term_freq == 0) ++it;
73  if (it == tmap->end() || !startswith(it->first, prefix)) {
74  return this;
75  }
76  current_term = it->first;
77  return NULL;
78 }
79 
80 TermList *
82 {
83  if (database->is_closed()) InMemoryDatabase::throw_database_closed();
84  Assert(it != tmap->end());
85  if (it->first.empty() && !prefix.empty()) {
86  it = tmap->lower_bound(prefix);
87  } else {
88  ++it;
89  }
90  while (it != tmap->end() && it->second.term_freq == 0) ++it;
91  if (it == tmap->end() || !startswith(it->first, prefix)) {
92  return this;
93  }
94  current_term = it->first;
95  return NULL;
96 }
97 
98 #ifdef DISABLE_GPL_LIBXAPIAN
99 # error GPL source we cannot relicense included in libxapian
100 #endif
Cast a value to a type, clamping out of range values.
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
TermList * next()
next() causes the AllTermsList to move to the next term in the list.
TermList * skip_to(std::string_view term)
Skip forward to the specified term.
static void throw_database_closed()
Abstract base class for termlists.
Definition: termlist.h:42
string term
Iterate all terms in an inmemory db.
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
#define Assert(COND)
Definition: omassert.h:122
Various handy string-related helpers.
bool startswith(std::string_view s, char pfx)
Definition: stringutils.h:56