xapian-core  1.4.25
chert_metadata.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2004,2005,2006,2007,2008,2011 Olly Betts
5  * Copyright (C) 2008 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, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <config.h>
23 #include "chert_metadata.h"
24 
25 #include "backends/database.h"
26 #include "debuglog.h"
27 #include "omassert.h"
28 #include "stringutils.h"
29 
30 using namespace std;
32 
35  ChertCursor * cursor_,
36  const string &prefix_)
37  : database(database_), cursor(cursor_), prefix(string("\x00\xc0", 2) + prefix_)
38 {
39  LOGCALL_CTOR(DB, "ChertMetadataTermList", database_ | cursor_ | prefix_);
40  Assert(cursor);
41  // Seek to the first key before the first metadata key.
43 }
44 
46 {
47  LOGCALL_DTOR(DB, "ChertMetadataTermList");
48  delete cursor;
49 }
50 
51 string
53 {
54  LOGCALL(DB, string, "ChertMetadataTermList::get_termname", NO_ARGS);
55  Assert(!at_end());
56  Assert(!cursor->current_key.empty());
58  RETURN(cursor->current_key.substr(2));
59 }
60 
63 {
64  throw Xapian::InvalidOperationError("ChertMetadataTermList::get_termfreq() not meaningful");
65 }
66 
67 TermList *
69 {
70  LOGCALL(DB, TermList *, "ChertMetadataTermList::next", NO_ARGS);
71  Assert(!at_end());
72 
73  cursor->next();
75  // We've reached the end of the prefixed terms.
76  cursor->to_end();
77  }
78 
79  RETURN(NULL);
80 }
81 
82 TermList *
84 {
85  LOGCALL(DB, TermList *, "ChertMetadataTermList::skip_to", key);
86  Assert(!at_end());
87 
88  if (!cursor->find_entry_ge(string("\x00\xc0", 2) + key)) {
89  // The exact term we asked for isn't there, so check if the next
90  // term after it also has the right prefix.
92  // We've reached the end of the prefixed terms.
93  cursor->to_end();
94  }
95  }
96  RETURN(NULL);
97 }
98 
99 bool
101 {
102  LOGCALL(DB, bool, "ChertMetadataTermList::at_end", NO_ARGS);
103  RETURN(cursor->after_end());
104 }
#define RETURN(A)
Definition: debuglog.h:493
#define Assert(COND)
Definition: omassert.h:122
A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches.
Definition: chert_cursor.h:66
std::string get_termname() const
Returns the current termname.
bool next()
Advance to the next key.
InvalidOperationError indicates the API was used in an invalid way.
Definition: error.h:283
Access to metadata for a chert database.
#define LOGCALL_DTOR(CATEGORY, CLASS)
Definition: debuglog.h:490
void to_end()
Set the cursor to be off the end of the table.
Definition: chert_cursor.h:231
Abstract base class for termlists.
Definition: termlist.h:39
STL namespace.
bool at_end() const
True if we&#39;re off the end of the list.
bool find_entry_ge(const string &key)
Position the cursor on the lowest entry with key >= key.
ChertCursor * cursor
A cursor which runs through the postlist table reading metadata keys.
ChertMetadataTermList(const ChertMetadataTermList &)
Copying is not allowed.
std::string prefix
The prefix that all returned keys must have.
bool startswith(const std::string &s, char pfx)
Definition: stringutils.h:51
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
Definition: debuglog.h:489
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
bool after_end() const
Determine whether cursor is off the end of table.
Definition: chert_cursor.h:238
string current_key
Current key pointed to by cursor.
Definition: chert_cursor.h:149
TermList * next()
Advance to the next term in the list.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Various handy helpers which std::string really should provide.
void find_entry_lt(const string &key)
Position the cursor on the highest entry with key < key.
Definition: chert_cursor.h:218
Various assertion macros.
TermList * skip_to(const std::string &key)
Advance to the first key which is >= key.
A smart pointer that uses intrusive reference counting.
Definition: intrusive_ptr.h:81
Debug logging macros.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:487