1

I am trying to apply filter on whoosh results. When I apply filter without a python function, I get results. However, when I put filter in a python function, I get 'AttributeError: 'Term' object has no attribute 'Term'. Please see the gist with example here: https://gist.github.com/akeahey/b6713a32cdff0ca2a58b63fdceab99be

akeahey
  • 11
  • 1

1 Answers1

0

In this block of code:


def filtered():
    
    #search for term in individual
    with iy.searcher() as searcher:
        query = QueryParser("content", iy.schema).parse("example")
        allow_q = query.Term("ind_id", "123")
        results = searcher.search(query, filter=allow_q, limit=None)
        print(results, len(results))

Assigning the parsed query to the variable, query, masks your ability to create a query.Term object.

Please try this, instead:


def filtered():
    
    #search for term in individual
    with iy.searcher() as searcher:
        parsedq = QueryParser("content", iy.schema).parse("example")
        allow_q = query.Term("ind_id", "123")
        results = searcher.search(parsedq, filter=allow_q, limit=None)
        print(results, len(results))
Mike Organek
  • 11,647
  • 3
  • 11
  • 26