Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def titleSearch(qStr):
    t = Term('title', qStr)
    q = TermQuery(t)
    
    return q
Ejemplo n.º 5
0
def termSearch(qStr):
    t = Term('text', qStr)
    q = TermQuery(t)
    
    return q
Ejemplo n.º 6
0
def termSearch(qStr):
    t = Term('body', qStr)
    q = TermQuery(t)
    return q
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
 def termSearch(self, field, term):
     "Search for a single C{term} in a C{field}."
     t = Term(field, term)
     q = TermQuery(t)
     return q