1.1 --- a/iixr/index.py Fri Nov 26 01:06:44 2010 +0100
1.2 +++ b/iixr/index.py Fri Nov 26 01:07:30 2010 +0100
1.3 @@ -184,6 +184,16 @@
1.4 self.dict_reader = get_term_reader(pathname, "merged")
1.5 self.field_dict_reader = get_field_reader(pathname, "merged")
1.6
1.7 + # Sequential access.
1.8 +
1.9 + def read_term(self):
1.10 + return self.dict_reader.read_term()
1.11 +
1.12 + def go_to_term(self, term):
1.13 + return self.dict_reader._get_term_and_positions(*self.dict_reader.go_to_term(term))
1.14 +
1.15 + # Query access.
1.16 +
1.17 def get_terms(self):
1.18 return self.dict_reader.get_terms()
1.19
2.1 --- a/iixr/terms.py Fri Nov 26 01:06:44 2010 +0100
2.2 +++ b/iixr/terms.py Fri Nov 26 01:07:30 2010 +0100
2.3 @@ -301,6 +301,15 @@
2.4 else:
2.5 return None
2.6
2.7 + def _get_term_and_positions(self, term, offset, frequency, doc_frequency):
2.8 +
2.9 + """
2.10 + Return the term plus positions details using the given 'term', 'offset',
2.11 + 'frequency' and 'doc_frequency'.
2.12 + """
2.13 +
2.14 + return term, frequency, doc_frequency, self._get_positions(offset, doc_frequency)
2.15 +
2.16 def _get_positions(self, offset, doc_frequency):
2.17
2.18 """
2.19 @@ -335,7 +344,24 @@
2.20 """
2.21
2.22 term, offset, frequency, doc_frequency = self.info_reader.read_term()
2.23 - return term, frequency, doc_frequency, self._get_positions(offset, doc_frequency)
2.24 + return self._get_term_and_positions(term, offset, frequency, doc_frequency)
2.25 +
2.26 + def go_to_term(self, term):
2.27 +
2.28 + """
2.29 + Navigate to 'term' in the dictionary, returning the details from its
2.30 + entry. The returned details can be augmented with position information
2.31 + when presented to the _get_term_and_positions method.
2.32 + """
2.33 +
2.34 + found_term, offset, frequency, doc_frequency, info_offset = self._find_closest_term(term)
2.35 +
2.36 + # Position the reader, if necessary.
2.37 +
2.38 + if info_offset is not None:
2.39 + self.info_reader.go_to_term(found_term, offset, info_offset)
2.40 +
2.41 + return found_term, offset, frequency, doc_frequency
2.42
2.43 # Query methods.
2.44
2.45 @@ -351,12 +377,7 @@
2.46
2.47 terms = []
2.48
2.49 - found_term, offset, frequency, doc_frequency, info_offset = self._find_closest_term(term)
2.50 -
2.51 - # Position the reader, if necessary.
2.52 -
2.53 - if info_offset is not None:
2.54 - self.info_reader.go_to_term(found_term, offset, info_offset)
2.55 + found_term, offset, frequency, doc_frequency = self.go_to_term(term)
2.56
2.57 # Read and record terms.
2.58