Ticket #289: testxapian

File testxapian, 680 bytes (added by Enrico Zini, 16 years ago)

The self-contained test suite

Line 
1#!/usr/bin/python
2# coding=UTF-8
3
4import xapian
5
6db = xapian.WritableDatabase("/tmp/test", xapian.DB_CREATE_OR_OVERWRITE)
7
8doc = xapian.Document()
9doc.add_term(u"♥".encode("UTF-8"));
10db.add_document(doc)
11
12doc = xapian.Document()
13doc.add_term(u"città".encode("UTF-8"));
14db.add_document(doc)
15
16db.flush()
17
18db = xapian.Database("/tmp/test")
19enquire = xapian.Enquire(db)
20enquire.set_query(xapian.Query(""))
21rset = xapian.RSet()
22for m in enquire.get_mset(0, 2):
23 rset.add_document(m[xapian.MSET_DID])
24
25class Filter(xapian.ExpandDecider):
26 def __call__(self, term):
27 return term.startswith(u"c")
28
29for res in enquire.get_eset(30, rset, Filter()):
30 print repr(res.term)