1.1 --- a/test.py Sat Sep 19 21:42:55 2009 +0200
1.2 +++ b/test.py Tue Sep 22 01:08:13 2009 +0200
1.3 @@ -415,6 +415,12 @@
1.4 ("shells", 37, None)
1.5 ]
1.6
1.7 +phrase_tests = [
1.8 + (["good", "boy"], [(2, [[1], [2]])]),
1.9 + (["good", "deserves"], [(2, [[1], [3]]), (13, [[1], [3]])]),
1.10 + (["sea", "shore"], [(36, [[2, 6], [7]])])
1.11 + ]
1.12 +
1.13 index = Index("test_index")
1.14 wi = index.get_writer(3, 2, 6)
1.15 for docnum, text in docs:
1.16 @@ -426,18 +432,34 @@
1.17 wi.close()
1.18
1.19 rd = index.get_reader()
1.20 +
1.21 +# (Test searching.)
1.22 +
1.23 for term, frequency, doc_positions in doc_tests:
1.24 dp = list(rd.find_positions(term))
1.25 print doc_positions == dp, doc_positions, dp
1.26 fr = rd.get_frequency(term)
1.27 print frequency == fr, frequency, fr
1.28 +
1.29 +# (Test fields.)
1.30 +
1.31 for docnum, text in docs:
1.32 df = dict(rd.get_fields(docnum))
1.33 print df[123] == text, text, df[123]
1.34 +
1.35 +# (Test navigation.)
1.36 +
1.37 for term, docnum, positions in position_tests:
1.38 dp = rd.find_positions(term)
1.39 pos = dp.from_document(docnum)
1.40 print positions is None and pos is None or pos is not None and positions == list(pos), positions, pos
1.41 +
1.42 +# (Test phrases.)
1.43 +
1.44 +for terms, results in phrase_tests:
1.45 + res = list(rd.find_common_positions(terms))
1.46 + print results == res, results, res
1.47 +
1.48 index.close()
1.49
1.50 # Test index updates.