paul@44 | 1 | #!/usr/bin/env python |
paul@44 | 2 | |
paul@44 | 3 | """ |
paul@44 | 4 | Specific classes for storing position information. |
paul@44 | 5 | |
paul@89 | 6 | Copyright (C) 2009, 2010, 2011 Paul Boddie <paul@boddie.org.uk> |
paul@44 | 7 | |
paul@44 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@44 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@44 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@44 | 11 | version. |
paul@44 | 12 | |
paul@44 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT ANY |
paul@44 | 14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
paul@44 | 15 | PARTICULAR PURPOSE. See the GNU General Public License for more details. |
paul@44 | 16 | |
paul@44 | 17 | You should have received a copy of the GNU General Public License along |
paul@44 | 18 | with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@44 | 19 | """ |
paul@44 | 20 | |
paul@89 | 21 | from iixr.data import * |
paul@44 | 22 | from iixr.files import * |
paul@44 | 23 | |
paul@44 | 24 | class PositionWriter(FileWriter): |
paul@44 | 25 | |
paul@44 | 26 | "Writing position information to files." |
paul@44 | 27 | |
paul@44 | 28 | def reset(self): |
paul@74 | 29 | self.last_docnum = None |
paul@89 | 30 | self.subtractor = None |
paul@44 | 31 | |
paul@44 | 32 | def write_positions(self, docnum, positions): |
paul@44 | 33 | |
paul@44 | 34 | """ |
paul@44 | 35 | Write for the document 'docnum' the given 'positions'. |
paul@44 | 36 | """ |
paul@44 | 37 | |
paul@89 | 38 | if not positions: |
paul@89 | 39 | return |
paul@44 | 40 | |
paul@44 | 41 | # Make sure that the positions are sorted. |
paul@44 | 42 | |
paul@44 | 43 | positions.sort() |
paul@44 | 44 | |
paul@89 | 45 | # Calculate an ongoing delta. |
paul@74 | 46 | |
paul@89 | 47 | if self.last_docnum is not None: |
paul@89 | 48 | if docnum < self.last_docnum: |
paul@89 | 49 | raise ValueError, "Document number %r is less than previous number %r." % (docnum, self.last_docnum) |
paul@89 | 50 | |
paul@89 | 51 | docnum_seq = self.subtractor(docnum, self.last_docnum) |
paul@52 | 52 | |
paul@89 | 53 | # Or preserve the document number and prepare for future deltas. |
paul@52 | 54 | |
paul@89 | 55 | else: |
paul@89 | 56 | self.subtractor = get_subtractor(docnum) |
paul@89 | 57 | docnum_seq = docnum |
paul@44 | 58 | |
paul@89 | 59 | self.begin_record() |
paul@89 | 60 | self.write_sequence_value(docnum_seq) |
paul@89 | 61 | self.write_monotonic_sequence(positions) |
paul@89 | 62 | self.end_record() |
paul@44 | 63 | |
paul@44 | 64 | self.last_docnum = docnum |
paul@44 | 65 | |
paul@69 | 66 | class PositionReader(FileReader): |
paul@69 | 67 | |
paul@69 | 68 | "Reading position information within term-specific regions of a file." |
paul@69 | 69 | |
paul@69 | 70 | def reset(self): |
paul@74 | 71 | self.last_docnum = None |
paul@89 | 72 | self.adder = None |
paul@69 | 73 | |
paul@69 | 74 | def read_positions(self): |
paul@69 | 75 | |
paul@74 | 76 | """ |
paul@74 | 77 | Read positions, returning a document number and a list of positions. |
paul@74 | 78 | """ |
paul@74 | 79 | |
paul@89 | 80 | self.begin_record() |
paul@74 | 81 | |
paul@89 | 82 | # Read the document number. |
paul@69 | 83 | |
paul@89 | 84 | docnum = self.read_sequence_value() |
paul@69 | 85 | |
paul@89 | 86 | # Calculate an ongoing delta. |
paul@69 | 87 | |
paul@89 | 88 | if self.last_docnum is not None: |
paul@89 | 89 | self.last_docnum = self.adder(docnum, self.last_docnum) |
paul@74 | 90 | |
paul@89 | 91 | # Or preserve the document number and prepare for future deltas. |
paul@74 | 92 | |
paul@89 | 93 | else: |
paul@89 | 94 | self.adder = get_adder(docnum) |
paul@89 | 95 | self.last_docnum = docnum |
paul@69 | 96 | |
paul@89 | 97 | positions = self.read_monotonic_sequence() |
paul@89 | 98 | self.end_record() |
paul@69 | 99 | |
paul@69 | 100 | return self.last_docnum, positions |
paul@69 | 101 | |
paul@44 | 102 | class PositionIndexWriter(FileWriter): |
paul@44 | 103 | |
paul@44 | 104 | "Writing position index information to files." |
paul@44 | 105 | |
paul@44 | 106 | def reset(self): |
paul@74 | 107 | self.last_docnum = None |
paul@89 | 108 | self.subtractor = None |
paul@44 | 109 | self.last_pos_offset = 0 |
paul@44 | 110 | |
paul@44 | 111 | def write_positions(self, docnum, pos_offset, count): |
paul@44 | 112 | |
paul@44 | 113 | """ |
paul@44 | 114 | Write the given 'docnum, 'pos_offset' and document 'count' to the |
paul@44 | 115 | position index file. |
paul@44 | 116 | """ |
paul@44 | 117 | |
paul@74 | 118 | # Find the size of document number values. |
paul@74 | 119 | |
paul@89 | 120 | if self.last_docnum is not None: |
paul@89 | 121 | docnum_seq = self.subtractor(docnum, self.last_docnum) |
paul@89 | 122 | else: |
paul@89 | 123 | self.subtractor = get_subtractor(docnum) |
paul@89 | 124 | docnum_seq = docnum |
paul@74 | 125 | |
paul@89 | 126 | self.begin_record() |
paul@89 | 127 | self.write_sequence_value(docnum_seq) |
paul@88 | 128 | self.write_number(pos_offset - self.last_pos_offset) |
paul@88 | 129 | self.write_number(count) |
paul@89 | 130 | self.end_record() |
paul@44 | 131 | |
paul@89 | 132 | self.last_docnum = docnum |
paul@52 | 133 | self.last_pos_offset = pos_offset |
paul@44 | 134 | |
paul@69 | 135 | class PositionIndexReader(FileReader): |
paul@68 | 136 | |
paul@69 | 137 | "Reading position index information within term-specific regions of a file." |
paul@44 | 138 | |
paul@44 | 139 | def reset(self): |
paul@74 | 140 | self.last_docnum = None |
paul@89 | 141 | self.adder = None |
paul@44 | 142 | self.last_pos_offset = 0 |
paul@68 | 143 | |
paul@44 | 144 | def read_positions(self): |
paul@44 | 145 | |
paul@44 | 146 | """ |
paul@44 | 147 | Read a document number, a position file offset for the position index |
paul@44 | 148 | file, and the number of documents in a section of that file. |
paul@44 | 149 | """ |
paul@44 | 150 | |
paul@89 | 151 | self.begin_record() |
paul@74 | 152 | |
paul@89 | 153 | # Read the document number. |
paul@89 | 154 | |
paul@89 | 155 | docnum = self.read_sequence_value() |
paul@44 | 156 | |
paul@89 | 157 | if self.last_docnum is not None: |
paul@89 | 158 | self.last_docnum = self.adder(docnum, self.last_docnum) |
paul@89 | 159 | else: |
paul@89 | 160 | self.adder = get_adder(docnum) |
paul@89 | 161 | self.last_docnum = docnum |
paul@44 | 162 | |
paul@44 | 163 | # Read the offset delta. |
paul@44 | 164 | |
paul@44 | 165 | self.last_pos_offset += self.read_number() |
paul@44 | 166 | |
paul@44 | 167 | # Read the document count. |
paul@44 | 168 | |
paul@44 | 169 | count = self.read_number() |
paul@89 | 170 | self.end_record() |
paul@44 | 171 | |
paul@44 | 172 | return self.last_docnum, self.last_pos_offset, count |
paul@44 | 173 | |
paul@69 | 174 | # Iterators for position-related files. |
paul@69 | 175 | |
paul@69 | 176 | class IteratorBase: |
paul@69 | 177 | |
paul@69 | 178 | "Support for iterating over results." |
paul@69 | 179 | |
paul@69 | 180 | def __init__(self, reader): |
paul@69 | 181 | |
paul@69 | 182 | "Initialise the iterator using the given 'reader'." |
paul@69 | 183 | |
paul@69 | 184 | self.reader = reader |
paul@69 | 185 | self.replenish(0) # no iteration initially permitted |
paul@69 | 186 | |
paul@69 | 187 | def replenish(self, count): |
paul@69 | 188 | |
paul@69 | 189 | "Replenish the iterator with 'count' results." |
paul@69 | 190 | |
paul@69 | 191 | self.count = count |
paul@69 | 192 | self.read_documents = 0 |
paul@69 | 193 | |
paul@69 | 194 | def __len__(self): |
paul@69 | 195 | |
paul@69 | 196 | "Return the total number of results." |
paul@69 | 197 | |
paul@69 | 198 | return self.count |
paul@69 | 199 | |
paul@69 | 200 | def sort(self): |
paul@69 | 201 | pass # Stored document positions are already sorted. |
paul@69 | 202 | |
paul@69 | 203 | def __iter__(self): |
paul@69 | 204 | return self |
paul@69 | 205 | |
paul@69 | 206 | class PositionIterator(IteratorBase): |
paul@69 | 207 | |
paul@69 | 208 | "Iterating over document positions." |
paul@69 | 209 | |
paul@69 | 210 | def replenish(self, count): |
paul@69 | 211 | IteratorBase.replenish(self, count) |
paul@69 | 212 | |
paul@69 | 213 | # Fill a cache of positions. |
paul@69 | 214 | |
paul@69 | 215 | self.cache = [] |
paul@69 | 216 | n = 0 |
paul@69 | 217 | |
paul@69 | 218 | while n < self.count: |
paul@69 | 219 | self.cache.append(self.reader.read_positions()) |
paul@69 | 220 | n += 1 |
paul@69 | 221 | |
paul@69 | 222 | def seek(self, offset, count): |
paul@69 | 223 | |
paul@69 | 224 | """ |
paul@69 | 225 | Seek to 'offset' in the file, limiting the number of documents available |
paul@69 | 226 | for reading to 'count'. |
paul@69 | 227 | """ |
paul@69 | 228 | |
paul@69 | 229 | self.reader.seek(offset) |
paul@69 | 230 | self.replenish(count) |
paul@69 | 231 | |
paul@44 | 232 | def next(self): |
paul@44 | 233 | |
paul@44 | 234 | "Read positions for a single document." |
paul@44 | 235 | |
paul@44 | 236 | if self.read_documents < self.count: |
paul@69 | 237 | positions = self.cache[self.read_documents] |
paul@69 | 238 | self.read_documents += 1 |
paul@69 | 239 | return positions |
paul@69 | 240 | else: |
paul@69 | 241 | raise StopIteration |
paul@69 | 242 | |
paul@69 | 243 | class PositionIndexIterator(IteratorBase): |
paul@69 | 244 | |
paul@69 | 245 | "Iterating over document positions." |
paul@69 | 246 | |
paul@69 | 247 | def replenish(self, count): |
paul@69 | 248 | IteratorBase.replenish(self, count) |
paul@69 | 249 | |
paul@69 | 250 | # Fill a cache of offsets. |
paul@69 | 251 | |
paul@69 | 252 | self.cache = [] |
paul@69 | 253 | self.current = 0 |
paul@69 | 254 | n = 0 |
paul@69 | 255 | |
paul@69 | 256 | while n < self.count: |
paul@69 | 257 | docnum, pos_offset, section_count = t = self.reader.read_positions() |
paul@69 | 258 | self.cache.append(t) |
paul@69 | 259 | n += section_count |
paul@69 | 260 | |
paul@69 | 261 | def seek(self, offset, doc_frequency): |
paul@69 | 262 | |
paul@69 | 263 | """ |
paul@69 | 264 | Seek to 'offset' in the file, limiting the number of documents available |
paul@69 | 265 | for reading to 'doc_frequency'. |
paul@69 | 266 | """ |
paul@69 | 267 | |
paul@69 | 268 | self.reader.seek(offset) |
paul@69 | 269 | self.replenish(doc_frequency) |
paul@69 | 270 | |
paul@69 | 271 | def next(self): |
paul@69 | 272 | |
paul@69 | 273 | "Read positions for a single document." |
paul@69 | 274 | |
paul@69 | 275 | if self.current < len(self.cache): |
paul@69 | 276 | docnum, pos_offset, self.section_count = t = self.cache[self.current] |
paul@69 | 277 | self.current += 1 |
paul@44 | 278 | return t |
paul@44 | 279 | else: |
paul@44 | 280 | raise StopIteration |
paul@44 | 281 | |
paul@44 | 282 | class PositionDictionaryWriter: |
paul@44 | 283 | |
paul@44 | 284 | "Writing position dictionaries." |
paul@44 | 285 | |
paul@44 | 286 | def __init__(self, position_writer, position_index_writer, interval): |
paul@44 | 287 | self.position_writer = position_writer |
paul@44 | 288 | self.position_index_writer = position_index_writer |
paul@44 | 289 | self.interval = interval |
paul@44 | 290 | |
paul@44 | 291 | def write_term_positions(self, doc_positions): |
paul@44 | 292 | |
paul@44 | 293 | """ |
paul@44 | 294 | Write all 'doc_positions' - a collection of tuples of the form (document |
paul@44 | 295 | number, position list) - to the file. |
paul@44 | 296 | |
paul@44 | 297 | Add some records to the index, making dictionary entries. |
paul@44 | 298 | |
paul@44 | 299 | Return a tuple containing the offset of the written data, the frequency |
paul@44 | 300 | (number of positions), and document frequency (number of documents) for |
paul@44 | 301 | the term involved. |
paul@44 | 302 | """ |
paul@44 | 303 | |
paul@44 | 304 | # Reset the writers. |
paul@44 | 305 | |
paul@44 | 306 | self.position_writer.reset() |
paul@44 | 307 | self.position_index_writer.reset() |
paul@44 | 308 | |
paul@55 | 309 | # Remember the first index entry offset. |
paul@55 | 310 | |
paul@88 | 311 | index_offset = self.position_index_writer.tell() |
paul@44 | 312 | |
paul@44 | 313 | # Write the positions. |
paul@44 | 314 | |
paul@44 | 315 | frequency = 0 |
paul@44 | 316 | count = 0 |
paul@44 | 317 | |
paul@55 | 318 | if doc_positions: |
paul@44 | 319 | |
paul@44 | 320 | # Retain the first record offset for a subsequent index entry. |
paul@44 | 321 | |
paul@88 | 322 | first_offset = self.position_writer.tell() |
paul@55 | 323 | first_docnum = None |
paul@44 | 324 | |
paul@55 | 325 | doc_positions.sort() |
paul@44 | 326 | |
paul@55 | 327 | for docnum, positions in doc_positions: |
paul@55 | 328 | if first_docnum is None: |
paul@55 | 329 | first_docnum = docnum |
paul@44 | 330 | |
paul@55 | 331 | self.position_writer.write_positions(docnum, positions) |
paul@44 | 332 | |
paul@55 | 333 | frequency += len(positions) |
paul@55 | 334 | count += 1 |
paul@55 | 335 | |
paul@55 | 336 | # Every {interval} entries, write an index entry. |
paul@44 | 337 | |
paul@55 | 338 | if count % self.interval == 0: |
paul@44 | 339 | |
paul@55 | 340 | self.position_index_writer.write_positions(first_docnum, first_offset, self.interval) |
paul@44 | 341 | |
paul@88 | 342 | first_offset = self.position_writer.tell() |
paul@55 | 343 | first_docnum = None |
paul@44 | 344 | |
paul@55 | 345 | # Reset the position writer so that position readers accessing |
paul@55 | 346 | # a section start with the correct document number. |
paul@55 | 347 | |
paul@55 | 348 | self.position_writer.reset() |
paul@44 | 349 | |
paul@55 | 350 | # Finish writing an index entry for the remaining documents. |
paul@44 | 351 | |
paul@55 | 352 | else: |
paul@55 | 353 | if first_docnum is not None: |
paul@55 | 354 | self.position_index_writer.write_positions(first_docnum, first_offset, count % self.interval) |
paul@44 | 355 | |
paul@44 | 356 | return index_offset, frequency, count |
paul@44 | 357 | |
paul@44 | 358 | def close(self): |
paul@44 | 359 | self.position_writer.close() |
paul@44 | 360 | self.position_index_writer.close() |
paul@44 | 361 | |
paul@44 | 362 | class PositionDictionaryReader: |
paul@44 | 363 | |
paul@69 | 364 | "Access to position dictionary entries through iterators." |
paul@44 | 365 | |
paul@68 | 366 | def __init__(self, position_reader, position_index_reader): |
paul@68 | 367 | self.position_reader = position_reader |
paul@68 | 368 | self.position_index_reader = position_index_reader |
paul@69 | 369 | |
paul@69 | 370 | def read_term_positions(self, offset, doc_frequency): |
paul@69 | 371 | iterator = PositionDictionaryIterator( |
paul@69 | 372 | PositionIterator(self.position_reader), |
paul@69 | 373 | PositionIndexIterator(self.position_index_reader) |
paul@69 | 374 | ) |
paul@69 | 375 | iterator.seek(offset, doc_frequency) |
paul@69 | 376 | return iterator |
paul@69 | 377 | |
paul@69 | 378 | def close(self): |
paul@69 | 379 | self.position_reader.close() |
paul@69 | 380 | self.position_index_reader.close() |
paul@69 | 381 | |
paul@69 | 382 | class PositionDictionaryIterator: |
paul@69 | 383 | |
paul@69 | 384 | "Iteration over position dictionary entries." |
paul@69 | 385 | |
paul@69 | 386 | def __init__(self, position_iterator, position_index_iterator): |
paul@69 | 387 | self.position_iterator = position_iterator |
paul@69 | 388 | self.position_index_iterator = position_index_iterator |
paul@68 | 389 | self.reset() |
paul@47 | 390 | |
paul@68 | 391 | def reset(self): |
paul@47 | 392 | |
paul@44 | 393 | # Remember the last values. |
paul@44 | 394 | |
paul@44 | 395 | self.found_docnum, self.found_positions = None, None |
paul@44 | 396 | |
paul@44 | 397 | # Maintain state for the next index entry, if read. |
paul@44 | 398 | |
paul@44 | 399 | self.next_docnum, self.next_pos_offset, self.next_section_count = None, None, None |
paul@44 | 400 | |
paul@68 | 401 | def seek(self, offset, doc_frequency): |
paul@68 | 402 | |
paul@68 | 403 | """ |
paul@68 | 404 | Seek to 'offset' in the index file, limiting the number of documents |
paul@68 | 405 | available for reading to 'doc_frequency'. |
paul@68 | 406 | """ |
paul@68 | 407 | |
paul@68 | 408 | self.reset() |
paul@68 | 409 | |
paul@68 | 410 | # Seek to the appropriate index entry. |
paul@68 | 411 | |
paul@69 | 412 | self.position_index_iterator.seek(offset, doc_frequency) |
paul@68 | 413 | |
paul@69 | 414 | # Initialise the current index entry and current position file iterator. |
paul@44 | 415 | |
paul@44 | 416 | self._next_section() |
paul@44 | 417 | self._init_section() |
paul@44 | 418 | |
paul@44 | 419 | # Sequence methods. |
paul@44 | 420 | |
paul@44 | 421 | def __len__(self): |
paul@69 | 422 | return len(self.position_index_iterator) |
paul@44 | 423 | |
paul@44 | 424 | def sort(self): |
paul@44 | 425 | pass |
paul@44 | 426 | |
paul@44 | 427 | # Iterator methods. |
paul@44 | 428 | |
paul@44 | 429 | def __iter__(self): |
paul@44 | 430 | return self |
paul@44 | 431 | |
paul@44 | 432 | def next(self): |
paul@44 | 433 | |
paul@44 | 434 | """ |
paul@44 | 435 | Attempt to get the next document record from the section in the |
paul@44 | 436 | positions file. |
paul@44 | 437 | """ |
paul@44 | 438 | |
paul@44 | 439 | # Return any visited but unrequested record. |
paul@44 | 440 | |
paul@44 | 441 | if self.found_docnum is not None: |
paul@44 | 442 | t = self.found_docnum, self.found_positions |
paul@44 | 443 | self.found_docnum, self.found_positions = None, None |
paul@44 | 444 | return t |
paul@44 | 445 | |
paul@44 | 446 | # Or search for the next record. |
paul@44 | 447 | |
paul@44 | 448 | while 1: |
paul@44 | 449 | |
paul@44 | 450 | # Either return the next record. |
paul@44 | 451 | |
paul@44 | 452 | try: |
paul@69 | 453 | return self.position_iterator.next() |
paul@44 | 454 | |
paul@44 | 455 | # Or, where a section is finished, get the next section and try again. |
paul@44 | 456 | |
paul@44 | 457 | except StopIteration: |
paul@44 | 458 | |
paul@69 | 459 | # Although, where a single iterator is in use, the file reader |
paul@69 | 460 | # would be positioned appropriately, this is not guaranteed in a |
paul@69 | 461 | # multiple iterator situation. |
paul@44 | 462 | |
paul@44 | 463 | self._next_section() |
paul@69 | 464 | self._init_section() |
paul@44 | 465 | |
paul@44 | 466 | def from_document(self, docnum): |
paul@44 | 467 | |
paul@44 | 468 | """ |
paul@44 | 469 | Attempt to navigate to a positions entry for the given 'docnum', |
paul@44 | 470 | returning the positions for 'docnum', or None otherwise. |
paul@44 | 471 | """ |
paul@44 | 472 | |
paul@44 | 473 | # Return any unrequested document positions. |
paul@44 | 474 | |
paul@44 | 475 | if docnum == self.found_docnum: |
paul@44 | 476 | return self.found_positions |
paul@44 | 477 | |
paul@44 | 478 | # Read ahead in the index until the next entry refers to a document |
paul@44 | 479 | # later than the desired document. |
paul@44 | 480 | |
paul@44 | 481 | try: |
paul@44 | 482 | if self.next_docnum is None: |
paul@69 | 483 | self.next_docnum, self.next_pos_offset, self.next_section_count = self.position_index_iterator.next() |
paul@44 | 484 | |
paul@44 | 485 | # Read until the next entry is after the desired document number, |
paul@44 | 486 | # or until the end of the results. |
paul@44 | 487 | |
paul@44 | 488 | while self.next_docnum <= docnum: |
paul@44 | 489 | self._next_read_section() |
paul@44 | 490 | if self.docnum < docnum: |
paul@69 | 491 | self.next_docnum, self.next_pos_offset, self.next_section_count = self.position_index_iterator.next() |
paul@44 | 492 | else: |
paul@44 | 493 | break |
paul@44 | 494 | |
paul@44 | 495 | except StopIteration: |
paul@44 | 496 | pass |
paul@44 | 497 | |
paul@44 | 498 | # Navigate in the position file to the document. |
paul@44 | 499 | |
paul@44 | 500 | self._init_section() |
paul@44 | 501 | |
paul@44 | 502 | try: |
paul@44 | 503 | while 1: |
paul@69 | 504 | found_docnum, found_positions = self.position_iterator.next() |
paul@44 | 505 | |
paul@44 | 506 | # Return the desired document positions or None (retaining the |
paul@44 | 507 | # positions for the document immediately after). |
paul@44 | 508 | |
paul@78 | 509 | if docnum <= found_docnum: |
paul@44 | 510 | self.found_docnum, self.found_positions = found_docnum, found_positions |
paul@78 | 511 | if docnum == found_docnum: |
paul@78 | 512 | return found_positions |
paul@78 | 513 | elif docnum < found_docnum: |
paul@78 | 514 | return None |
paul@44 | 515 | |
paul@44 | 516 | except StopIteration: |
paul@44 | 517 | return None |
paul@44 | 518 | |
paul@44 | 519 | # Internal methods. |
paul@44 | 520 | |
paul@44 | 521 | def _next_section(self): |
paul@44 | 522 | |
paul@44 | 523 | "Attempt to get the next section in the index." |
paul@44 | 524 | |
paul@44 | 525 | if self.next_docnum is None: |
paul@69 | 526 | self.docnum, self.pos_offset, self.section_count = self.position_index_iterator.next() |
paul@44 | 527 | else: |
paul@44 | 528 | self._next_read_section() |
paul@44 | 529 | |
paul@44 | 530 | def _next_read_section(self): |
paul@44 | 531 | |
paul@44 | 532 | """ |
paul@44 | 533 | Make the next index entry the current one without reading from the |
paul@44 | 534 | index. |
paul@44 | 535 | """ |
paul@44 | 536 | |
paul@44 | 537 | self.docnum, self.pos_offset, self.section_count = self.next_docnum, self.next_pos_offset, self.next_section_count |
paul@44 | 538 | self.next_docnum, self.next_pos_offset, self.next_section_count = None, None, None |
paul@44 | 539 | |
paul@44 | 540 | def _init_section(self): |
paul@44 | 541 | |
paul@69 | 542 | "Initialise the iterator for the section in the position file." |
paul@47 | 543 | |
paul@68 | 544 | # Seek to the position entry. |
paul@47 | 545 | |
paul@69 | 546 | self.position_iterator.seek(self.pos_offset, self.section_count) |
paul@47 | 547 | |
paul@44 | 548 | # vim: tabstop=4 expandtab shiftwidth=4 |