1.1 --- a/iixr/index.py Mon Nov 22 23:45:44 2010 +0100
1.2 +++ b/iixr/index.py Mon Nov 22 23:50:03 2010 +0100
1.3 @@ -21,14 +21,9 @@
1.4 from iixr.filesystem import *
1.5 from iixr.merging import *
1.6 from itertools import islice
1.7 -from os import listdir, mkdir # index and partition discovery
1.8 +from os import mkdir # index discovery
1.9 from os.path import exists
1.10
1.11 -try:
1.12 - set
1.13 -except NameError:
1.14 - from sets import Set as set
1.15 -
1.16 # Constants.
1.17
1.18 TERM_INTERVAL = 100
1.19 @@ -98,8 +93,8 @@
1.20 self.field_interval = field_interval
1.21 self.flush_interval = flush_interval
1.22
1.23 - self.dict_partition = 0
1.24 - self.field_dict_partition = 0
1.25 + self.dict_partition = get_next_partition(get_term_partitions(self.pathname))
1.26 + self.field_dict_partition = get_next_partition(get_field_partitions(self.pathname))
1.27
1.28 self.terms = {}
1.29 self.docs = []
1.30 @@ -176,9 +171,9 @@
1.31 self.field_dict_partition += 1
1.32
1.33 def close(self):
1.34 - if self.terms:
1.35 + if self.terms or not get_term_partitions(self.pathname):
1.36 self.flush_terms()
1.37 - if self.docs:
1.38 + if self.docs or not get_field_partitions(self.pathname):
1.39 self.flush_fields()
1.40
1.41 class IndexReader:
1.42 @@ -265,32 +260,17 @@
1.43 self.reader = IndexReader(self.pathname)
1.44 return self.reader
1.45
1.46 - def _get_partitions(self, prefix):
1.47 -
1.48 - """
1.49 - Return a set of partition identifiers using 'prefix' to identify
1.50 - relevant files.
1.51 - """
1.52 -
1.53 - prefix_length = len(prefix)
1.54 -
1.55 - partitions = set()
1.56 - for filename in listdir(self.pathname):
1.57 - if filename.startswith(prefix):
1.58 - partitions.add(filename[prefix_length:])
1.59 - return partitions
1.60 -
1.61 def get_term_partitions(self):
1.62
1.63 "Return a set of term partition identifiers."
1.64
1.65 - return self._get_partitions("terms-")
1.66 + return get_term_partitions(self.pathname)
1.67
1.68 def get_field_partitions(self):
1.69
1.70 "Return a set of field partition identifiers."
1.71
1.72 - return self._get_partitions("fields-")
1.73 + return get_field_partitions(self.pathname)
1.74
1.75 def merge(self):
1.76