00001 00004 /* Copyright (C) 2007,2008,2009 Olly Betts 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (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 USA 00019 */ 00020 00021 #include <config.h> 00022 00023 #include <string> 00024 00025 #include "contiguousalldocspostlist.h" 00026 00027 #include "omassert.h" 00028 #include "str.h" 00029 00030 using namespace std; 00031 00032 Xapian::doccount 00033 ContiguousAllDocsPostList::get_termfreq() const 00034 { 00035 return doccount; 00036 } 00037 00038 Xapian::docid 00039 ContiguousAllDocsPostList::get_docid() const 00040 { 00041 Assert(did != 0); 00042 Assert(!at_end()); 00043 return did; 00044 } 00045 00046 Xapian::termcount 00047 ContiguousAllDocsPostList::get_doclength() const 00048 { 00049 Assert(did != 0); 00050 Assert(!at_end()); 00051 return db->get_doclength(did); 00052 } 00053 00054 Xapian::termcount 00055 ContiguousAllDocsPostList::get_wdf() const 00056 { 00057 Assert(did != 0); 00058 Assert(!at_end()); 00059 return 1; 00060 } 00061 00062 PositionList * 00063 ContiguousAllDocsPostList::read_position_list() 00064 { 00065 // Throws the same exception. 00066 return ContiguousAllDocsPostList::open_position_list(); 00067 } 00068 00069 PositionList * 00070 ContiguousAllDocsPostList::open_position_list() const 00071 { 00072 throw Xapian::InvalidOperationError("Position lists not meaningful for ContiguousAllDocsPostList"); 00073 } 00074 00075 PostList * 00076 ContiguousAllDocsPostList::next(Xapian::weight) 00077 { 00078 Assert(!at_end()); 00079 if (did == doccount) { 00080 db = NULL; 00081 } else { 00082 ++did; 00083 } 00084 return NULL; 00085 } 00086 00087 PostList * 00088 ContiguousAllDocsPostList::skip_to(Xapian::docid target, Xapian::weight) 00089 { 00090 Assert(!at_end()); 00091 if (target > did) { 00092 if (target > doccount) { 00093 db = NULL; 00094 } else { 00095 did = target; 00096 } 00097 } 00098 return NULL; 00099 } 00100 00101 bool 00102 ContiguousAllDocsPostList::at_end() const 00103 { 00104 return db.get() == NULL; 00105 } 00106 00107 string 00108 ContiguousAllDocsPostList::get_description() const 00109 { 00110 string msg("ContiguousAllDocsPostList(1.."); 00111 msg += str(doccount); 00112 msg += ')'; 00113 return msg; 00114 }