def boolSearch(ands=[], ors=[], nots=[]): """Build a simple boolean query. each word in B{ands} is equiv to +word each word in B{ors} is equiv to word each word in B{nots} is equiv to -word e.g. boolSearch(['spam'], ['eggs'], ['parrot', 'cheese']) is equiv to +spam eggs -parrot -cheese in Google/Lucene syntax""" q = BooleanQuery() for a in ands: t = Term('text', a) tq = TermQuery(t) q.add(tq, True, False) for a in ors: t = Term('text', a) tq = TermQuery(t) q.add(tq, False, False) for a in nots: t = Term('text', a) tq = TermQuery(t) q.add(tq, False, True) return q
def boolSearch(self, field, ands=[], ors=[], nots=[]): """Build a simple boolean query. Each word in C{ands} is equiv to +word Each word in C{ors} is equiv to word Each word in C{nots} is equiv to -word E.g. C{boolSearch(['spam'], ['eggs'], ['parrot', 'cheese'])} is equiv to C{+spam eggs -parrot -cheese} in Google/Lucene syntax. """ q = BooleanQuery() for a in ands: t = Term(field, a) tq = TermQuery(t) q.add(tq, True, False) for a in ors: t = Term(field, a) tq = TermQuery(t) q.add(tq, False, False) for a in nots: t = Term(field, a) tq = TermQuery(t) q.add(tq, False, True) return q
def _formats_query(main_query, formats): if formats is None: return main_query q = BooleanQuery() fq = BooleanQuery() for f in formats: t = Term("formats", f.lower()) tq = TermQuery(t) fq.add(tq, required = False, prohibited = False) q.add(fq, required = True, prohibited = False) q.add(main_query, required = True, prohibited = False) return q
def titleSearch(qStr): t = Term('title', qStr) q = TermQuery(t) return q
def termSearch(qStr): t = Term('text', qStr) q = TermQuery(t) return q
def termSearch(qStr): t = Term('body', qStr) q = TermQuery(t) return q
def _phrase_query(field, phrase): q = BooleanQuery() for p in phrase.split(): t = Term(field, p.lower()) q.add(TermQuery(t), required = True, prohibited = False) return q
def termSearch(self, field, term): "Search for a single C{term} in a C{field}." t = Term(field, term) q = TermQuery(t) return q