00001 /* inmemoryalltermslist.cc 00002 * 00003 * Copyright 1999,2000,2001 BrightStation PLC 00004 * Copyright 2003,2004,2007,2008,2009 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 string 00028 InMemoryAllTermsList::get_termname() const 00029 { 00030 if (database->is_closed()) InMemoryDatabase::throw_database_closed(); 00031 Assert(!at_end()); 00032 Assert(!it->first.empty()); 00033 return it->first; 00034 } 00035 00036 Xapian::doccount 00037 InMemoryAllTermsList::get_termfreq() const 00038 { 00039 if (database->is_closed()) InMemoryDatabase::throw_database_closed(); 00040 Assert(!at_end()); 00041 Assert(!it->first.empty()); 00042 /* FIXME: this isn't quite right. */ 00043 return it->second.docs.size(); 00044 } 00045 00046 Xapian::termcount 00047 InMemoryAllTermsList::get_collection_freq() const 00048 { 00049 if (database->is_closed()) InMemoryDatabase::throw_database_closed(); 00050 Assert(!at_end()); 00051 Assert(!it->first.empty()); 00052 throw Xapian::UnimplementedError("Collection frequency not implemented in InMemory backend"); 00053 } 00054 00055 TermList * 00056 InMemoryAllTermsList::skip_to(const string &tname_) 00057 { 00058 if (database->is_closed()) InMemoryDatabase::throw_database_closed(); 00059 string tname(tname_); 00060 Assert(it != tmap->end()); 00061 if (!it->first.empty()) { 00062 // Don't skip backwards. 00063 if (tname <= it->first) return NULL; 00064 } else { 00065 // Don't skip to before where we're supposed to start. 00066 if (tname < prefix) { 00067 tname = prefix; 00068 } else if (tname.empty()) { 00069 ++it; 00070 return NULL; 00071 } 00072 } 00073 it = tmap->lower_bound(tname); 00074 while (it != tmap->end() && it->second.term_freq == 0) ++it; 00075 if (it != tmap->end() && !startswith(it->first, prefix)) 00076 it = tmap->end(); 00077 return NULL; 00078 } 00079 00080 TermList * 00081 InMemoryAllTermsList::next() 00082 { 00083 if (database->is_closed()) InMemoryDatabase::throw_database_closed(); 00084 Assert(it != tmap->end()); 00085 if (it->first.empty() && !prefix.empty()) { 00086 it = tmap->lower_bound(prefix); 00087 } else { 00088 ++it; 00089 } 00090 while (it != tmap->end() && it->second.term_freq == 0) ++it; 00091 if (it != tmap->end() && !startswith(it->first, prefix)) 00092 it = tmap->end(); 00093 return NULL; 00094 } 00095 00096 bool 00097 InMemoryAllTermsList::at_end() const 00098 { 00099 if (database->is_closed()) InMemoryDatabase::throw_database_closed(); 00100 Assert(it == tmap->end() || !it->first.empty()); 00101 return (it == tmap->end()); 00102 }