Branch data Line data Source code
1 : : /** @file brass_termlisttable.h
2 : : * @brief Subclass of BrassTable which holds termlists.
3 : : */
4 : : /* Copyright (C) 2007,2008,2009 Olly Betts
5 : : *
6 : : * This program is free software; you can redistribute it and/or modify
7 : : * it under the terms of the GNU General Public License as published by
8 : : * the Free Software Foundation; either version 2 of the License, or
9 : : * (at your option) any later version.
10 : : *
11 : : * This program is distributed in the hope that it will be useful,
12 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : : * GNU General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU General Public License
17 : : * along with this program; if not, write to the Free Software
18 : : * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 : : */
20 : :
21 : : #ifndef XAPIAN_INCLUDED_BRASS_TERMLISTTABLE_H
22 : : #define XAPIAN_INCLUDED_BRASS_TERMLISTTABLE_H
23 : :
24 : : #include <xapian/types.h>
25 : :
26 : : #include "brass_lazytable.h"
27 : : #include "pack.h"
28 : :
29 : : #include <string>
30 : :
31 : : namespace Xapian {
32 : : class Document;
33 : : }
34 : :
35 : 2208 : class BrassTermListTable : public BrassLazyTable {
36 : : public:
37 : 140966 : static std::string make_key(Xapian::docid did) {
38 : 140966 : std::string key;
39 : 140966 : pack_uint_preserving_sort(key, did);
40 : 0 : return key;
41 : : }
42 : :
43 : : /** Create a new BrassTermListTable object.
44 : : *
45 : : * This method does not create or open the table on disk - you
46 : : * must call the create() or open() methods respectively!
47 : : *
48 : : * @param dbdir The directory the brass database is stored in.
49 : : * @param readonly true if we're opening read-only, else false.
50 : : */
51 : 2208 : BrassTermListTable(const std::string & dbdir, bool readonly)
52 : : : BrassLazyTable("termlist", dbdir + "/termlist.", readonly,
53 : 2208 : Z_DEFAULT_STRATEGY) { }
54 : :
55 : : /** Set the termlist data for document @a did.
56 : : *
57 : : * Any existing data is replaced.
58 : : *
59 : : * @param did The docid to set the termlist data for.
60 : : * @param doc The Xapian::Document object to read term data from.
61 : : * @param doclen The document length.
62 : : */
63 : : void set_termlist(Xapian::docid did, const Xapian::Document & doc,
64 : : brass_doclen_t doclen);
65 : :
66 : : /** Delete the termlist data for document @a did.
67 : : *
68 : : * @param did The docid to delete the termlist data for.
69 : : */
70 : 9891 : void delete_termlist(Xapian::docid did) { del(make_key(did)); }
71 : :
72 : : /** Non-lazy override of BrassLazyTable::create_and_open().
73 : : *
74 : : * Don't create lazily, but if the termlist is deleted, work without it.
75 : : *
76 : : * This method isn't virtual, but we never call it such that it needs to
77 : : * be.
78 : : */
79 : 308 : void create_and_open(unsigned int blocksize) {
80 : 308 : BrassTable::create_and_open(blocksize);
81 : 308 : }
82 : : };
83 : :
84 : : #endif // XAPIAN_INCLUDED_BRASS_TERMLISTTABLE_H
|