backends/inmemory/inmemory_alltermslist.cc

Go to the documentation of this file.
00001 /* inmemoryalltermslist.cc
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2003,2004,2007 Olly Betts
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00019  * USA
00020  */
00021 
00022 #include <config.h>
00023 #include "inmemory_alltermslist.h"
00024 
00025 #include "stringutils.h"
00026 
00027 InMemoryAllTermsList::InMemoryAllTermsList(const std::map<string, InMemoryTerm> *tmap_,
00028                                            Xapian::Internal::RefCntPtr<const InMemoryDatabase> database_,
00029                                            const string & prefix_)
00030         : tmap(tmap_), database(database_), started(false), prefix(prefix_)
00031 {
00032 }
00033 
00034 InMemoryAllTermsList::~InMemoryAllTermsList()
00035 {
00036 }
00037 
00038 string
00039 InMemoryAllTermsList::get_termname() const
00040 {
00041     Assert(started);
00042     Assert(!at_end());
00043     return it->first;
00044 }
00045 
00046 Xapian::doccount
00047 InMemoryAllTermsList::get_termfreq() const
00048 {
00049     Assert(started);
00050     Assert(!at_end());
00051     /* FIXME: this isn't quite right. */
00052     return it->second.docs.size();
00053 }
00054 
00055 Xapian::termcount
00056 InMemoryAllTermsList::get_collection_freq() const
00057 {
00058     Assert(started);
00059     Assert(!at_end());
00060     throw Xapian::UnimplementedError("Collection frequency not implemented in InMemory backend");
00061 }
00062 
00063 TermList *
00064 InMemoryAllTermsList::skip_to(const string &tname_)
00065 {
00066     string tname(tname_);
00067     if (started) {
00068         Assert(!at_end());
00069         // Don't skip backwards.
00070         if (tname <= get_termname()) return NULL;
00071     } else {
00072         started = true;
00073         // Don't skip to before where we're supposed to start.
00074         if (tname < prefix) tname = prefix;
00075     }
00076     it = tmap->lower_bound(tname);
00077     while (it != tmap->end() && it->second.term_freq == 0) ++it;
00078     if (it != tmap->end() && !startswith(it->first, prefix))
00079         it = tmap->end();
00080     return NULL;
00081 }
00082 
00083 TermList *
00084 InMemoryAllTermsList::next()
00085 {
00086     if (!started) {
00087         started = true;
00088         it = tmap->lower_bound(prefix);
00089     } else {
00090         Assert(!at_end());
00091         ++it;
00092     }
00093     while (it != tmap->end() && it->second.term_freq == 0) ++it;
00094     if (it != tmap->end() && !startswith(it->first, prefix))
00095         it = tmap->end();
00096     return NULL;
00097 }
00098 
00099 bool
00100 InMemoryAllTermsList::at_end() const
00101 {
00102     Assert(started);
00103     return (it == tmap->end());
00104 }

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