backends/flint/flint_postlist.h

Go to the documentation of this file.
00001 /* flint_postlist.h: Postlists in flint databases
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2002 Ananova Ltd
00005  * Copyright 2002,2003,2004,2005,2007 Olly Betts
00006  * Copyright 2007 Lemur Consulting Ltd
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as
00010  * published by the Free Software Foundation; either version 2 of the
00011  * License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00021  * USA
00022  */
00023 
00024 #ifndef OM_HGUARD_FLINT_POSTLIST_H
00025 #define OM_HGUARD_FLINT_POSTLIST_H
00026 
00027 #include <xapian/database.h>
00028 
00029 #include "flint_types.h"
00030 #include "flint_positionlist.h"
00031 #include "leafpostlist.h"
00032 #include "omassert.h"
00033 #include "omdebug.h"
00034 
00035 #include "autoptr.h"
00036 #include <map>
00037 #include <string>
00038 
00039 using namespace std;
00040 
00041 class FlintCursor;
00042 class FlintDatabase;
00043 
00044 class PostlistChunkReader;
00045 class PostlistChunkWriter;
00046 
00047 class FlintPostListTable : public FlintTable {
00048     public:
00061         FlintPostListTable(string path_, bool readonly_)
00062             : FlintTable(path_ + "/postlist.", readonly_) { }
00063 
00065         void merge_changes(
00066             const map<string, map<Xapian::docid, pair<char, Xapian::termcount> > > & mod_plists,
00067             const map<Xapian::docid, Xapian::termcount> & doclens,
00068             const map<string, pair<Xapian::termcount_diff, Xapian::termcount_diff> > & freq_deltas);
00069 
00070         Xapian::docid get_chunk(const string &tname,
00071                 Xapian::docid did, bool adding,
00072                 PostlistChunkReader ** from, PostlistChunkWriter **to);
00073 
00075         static string make_key(const string & term, Xapian::docid did) {
00076             string key = pack_string_preserving_sort(term);
00077             key += pack_uint_preserving_sort(did);
00078             return key;
00079         }
00080 
00082         static string make_key(const string & term) {
00083             return pack_string_preserving_sort(term);
00084         }
00085 
00086         bool term_exists(const string & term) const {
00087             return key_exists(make_key(term));
00088         }
00089 
00094         Xapian::doccount get_termfreq(const std::string & term) const;
00095 
00100         Xapian::termcount get_collection_freq(const std::string & term) const;
00101 };
00102 
00105 class FlintPostList : public LeafPostList {
00106    protected: // FlintModifiedPostList needs to access these.
00111         Xapian::Internal::RefCntPtr<const FlintDatabase> this_db;
00112 
00114         string tname;
00115 
00117         bool have_started;
00118 
00120         FlintPositionList positionlist;
00121 
00122     private:
00124         AutoPtr<FlintCursor> cursor;
00125 
00127         bool is_last_chunk;
00128 
00130         Xapian::docid first_did_in_chunk;
00131 
00133         Xapian::docid last_did_in_chunk;
00134 
00136         const char * pos;
00137 
00139         const char * end;
00140 
00142         Xapian::docid did;
00143 
00145         flint_doclen_t doclength;
00146 
00148         Xapian::termcount wdf;
00149 
00151         bool is_at_end;
00152 
00154         Xapian::doccount number_of_entries;
00155 
00157         FlintPostList(const FlintPostList &);
00158 
00160         void operator=(const FlintPostList &);
00161 
00165         bool next_in_chunk();
00166 
00172         void next_chunk();
00173 
00181         bool current_chunk_contains(Xapian::docid desired_did);
00182 
00194         void move_to_chunk_containing(Xapian::docid desired_did);
00195 
00205         bool move_forward_in_chunk_to_at_least(Xapian::docid desired_did);
00206 
00207     public:
00209         FlintPostList(Xapian::Internal::RefCntPtr<const FlintDatabase> this_db_,
00210                       const string & tname);
00211 
00213         ~FlintPostList();
00214 
00219         Xapian::doccount get_termfreq() const { return number_of_entries; }
00220 
00222         Xapian::docid get_docid() const { Assert(have_started); return did; }
00223 
00225         Xapian::doclength get_doclength() const {
00226             DEBUGCALL(DB, Xapian::doclength, "FlintPostList::get_doclength", "");
00227             Assert(have_started);
00228             RETURN(static_cast<Xapian::doclength>(doclength));
00229         }
00230 
00234         Xapian::termcount get_wdf() const { Assert(have_started); return wdf; }
00235 
00238         PositionList *read_position_list();
00239 
00242         PositionList * open_position_list() const;
00243 
00245         PostList * next(Xapian::weight w_min);
00246 
00248         PostList * skip_to(Xapian::docid desired_did, Xapian::weight w_min);
00249 
00251         bool at_end() const { return is_at_end; }
00252 
00254         std::string get_description() const;
00255 
00257         static void read_number_of_entries(const char ** posptr,
00258                                            const char * end,
00259                                            Xapian::termcount * number_of_entries_ptr,
00260                                            Xapian::termcount * collection_freq_ptr);
00261 };
00262 
00263 #endif /* OM_HGUARD_FLINT_POSTLIST_H */

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