00001 /* maptermlist.h 00002 * 00003 * Copyright 1999,2000,2001 BrightStation PLC 00004 * Copyright 2002,2003,2004,2005,2006,2007,2008 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 #ifndef OM_HGUARD_MAPTERMLIST_H 00023 #define OM_HGUARD_MAPTERMLIST_H 00024 00025 #include "termlist.h" 00026 00027 #include "inmemory_positionlist.h" 00028 #include "document.h" 00029 00030 #include "omassert.h" 00031 00032 using namespace std; 00033 00034 class MapTermList : public TermList { 00035 private: 00036 Xapian::Document::Internal::document_terms::const_iterator it; 00037 Xapian::Document::Internal::document_terms::const_iterator it_end; 00038 bool started; 00039 00040 public: 00041 MapTermList(const Xapian::Document::Internal::document_terms::const_iterator &it_, 00042 const Xapian::Document::Internal::document_terms::const_iterator &it_end_) 00043 : it(it_), it_end(it_end_), started(false) 00044 { } 00045 00046 // Gets size of termlist 00047 Xapian::termcount get_approx_size() const { 00048 // This method shouldn't get called on a MapTermList. 00049 Assert(false); 00050 return 0; 00051 } 00052 00053 // Gets current termname 00054 string get_termname() const { 00055 Assert(started); 00056 Assert(!at_end()); 00057 return it->first; 00058 } 00059 00060 // Get wdf of current term 00061 Xapian::termcount get_wdf() const { 00062 Assert(started); 00063 Assert(!at_end()); 00064 return it->second.wdf; 00065 } 00066 00067 // Get num of docs indexed by term 00068 Xapian::doccount get_termfreq() const { 00069 throw Xapian::InvalidOperationError("Can't get term frequency from a document termlist which is not associated with a database."); 00070 } 00071 00072 Xapian::PositionIterator positionlist_begin() const { 00073 return Xapian::PositionIterator(new InMemoryPositionList(it->second.positions)); 00074 } 00075 00076 Xapian::termcount positionlist_count() const { 00077 return it->second.positions.size(); 00078 } 00079 00080 TermList * next() { 00081 if (!started) { 00082 started = true; 00083 } else { 00084 Assert(!at_end()); 00085 it++; 00086 } 00087 return NULL; 00088 } 00089 00090 // True if we're off the end of the list 00091 bool at_end() const { 00092 Assert(started); 00093 return it == it_end; 00094 } 00095 }; 00096 00097 #endif /* OM_HGUARD_MAPTERMLIST_H */