WordListOne.h

Go to the documentation of this file.
00001 //
00002 // WordListOne.h
00003 //
00004 // NAME
00005 // 
00006 // manage and use an inverted index file.
00007 //
00008 // SYNOPSIS
00009 // 
00010 // #include <mifluz.h>
00011 // 
00012 // WordContext context;
00013 //
00014 // WordList* words = context->List();
00015 // WordList* words = WordListOne(&context);
00016 // 
00017 // DESCRIPTION
00018 // 
00019 // WordList is the <i>mifluz</i> equivalent of a database handler. Each
00020 // WordList object is bound to an inverted index file and implements the
00021 // operations to create it, fill it with word occurrences and search 
00022 // for an entry matching a given criterion.
00023 //
00024 // The general behavious of WordListOne is described in the WordList
00025 // manual page. It is prefered to create a WordListOne instance by
00026 // setting the <i>wordlist_multi</i> configuration parameter to false
00027 // and calling the <b>WordContext::List</b> method. 
00028 // 
00029 // Only the methods that differ from WordList are listed here.
00030 // All the methods of WordList are implemented by WordListOne and
00031 // you should refer to the manual page for more information.
00032 //
00033 // The <b>Cursor</b> methods all return a WordCursorOne instance
00034 // cast to a WordCursor object.
00035 //
00036 // END
00037 //
00038 // Part of the ht://Dig package   <http://www.htdig.org/>
00039 // Copyright (c) 1999, 2000, 2001 The ht://Dig Group
00040 // For copyright details, see the file COPYING in your distribution
00041 // or the GNU General Public License version 2 or later
00042 // <http://www.gnu.org/copyleft/gpl.html>
00043 //
00044 // $Id: WordListOne_8h-source.html,v 1.1 2008/06/08 10:13:15 sebdiaz Exp $
00045 //
00046 
00047 #ifndef _WordListOne_h_
00048 #define _WordListOne_h_
00049 
00050 #include <fcntl.h>
00051 #include <stdio.h>
00052 
00053 #include "WordList.h"
00054 #include "WordCursorOne.h"
00055 #include "WordDict.h"
00056 #include "WordMeta.h"
00057 #include "WordDead.h"
00058 
00059 class WordContext;
00060 
00061 // 
00062 // Inverted index interface
00063 //
00064 class WordListOne : public WordList
00065 {
00066  public:
00067     //-
00068     // Constructor. Build inverted index handling object using
00069     // run time configuration parameters listed in the <b>CONFIGURATION</b>
00070     // section of the <b>WordList</b> manual page.
00071     //
00072     WordListOne(WordContext* ncontext);
00073     virtual ~WordListOne();
00074 
00075     virtual int Override(const WordReference& wordRef);
00076 
00077     virtual inline int Exists(const WordReference& wordRef) {
00078       return (!Dead()->Exists(wordRef.Key()) && db->Exists(wordRef) == 0) ? OK : NOTOK; }
00079 
00080     virtual int WalkDelete(const WordReference& wordRef);
00081     virtual inline int Delete(const WordReference& wordRef) {
00082       if(db->Del(wordRef) == 0)
00083         return dict->Unref(wordRef.GetWord());
00084       else
00085         return NOTOK;
00086     }
00087     //-
00088     // Delete the inverted index entry currently pointed to by the
00089     // <b>cursor.</b> 
00090     // Returns 0 on success, Berkeley DB error code on error. This
00091     // is mainly useful when implementing a callback function for
00092     // a <b>WordCursor.</b> 
00093     //
00094     int DeleteCursor(WordDBCursor& cursor) { return cursor.Del(); }
00095 
00096     virtual int Open(const String& filename, int mode);
00097     virtual int Close();
00098     virtual unsigned int Size() const;
00099     virtual int Pagesize() const {
00100       Configuration& config = context->GetConfiguration();
00101 
00102       return config.Value("wordlist_page_size", 0);
00103     }
00104 
00105     virtual inline WordDict *Dict() { return dict; }
00106     virtual inline WordMeta *Meta() { return meta; }
00107     virtual inline WordDead *Dead() { return dead; }
00108 
00109     virtual List *operator [] (const WordReference& wordRef);
00110     virtual List *Prefix (const WordReference& prefix);
00111 
00112     virtual List *Words() { return dict->Words(); }
00113     virtual List *WordRefs();
00114 
00115     virtual inline WordCursor *Cursor(wordlist_walk_callback_t callback, Object *callback_data) { return new WordCursorOne(this, callback, callback_data); }
00116     virtual inline WordCursor *Cursor(const WordKey &searchKey, int action = HTDIG_WORDLIST_WALKER) { return new WordCursorOne(this, searchKey, action); }
00117     virtual inline WordCursor *Cursor(const WordKey &searchKey, wordlist_walk_callback_t callback, Object * callback_data) { return new WordCursorOne(this, searchKey, callback, callback_data); }
00118 
00119     virtual WordKey Key(const String& bufferin);
00120 
00121     virtual WordReference Word(const String& bufferin, int exists = 0);
00122 
00123     virtual void BatchEnd();
00124 
00125     virtual int Noccurrence(const String& key, unsigned int& noccurrence) const;
00126 
00127     virtual int Write(FILE* f);
00128 
00129     virtual inline int WriteDict(FILE* f) { return dict->Write(f); }
00130 
00131     virtual int Read(FILE* f);
00132 
00133     virtual List *Collect(const WordReference& word);
00134 
00135     WordDB                      *db;
00136     WordDict                    *dict;
00137     WordMeta                    *meta;
00138     WordDead                    *dead;
00139 };
00140 
00141 #endif /* _WordListOne_h_ */
00142 

Generated on Sun Jun 8 10:56:40 2008 for GNUmifluz by  doxygen 1.5.5