backends/flint/flint_record.cc

Go to the documentation of this file.
00001 /* flint_record.cc: Records in flint databases
00002  *
00003  * ----START-LICENCE----
00004  * Copyright 1999,2000,2001 BrightStation PLC
00005  * Copyright 2002 Ananova Ltd
00006  * Copyright 2002,2003,2004,2005 Olly Betts
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as
00010  * published by the Free Software Foundation; either version 2 of the
00011  * License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021  * USA
00022  * -----END-LICENCE-----
00023  */
00024 
00025 #include <config.h>
00026 #include "flint_record.h"
00027 #include "flint_utils.h"
00028 #include "utils.h"
00029 #include <xapian/error.h>
00030 #include "omassert.h"
00031 #include "omdebug.h"
00032 
00033 using std::string;
00034 
00035 string
00036 FlintRecordTable::get_record(Xapian::docid did) const
00037 {
00038     DEBUGCALL(DB, string, "FlintRecordTable::get_record", did);
00039     string tag;
00040 
00041     if (!get_exact_entry(flint_docid_to_key(did), tag)) {
00042         throw Xapian::DocNotFoundError("Document " + om_tostring(did) + " not found.");
00043     }
00044 
00045     RETURN(tag);
00046 }
00047 
00048 
00049 Xapian::doccount
00050 FlintRecordTable::get_doccount() const
00051 {   
00052     DEBUGCALL(DB, Xapian::doccount, "FlintRecordTable::get_doccount", "");
00053     // Check that we can't overflow (the unsigned test is actually too
00054     // strict as we can typically assign an unsigned short to a signed long,
00055     // but this shouldn't actually matter here).
00056     CASSERT(sizeof(Xapian::doccount) >= sizeof(flint_tablesize_t));
00057     CASSERT_TYPE_UNSIGNED(Xapian::doccount);
00058     CASSERT_TYPE_UNSIGNED(flint_tablesize_t);
00059     RETURN(get_entry_count());
00060 }
00061 
00062 void
00063 FlintRecordTable::replace_record(const string & data, Xapian::docid did)
00064 {
00065     DEBUGCALL(DB, void, "FlintRecordTable::replace_record", data << ", " << did);
00066     add(flint_docid_to_key(did), data);
00067 }
00068 
00069 void
00070 FlintRecordTable::delete_record(Xapian::docid did)
00071 {
00072     DEBUGCALL(DB, void, "FlintRecordTable::delete_record", did);
00073     if (!del(flint_docid_to_key(did)))
00074         throw Xapian::DocNotFoundError("Can't delete non-existent document #" + om_tostring(did));
00075 }

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.