1.1 --- a/test.py Wed Sep 02 01:30:42 2009 +0200
1.2 +++ b/test.py Wed Sep 02 22:25:29 2009 +0200
1.3 @@ -12,7 +12,9 @@
1.4 pass
1.5
1.6 try:
1.7 - os.removedirs("test_index")
1.8 + for filename in os.listdir("test_index"):
1.9 + os.remove(os.path.join("test_index", filename))
1.10 + os.rmdir("test_index")
1.11 except OSError:
1.12 pass
1.13
1.14 @@ -118,7 +120,7 @@
1.15 for doc_positions in all_doc_positions:
1.16 offset, frequency, doc_frequency = wd.write_term_positions(doc_positions)
1.17 offsets.append((offset, doc_frequency))
1.18 -w.close()
1.19 +wd.close()
1.20
1.21 f = open("testP", "rb")
1.22 r = iixr.PositionReader(f)
1.23 @@ -130,7 +132,7 @@
1.24 for (offset, doc_frequency), doc_positions in zip(offsets, all_doc_positions):
1.25 dp = list(rd.read_term_positions(offset, doc_frequency))
1.26 print doc_positions == dp, doc_positions, dp
1.27 -r.close()
1.28 +rd.close()
1.29
1.30 # Test fields.
1.31
1.32 @@ -277,7 +279,12 @@
1.33 w = iixr.TermWriter(f)
1.34 f2 = open("testI", "wb")
1.35 w2 = iixr.TermIndexWriter(f2)
1.36 -wd = iixr.TermDictionaryWriter(w, w2, None, 3)
1.37 +f3 = open("testP", "wb")
1.38 +w3 = iixr.PositionWriter(f3)
1.39 +f4 = open("testPI", "wb")
1.40 +w4 = iixr.PositionIndexWriter(f4)
1.41 +wp = iixr.PositionDictionaryWriter(w3, w4, 2)
1.42 +wd = iixr.TermDictionaryWriter(w, w2, wp, 3)
1.43 for term, offset, frequency, doc_frequency in terms:
1.44 wd._write_term(term, offset, frequency, doc_frequency)
1.45 wd.close()
1.46 @@ -286,7 +293,12 @@
1.47 r = iixr.TermReader(f)
1.48 f2 = open("testI", "rb")
1.49 r2 = iixr.TermIndexReader(f2)
1.50 -rd = iixr.TermDictionaryReader(r, r2, None)
1.51 +f3 = open("testP", "rb")
1.52 +r3 = iixr.PositionReader(f3)
1.53 +f4 = open("testPI", "rb")
1.54 +r4 = iixr.PositionIndexReader(f4)
1.55 +rp = iixr.PositionDictionaryReader(r3, r4)
1.56 +rd = iixr.TermDictionaryReader(r, r2, rp)
1.57 terms_reversed = terms[:]
1.58 terms_reversed.reverse()
1.59 for term, offset, frequency, doc_frequency in terms_reversed:
1.60 @@ -318,7 +330,7 @@
1.61 w3 = iixr.PositionWriter(f3)
1.62 f4 = open("testPI", "wb")
1.63 w4 = iixr.PositionIndexWriter(f4)
1.64 -wp = iixr.PositionDictionaryWriter(r3, r4, 2)
1.65 +wp = iixr.PositionDictionaryWriter(w3, w4, 2)
1.66 wd = iixr.TermDictionaryWriter(w, w2, wp, 3)
1.67 for term, doc_positions in terms_with_positions:
1.68 wd.write_term_positions(term, doc_positions)
1.69 @@ -372,7 +384,7 @@
1.70 ]
1.71
1.72 index = iixr.Index("test_index")
1.73 -wi = index.get_writer(3, 6)
1.74 +wi = index.get_writer(3, 2, 6)
1.75 for docnum, text in docs:
1.76 for position, term in enumerate(text.split()):
1.77 wi.add_position(term, docnum, position)