2 * @brief Subclass of GlassTable which holds document data.
4 /* Copyright (C) 2007,2008,2009,2010,2014,2016 Olly Betts
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.
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.
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
21 #ifndef XAPIAN_INCLUDED_GLASS_DOCDATA_H
22 #define XAPIAN_INCLUDED_GLASS_DOCDATA_H
24 #include <xapian/types.h>
26 #include "glass_lazytable.h"
31 class GlassDocDataTable
: public GlassLazyTable
{
33 static std::string
make_key(Xapian::docid did
) {
35 pack_uint_preserving_sort(key
, did
);
39 /** Create a new GlassDocDataTable object.
41 * This method does not create or open the table on disk - you
42 * must call the create() or open() methods respectively!
44 * @param dbdir The directory the glass database is stored in.
45 * @param readonly true if we're opening read-only, else false.
47 GlassDocDataTable(const std::string
& dbdir
, bool readonly
)
48 : GlassLazyTable("docdata", dbdir
+ "/docdata.", readonly
) { }
50 GlassDocDataTable(int fd
, off_t offset_
, bool readonly
)
51 : GlassLazyTable("docdata", fd
, offset_
, readonly
) { }
53 /** Get the document data for document @a did.
55 * If the document doesn't exist, the empty string is returned.
57 * @param did The docid to set the document data for.
59 std::string
get_document_data(Xapian::docid did
) const {
60 // We don't store the document data if it is empty.
62 (void)get_exact_entry(make_key(did
), data
);
66 /** Set the document data for document @a did.
68 * If the document might already exist, use replace_document_data()
71 * @param did The docid to set the document data for.
72 * @param data The document data to set.
74 void add_document_data(Xapian::docid did
, const std::string
& data
) {
75 // We don't store the document data if it is empty.
77 add(make_key(did
), data
);
80 /** Replace the document data for document @a did.
82 * Any existing data is replaced.
84 * @param did The docid to replace the document data for.
85 * @param data The document data to set.
87 void replace_document_data(Xapian::docid did
, const std::string
& data
) {
89 // We don't store the document data if it is empty.
90 delete_document_data(did
);
93 add(make_key(did
), data
);
96 /** Delete the document data for document @a did.
98 * @param did The docid to delete the document data for.
100 * @return true if document data was actually removed (false means either
101 * there's no such document, or the document has no data).
103 bool delete_document_data(Xapian::docid did
) { return del(make_key(did
)); }
105 void readahead_for_document(Xapian::docid did
) const {
106 readahead_key(make_key(did
));
110 #endif // XAPIAN_INCLUDED_GLASS_DOCDATA_H