Branch data Line data Source code
1 : : /* brass_alltermslist.h: A termlist containing all terms in a brass database.
2 : : *
3 : : * Copyright (C) 2005,2007,2008,2009,2010 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_BRASS_ALLTERMSLIST_H
22 : : #define XAPIAN_INCLUDED_BRASS_ALLTERMSLIST_H
23 : :
24 : : #include "alltermslist.h"
25 : : #include "brass_database.h"
26 : : #include "brass_postlist.h"
27 : :
28 : : class BrassCursor;
29 : :
30 : : class BrassAllTermsList : public AllTermsList {
31 : : /// Copying is not allowed.
32 : : BrassAllTermsList(const BrassAllTermsList &);
33 : :
34 : : /// Assignment is not allowed.
35 : : void operator=(const BrassAllTermsList &);
36 : :
37 : : /// Keep a reference to our database to stop it being deleted.
38 : : Xapian::Internal::RefCntPtr<const BrassDatabase> database;
39 : :
40 : : /** A cursor which runs through the postlist table reading termnames from
41 : : * the keys.
42 : : */
43 : : BrassCursor * cursor;
44 : :
45 : : /// The termname at the current position.
46 : : std::string current_term;
47 : :
48 : : /// The prefix to restrict the terms to.
49 : : std::string prefix;
50 : :
51 : : /** The term frequency of the term at the current position.
52 : : *
53 : : * If this value is zero, then we haven't read the term frequency or
54 : : * collection frequency for the current term yet. We need to call
55 : : * read_termfreq_and_collfreq() to read these.
56 : : */
57 : : mutable Xapian::doccount termfreq;
58 : :
59 : : /// The collection frequency of the term at the current position.
60 : : mutable Xapian::termcount collfreq;
61 : :
62 : : /// Read and cache the term frequency and collection frequency.
63 : : void read_termfreq_and_collfreq() const;
64 : :
65 : : public:
66 : 223 : BrassAllTermsList(Xapian::Internal::RefCntPtr<const BrassDatabase> database_,
67 : : const std::string & prefix_)
68 : 223 : : database(database_), cursor(NULL), prefix(prefix_), termfreq(0) { }
69 : :
70 : : /// Destructor.
71 : : ~BrassAllTermsList();
72 : :
73 : : /** Returns the current termname.
74 : : *
75 : : * Either next() or skip_to() must have been called before this
76 : : * method can be called.
77 : : */
78 : : std::string get_termname() const;
79 : :
80 : : /** Returns the term frequency of the current term.
81 : : *
82 : : * Either next() or skip_to() must have been called before this
83 : : * method can be called.
84 : : */
85 : : Xapian::doccount get_termfreq() const;
86 : :
87 : : /** Returns the collection frequency of the current term.
88 : : *
89 : : * Either next() or skip_to() must have been called before this
90 : : * method can be called.
91 : : */
92 : : Xapian::termcount get_collection_freq() const;
93 : :
94 : : /// Advance to the next term in the list.
95 : : TermList * next();
96 : :
97 : : /// Advance to the first term which is >= tname.
98 : : TermList * skip_to(const std::string &tname);
99 : :
100 : : /// True if we're off the end of the list
101 : : bool at_end() const;
102 : : };
103 : :
104 : : #endif /* XAPIAN_INCLUDED_BRASS_ALLTERMSLIST_H */
|