Reduce overheads of PostList positional data support
[xapian.git] / xapian-core / backends / glass / glass_metadata.cc
blob717bd87a1b89fa24a1c0d2f383eae8ad7a5636e8
1 /** @file glass_metadata.cc
2 * @brief Access to metadata for a glass database.
3 */
4 /* Copyright (C) 2004,2005,2006,2007,2008,2009,2010,2011,2017 Olly Betts
5 * Copyright (C) 2008 Lemur Consulting Ltd
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.
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.
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
22 #include <config.h>
24 #include "glass_metadata.h"
26 #include "glass_cursor.h"
28 #include "backends/databaseinternal.h"
29 #include "debuglog.h"
30 #include "omassert.h"
31 #include "stringutils.h"
33 #include "xapian/error.h"
35 using namespace std;
36 using Xapian::Internal::intrusive_ptr;
38 GlassMetadataTermList::GlassMetadataTermList(
39 intrusive_ptr<const Xapian::Database::Internal> database_,
40 GlassCursor * cursor_,
41 const string &prefix_)
42 : database(database_), cursor(cursor_), prefix(string("\x00\xc0", 2) + prefix_)
44 LOGCALL_CTOR(DB, "GlassMetadataTermList", database_ | cursor_ | prefix_);
45 Assert(cursor);
46 // Seek to the first key before the first metadata key.
47 cursor->find_entry_lt(prefix);
50 GlassMetadataTermList::~GlassMetadataTermList()
52 LOGCALL_DTOR(DB, "GlassMetadataTermList");
53 delete cursor;
56 Xapian::termcount
57 GlassMetadataTermList::get_approx_size() const
59 // Very approximate! This is only used to build a balanced or tree, so
60 // at least we'll get an even tree by returning a constant answer.
61 return 1;
64 string
65 GlassMetadataTermList::get_termname() const
67 LOGCALL(DB, string, "GlassMetadataTermList::get_termname", NO_ARGS);
68 Assert(!at_end());
69 Assert(!cursor->current_key.empty());
70 Assert(startswith(cursor->current_key, prefix));
71 RETURN(cursor->current_key.substr(2));
74 Xapian::doccount
75 GlassMetadataTermList::get_termfreq() const
77 throw Xapian::InvalidOperationError("GlassMetadataTermList::get_termfreq() not meaningful");
80 Xapian::termcount
81 GlassMetadataTermList::get_collection_freq() const
83 throw Xapian::InvalidOperationError("GlassMetadataTermList::get_collection_freq() not meaningful");
86 TermList *
87 GlassMetadataTermList::next()
89 LOGCALL(DB, TermList *, "GlassMetadataTermList::next", NO_ARGS);
90 Assert(!at_end());
92 cursor->next();
93 if (!cursor->after_end() && !startswith(cursor->current_key, prefix)) {
94 // We've reached the end of the prefixed terms.
95 cursor->to_end();
98 RETURN(NULL);
101 TermList *
102 GlassMetadataTermList::skip_to(const string &key)
104 LOGCALL(DB, TermList *, "GlassMetadataTermList::skip_to", key);
105 Assert(!at_end());
107 if (!cursor->find_entry_ge(string("\x00\xc0", 2) + key)) {
108 // The exact term we asked for isn't there, so check if the next
109 // term after it also has the right prefix.
110 if (!cursor->after_end() && !startswith(cursor->current_key, prefix)) {
111 // We've reached the end of the prefixed terms.
112 cursor->to_end();
115 RETURN(NULL);
118 bool
119 GlassMetadataTermList::at_end() const
121 LOGCALL(DB, bool, "GlassMetadataTermList::at_end", NO_ARGS);
122 RETURN(cursor->after_end());