matcher/valuerangepostlist.cc

Go to the documentation of this file.
00001 
00004 /* Copyright 2007,2008 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 "valuerangepostlist.h"
00024 
00025 #include "autoptr.h"
00026 #include "omassert.h"
00027 #include "document.h"
00028 #include "leafpostlist.h"
00029 #include "utils.h"
00030 
00031 using namespace std;
00032 
00033 ValueRangePostList::~ValueRangePostList()
00034 {
00035     delete alldocs_pl;
00036 }
00037 
00038 Xapian::doccount
00039 ValueRangePostList::get_termfreq_min() const
00040 {
00041     return 0;
00042 }
00043 
00044 Xapian::doccount
00045 ValueRangePostList::get_termfreq_est() const
00046 {
00047     AssertParanoid(!db || db_size == db->get_doccount());
00048     // FIXME: It's hard to estimate well - perhaps consider the values of
00049     // begin and end?
00050     return db_size / 2;
00051 }
00052 
00053 Xapian::doccount
00054 ValueRangePostList::get_termfreq_max() const
00055 {
00056     AssertParanoid(!db || db_size == db->get_doccount());
00057     return db_size;
00058 }
00059 
00060 Xapian::weight
00061 ValueRangePostList::get_maxweight() const
00062 {
00063     return 0;
00064 }
00065 
00066 Xapian::docid
00067 ValueRangePostList::get_docid() const
00068 {
00069     Assert(current);
00070     Assert(db);
00071     return current;
00072 }
00073 
00074 Xapian::weight
00075 ValueRangePostList::get_weight() const
00076 {
00077     Assert(db);
00078     return 0;
00079 }
00080 
00081 Xapian::doclength
00082 ValueRangePostList::get_doclength() const
00083 {
00084     Assert(db);
00085     return 0;
00086 }
00087 
00088 Xapian::weight
00089 ValueRangePostList::recalc_maxweight()
00090 {
00091     Assert(db);
00092     return 0;
00093 }
00094 
00095 PositionList *
00096 ValueRangePostList::read_position_list()
00097 {
00098     Assert(db);
00099     return NULL;
00100 }
00101 
00102 PositionList *
00103 ValueRangePostList::open_position_list() const
00104 {
00105     Assert(db);
00106     return NULL;
00107 }
00108 
00109 PostList *
00110 ValueRangePostList::next(Xapian::weight)
00111 {
00112     Assert(db);
00113     if (!alldocs_pl) alldocs_pl = db->open_post_list(string());
00114     alldocs_pl->skip_to(current + 1);
00115     while (!alldocs_pl->at_end()) {
00116         current = alldocs_pl->get_docid();
00117         AutoPtr<Xapian::Document::Internal> doc(db->open_document(current, true));
00118         string v = doc->get_value(valno);
00119         if (v >= begin && v <= end) return NULL;
00120         alldocs_pl->next();
00121     }
00122     db = NULL;
00123     return NULL;
00124 }
00125 
00126 PostList *
00127 ValueRangePostList::skip_to(Xapian::docid did, Xapian::weight w_min)
00128 {
00129     Assert(db);
00130     if (did <= current) return NULL;
00131     current = did - 1;
00132     return ValueRangePostList::next(w_min);
00133 }
00134 
00135 PostList *
00136 ValueRangePostList::check(Xapian::docid did, Xapian::weight, bool &valid)
00137 {
00138     Assert(db);
00139     if (did <= current) {
00140         valid = true;
00141         return NULL;
00142     }
00143     AssertRelParanoid(did, <=, db->get_lastdocid());
00144     current = did;
00145     AutoPtr<Xapian::Document::Internal> doc(db->open_document(current, true));
00146     string v = doc->get_value(valno);
00147     valid = (v >= begin && v <= end);
00148     return NULL;
00149 }
00150 
00151 bool
00152 ValueRangePostList::at_end() const
00153 {
00154     return (db == NULL);
00155 }
00156 
00157 string
00158 ValueRangePostList::get_description() const
00159 {
00160     string desc = "ValueRangePostList(";
00161     desc += om_tostring(valno);
00162     desc += ", ";
00163     desc += begin;
00164     desc += ", ";
00165     desc += end;
00166     desc += ")";
00167     return desc;
00168 }

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.