00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <config.h>
00025
00026 #include "database.h"
00027
00028 #include "xapian/error.h"
00029
00030 #include "leafpostlist.h"
00031 #include "omassert.h"
00032 #include "slowvaluelist.h"
00033
00034 #include <algorithm>
00035 #include <string>
00036
00037 using namespace std;
00038
00039 namespace Xapian {
00040
00041 Database::Internal::~Internal()
00042 {
00043 }
00044
00045 void
00046 Database::Internal::keep_alive()
00047 {
00048
00049 }
00050
00051
00052 Xapian::doccount
00053 Database::Internal::get_value_freq(Xapian::valueno) const
00054 {
00055 throw Xapian::UnimplementedError("This backend doesn't support get_value_freq");
00056 }
00057
00058 string
00059 Database::Internal::get_value_lower_bound(Xapian::valueno) const
00060 {
00061 return string();
00062 }
00063
00064 string
00065 Database::Internal::get_value_upper_bound(Xapian::valueno) const
00066 {
00067 throw Xapian::UnimplementedError("This backend doesn't support get_value_upper_bound");
00068 }
00069
00070 Xapian::termcount
00071 Database::Internal::get_doclength_lower_bound() const
00072 {
00073
00074
00075 return 1;
00076 }
00077
00078 Xapian::termcount
00079 Database::Internal::get_doclength_upper_bound() const
00080 {
00081
00082
00083 return min(get_total_length(), totlen_t(Xapian::termcount(-1)));
00084 }
00085
00086 Xapian::termcount
00087 Database::Internal::get_wdf_upper_bound(const string & term) const
00088 {
00089
00090
00091 return get_collection_freq(term);
00092 }
00093
00094
00095
00096 void
00097 Database::Internal::dtor_called()
00098 {
00099 try {
00100 if (transaction_active()) {
00101 cancel_transaction();
00102 } else if (transaction_state == TRANSACTION_NONE) {
00103 commit();
00104 }
00105 } catch (...) {
00106
00107
00108 }
00109 }
00110
00111 void
00112 Database::Internal::commit()
00113 {
00114
00115 Assert(false);
00116 }
00117
00118 void
00119 Database::Internal::cancel()
00120 {
00121
00122 Assert(false);
00123 }
00124
00125 void
00126 Database::Internal::begin_transaction(bool flushed)
00127 {
00128 if (transaction_state != TRANSACTION_NONE) {
00129 if (transaction_state == TRANSACTION_UNIMPLEMENTED)
00130 throw Xapian::UnimplementedError("This backend doesn't implement transactions");
00131 throw InvalidOperationError("Cannot begin transaction - transaction already in progress");
00132 }
00133 if (flushed) {
00134
00135
00136 commit();
00137 transaction_state = TRANSACTION_FLUSHED;
00138 } else {
00139 transaction_state = TRANSACTION_UNFLUSHED;
00140 }
00141 }
00142
00143 void
00144 Database::Internal::commit_transaction()
00145 {
00146 if (!transaction_active()) {
00147 if (transaction_state == TRANSACTION_UNIMPLEMENTED)
00148 throw Xapian::UnimplementedError("This backend doesn't implement transactions");
00149 throw InvalidOperationError("Cannot commit transaction - no transaction currently in progress");
00150 }
00151 bool flushed = (transaction_state == TRANSACTION_FLUSHED);
00152 transaction_state = TRANSACTION_NONE;
00153
00154
00155 if (flushed) commit();
00156 }
00157
00158 void
00159 Database::Internal::cancel_transaction()
00160 {
00161 if (!transaction_active()) {
00162 if (transaction_state == TRANSACTION_UNIMPLEMENTED)
00163 throw Xapian::UnimplementedError("This backend doesn't implement transactions");
00164 throw InvalidOperationError("Cannot cancel transaction - no transaction currently in progress");
00165 }
00166 transaction_state = TRANSACTION_NONE;
00167 cancel();
00168 }
00169
00170 Xapian::docid
00171 Database::Internal::add_document(const Xapian::Document &)
00172 {
00173
00174 Assert(false);
00175 return 0;
00176 }
00177
00178 void
00179 Database::Internal::delete_document(Xapian::docid)
00180 {
00181
00182 Assert(false);
00183 }
00184
00185 void
00186 Database::Internal::delete_document(const string & unique_term)
00187 {
00188
00189 Xapian::Internal::RefCntPtr<LeafPostList> pl(open_post_list(unique_term));
00190 while (pl->next(), !pl->at_end()) {
00191 delete_document(pl->get_docid());
00192 }
00193 }
00194
00195 void
00196 Database::Internal::replace_document(Xapian::docid, const Xapian::Document &)
00197 {
00198
00199 Assert(false);
00200 }
00201
00202 Xapian::docid
00203 Database::Internal::replace_document(const string & unique_term,
00204 const Xapian::Document & document)
00205 {
00206
00207 Xapian::Internal::RefCntPtr<LeafPostList> pl(open_post_list(unique_term));
00208 pl->next();
00209 if (pl->at_end()) {
00210 return add_document(document);
00211 }
00212 Xapian::docid did = pl->get_docid();
00213 replace_document(did, document);
00214 while (pl->next(), !pl->at_end()) {
00215 delete_document(pl->get_docid());
00216 }
00217 return did;
00218 }
00219
00220 ValueList *
00221 Database::Internal::open_value_list(Xapian::valueno slot) const
00222 {
00223 return new SlowValueList(Xapian::Database(const_cast<Database::Internal*>(this)), slot);
00224 }
00225
00226 TermList *
00227 Database::Internal::open_spelling_termlist(const string &) const
00228 {
00229
00230
00231
00232 return NULL;
00233 }
00234
00235 TermList *
00236 Database::Internal::open_spelling_wordlist() const
00237 {
00238
00239
00240
00241 return NULL;
00242 }
00243
00244 Xapian::doccount
00245 Database::Internal::get_spelling_frequency(const string &) const
00246 {
00247
00248
00249
00250 return 0;
00251 }
00252
00253 void
00254 Database::Internal::add_spelling(const string &, Xapian::termcount) const
00255 {
00256 throw Xapian::UnimplementedError("This backend doesn't implement spelling correction");
00257 }
00258
00259 void
00260 Database::Internal::remove_spelling(const string &, Xapian::termcount) const
00261 {
00262 throw Xapian::UnimplementedError("This backend doesn't implement spelling correction");
00263 }
00264
00265 TermList *
00266 Database::Internal::open_synonym_termlist(const string &) const
00267 {
00268
00269
00270
00271 return NULL;
00272 }
00273
00274 TermList *
00275 Database::Internal::open_synonym_keylist(const string &) const
00276 {
00277
00278
00279
00280 return NULL;
00281 }
00282
00283 void
00284 Database::Internal::add_synonym(const string &, const string &) const
00285 {
00286 throw Xapian::UnimplementedError("This backend doesn't implement synonyms");
00287 }
00288
00289 void
00290 Database::Internal::remove_synonym(const string &, const string &) const
00291 {
00292 throw Xapian::UnimplementedError("This backend doesn't implement synonyms");
00293 }
00294
00295 void
00296 Database::Internal::clear_synonyms(const string &) const
00297 {
00298 throw Xapian::UnimplementedError("This backend doesn't implement synonyms");
00299 }
00300
00301 string
00302 Database::Internal::get_metadata(const string &) const
00303 {
00304 return string();
00305 }
00306
00307 TermList *
00308 Database::Internal::open_metadata_keylist(const string &) const
00309 {
00310
00311
00312 return NULL;
00313 }
00314
00315 void
00316 Database::Internal::set_metadata(const string &, const string &)
00317 {
00318 throw Xapian::UnimplementedError("This backend doesn't implement metadata");
00319 }
00320
00321 void
00322 Database::Internal::reopen()
00323 {
00324
00325
00326 }
00327
00328 void
00329 Database::Internal::request_document(Xapian::docid ) const
00330 {
00331 }
00332
00333 Xapian::Document::Internal *
00334 Database::Internal::collect_document(Xapian::docid did) const
00335 {
00336
00337
00338
00339 return open_document(did, true);
00340 }
00341
00342 void
00343 Database::Internal::write_changesets_to_fd(int, const string &, bool, ReplicationInfo *)
00344 {
00345 throw Xapian::UnimplementedError("This backend doesn't provide changesets");
00346 }
00347
00348 string
00349 Database::Internal::get_revision_info() const
00350 {
00351 throw Xapian::UnimplementedError("This backend doesn't provide access to revision information");
00352 }
00353
00354 string
00355 Database::Internal::get_uuid() const
00356 {
00357 return string();
00358 }
00359
00360 void
00361 Database::Internal::invalidate_doc_object(Xapian::Document::Internal *) const
00362 {
00363
00364 }
00365
00366 RemoteDatabase *
00367 Database::Internal::as_remotedatabase()
00368 {
00369 return NULL;
00370 }
00371
00372 }