| 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 | #include <config.h> |
|---|
| 26 | |
|---|
| 27 | #include <xapian/error.h> |
|---|
| 28 | |
|---|
| 29 | #include "safeerrno.h" |
|---|
| 30 | |
|---|
| 31 | #include "flint_database.h" |
|---|
| 32 | #include "utils.h" |
|---|
| 33 | #include "omdebug.h" |
|---|
| 34 | #include "autoptr.h" |
|---|
| 35 | #include <xapian/error.h> |
|---|
| 36 | #include <xapian/valueiterator.h> |
|---|
| 37 | |
|---|
| 38 | #include "contiguousalldocspostlist.h" |
|---|
| 39 | #include "flint_modifiedpostlist.h" |
|---|
| 40 | #include "flint_postlist.h" |
|---|
| 41 | #include "flint_alldocspostlist.h" |
|---|
| 42 | #include "flint_termlist.h" |
|---|
| 43 | #include "flint_positionlist.h" |
|---|
| 44 | #include "flint_utils.h" |
|---|
| 45 | #include "flint_record.h" |
|---|
| 46 | #include "flint_values.h" |
|---|
| 47 | #include "flint_document.h" |
|---|
| 48 | #include "flint_alltermslist.h" |
|---|
| 49 | #include "flint_lock.h" |
|---|
| 50 | #include "flint_spellingwordslist.h" |
|---|
| 51 | #include "stringutils.h" |
|---|
| 52 | |
|---|
| 53 | #include <sys/types.h> |
|---|
| 54 | #include "safesysstat.h" |
|---|
| 55 | |
|---|
| 56 | #include <list> |
|---|
| 57 | #include <string> |
|---|
| 58 | |
|---|
| 59 | using namespace std; |
|---|
| 60 | using namespace Xapian; |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | #define MAX_SAFE_TERM_LENGTH 245 |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | static const string METAINFO_KEY("", 1); |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | FlintDatabase::FlintDatabase(const string &flint_dir, int action, |
|---|
| 79 |                unsigned int block_size) |
|---|
| 80 | Â Â Â Â : db_dir(flint_dir), |
|---|
| 81 | Â Â Â Â Â readonly(action == XAPIAN_DB_READONLY), |
|---|
| 82 | Â Â Â Â Â version_file(db_dir), |
|---|
| 83 | Â Â Â Â Â postlist_table(db_dir, readonly), |
|---|
| 84 | Â Â Â Â Â position_table(db_dir, readonly), |
|---|
| 85 | Â Â Â Â Â termlist_table(db_dir, readonly), |
|---|
| 86 | Â Â Â Â Â value_table(db_dir, readonly), |
|---|
| 87 | Â Â Â Â Â synonym_table(db_dir, readonly), |
|---|
| 88 | Â Â Â Â Â spelling_table(db_dir, readonly), |
|---|
| 89 | Â Â Â Â Â record_table(db_dir, readonly), |
|---|
| 90 | Â Â Â Â Â lock(db_dir + "/flintlock"), |
|---|
| 91 | Â Â Â Â Â total_length(0), |
|---|
| 92 | Â Â Â Â Â lastdocid(0) |
|---|
| 93 | { |
|---|
| 94 | Â Â DEBUGCALL(DB, void, "FlintDatabase", flint_dir << ", "Â << action << |
|---|
| 95 | Â Â Â Â Â Â Â ", "Â << block_size); |
|---|
| 96 | |
|---|
| 97 |   if (action == XAPIAN_DB_READONLY) { |
|---|
| 98 | Â Â Â Â open_tables_consistent(); |
|---|
| 99 | Â Â Â Â return; |
|---|
| 100 | Â Â } |
|---|
| 101 | |
|---|
| 102 |   if (action != Xapian::DB_OPEN && !database_exists()) { |
|---|
| 103 | Â Â Â Â |
|---|
| 104 | |
|---|
| 105 | Â Â Â Â |
|---|
| 106 | Â Â Â Â |
|---|
| 107 |     bool fail = false; |
|---|
| 108 |     struct stat statbuf; |
|---|
| 109 |     if (stat(db_dir, &statbuf) == 0) { |
|---|
| 110 |       if (!S_ISDIR(statbuf.st_mode)) fail = true; |
|---|
| 111 |     } else if (errno != ENOENT || mkdir(db_dir, 0755) == -1) { |
|---|
| 112 | Â Â Â Â Â Â fail = true; |
|---|
| 113 | Â Â Â Â } |
|---|
| 114 |     if (fail) { |
|---|
| 115 |       throw Xapian::DatabaseCreateError("Cannot create directory `" + |
|---|
| 116 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â db_dir + "'", errno); |
|---|
| 117 | Â Â Â Â } |
|---|
| 118 | Â Â Â Â get_database_write_lock(); |
|---|
| 119 | |
|---|
| 120 | Â Â Â Â create_and_open_tables(block_size); |
|---|
| 121 | Â Â Â Â return; |
|---|
| 122 | Â Â } |
|---|
| 123 | |
|---|
| 124 |   if (action == Xapian::DB_CREATE) { |
|---|
| 125 |     throw Xapian::DatabaseCreateError("Can't create new database at `" + |
|---|
| 126 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â db_dir + "': a database already exists and I was told " |
|---|
| 127 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "not to overwrite it"); |
|---|
| 128 | Â Â } |
|---|
| 129 | |
|---|
| 130 | Â Â get_database_write_lock(); |
|---|
| 131 | Â Â |
|---|
| 132 | Â Â |
|---|
| 133 |   if (action == Xapian::DB_CREATE_OR_OVERWRITE) { |
|---|
| 134 | Â Â Â Â create_and_open_tables(block_size); |
|---|
| 135 | Â Â Â Â return; |
|---|
| 136 | Â Â } |
|---|
| 137 | |
|---|
| 138 | Â Â |
|---|
| 139 | Â Â open_tables_consistent(); |
|---|
| 140 | |
|---|
| 141 | Â Â |
|---|
| 142 | Â Â |
|---|
| 143 | Â Â |
|---|
| 144 |   if (record_table.get_open_revision_number() != |
|---|
| 145 | Â Â Â Â postlist_table.get_latest_revision_number()) { |
|---|
| 146 | Â Â Â Â flint_revision_number_t new_revision = get_next_revision_number(); |
|---|
| 147 | |
|---|
| 148 | Â Â Â Â set_revision_number(new_revision); |
|---|
| 149 | Â Â } |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | FlintDatabase::~FlintDatabase() |
|---|
| 153 | { |
|---|
| 154 | Â Â DEBUGCALL(DB, void, "~FlintDatabase", ""); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | void |
|---|
| 158 | FlintDatabase::read_metainfo() |
|---|
| 159 | { |
|---|
| 160 | Â Â DEBUGCALL(DB, void, "FlintDatabase::read_metainfo", ""); |
|---|
| 161 | |
|---|
| 162 | Â Â string tag; |
|---|
| 163 |   if (!postlist_table.get_exact_entry(METAINFO_KEY, tag)) { |
|---|
| 164 | Â Â Â Â lastdocid = 0; |
|---|
| 165 | Â Â Â Â total_length = 0; |
|---|
| 166 | Â Â Â Â return; |
|---|
| 167 | Â Â } |
|---|
| 168 | |
|---|
| 169 |   const char * data = tag.data(); |
|---|
| 170 |   const char * end = data + tag.size(); |
|---|
| 171 |   if (!unpack_uint(&data, end, &lastdocid) || |
|---|
| 172 | Â Â Â Â !unpack_uint_last(&data, end, &total_length)) { |
|---|
| 173 |     throw Xapian::DatabaseCorruptError("Meta information is corrupt."); |
|---|
| 174 | Â Â } |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | bool |
|---|
| 178 | FlintDatabase::database_exists() { |
|---|
| 179 | Â Â DEBUGCALL(DB, bool, "FlintDatabase::database_exists", ""); |
|---|
| 180 | Â Â RETURN(record_table.exists() && |
|---|
| 181 | Â Â Â Â Â Â postlist_table.exists() && |
|---|
| 182 | Â Â Â Â Â Â termlist_table.exists()); |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | void |
|---|
| 186 | FlintDatabase::create_and_open_tables(unsigned int block_size) |
|---|
| 187 | { |
|---|
| 188 | Â Â DEBUGCALL(DB, void, "FlintDatabase::create_and_open_tables", ""); |
|---|
| 189 | Â Â |
|---|
| 190 | Â Â |
|---|
| 191 | |
|---|
| 192 | Â Â |
|---|
| 193 | Â Â |
|---|
| 194 | Â Â version_file.create(); |
|---|
| 195 | Â Â postlist_table.create_and_open(block_size); |
|---|
| 196 | Â Â |
|---|
| 197 | Â Â |
|---|
| 198 | Â Â position_table.erase(); |
|---|
| 199 | Â Â position_table.set_block_size(block_size); |
|---|
| 200 | |
|---|
| 201 | Â Â termlist_table.create_and_open(block_size); |
|---|
| 202 | Â Â |
|---|
| 203 | Â Â |
|---|
| 204 | Â Â value_table.erase(); |
|---|
| 205 | Â Â value_table.set_block_size(block_size); |
|---|
| 206 | |
|---|
| 207 | Â Â synonym_table.create_and_open(block_size); |
|---|
| 208 | Â Â spelling_table.create_and_open(block_size); |
|---|
| 209 | Â Â record_table.create_and_open(block_size); |
|---|
| 210 | |
|---|
| 211 | Â Â Assert(database_exists()); |
|---|
| 212 | |
|---|
| 213 | Â Â |
|---|
| 214 | Â Â flint_revision_number_t revision = record_table.get_open_revision_number(); |
|---|
| 215 |   if (revision != termlist_table.get_open_revision_number() || |
|---|
| 216 | Â Â Â Â revision != postlist_table.get_open_revision_number()) { |
|---|
| 217 |     throw Xapian::DatabaseCreateError("Newly created tables are not in consistent state"); |
|---|
| 218 | Â Â } |
|---|
| 219 | |
|---|
| 220 | Â Â total_length = 0; |
|---|
| 221 | Â Â lastdocid = 0; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | void |
|---|
| 225 | FlintDatabase::open_tables_consistent() |
|---|
| 226 | { |
|---|
| 227 | Â Â DEBUGCALL(DB, void, "FlintDatabase::open_tables_consistent", ""); |
|---|
| 228 | Â Â |
|---|
| 229 | Â Â |
|---|
| 230 | Â Â |
|---|
| 231 | Â Â |
|---|
| 232 | Â Â |
|---|
| 233 | Â Â |
|---|
| 234 | Â Â |
|---|
| 235 | |
|---|
| 236 | Â Â flint_revision_number_t cur_rev = record_table.get_open_revision_number(); |
|---|
| 237 | |
|---|
| 238 | Â Â |
|---|
| 239 |   if (cur_rev == 0) version_file.read_and_check(readonly); |
|---|
| 240 | |
|---|
| 241 | Â Â record_table.open(); |
|---|
| 242 | Â Â flint_revision_number_t revision = record_table.get_open_revision_number(); |
|---|
| 243 | |
|---|
| 244 |   if (cur_rev && cur_rev == revision) { |
|---|
| 245 | Â Â Â Â |
|---|
| 246 | Â Â Â Â |
|---|
| 247 | Â Â Â Â return; |
|---|
| 248 | Â Â } |
|---|
| 249 | |
|---|
| 250 | Â Â |
|---|
| 251 | Â Â |
|---|
| 252 |   unsigned int block_size = record_table.get_block_size(); |
|---|
| 253 | Â Â position_table.set_block_size(block_size); |
|---|
| 254 | Â Â value_table.set_block_size(block_size); |
|---|
| 255 | Â Â synonym_table.set_block_size(block_size); |
|---|
| 256 | Â Â spelling_table.set_block_size(block_size); |
|---|
| 257 | |
|---|
| 258 |   bool fully_opened = false; |
|---|
| 259 |   int tries = 100; |
|---|
| 260 |   int tries_left = tries; |
|---|
| 261 |   while (!fully_opened && (tries_left--) > 0) { |
|---|
| 262 |     if (spelling_table.open(revision) && |
|---|
| 263 | Â Â Â Â Â Â synonym_table.open(revision) && |
|---|
| 264 | Â Â Â Â Â Â value_table.open(revision) && |
|---|
| 265 | Â Â Â Â Â Â termlist_table.open(revision) && |
|---|
| 266 | Â Â Â Â Â Â position_table.open(revision) && |
|---|
| 267 | Â Â Â Â Â Â postlist_table.open(revision)) { |
|---|
| 268 | Â Â Â Â Â Â |
|---|
| 269 | Â Â Â Â Â Â fully_opened = true; |
|---|
| 270 |     } else { |
|---|
| 271 | Â Â Â Â Â Â |
|---|
| 272 | Â Â Â Â Â Â |
|---|
| 273 | Â Â Â Â Â Â |
|---|
| 274 | Â Â Â Â Â Â |
|---|
| 275 | Â Â Â Â Â Â |
|---|
| 276 | Â Â Â Â Â Â |
|---|
| 277 | Â Â Â Â Â Â |
|---|
| 278 | Â Â Â Â Â Â |
|---|
| 279 | Â Â Â Â Â Â |
|---|
| 280 | Â Â Â Â Â Â |
|---|
| 281 | Â Â Â Â Â Â record_table.open(); |
|---|
| 282 | Â Â Â Â Â Â flint_revision_number_t newrevision = |
|---|
| 283 | Â Â Â Â Â Â Â Â Â Â record_table.get_open_revision_number(); |
|---|
| 284 |       if (revision == newrevision) { |
|---|
| 285 | Â Â Â Â Â Â Â Â |
|---|
| 286 | Â Â Â Â Â Â Â Â |
|---|
| 287 | Â Â Â Â Â Â Â Â |
|---|
| 288 |         throw Xapian::DatabaseCorruptError("Cannot open tables at consistent revisions"); |
|---|
| 289 | Â Â Â Â Â Â } |
|---|
| 290 | Â Â Â Â Â Â revision = newrevision; |
|---|
| 291 | Â Â Â Â } |
|---|
| 292 | Â Â } |
|---|
| 293 | |
|---|
| 294 |   if (!fully_opened) { |
|---|
| 295 |     throw Xapian::DatabaseModifiedError("Cannot open tables at stable revision - changing too fast"); |
|---|
| 296 | Â Â } |
|---|
| 297 | |
|---|
| 298 | Â Â read_metainfo(); |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | void |
|---|
| 302 | FlintDatabase::open_tables(flint_revision_number_t revision) |
|---|
| 303 | { |
|---|
| 304 | Â Â DEBUGCALL(DB, void, "FlintDatabase::open_tables", revision); |
|---|
| 305 | Â Â version_file.read_and_check(readonly); |
|---|
| 306 | Â Â record_table.open(revision); |
|---|
| 307 | |
|---|
| 308 | Â Â |
|---|
| 309 | Â Â |
|---|
| 310 |   unsigned int block_size = record_table.get_block_size(); |
|---|
| 311 | Â Â position_table.set_block_size(block_size); |
|---|
| 312 | Â Â value_table.set_block_size(block_size); |
|---|
| 313 | Â Â synonym_table.set_block_size(block_size); |
|---|
| 314 | Â Â spelling_table.set_block_size(block_size); |
|---|
| 315 | |
|---|
| 316 | Â Â spelling_table.open(revision); |
|---|
| 317 | Â Â synonym_table.open(revision); |
|---|
| 318 | Â Â value_table.open(revision); |
|---|
| 319 | Â Â termlist_table.open(revision); |
|---|
| 320 | Â Â position_table.open(revision); |
|---|
| 321 | Â Â postlist_table.open(revision); |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | flint_revision_number_t |
|---|
| 325 | FlintDatabase::get_revision_number() const |
|---|
| 326 | { |
|---|
| 327 | Â Â DEBUGCALL(DB, flint_revision_number_t, "FlintDatabase::get_revision_number", ""); |
|---|
| 328 | Â Â |
|---|
| 329 | Â Â RETURN(postlist_table.get_open_revision_number()); |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | flint_revision_number_t |
|---|
| 333 | FlintDatabase::get_next_revision_number() const |
|---|
| 334 | { |
|---|
| 335 | Â Â DEBUGCALL(DB, flint_revision_number_t, "FlintDatabase::get_next_revision_number", ""); |
|---|
| 336 | Â Â |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | Â Â flint_revision_number_t new_revision = |
|---|
| 341 | Â Â Â Â Â Â postlist_table.get_latest_revision_number(); |
|---|
| 342 | Â Â ++new_revision; |
|---|
| 343 | Â Â RETURN(new_revision); |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | void |
|---|
| 347 | FlintDatabase::set_revision_number(flint_revision_number_t new_revision) |
|---|
| 348 | { |
|---|
| 349 | Â Â DEBUGCALL(DB, void, "FlintDatabase::set_revision_number", new_revision); |
|---|
| 350 | Â Â postlist_table.commit(new_revision); |
|---|
| 351 | Â Â position_table.commit(new_revision); |
|---|
| 352 | Â Â termlist_table.commit(new_revision); |
|---|
| 353 | Â Â value_table.commit(new_revision); |
|---|
| 354 | Â Â synonym_table.commit(new_revision); |
|---|
| 355 | Â Â spelling_table.commit(new_revision); |
|---|
| 356 | Â Â record_table.commit(new_revision); |
|---|
| 357 | } |
|---|
| 358 | |
|---|
| 359 | void |
|---|
| 360 | FlintDatabase::reopen() |
|---|
| 361 | { |
|---|
| 362 | Â Â DEBUGCALL(DB, void, "FlintDatabase::reopen", ""); |
|---|
| 363 |   if (readonly) { |
|---|
| 364 | Â Â Â Â open_tables_consistent(); |
|---|
| 365 | Â Â } |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | void |
|---|
| 369 | FlintDatabase::get_database_write_lock() |
|---|
| 370 | { |
|---|
| 371 | Â Â DEBUGCALL(DB, void, "FlintDatabase::get_database_write_lock", ""); |
|---|
| 372 | Â Â FlintLock::reason why = lock.lock(true); |
|---|
| 373 |   if (why != FlintLock::SUCCESS) { |
|---|
| 374 |     if (why == FlintLock::UNKNOWN && !database_exists()) { |
|---|
| 375 | Â Â Â Â Â Â string msg("No flint database found at path `"); |
|---|
| 376 | Â Â Â Â Â Â msg += db_dir; |
|---|
| 377 | Â Â Â Â Â Â msg += '\''; |
|---|
| 378 |       throw Xapian::DatabaseOpeningError(msg); |
|---|
| 379 | Â Â Â Â } |
|---|
| 380 | Â Â Â Â string msg("Unable to acquire database write lock on "); |
|---|
| 381 | Â Â Â Â msg += db_dir; |
|---|
| 382 |     if (why == FlintLock::INUSE) { |
|---|
| 383 | Â Â Â Â Â Â msg += ": already locked"; |
|---|
| 384 |     } else if (why == FlintLock::UNSUPPORTED) { |
|---|
| 385 | Â Â Â Â Â Â msg += ": locking probably not supported by this FS"; |
|---|
| 386 | Â Â Â Â } |
|---|
| 387 |     throw Xapian::DatabaseLockError(msg); |
|---|
| 388 | Â Â } |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | void |
|---|
| 392 | FlintDatabase::apply() |
|---|
| 393 | { |
|---|
| 394 | Â Â DEBUGCALL(DB, void, "FlintDatabase::apply", ""); |
|---|
| 395 |   if (!postlist_table.is_modified() && |
|---|
| 396 | Â Â Â Â !position_table.is_modified() && |
|---|
| 397 | Â Â Â Â !termlist_table.is_modified() && |
|---|
| 398 | Â Â Â Â !value_table.is_modified() && |
|---|
| 399 | Â Â Â Â !synonym_table.is_modified() && |
|---|
| 400 | Â Â Â Â !spelling_table.is_modified() && |
|---|
| 401 | Â Â Â Â !record_table.is_modified()) { |
|---|
| 402 | Â Â Â Â return; |
|---|
| 403 | Â Â } |
|---|
| 404 | |
|---|
| 405 | Â Â flint_revision_number_t old_revision = get_revision_number(); |
|---|
| 406 | Â Â flint_revision_number_t new_revision = get_next_revision_number(); |
|---|
| 407 | |
|---|
| 408 |   try { |
|---|
| 409 | Â Â Â Â set_revision_number(new_revision); |
|---|
| 410 |   } catch (...) { |
|---|
| 411 | Â Â Â Â |
|---|
| 412 |     try { |
|---|
| 413 | Â Â Â Â Â Â |
|---|
| 414 | Â Â Â Â Â Â |
|---|
| 415 | Â Â Â Â Â Â cancel(); |
|---|
| 416 | |
|---|
| 417 | Â Â Â Â Â Â |
|---|
| 418 | Â Â Â Â Â Â open_tables(old_revision); |
|---|
| 419 | |
|---|
| 420 | Â Â Â Â Â Â |
|---|
| 421 | Â Â Â Â Â Â |
|---|
| 422 | Â Â Â Â Â Â ++new_revision; |
|---|
| 423 | Â Â Â Â Â Â set_revision_number(new_revision); |
|---|
| 424 |     } catch (const Xapian::Error &e) { |
|---|
| 425 |       throw Xapian::DatabaseError("Modifications failed, and cannot set consistent table revision numbers: " + e.get_msg()); |
|---|
| 426 | Â Â Â Â } |
|---|
| 427 | Â Â Â Â throw; |
|---|
| 428 | Â Â } |
|---|
| 429 | } |
|---|
| 430 | |
|---|
| 431 | void |
|---|
| 432 | FlintDatabase::cancel() |
|---|
| 433 | { |
|---|
| 434 | Â Â DEBUGCALL(DB, void, "FlintDatabase::cancel", ""); |
|---|
| 435 | Â Â postlist_table.cancel(); |
|---|
| 436 | Â Â position_table.cancel(); |
|---|
| 437 | Â Â termlist_table.cancel(); |
|---|
| 438 | Â Â value_table.cancel(); |
|---|
| 439 | Â Â synonym_table.cancel(); |
|---|
| 440 | Â Â spelling_table.cancel(); |
|---|
| 441 | Â Â record_table.cancel(); |
|---|
| 442 | } |
|---|
| 443 | |
|---|
| 444 | Xapian::doccount |
|---|
| 445 | FlintDatabase::get_doccount() const |
|---|
| 446 | { |
|---|
| 447 | Â Â DEBUGCALL(DB, Xapian::doccount, "FlintDatabase::get_doccount", ""); |
|---|
| 448 | Â Â RETURN(record_table.get_doccount()); |
|---|
| 449 | } |
|---|
| 450 | |
|---|
| 451 | Xapian::docid |
|---|
| 452 | FlintDatabase::get_lastdocid() const |
|---|
| 453 | { |
|---|
| 454 | Â Â DEBUGCALL(DB, Xapian::docid, "FlintDatabase::get_lastdocid", ""); |
|---|
| 455 | Â Â RETURN(lastdocid); |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | Xapian::doclength |
|---|
| 459 | FlintDatabase::get_avlength() const |
|---|
| 460 | { |
|---|
| 461 | Â Â DEBUGCALL(DB, Xapian::doclength, "FlintDatabase::get_avlength", ""); |
|---|
| 462 | Â Â Xapian::doccount doccount = record_table.get_doccount(); |
|---|
| 463 |   if (doccount == 0) { |
|---|
| 464 | Â Â Â Â |
|---|
| 465 | Â Â Â Â RETURN(0); |
|---|
| 466 | Â Â } |
|---|
| 467 | Â Â RETURN(double(total_length) / doccount); |
|---|
| 468 | } |
|---|
| 469 | |
|---|
| 470 | Xapian::doclength |
|---|
| 471 | FlintDatabase::get_doclength(Xapian::docid did) const |
|---|
| 472 | { |
|---|
| 473 | Â Â DEBUGCALL(DB, Xapian::doclength, "FlintDatabase::get_doclength", did); |
|---|
| 474 | Â Â Assert(did != 0); |
|---|
| 475 | Â Â RETURN(termlist_table.get_doclength(did)); |
|---|
| 476 | } |
|---|
| 477 | |
|---|
| 478 | Xapian::doccount |
|---|
| 479 | FlintDatabase::get_termfreq(const string & term) const |
|---|
| 480 | { |
|---|
| 481 | Â Â DEBUGCALL(DB, Xapian::doccount, "FlintDatabase::get_termfreq", term); |
|---|
| 482 | Â Â Assert(!term.empty()); |
|---|
| 483 | Â Â RETURN(postlist_table.get_termfreq(term)); |
|---|
| 484 | } |
|---|
| 485 | |
|---|
| 486 | Xapian::termcount |
|---|
| 487 | FlintDatabase::get_collection_freq(const string & term) const |
|---|
| 488 | { |
|---|
| 489 | Â Â DEBUGCALL(DB, Xapian::termcount, "FlintDatabase::get_collection_freq", term); |
|---|
| 490 | Â Â Assert(!term.empty()); |
|---|
| 491 | Â Â RETURN(postlist_table.get_collection_freq(term)); |
|---|
| 492 | } |
|---|
| 493 | |
|---|
| 494 | bool |
|---|
| 495 | FlintDatabase::term_exists(const string & term) const |
|---|
| 496 | { |
|---|
| 497 | Â Â DEBUGCALL(DB, bool, "FlintDatabase::term_exists", term); |
|---|
| 498 | Â Â Assert(!term.empty()); |
|---|
| 499 |   return postlist_table.term_exists(term); |
|---|
| 500 | } |
|---|
| 501 | |
|---|
| 502 | bool |
|---|
| 503 | FlintDatabase::has_positions() const |
|---|
| 504 | { |
|---|
| 505 |   return position_table.get_entry_count() > 0; |
|---|
| 506 | } |
|---|
| 507 | |
|---|
| 508 | LeafPostList * |
|---|
| 509 | FlintDatabase::open_post_list(const string& term) const |
|---|
| 510 | { |
|---|
| 511 | Â Â DEBUGCALL(DB, LeafPostList *, "FlintDatabase::open_post_list", term); |
|---|
| 512 |   Xapian::Internal::RefCntPtr<const FlintDatabase> ptrtothis(this); |
|---|
| 513 | |
|---|
| 514 |   if (term.empty()) { |
|---|
| 515 | Â Â Â Â Xapian::doccount doccount = get_doccount(); |
|---|
| 516 |     if (lastdocid == doccount) { |
|---|
| 517 |       RETURN(new ContiguousAllDocsPostList(ptrtothis, doccount)); |
|---|
| 518 | Â Â Â Â } |
|---|
| 519 |     RETURN(new FlintAllDocsPostList(ptrtothis, doccount)); |
|---|
| 520 | Â Â } |
|---|
| 521 | |
|---|
| 522 |   RETURN(new FlintPostList(ptrtothis, term)); |
|---|
| 523 | } |
|---|
| 524 | |
|---|
| 525 | TermList * |
|---|
| 526 | FlintDatabase::open_term_list(Xapian::docid did) const |
|---|
| 527 | { |
|---|
| 528 | Â Â DEBUGCALL(DB, TermList *, "FlintDatabase::open_term_list", did); |
|---|
| 529 | Â Â Assert(did != 0); |
|---|
| 530 | |
|---|
| 531 |   Xapian::Internal::RefCntPtr<const FlintDatabase> ptrtothis(this); |
|---|
| 532 |   RETURN(new FlintTermList(ptrtothis, did)); |
|---|
| 533 | } |
|---|
| 534 | |
|---|
| 535 | Xapian::Document::Internal * |
|---|
| 536 | FlintDatabase::open_document(Xapian::docid did, bool lazy) const |
|---|
| 537 | { |
|---|
| 538 | Â Â DEBUGCALL(DB, Xapian::Document::Internal *, "FlintDatabase::open_document", |
|---|
| 539 | Â Â Â Â Â Â Â did << ", "Â << lazy); |
|---|
| 540 | Â Â Assert(did != 0); |
|---|
| 541 | |
|---|
| 542 |   Xapian::Internal::RefCntPtr<const FlintDatabase> ptrtothis(this); |
|---|
| 543 |   RETURN(new FlintDocument(ptrtothis, |
|---|
| 544 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &value_table, |
|---|
| 545 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &record_table, |
|---|
| 546 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â did, lazy)); |
|---|
| 547 | } |
|---|
| 548 | |
|---|
| 549 | PositionList * |
|---|
| 550 | FlintDatabase::open_position_list(Xapian::docid did, const string & term) const |
|---|
| 551 | { |
|---|
| 552 | Â Â Assert(did != 0); |
|---|
| 553 | |
|---|
| 554 |   AutoPtr<FlintPositionList> poslist(new FlintPositionList()); |
|---|
| 555 |   if (!poslist->read_data(&position_table, did, term)) { |
|---|
| 556 | Â Â Â Â |
|---|
| 557 | Â Â Â Â |
|---|
| 558 | Â Â Â Â AutoPtr<TermList> tl(open_term_list(did)); |
|---|
| 559 | Â Â Â Â tl->skip_to(term); |
|---|
| 560 |     if (tl->at_end() || tl->get_termname() != term) |
|---|
| 561 |       throw Xapian::RangeError("Can't open position list: requested term is not present in document."); |
|---|
| 562 | Â Â Â Â |
|---|
| 563 | Â Â Â Â |
|---|
| 564 | Â Â } |
|---|
| 565 | |
|---|
| 566 |   return poslist.release(); |
|---|
| 567 | } |
|---|
| 568 | |
|---|
| 569 | TermList * |
|---|
| 570 | FlintDatabase::open_allterms(const string & prefix) const |
|---|
| 571 | { |
|---|
| 572 | Â Â DEBUGCALL(DB, TermList *, "FlintDatabase::open_allterms", ""); |
|---|
| 573 |   RETURN(new FlintAllTermsList(Xapian::Internal::RefCntPtr<const FlintDatabase>(this), |
|---|
| 574 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â prefix)); |
|---|
| 575 | } |
|---|
| 576 | |
|---|
| 577 | TermList * |
|---|
| 578 | FlintDatabase::open_spelling_termlist(const string & word) const |
|---|
| 579 | { |
|---|
| 580 |   return spelling_table.open_termlist(word); |
|---|
| 581 | } |
|---|
| 582 | |
|---|
| 583 | TermList * |
|---|
| 584 | FlintDatabase::open_spelling_wordlist() const |
|---|
| 585 | { |
|---|
| 586 | Â Â FlintCursor * cursor = spelling_table.cursor_get(); |
|---|
| 587 |   if (!cursor) return NULL; |
|---|
| 588 |   return new FlintSpellingWordsList(Xapian::Internal::RefCntPtr<const FlintDatabase>(this), |
|---|
| 589 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cursor); |
|---|
| 590 | } |
|---|
| 591 | |
|---|
| 592 | Xapian::doccount |
|---|
| 593 | FlintDatabase::get_spelling_frequency(const string & word) const |
|---|
| 594 | { |
|---|
| 595 |   return spelling_table.get_word_frequency(word); |
|---|
| 596 | } |
|---|
| 597 | |
|---|
| 598 | TermList * |
|---|
| 599 | FlintDatabase::open_synonym_termlist(const string & term) const |
|---|
| 600 | { |
|---|
| 601 |   return synonym_table.open_termlist(term); |
|---|
| 602 | } |
|---|
| 603 | |
|---|
| 604 | TermList * |
|---|
| 605 | FlintDatabase::open_synonym_keylist(const string & prefix) const |
|---|
| 606 | { |
|---|
| 607 | Â Â FlintCursor * cursor = synonym_table.cursor_get(); |
|---|
| 608 |   if (!cursor) return NULL; |
|---|
| 609 |   return new FlintSynonymTermList(Xapian::Internal::RefCntPtr<const FlintDatabase>(this), |
|---|
| 610 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cursor, synonym_table.get_entry_count(), |
|---|
| 611 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â prefix); |
|---|
| 612 | } |
|---|
| 613 | |
|---|
| 614 | string |
|---|
| 615 | FlintDatabase::get_metadata(const string & key) const |
|---|
| 616 | { |
|---|
| 617 | Â Â DEBUGCALL(DB, string, "FlintDatabase::get_metadata", key); |
|---|
| 618 | Â Â string btree_key("\x00\xc0", 2); |
|---|
| 619 | Â Â btree_key += key; |
|---|
| 620 | Â Â string tag; |
|---|
| 621 | Â Â (void)postlist_table.get_exact_entry(btree_key, tag); |
|---|
| 622 | Â Â RETURN(tag); |
|---|
| 623 | } |
|---|
| 624 | |
|---|
| 625 | |
|---|
| 626 | |
|---|
| 627 | FlintWritableDatabase::FlintWritableDatabase(const string &dir, int action, |
|---|
| 628 |                         int block_size) |
|---|
| 629 | Â Â Â Â : FlintDatabase(dir, action, block_size), |
|---|
| 630 | Â Â Â Â Â freq_deltas(), |
|---|
| 631 | Â Â Â Â Â doclens(), |
|---|
| 632 | Â Â Â Â Â mod_plists(), |
|---|
| 633 | Â Â Â Â Â change_count(0), |
|---|
| 634 | Â Â Â Â Â flush_threshold(0) |
|---|
| 635 | { |
|---|
| 636 | Â Â DEBUGCALL(DB, void, "FlintWritableDatabase", dir << ", "Â << action << ", " |
|---|
| 637 | Â Â Â Â Â Â Â << block_size); |
|---|
| 638 | |
|---|
| 639 |   const char *p = getenv("XAPIAN_FLUSH_THRESHOLD"); |
|---|
| 640 |   if (p) |
|---|
| 641 | Â Â Â Â flush_threshold = atoi(p); |
|---|
| 642 |   if (flush_threshold == 0) |
|---|
| 643 | Â Â Â Â flush_threshold = 10000; |
|---|
| 644 | } |
|---|
| 645 | |
|---|
| 646 | FlintWritableDatabase::~FlintWritableDatabase() |
|---|
| 647 | { |
|---|
| 648 | Â Â DEBUGCALL(DB, void, "~FlintWritableDatabase", ""); |
|---|
| 649 | Â Â dtor_called(); |
|---|
| 650 | } |
|---|
| 651 | |
|---|
| 652 | void |
|---|
| 653 | FlintWritableDatabase::flush() |
|---|
| 654 | { |
|---|
| 655 |   if (transaction_active()) |
|---|
| 656 |     throw Xapian::InvalidOperationError("Can't flush during a transaction"); |
|---|
| 657 |   if (change_count) flush_postlist_changes(); |
|---|
| 658 | Â Â apply(); |
|---|
| 659 | } |
|---|
| 660 | |
|---|
| 661 | void |
|---|
| 662 | FlintWritableDatabase::flush_postlist_changes() const |
|---|
| 663 | { |
|---|
| 664 | Â Â postlist_table.merge_changes(mod_plists, doclens, freq_deltas); |
|---|
| 665 | |
|---|
| 666 | Â Â |
|---|
| 667 | Â Â string tag = pack_uint(lastdocid); |
|---|
| 668 | Â Â tag += pack_uint_last(total_length); |
|---|
| 669 | Â Â postlist_table.add(METAINFO_KEY, tag); |
|---|
| 670 | |
|---|
| 671 | Â Â freq_deltas.clear(); |
|---|
| 672 | Â Â doclens.clear(); |
|---|
| 673 | Â Â mod_plists.clear(); |
|---|
| 674 | Â Â change_count = 0; |
|---|
| 675 | } |
|---|
| 676 | |
|---|
| 677 | Xapian::docid |
|---|
| 678 | FlintWritableDatabase::add_document(const Xapian::Document & document) |
|---|
| 679 | { |
|---|
| 680 | Â Â DEBUGCALL(DB, Xapian::docid, |
|---|
| 681 | Â Â Â Â Â Â Â "FlintWritableDatabase::add_document", document); |
|---|
| 682 | Â Â |
|---|
| 683 |   if (lastdocid == Xapian::docid(-1)) |
|---|
| 684 |     throw Xapian::DatabaseError("Run out of docids - you'll have to use copydatabase to eliminate any gaps before you can add more documents"); |
|---|
| 685 | Â Â |
|---|
| 686 | Â Â RETURN(add_document_(++lastdocid, document)); |
|---|
| 687 | } |
|---|
| 688 | |
|---|
| 689 | Xapian::docid |
|---|
| 690 | FlintWritableDatabase::add_document_(Xapian::docid did, |
|---|
| 691 |                    const Xapian::Document & document) |
|---|
| 692 | { |
|---|
| 693 | Â Â DEBUGCALL(DB, Xapian::docid, |
|---|
| 694 | Â Â Â Â Â Â Â "FlintWritableDatabase::add_document_", did << ", "Â << document); |
|---|
| 695 | Â Â Assert(did != 0); |
|---|
| 696 |   try { |
|---|
| 697 | Â Â Â Â |
|---|
| 698 | Â Â Â Â record_table.replace_record(document.get_data(), did); |
|---|
| 699 | |
|---|
| 700 | Â Â Â Â |
|---|
| 701 | Â Â Â Â { |
|---|
| 702 | Â Â Â Â Â Â Xapian::ValueIterator value = document.values_begin(); |
|---|
| 703 | Â Â Â Â Â Â Xapian::ValueIterator value_end = document.values_end(); |
|---|
| 704 | Â Â Â Â Â Â string s; |
|---|
| 705 | Â Â Â Â Â Â value_table.encode_values(s, value, value_end); |
|---|
| 706 | Â Â Â Â Â Â value_table.set_encoded_values(did, s); |
|---|
| 707 | Â Â Â Â } |
|---|
| 708 | |
|---|
| 709 | Â Â Â Â flint_doclen_t new_doclen = 0; |
|---|
| 710 | Â Â Â Â { |
|---|
| 711 | Â Â Â Â Â Â Xapian::TermIterator term = document.termlist_begin(); |
|---|
| 712 | Â Â Â Â Â Â Xapian::TermIterator term_end = document.termlist_end(); |
|---|
| 713 |       for ( ; term != term_end; ++term) { |
|---|
| 714 | Â Â Â Â Â Â Â Â termcount wdf = term.get_wdf(); |
|---|
| 715 | Â Â Â Â Â Â Â Â |
|---|
| 716 | Â Â Â Â Â Â Â Â new_doclen += wdf; |
|---|
| 717 | |
|---|
| 718 | Â Â Â Â Â Â Â Â string tname = *term; |
|---|
| 719 |         if (tname.size() > MAX_SAFE_TERM_LENGTH) |
|---|
| 720 |           throw Xapian::InvalidArgumentError("Term too long (> "STRINGIZE(MAX_SAFE_TERM_LENGTH)"): " + tname); |
|---|
| 721 | Â Â Â Â Â Â Â Â map<string, pair<termcount_diff, termcount_diff> >::iterator i; |
|---|
| 722 | Â Â Â Â Â Â Â Â i = freq_deltas.find(tname); |
|---|
| 723 |         if (i == freq_deltas.end()) { |
|---|
| 724 | Â Â Â Â Â Â Â Â Â Â freq_deltas.insert(make_pair(tname, make_pair(1, termcount_diff(wdf)))); |
|---|
| 725 |         } else { |
|---|
| 726 | Â Â Â Â Â Â Â Â Â Â ++i->second.first; |
|---|
| 727 | Â Â Â Â Â Â Â Â Â Â i->second.second += wdf; |
|---|
| 728 | Â Â Â Â Â Â Â Â } |
|---|
| 729 | |
|---|
| 730 | Â Â Â Â Â Â Â Â |
|---|
| 731 | Â Â Â Â Â Â Â Â map<string, map<docid, pair<char, termcount> > >::iterator j; |
|---|
| 732 | Â Â Â Â Â Â Â Â j = mod_plists.find(tname); |
|---|
| 733 |         if (j == mod_plists.end()) { |
|---|
| 734 | Â Â Â Â Â Â Â Â Â Â map<docid, pair<char, termcount> > m; |
|---|
| 735 | Â Â Â Â Â Â Â Â Â Â j = mod_plists.insert(make_pair(tname, m)).first; |
|---|
| 736 | Â Â Â Â Â Â Â Â } |
|---|
| 737 | Â Â Â Â Â Â Â Â Assert(j->second.find(did) == j->second.end()); |
|---|
| 738 | Â Â Â Â Â Â Â Â j->second.insert(make_pair(did, make_pair('A', wdf))); |
|---|
| 739 | |
|---|
| 740 |         if (term.positionlist_begin() != term.positionlist_end()) { |
|---|
| 741 | Â Â Â Â Â Â Â Â Â Â position_table.set_positionlist( |
|---|
| 742 | Â Â Â Â Â Â Â Â Â Â Â Â did, tname, |
|---|
| 743 | Â Â Â Â Â Â Â Â Â Â Â Â term.positionlist_begin(), term.positionlist_end()); |
|---|
| 744 | Â Â Â Â Â Â Â Â } |
|---|
| 745 | Â Â Â Â Â Â } |
|---|
| 746 | Â Â Â Â } |
|---|
| 747 | Â Â Â Â DEBUGLINE(DB, "Calculated doclen for new document "Â << did << " as "Â << new_doclen); |
|---|
| 748 | |
|---|
| 749 | Â Â Â Â |
|---|
| 750 | Â Â Â Â termlist_table.set_termlist(did, document, new_doclen); |
|---|
| 751 | |
|---|
| 752 | Â Â Â Â |
|---|
| 753 | Â Â Â Â Assert(doclens.find(did) == doclens.end()); |
|---|
| 754 | Â Â Â Â doclens[did] = new_doclen; |
|---|
| 755 | Â Â Â Â total_length += new_doclen; |
|---|
| 756 |   } catch (...) { |
|---|
| 757 | Â Â Â Â |
|---|
| 758 | Â Â Â Â |
|---|
| 759 | Â Â Â Â |
|---|
| 760 | Â Â Â Â |
|---|
| 761 | Â Â Â Â cancel(); |
|---|
| 762 | Â Â Â Â throw; |
|---|
| 763 | Â Â } |
|---|
| 764 | |
|---|
| 765 | Â Â |
|---|
| 766 | Â Â |
|---|
| 767 | Â Â |
|---|
| 768 | Â Â |
|---|
| 769 | Â Â |
|---|
| 770 | Â Â |
|---|
| 771 | Â Â |
|---|
| 772 | Â Â |
|---|
| 773 | Â Â |
|---|
| 774 | Â Â |
|---|
| 775 |   if (++change_count >= flush_threshold) { |
|---|
| 776 | Â Â Â Â flush_postlist_changes(); |
|---|
| 777 |     if (!transaction_active()) apply(); |
|---|
| 778 | Â Â } |
|---|
| 779 | |
|---|
| 780 | Â Â RETURN(did); |
|---|
| 781 | } |
|---|
| 782 | |
|---|
| 783 | void |
|---|
| 784 | FlintWritableDatabase::delete_document(Xapian::docid did) |
|---|
| 785 | { |
|---|
| 786 | Â Â DEBUGCALL(DB, void, "FlintWritableDatabase::delete_document", did); |
|---|
| 787 | Â Â Assert(did != 0); |
|---|
| 788 | |
|---|
| 789 | Â Â |
|---|
| 790 | Â Â |
|---|
| 791 | Â Â |
|---|
| 792 | Â Â record_table.delete_record(did); |
|---|
| 793 | |
|---|
| 794 |   try { |
|---|
| 795 | Â Â Â Â |
|---|
| 796 | Â Â Â Â value_table.delete_all_values(did); |
|---|
| 797 | |
|---|
| 798 | Â Â Â Â |
|---|
| 799 |     Xapian::Internal::RefCntPtr<const FlintWritableDatabase> ptrtothis(this); |
|---|
| 800 | Â Â Â Â FlintTermList termlist(ptrtothis, did); |
|---|
| 801 | |
|---|
| 802 | Â Â Â Â total_length -= termlist.get_doclength(); |
|---|
| 803 | |
|---|
| 804 | Â Â Â Â termlist.next(); |
|---|
| 805 |     while (!termlist.at_end()) { |
|---|
| 806 | Â Â Â Â Â Â string tname = termlist.get_termname(); |
|---|
| 807 | Â Â Â Â Â Â position_table.delete_positionlist(did, tname); |
|---|
| 808 | Â Â Â Â Â Â termcount wdf = termlist.get_wdf(); |
|---|
| 809 | |
|---|
| 810 | Â Â Â Â Â Â map<string, pair<termcount_diff, termcount_diff> >::iterator i; |
|---|
| 811 | Â Â Â Â Â Â i = freq_deltas.find(tname); |
|---|
| 812 |       if (i == freq_deltas.end()) { |
|---|
| 813 | Â Â Â Â Â Â Â Â freq_deltas.insert(make_pair(tname, make_pair(-1, -termcount_diff(wdf)))); |
|---|
| 814 |       } else { |
|---|
| 815 | Â Â Â Â Â Â Â Â --i->second.first; |
|---|
| 816 | Â Â Â Â Â Â Â Â i->second.second -= wdf; |
|---|
| 817 | Â Â Â Â Â Â } |
|---|
| 818 | |
|---|
| 819 | Â Â Â Â Â Â |
|---|
| 820 | Â Â Â Â Â Â map<string, map<docid, pair<char, termcount> > >::iterator j; |
|---|
| 821 | Â Â Â Â Â Â j = mod_plists.find(tname); |
|---|
| 822 |       if (j == mod_plists.end()) { |
|---|
| 823 | Â Â Â Â Â Â Â Â map<docid, pair<char, termcount> > m; |
|---|
| 824 | Â Â Â Â Â Â Â Â j = mod_plists.insert(make_pair(tname, m)).first; |
|---|
| 825 | Â Â Â Â Â Â } |
|---|
| 826 | |
|---|
| 827 | Â Â Â Â Â Â map<docid, pair<char, termcount> >::iterator k; |
|---|
| 828 | Â Â Â Â Â Â k = j->second.find(did); |
|---|
| 829 |       if (k == j->second.end()) { |
|---|
| 830 | Â Â Â Â Â Â Â Â j->second.insert(make_pair(did, make_pair('D', 0u))); |
|---|
| 831 |       } else { |
|---|
| 832 | Â Â Â Â Â Â Â Â |
|---|
| 833 | Â Â Â Â Â Â Â Â k->second = make_pair('D', 0u); |
|---|
| 834 | Â Â Â Â Â Â } |
|---|
| 835 | |
|---|
| 836 | Â Â Â Â Â Â termlist.next(); |
|---|
| 837 | Â Â Â Â } |
|---|
| 838 | |
|---|
| 839 | Â Â Â Â |
|---|
| 840 | Â Â Â Â termlist_table.delete_termlist(did); |
|---|
| 841 | |
|---|
| 842 | Â Â Â Â |
|---|
| 843 | Â Â Â Â doclens.erase(did); |
|---|
| 844 |   } catch (...) { |
|---|
| 845 | Â Â Â Â |
|---|
| 846 | Â Â Â Â |
|---|
| 847 | Â Â Â Â |
|---|
| 848 | Â Â Â Â |
|---|
| 849 | Â Â Â Â cancel(); |
|---|
| 850 | Â Â Â Â throw; |
|---|
| 851 | Â Â } |
|---|
| 852 | |
|---|
| 853 |   if (++change_count >= flush_threshold) { |
|---|
| 854 | Â Â Â Â flush_postlist_changes(); |
|---|
| 855 |     if (!transaction_active()) apply(); |
|---|
| 856 | Â Â } |
|---|
| 857 | } |
|---|
| 858 | |
|---|
| 859 | void |
|---|
| 860 | FlintWritableDatabase::replace_document(Xapian::docid did, |
|---|
| 861 |                     const Xapian::Document & document) |
|---|
| 862 | { |
|---|
| 863 | Â Â DEBUGCALL(DB, void, "FlintWritableDatabase::replace_document", did << ", "Â << document); |
|---|
| 864 | Â Â Assert(did != 0); |
|---|
| 865 | |
|---|
| 866 |   try { |
|---|
| 867 |     if (did > lastdocid) { |
|---|
| 868 | Â Â Â Â Â Â lastdocid = did; |
|---|
| 869 | Â Â Â Â Â Â |
|---|
| 870 | Â Â Â Â Â Â |
|---|
| 871 | Â Â Â Â Â Â (void)add_document_(did, document); |
|---|
| 872 | Â Â Â Â Â Â return; |
|---|
| 873 | Â Â Â Â } |
|---|
| 874 | |
|---|
| 875 | Â Â Â Â |
|---|
| 876 |     Xapian::Internal::RefCntPtr<const FlintWritableDatabase> ptrtothis(this); |
|---|
| 877 | Â Â Â Â FlintTermList termlist(ptrtothis, did); |
|---|
| 878 | |
|---|
| 879 | Â Â Â Â termlist.next(); |
|---|
| 880 |     while (!termlist.at_end()) { |
|---|
| 881 | Â Â Â Â Â Â string tname = termlist.get_termname(); |
|---|
| 882 | Â Â Â Â Â Â termcount wdf = termlist.get_wdf(); |
|---|
| 883 | |
|---|
| 884 | Â Â Â Â Â Â map<string, pair<termcount_diff, termcount_diff> >::iterator i; |
|---|
| 885 | Â Â Â Â Â Â i = freq_deltas.find(tname); |
|---|
| 886 |       if (i == freq_deltas.end()) { |
|---|
| 887 | Â Â Â Â Â Â Â Â freq_deltas.insert(make_pair(tname, make_pair(-1, -termcount_diff(wdf)))); |
|---|
| 888 |       } else { |
|---|
| 889 | Â Â Â Â Â Â Â Â --i->second.first; |
|---|
| 890 | Â Â Â Â Â Â Â Â i->second.second -= wdf; |
|---|
| 891 | Â Â Â Â Â Â } |
|---|
| 892 | |
|---|
| 893 | Â Â Â Â Â Â |
|---|
| 894 | Â Â Â Â Â Â map<string, map<docid, pair<char, termcount> > >::iterator j; |
|---|
| 895 | Â Â Â Â Â Â j = mod_plists.find(tname); |
|---|
| 896 |       if (j == mod_plists.end()) { |
|---|
| 897 | Â Â Â Â Â Â Â Â map<docid, pair<char, termcount> > m; |
|---|
| 898 | Â Â Â Â Â Â Â Â j = mod_plists.insert(make_pair(tname, m)).first; |
|---|
| 899 | Â Â Â Â Â Â } |
|---|
| 900 | |
|---|
| 901 | Â Â Â Â Â Â map<docid, pair<char, termcount> >::iterator k; |
|---|
| 902 | Â Â Â Â Â Â k = j->second.find(did); |
|---|
| 903 |       if (k == j->second.end()) { |
|---|
| 904 | Â Â Â Â Â Â Â Â j->second.insert(make_pair(did, make_pair('D', 0u))); |
|---|
| 905 |       } else { |
|---|
| 906 | Â Â Â Â Â Â Â Â |
|---|
| 907 | Â Â Â Â Â Â Â Â k->second = make_pair('D', 0u); |
|---|
| 908 | Â Â Â Â Â Â } |
|---|
| 909 | |
|---|
| 910 | Â Â Â Â Â Â termlist.next(); |
|---|
| 911 | Â Â Â Â } |
|---|
| 912 | |
|---|
| 913 | Â Â Â Â total_length -= termlist.get_doclength(); |
|---|
| 914 | |
|---|
| 915 | Â Â Â Â |
|---|
| 916 | Â Â Â Â |
|---|