backends/flint/flint_metadata.cc

Go to the documentation of this file.
00001 
00004 /* Copyright (C) 2004,2005,2006,2007,2008 Olly Betts
00005  * Copyright (C) 2008 Lemur Consulting Ltd
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00020  */
00021 
00022 #include <config.h>
00023 #include "flint_metadata.h"
00024 
00025 #include "database.h"
00026 #include "omassert.h"
00027 #include "stringutils.h"
00028 
00029 using namespace std;
00030 
00031 FlintMetadataTermList::FlintMetadataTermList(
00032         Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> database_,
00033         FlintCursor * cursor_,
00034         const string &prefix_)
00035         : database(database_), cursor(cursor_), prefix(string("\x00\xc0", 2) + prefix_)
00036 {
00037     DEBUGCALL(DB, void, "FlintMetadataTermList", "<database>, <cursor>");
00038     Assert(cursor);
00039     // Seek to the first key before the first metadata key.
00040     cursor->find_entry_lt(prefix);
00041 }
00042 
00043 FlintMetadataTermList::~FlintMetadataTermList()
00044 {
00045     DEBUGCALL(DB, void, "~FlintMetadataTermList", "");
00046     delete cursor;
00047 }
00048 
00049 string
00050 FlintMetadataTermList::get_termname() const
00051 {
00052     DEBUGCALL(DB, string, "FlintMetadataTermList::get_termname", "");
00053     Assert(!at_end());
00054     Assert(!cursor->current_key.empty());
00055     Assert(startswith(cursor->current_key, prefix));
00056     RETURN(cursor->current_key.substr(2));
00057 }
00058 
00059 Xapian::doccount
00060 FlintMetadataTermList::get_termfreq() const
00061 {
00062     throw Xapian::InvalidOperationError("FlintMetadataTermList::get_termfreq() not meaningful");
00063 }
00064 
00065 Xapian::termcount
00066 FlintMetadataTermList::get_collection_freq() const
00067 {
00068     throw Xapian::InvalidOperationError("FlintMetadataTermList::get_collection_freq() not meaningful");
00069 }
00070 
00071 TermList *
00072 FlintMetadataTermList::next()
00073 {
00074     DEBUGCALL(DB, TermList *, "FlintMetadataTermList::next", "");
00075     Assert(!at_end());
00076 
00077     cursor->next();
00078     if (!cursor->after_end() && !startswith(cursor->current_key, prefix)) {
00079         // We've reached the end of the end of the prefixed terms.
00080         cursor->to_end();
00081     }
00082 
00083     RETURN(NULL);
00084 }
00085 
00086 TermList *
00087 FlintMetadataTermList::skip_to(const string &tname)
00088 {
00089     DEBUGCALL(DB, TermList *, "FlintMetadataTermList::skip_to", tname);
00090     Assert(!at_end());
00091 
00092     if (!cursor->find_entry_ge(tname)) {
00093         // The exact term we asked for isn't there, so check if the next
00094         // term after it also has the right prefix.
00095         if (!cursor->after_end() && !startswith(cursor->current_key, prefix)) {
00096             // We've reached the end of the prefixed terms.
00097             cursor->to_end();
00098         }
00099     }
00100     RETURN(NULL);
00101 }
00102 
00103 bool
00104 FlintMetadataTermList::at_end() const
00105 {
00106     DEBUGCALL(DB, bool, "FlintMetadataTermList::at_end", "");
00107     RETURN(cursor->after_end());
00108 }

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.