00001 00004 /* Copyright (C) 2007 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 "utils.h" 00029 00030 using namespace std; 00031 00032 ContiguousAllDocsPostList::~ContiguousAllDocsPostList() { } 00033 00034 Xapian::doccount 00035 ContiguousAllDocsPostList::get_termfreq() const 00036 { 00037 return doccount; 00038 } 00039 00040 Xapian::docid 00041 ContiguousAllDocsPostList::get_docid() const 00042 { 00043 Assert(did != 0); 00044 Assert(!at_end()); 00045 return did; 00046 } 00047 00048 Xapian::doclength 00049 ContiguousAllDocsPostList::get_doclength() const 00050 { 00051 Assert(did != 0); 00052 Assert(!at_end()); 00053 return db->get_doclength(did); 00054 } 00055 00056 Xapian::termcount 00057 ContiguousAllDocsPostList::get_wdf() const 00058 { 00059 Assert(did != 0); 00060 Assert(!at_end()); 00061 return 1; 00062 } 00063 00064 PositionList * 00065 ContiguousAllDocsPostList::read_position_list() 00066 { 00067 // Throws the same exception. 00068 return ContiguousAllDocsPostList::open_position_list(); 00069 } 00070 00071 PositionList * 00072 ContiguousAllDocsPostList::open_position_list() const 00073 { 00074 throw Xapian::InvalidOperationError("Position lists not meaningful for ContiguousAllDocsPostList"); 00075 } 00076 00077 PostList * 00078 ContiguousAllDocsPostList::next(Xapian::weight) 00079 { 00080 Assert(!at_end()); 00081 if (did == doccount) { 00082 db = NULL; 00083 } else { 00084 ++did; 00085 } 00086 return NULL; 00087 } 00088 00089 PostList * 00090 ContiguousAllDocsPostList::skip_to(Xapian::docid target, Xapian::weight) 00091 { 00092 Assert(!at_end()); 00093 if (target > did) { 00094 if (target > doccount) { 00095 db = NULL; 00096 } else { 00097 did = target; 00098 } 00099 } 00100 return NULL; 00101 } 00102 00103 bool 00104 ContiguousAllDocsPostList::at_end() const 00105 { 00106 return db.get() == NULL; 00107 } 00108 00109 string 00110 ContiguousAllDocsPostList::get_description() const 00111 { 00112 string msg("ContiguousAllDocsPostList(1.."); 00113 msg += om_tostring(doccount); 00114 msg += ')'; 00115 return msg; 00116 }