xapian-core  1.4.20
glass_metadata.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2004,2005,2006,2007,2008,2009,2010,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 
24 #include "glass_metadata.h"
25 
26 #include "glass_cursor.h"
27 
28 #include "backends/database.h"
29 #include "debuglog.h"
30 #include "omassert.h"
31 #include "stringutils.h"
32 
33 #include "xapian/error.h"
34 
35 using namespace std;
37 
40  GlassCursor * cursor_,
41  const string &prefix_)
42  : database(database_), cursor(cursor_), prefix(string("\x00\xc0", 2) + prefix_)
43 {
44  LOGCALL_CTOR(DB, "GlassMetadataTermList", database_ | cursor_ | prefix_);
45  Assert(cursor);
46  // Seek to the first key before the first metadata key.
48 }
49 
51 {
52  LOGCALL_DTOR(DB, "GlassMetadataTermList");
53  delete cursor;
54 }
55 
56 string
58 {
59  LOGCALL(DB, string, "GlassMetadataTermList::get_termname", NO_ARGS);
60  Assert(!at_end());
61  Assert(!cursor->current_key.empty());
63  RETURN(cursor->current_key.substr(2));
64 }
65 
68 {
69  throw Xapian::InvalidOperationError("GlassMetadataTermList::get_termfreq() not meaningful");
70 }
71 
72 TermList *
74 {
75  LOGCALL(DB, TermList *, "GlassMetadataTermList::next", NO_ARGS);
76  Assert(!at_end());
77 
78  cursor->next();
80  // We've reached the end of the prefixed terms.
81  cursor->to_end();
82  }
83 
84  RETURN(NULL);
85 }
86 
87 TermList *
89 {
90  LOGCALL(DB, TermList *, "GlassMetadataTermList::skip_to", key);
91  Assert(!at_end());
92 
93  if (!cursor->find_entry_ge(string("\x00\xc0", 2) + key)) {
94  // The exact term we asked for isn't there, so check if the next
95  // term after it also has the right prefix.
97  // We've reached the end of the prefixed terms.
98  cursor->to_end();
99  }
100  }
101  RETURN(NULL);
102 }
103 
104 bool
106 {
107  LOGCALL(DB, bool, "GlassMetadataTermList::at_end", NO_ARGS);
108  RETURN(cursor->after_end());
109 }
#define RETURN(A)
Definition: debuglog.h:482
#define Assert(COND)
Definition: omassert.h:122
InvalidOperationError indicates the API was used in an invalid way.
Definition: error.h:283
void find_entry_lt(const string &key)
Position the cursor on the highest entry with key < key.
std::string prefix
The prefix that all returned keys must have.
GlassMetadataTermList(const GlassMetadataTermList &)
Copying is not allowed.
#define LOGCALL_DTOR(CATEGORY, CLASS)
Definition: debuglog.h:479
bool next()
Advance to the next key.
Abstract base class for termlists.
Definition: termlist.h:39
STL namespace.
bool after_end() const
Determine whether cursor is off the end of table.
Definition: glass_cursor.h:329
Access to metadata for a glass database.
Hierarchy of classes which Xapian can throw as exceptions.
GlassCursor * cursor
A cursor which runs through the postlist table reading metadata keys.
string current_key
Current key pointed to by cursor.
Definition: glass_cursor.h:239
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
bool startswith(const std::string &s, char pfx)
Definition: stringutils.h:46
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
Definition: debuglog.h:478
bool find_entry_ge(const string &key)
Position the cursor on the lowest entry with key >= key.
A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches.
Definition: glass_cursor.h:147
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Interface to Btree cursors.
Various handy helpers which std::string really should provide.
bool at_end() const
True if we&#39;re off the end of the list.
Various assertion macros.
A smart pointer that uses intrusive reference counting.
Definition: intrusive_ptr.h:81
std::string get_termname() const
Returns the current termname.
TermList * next()
Advance to the next term in the list.
TermList * skip_to(const std::string &key)
Advance to the first key which is >= key.
Debug logging macros.
void to_end()
Set the cursor to be off the end of the table.
Definition: glass_cursor.h:322
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:476