xapian-core  2.0.0
glass_spellingwordslist.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2004,2005,2006,2007,2008,2009,2017,2024 Olly Betts
5  * Copyright (C) 2007 Lemur Consulting Ltd
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (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 
25 
26 #include "xapian/error.h"
27 #include "xapian/types.h"
28 
29 #include "debuglog.h"
30 #include "glass_database.h"
31 #include "pack.h"
32 #include "stringutils.h"
33 
34 using namespace std;
35 
37 {
38  LOGCALL_DTOR(DB, "GlassSpellingWordsList");
39  delete cursor;
40 }
41 
44 {
45  // This is an over-estimate, but we only use this value to build a balanced
46  // or-tree, and it'll do a decent enough job for that.
47  return database->spelling_table.get_entry_count();
48 }
49 
52 {
53  LOGCALL(DB, Xapian::doccount, "GlassSpellingWordsList::get_termfreq", NO_ARGS);
54  Assert(cursor);
55  Assert(!cursor->after_end());
56  Assert(!cursor->current_key.empty());
57  Assert(cursor->current_key[0] == 'W');
58  cursor->read_tag();
59 
60  Xapian::termcount freq;
61  const char *p = cursor->current_tag.data();
62  if (!unpack_uint_last(&p, p + cursor->current_tag.size(), &freq)) {
63  throw Xapian::DatabaseCorruptError("Bad spelling word freq");
64  }
65  RETURN(freq);
66 }
67 
68 TermList *
70 {
71  LOGCALL(DB, TermList *, "GlassSpellingWordsList::next", NO_ARGS);
72  Assert(!cursor->after_end());
73 
74  if (!cursor->next() || cursor->current_key[0] != 'W') {
75  // We've reached the end of the prefixed terms.
76  RETURN(this);
77  }
78  current_term.assign(cursor->current_key, 1);
79  RETURN(NULL);
80 }
81 
82 TermList*
84 {
85  LOGCALL(DB, TermList *, "GlassSpellingWordsList::skip_to", tname);
86  Assert(!cursor->after_end());
87 
88  if (cursor->find_entry_ge("W"s.append(tname))) {
89  // Exact match.
90  current_term = tname;
91  } else {
92  // The exact term we asked for isn't there, so check if the next term
93  // after it also has a W prefix.
94  if (cursor->after_end() || cursor->current_key[0] != 'W') {
95  // We've reached the end of the prefixed terms.
96  RETURN(this);
97  }
98  current_term.assign(cursor->current_key, 1);
99  }
100  RETURN(NULL);
101 }
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
TermList * next()
Advance to the next term in the list.
Xapian::doccount get_termfreq() const
Returns the term frequency of the current term.
TermList * skip_to(std::string_view tname)
Advance to the first term which is >= tname.
DatabaseCorruptError indicates database corruption was detected.
Definition: error.h:397
Abstract base class for termlists.
Definition: termlist.h:42
PositionList * p
Debug logging macros.
#define RETURN(...)
Definition: debuglog.h:484
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:478
#define LOGCALL_DTOR(CATEGORY, CLASS)
Definition: debuglog.h:481
Hierarchy of classes which Xapian can throw as exceptions.
C++ class definition for glass database.
A termlist containing all words which are spelling targets.
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
Pack types into strings and unpack them again.
bool unpack_uint_last(const char **p, const char *end, U *result)
Decode an unsigned integer as the last item in a string.
Definition: pack.h:118
Various handy string-related helpers.
typedefs for Xapian