00001 00004 /* Copyright (C) 2007 Lemur Consulting Ltd 00005 * Copyright (C) 2007,2008,2009 Olly Betts 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License as 00009 * published by the Free Software Foundation; either version 2 of the 00010 * License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00020 * USA 00021 */ 00022 00023 #include <config.h> 00024 00025 #include "net_postlist.h" 00026 #include "serialise.h" 00027 00028 using namespace std; 00029 00030 Xapian::doccount 00031 NetworkPostList::get_termfreq() const 00032 { 00033 return termfreq; 00034 } 00035 00036 Xapian::docid 00037 NetworkPostList::get_docid() const 00038 { 00039 return lastdocid; 00040 } 00041 00042 Xapian::termcount 00043 NetworkPostList::get_doclength() const 00044 { 00045 return db->get_doclength(lastdocid); 00046 } 00047 00048 Xapian::termcount 00049 NetworkPostList::get_wdf() const 00050 { 00051 return lastwdf; 00052 } 00053 00054 PositionList * 00055 NetworkPostList::read_position_list() 00056 { 00057 lastposlist = db->open_position_list(lastdocid, term); 00058 return lastposlist.get(); 00059 } 00060 00061 PositionList * 00062 NetworkPostList::open_position_list() const 00063 { 00064 return db->open_position_list(lastdocid, term); 00065 } 00066 00067 PostList * 00068 NetworkPostList::next(Xapian::weight) 00069 { 00070 if (!started) { 00071 started = true; 00072 pos = postings.data(); 00073 pos_end = pos + postings.size(); 00074 lastdocid = 0; 00075 } 00076 00077 if (pos == pos_end) { 00078 pos = NULL; 00079 } else { 00080 lastdocid += decode_length(&pos, pos_end, false) + 1; 00081 lastwdf = decode_length(&pos, pos_end, false); 00082 } 00083 00084 return NULL; 00085 } 00086 00087 PostList * 00088 NetworkPostList::skip_to(Xapian::docid did, Xapian::weight min_weight) 00089 { 00090 if (!started) 00091 next(min_weight); 00092 while (pos && lastdocid < did) 00093 next(min_weight); 00094 return NULL; 00095 } 00096 00097 bool 00098 NetworkPostList::at_end() const 00099 { 00100 return (pos == NULL && started); 00101 } 00102 00103 string 00104 NetworkPostList::get_description() const 00105 { 00106 string desc = "NetworkPostList("; 00107 desc += term; 00108 desc += ')'; 00109 return desc; 00110 }