chert_termlist.cc
Go to the documentation of this file.
1 /* chert_termlist.cc: Termlists in a chert database
2  *
3  * Copyright 1999,2000,2001 BrightStation PLC
4  * Copyright 2002 Ananova Ltd
5  * Copyright 2002,2003,2004,2006,2007,2008,2010 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, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20  * USA
21  */
22 
23 #include <config.h>
24 #include "chert_termlist.h"
25 
26 #include "xapian/error.h"
27 
28 #include "expandweight.h"
29 #include "chert_positionlist.h"
30 #include "debuglog.h"
31 #include "omassert.h"
32 #include "pack.h"
33 #include "str.h"
34 
35 using namespace std;
36 
38  Xapian::docid did_)
39  : db(db_), did(did_), current_wdf(0), current_termfreq(0)
40 {
41  LOGCALL_CTOR(DB, "ChertTermList", db_ | did_);
42 
44  data))
45  throw Xapian::DocNotFoundError("No termlist for document " + str(did));
46 
47  pos = data.data();
48  end = pos + data.size();
49 
50  if (pos == end) {
51  doclen = 0;
52  termlist_size = 0;
53  return;
54  }
55 
56  // Read doclen
57  if (!unpack_uint(&pos, end, &doclen)) {
58  const char *msg;
59  if (pos == 0) {
60  msg = "Too little data for doclen in termlist";
61  } else {
62  msg = "Overflowed value for doclen in termlist";
63  }
65  }
66 
67  // Read termlist_size
68  if (!unpack_uint(&pos, end, &termlist_size)) {
69  const char *msg;
70  if (pos == 0) {
71  msg = "Too little data for list size in termlist";
72  } else {
73  msg = "Overflowed value for list size in termlist";
74  }
76  }
77 }
78 
81 {
82  LOGCALL(DB, chert_doclen_t, "ChertTermList::get_doclength", NO_ARGS);
83  RETURN(doclen);
84 }
85 
88 {
89  LOGCALL(DB, Xapian::termcount, "ChertTermList::get_approx_size", NO_ARGS);
91 }
92 
93 void
95 {
96  LOGCALL_VOID(DB, "ChertTermList::accumulate_stats", stats);
97  Assert(!at_end());
99 }
100 
101 string
103 {
104  LOGCALL(DB, string, "ChertTermList::get_termname", NO_ARGS);
106 }
107 
110 {
111  LOGCALL(DB, Xapian::termcount, "ChertTermList::get_wdf", NO_ARGS);
113 }
114 
117 {
118  LOGCALL(DB, Xapian::doccount, "ChertTermList::get_termfreq", NO_ARGS);
119  if (current_termfreq == 0)
122 }
123 
124 TermList *
126 {
127  LOGCALL(DB, TermList *, "ChertTermList::next", NO_ARGS);
128  Assert(!at_end());
129  if (pos == end) {
130  pos = NULL;
131  RETURN(NULL);
132  }
133 
134  // Reset to 0 to indicate that the termfreq needs to be read.
135  current_termfreq = 0;
136 
137  bool wdf_in_reuse = false;
138  if (!current_term.empty()) {
139  // Find out how much of the previous term to reuse.
140  size_t len = static_cast<unsigned char>(*pos++);
141  if (len > current_term.size()) {
142  // The wdf is also stored in the "reuse" byte.
143  wdf_in_reuse = true;
144  size_t divisor = current_term.size() + 1;
145  current_wdf = len / divisor - 1;
146  len %= divisor;
147  }
148  current_term.resize(len);
149  }
150 
151  // Append the new tail to form the next term.
152  size_t append_len = static_cast<unsigned char>(*pos++);
153  current_term.append(pos, append_len);
154  pos += append_len;
155 
156  // Read the wdf if it wasn't packed into the reuse byte.
157  if (!wdf_in_reuse && !unpack_uint(&pos, end, &current_wdf)) {
158  const char *msg;
159  if (pos == 0) {
160  msg = "Too little data for wdf in termlist";
161  } else {
162  msg = "Overflowed value for wdf in termlist";
163  }
164  throw Xapian::DatabaseCorruptError(msg);
165  }
166 
167  RETURN(NULL);
168 }
169 
170 TermList *
171 ChertTermList::skip_to(const string & term)
172 {
173  LOGCALL(API, TermList *, "ChertTermList::skip_to", term);
174  while (pos != NULL && current_term < term) {
175  (void)ChertTermList::next();
176  }
177  RETURN(NULL);
178 }
179 
180 bool
182 {
183  LOGCALL(DB, bool, "ChertTermList::at_end", NO_ARGS);
184  RETURN(pos == NULL);
185 }
186 
189 {
190  LOGCALL(DB, Xapian::termcount, "ChertTermList::positionlist_count", NO_ARGS);
192 }
193 
196 {
197  LOGCALL(DB, Xapian::PositionIterator, "ChertTermList::positionlist_begin", NO_ARGS);
200 }

Documentation for Xapian (version 1.2.19).
Generated on Tue Oct 21 2014 by Doxygen 1.8.1.2.