1.1 --- a/iixr/terms.py Fri Nov 26 01:06:44 2010 +0100
1.2 +++ b/iixr/terms.py Fri Nov 26 01:07:30 2010 +0100
1.3 @@ -301,6 +301,15 @@
1.4 else:
1.5 return None
1.6
1.7 + def _get_term_and_positions(self, term, offset, frequency, doc_frequency):
1.8 +
1.9 + """
1.10 + Return the term plus positions details using the given 'term', 'offset',
1.11 + 'frequency' and 'doc_frequency'.
1.12 + """
1.13 +
1.14 + return term, frequency, doc_frequency, self._get_positions(offset, doc_frequency)
1.15 +
1.16 def _get_positions(self, offset, doc_frequency):
1.17
1.18 """
1.19 @@ -335,7 +344,24 @@
1.20 """
1.21
1.22 term, offset, frequency, doc_frequency = self.info_reader.read_term()
1.23 - return term, frequency, doc_frequency, self._get_positions(offset, doc_frequency)
1.24 + return self._get_term_and_positions(term, offset, frequency, doc_frequency)
1.25 +
1.26 + def go_to_term(self, term):
1.27 +
1.28 + """
1.29 + Navigate to 'term' in the dictionary, returning the details from its
1.30 + entry. The returned details can be augmented with position information
1.31 + when presented to the _get_term_and_positions method.
1.32 + """
1.33 +
1.34 + found_term, offset, frequency, doc_frequency, info_offset = self._find_closest_term(term)
1.35 +
1.36 + # Position the reader, if necessary.
1.37 +
1.38 + if info_offset is not None:
1.39 + self.info_reader.go_to_term(found_term, offset, info_offset)
1.40 +
1.41 + return found_term, offset, frequency, doc_frequency
1.42
1.43 # Query methods.
1.44
1.45 @@ -351,12 +377,7 @@
1.46
1.47 terms = []
1.48
1.49 - found_term, offset, frequency, doc_frequency, info_offset = self._find_closest_term(term)
1.50 -
1.51 - # Position the reader, if necessary.
1.52 -
1.53 - if info_offset is not None:
1.54 - self.info_reader.go_to_term(found_term, offset, info_offset)
1.55 + found_term, offset, frequency, doc_frequency = self.go_to_term(term)
1.56
1.57 # Read and record terms.
1.58