root / tags / 1.0.8 / xapian-core / backends / flint / flint_alltermslist.h

Revision 9275, 4.6 kB (checked in by olly, 16 months ago)

backends/flint/flint_spellingwordslist.cc,
backends/flint/flint_synonym.cc: Use FlintCursor::find_entry_ge().
backends/flint/flint_synonym.h: Use FlintCursor::find_entry_lt().
backends/flint/flint_alltermslist.h: Use FlintCursor::find_entry_lt()
and skip any keys before "\x00\xff" to allow for extra metadata
keys.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* flint_alltermslist.h: A termlist containing all terms in a flint database.
2 *
3 * Copyright (C) 2005,2007 Olly Betts
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
18 * USA
19 */
20
21#ifndef XAPIAN_INCLUDED_FLINT_ALLTERMSLIST_H
22#define XAPIAN_INCLUDED_FLINT_ALLTERMSLIST_H
23
24#include "alltermslist.h"
25#include "flint_database.h"
26#include "flint_postlist.h"
27
28class FlintCursor;
29
30class FlintAllTermsList : public AllTermsList {
31    /// Copying is not allowed.
32    FlintAllTermsList(const FlintAllTermsList &);
33
34    /// Assignment is not allowed.
35    void operator=(const FlintAllTermsList &);
36
37    /// Keep a reference to our database to stop it being deleted.
38    Xapian::Internal::RefCntPtr<const FlintDatabase> database;
39
40    /** A cursor which runs through the postlist table reading termnames from
41     *  the keys.
42     */
43    FlintCursor * cursor;
44
45    /// The approximate number of terms in this list.
46    Xapian::termcount approx_size;
47
48    /// The termname at the current position.
49    string current_term;
50
51    /// The prefix to restrict the terms to.
52    string prefix;
53
54    /** The term frequency of the term at the current position.
55     *
56     *  If this value is zero, then we haven't read the term frequency or
57     *  collection frequency for the current term yet.  We need to call
58     *  read_termfreq_and_collfreq() to read these.
59     */
60    mutable Xapian::termcount termfreq;
61
62    /// The collection frequency of the term at the current position.
63    mutable Xapian::termcount collfreq;
64
65    /// Read and cache the term frequency and collection frequency.
66    void read_termfreq_and_collfreq() const;
67
68  public:
69    FlintAllTermsList(Xapian::Internal::RefCntPtr<const FlintDatabase> database_,
70                      const string & prefix_)
71            : database(database_), prefix(prefix_), termfreq(0) {
72        // The number of entries in the postlist table will be the number of
73        // terms, probably plus some extra entries for chunked posting lists,
74        // plus 1 for the metainfo key (unless the table is completely empty).
75        // FIXME : this can badly overestimate (it could be several times too
76        // large) - perhaps keep track of the number of terms (or number of
77        // extra chunks) and store this along with the last_docid and
78        // total_doclen?  (Mind you, not sure this value is ever used, but
79        // we should really make the exact number of terms available somewhere
80        // in the API).
81        approx_size = database->postlist_table.get_entry_count();
82        if (approx_size) --approx_size;
83
84        cursor = database->postlist_table.cursor_get();
85        Assert(cursor); // The postlist table isn't optional.
86
87        // Position the cursor on the highest key before the first key we want,
88        // so that the first call to next() will put us on the first key we
89        // want.
90        if (prefix.empty()) {
91            cursor->find_entry_lt(string("\x00\xff", 2));
92        } else {
93            cursor->find_entry_lt(pack_string_preserving_sort(prefix));
94        }
95    }
96
97    /// Destructor.
98    ~FlintAllTermsList();
99
100    /** Returns the approximate size of the list.
101     *
102     *  This is probably unused for this class.
103     */
104    Xapian::termcount get_approx_size() const;
105
106    /** Returns the current termname.
107     *
108     *  Either next() or skip_to() must have been called before this
109     *  method can be called.
110     */
111    string get_termname() const;
112
113    /** Returns the term frequency of the current term.
114     *
115     *  Either next() or skip_to() must have been called before this
116     *  method can be called.
117     */
118    Xapian::doccount get_termfreq() const;
119
120    /** Returns the collection frequency of the current term.
121     *
122     *  Either next() or skip_to() must have been called before this
123     *  method can be called.
124     */
125    Xapian::termcount get_collection_freq() const;
126
127    /// Advance to the next term in the list.
128    TermList * next();
129
130    /// Advance to the first term which is >= tname.
131    TermList * skip_to(const string &tname);
132
133    /// True if we're off the end of the list
134    bool at_end() const;
135};
136
137#endif /* XAPIAN_INCLUDED_FLINT_ALLTERMSLIST_H */
Note: See TracBrowser for help on using the browser.