Commit 5fd67b93 authored by Clément Schreiner's avatar Clément Schreiner
Browse files

Add a AND_NOT subquery.

parent 19ddbeb2
......@@ -46,6 +46,7 @@ class XapianQuery(object):
self.stemmer = xapian.Stem("english")
self.terms = []
self.not_terms = []
@classmethod
def tokenize(cls, text):
......@@ -79,12 +80,20 @@ class XapianQuery(object):
for tag in tags:
self.terms.append('XT'+tag)
def add_not(self, *terms):
"""
Add terms that should be added to the query as a AND_NOT subquery.
"""
self.not_terms.extend(terms)
def query(self):
"""
Actually performs the query and return the results as a
generator.
"""
query = xapian.Query(xapian.Query.OP_OR, self.terms)
query = xapian.Query(xapian.Query.OP_AND_NOT,
xapian.Query(xapian.Query.OP_OR, self.terms),
xapian.Query(xapian.Query.OP_OR, self.not_terms))
enquire = xapian.Enquire(self.db)
enquire.set_query(query)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment