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