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