Ticket #590: bool-filter-test.py

File bool-filter-test.py, 751 bytes (added by Michael Henson, 13 years ago)

Test Case Illustrating the Bug

Line 
1#!/usr/bin/env python
2
3from xapian import Document, Query, WritableDatabase, Enquire, DB_CREATE_OR_OPEN
4
5def search(db, query):
6 print("Query: %s" % query)
7
8 enquire = Enquire(db)
9 enquire.set_query(query)
10
11 for m in enquire.get_mset(0, 10):
12 print '%s - %s - %s' % (m.docid, m.percent, ', '.join(t.term for t in m.document))
13
14OWNER = 'Ome'
15
16db = WritableDatabase('/tmp/test.db', DB_CREATE_OR_OPEN)
17
18for t in ['cold', 'kids']:
19 doc = Document()
20
21 doc.add_term(t)
22 doc.add_boolean_term(OWNER)
23
24 db.add_document(doc)
25
26term_q = Query(Query.OP_OR, ['cold', 'kids'])
27owner_q = Query(OWNER)
28filtered_term_q = Query(Query.OP_FILTER, term_q, owner_q)
29
30search(db, term_q)
31search(db, filtered_term_q)
32
33db.close()