File: chert_record.cc

package info (click to toggle)
xapian-core 1.4.3-2%2Bdeb9u3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 21,412 kB
  • sloc: cpp: 113,868; ansic: 8,723; sh: 4,433; perl: 836; makefile: 566; tcl: 317; python: 40
file content (86 lines) | stat: -rw-r--r-- 2,539 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* chert_record.cc: Records in chert databases
 *
 * Copyright 2002 Ananova Ltd
 * Copyright 2002,2003,2004,2005,2008 Olly Betts
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

#include <config.h>

#include "chert_record.h"

#include <xapian/error.h>
#include "debuglog.h"
#include "omassert.h"
#include "pack.h"
#include "str.h"

using std::string;

inline string
make_key(Xapian::docid did)
{
    string key;
    C_pack_uint_preserving_sort(key, did);
    return key;
}

string
ChertRecordTable::get_record(Xapian::docid did) const
{
    LOGCALL(DB, string, "ChertRecordTable::get_record", did);
    string tag;
    // get_document() checks that the docid is valid, unless DOC_ASSUME_VALID
    // is used in which case returning an empty string here is the most
    // sensible behaviour.
    (void)get_exact_entry(make_key(did), tag);
    RETURN(tag);
}

Xapian::doccount
ChertRecordTable::get_doccount() const
{
    LOGCALL(DB, Xapian::doccount, "ChertRecordTable::get_doccount", NO_ARGS);
    chert_tablesize_t count = get_entry_count();
    if (rare(count > chert_tablesize_t(Xapian::doccount(-1)))) {
	// If we've got more entries than there are possible docids, the
	// database is in an odd state.
	throw Xapian::DatabaseCorruptError("Impossibly many entries in the record table");
    }
    RETURN(Xapian::doccount(count));
}

void
ChertRecordTable::replace_record(const string & data, Xapian::docid did)
{
    LOGCALL_VOID(DB, "ChertRecordTable::replace_record", data | did);
    add(make_key(did), data);
}

void
ChertRecordTable::delete_record(Xapian::docid did)
{
    LOGCALL_VOID(DB, "ChertRecordTable::delete_record", did);
    if (!del(make_key(did)))
	throw Xapian::DocNotFoundError("Can't delete non-existent document #" + str(did));
}

void
ChertRecordTable::readahead_for_record(Xapian::docid did) const
{
    readahead_key(make_key(did));
}