backends/flint/flint_spellingwordslist.cc

Go to the documentation of this file.
00001 
00004 /* Copyright (C) 2004,2005,2006,2007 Olly Betts
00005  * Copyright (C) 2007 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 
00023 #include <config.h>
00024 
00025 #include <xapian/error.h>
00026 #include <xapian/types.h>
00027 
00028 #include "flint_spellingwordslist.h"
00029 #include "flint_utils.h"
00030 #include "stringutils.h"
00031 
00032 FlintSpellingWordsList::~FlintSpellingWordsList()
00033 {
00034     DEBUGCALL(DB, void, "~FlintSpellingWordsList", "");
00035     delete cursor;
00036 }
00037 
00038 string
00039 FlintSpellingWordsList::get_termname() const
00040 {
00041     DEBUGCALL(DB, string, "FlintSpellingWordsList::get_termname", "");
00042     Assert(cursor);
00043     Assert(!at_end());
00044     Assert(!cursor->current_key.empty());
00045     Assert(cursor->current_key[0] == 'W');
00046     RETURN(cursor->current_key.substr(1));
00047 }
00048 
00049 Xapian::doccount
00050 FlintSpellingWordsList::get_termfreq() const
00051 {
00052     DEBUGCALL(DB, string, "FlintSpellingWordsList::get_termfreq", "");
00053     Assert(cursor);
00054     Assert(!at_end());
00055     Assert(!cursor->current_key.empty());
00056     Assert(cursor->current_key[0] == 'W');
00057     cursor->read_tag();
00058 
00059     Xapian::termcount freq;
00060     const char *p = cursor->current_tag.data();
00061     if (!unpack_uint_last(&p, p + cursor->current_tag.size(), &freq)) {
00062         throw Xapian::DatabaseCorruptError("Bad spelling word freq");
00063     }
00064     return freq;
00065 }
00066 
00067 Xapian::termcount
00068 FlintSpellingWordsList::get_collection_freq() const
00069 {
00070     throw Xapian::InvalidOperationError("FlintSpellingWordsList::get_collection_freq() not meaningful");
00071 }
00072 
00073 TermList *
00074 FlintSpellingWordsList::next()
00075 {
00076     DEBUGCALL(DB, TermList *, "FlintSpellingWordsList::next", "");
00077     Assert(!at_end());
00078 
00079     cursor->next();
00080     if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
00081         // We've reached the end of the prefixed terms.
00082         cursor->to_end();
00083     }
00084 
00085     RETURN(NULL);
00086 }
00087 
00088 TermList *
00089 FlintSpellingWordsList::skip_to(const string &tname)
00090 {
00091     DEBUGCALL(DB, TermList *, "FlintSpellingWordsList::skip_to", tname);
00092     Assert(!at_end());
00093 
00094     if (!cursor->find_entry_ge("W" + tname)) {
00095         // The exact term we asked for isn't there, so check if the next
00096         // term after it also has a W prefix.
00097         if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
00098             // We've reached the end of the prefixed terms.
00099             cursor->to_end();
00100         }
00101     }
00102     RETURN(NULL);
00103 }
00104 
00105 bool
00106 FlintSpellingWordsList::at_end() const
00107 {
00108     DEBUGCALL(DB, bool, "FlintSpellingWordsList::at_end", "");
00109     RETURN(cursor->after_end());
00110 }

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