1.1 --- a/iixr/index.py Sat Sep 19 21:36:32 2009 +0200
1.2 +++ b/iixr/index.py Sat Sep 19 21:42:55 2009 +0200
1.3 @@ -209,12 +209,14 @@
1.4 'doc_interval' and 'flush_interval'.
1.5 """
1.6
1.7 + self._ensure_directory()
1.8 + self.writer = IndexWriter(self.pathname, interval, doc_interval, flush_interval)
1.9 + return self.writer
1.10 +
1.11 + def _ensure_directory(self):
1.12 if not exists(self.pathname):
1.13 mkdir(self.pathname)
1.14
1.15 - self.writer = IndexWriter(self.pathname, interval, doc_interval, flush_interval)
1.16 - return self.writer
1.17 -
1.18 def get_reader(self, partition=0):
1.19
1.20 "Return a reader for the index."
1.21 @@ -341,6 +343,8 @@
1.22
1.23 "Copy the content of the 'other_indexes' into this index and merge."
1.24
1.25 + self._ensure_directory()
1.26 +
1.27 for i, index in enumerate(other_indexes):
1.28 for partition in index.get_term_partitions():
1.29 copy_term_files(index.pathname, partition, self.pathname, "-added-%d" % i)
2.1 --- a/test.py Sat Sep 19 21:36:32 2009 +0200
2.2 +++ b/test.py Sat Sep 19 21:42:55 2009 +0200
2.3 @@ -5,23 +5,27 @@
2.4 from iixr.terms import *
2.5 from iixr.positions import *
2.6 from iixr.index import *
2.7 -import os
2.8 +import os, sys
2.9
2.10 # Remove old test files.
2.11
2.12 -for filename in ("test", "testF", "testFI", "testI", "testP"):
2.13 +for filename in ("test", "testF", "testFI", "testI", "testP", "testPI"):
2.14 try:
2.15 os.remove(filename)
2.16 except OSError:
2.17 pass
2.18
2.19 try:
2.20 - for filename in os.listdir("test_index"):
2.21 - os.remove(os.path.join("test_index", filename))
2.22 - os.rmdir("test_index")
2.23 + for dirname in ("test_index", "test_index2", "test_index3"):
2.24 + for filename in os.listdir(dirname):
2.25 + os.remove(os.path.join(dirname, filename))
2.26 + os.rmdir(dirname)
2.27 except OSError:
2.28 pass
2.29
2.30 +if "clean" in sys.argv:
2.31 + sys.exit(0)
2.32 +
2.33 # Test basic data types.
2.34
2.35 numbers = [12345678, 0, 1, 127, 128, 255, 256]
2.36 @@ -439,7 +443,6 @@
2.37 # Test index updates.
2.38
2.39 index = Index("test_index")
2.40 -
2.41 index2 = Index("test_index2")
2.42 wi = index2.get_writer(3, 2, 6)
2.43 for docnum, text in docs:
2.44 @@ -461,7 +464,10 @@
2.45
2.46 # Add the extra documents to the expected result.
2.47
2.48 - for docnum, positions in doc_positions[:]:
2.49 + orig_doc_positions = doc_positions
2.50 + doc_positions = doc_positions[:]
2.51 +
2.52 + for docnum, positions in orig_doc_positions:
2.53 doc_positions.append((docnum + 100, positions))
2.54 frequency *= 2
2.55
2.56 @@ -471,4 +477,19 @@
2.57 print frequency == fr, frequency, fr
2.58 index2.close()
2.59
2.60 +# (Test update of an empty index.)
2.61 +
2.62 +index = Index("test_index")
2.63 +index3 = Index("test_index3")
2.64 +index3.update([index])
2.65 +index.close()
2.66 +
2.67 +rd = index3.get_reader()
2.68 +for term, frequency, doc_positions in doc_tests:
2.69 + dp = list(rd.find_positions(term))
2.70 + print doc_positions == dp, doc_positions, dp
2.71 + fr = rd.get_frequency(term)
2.72 + print frequency == fr, frequency, fr
2.73 +index3.close()
2.74 +
2.75 # vim: tabstop=4 expandtab shiftwidth=4