"Query has no attribute 'whoosh_search" AttributeError in Flask + Whoosh + SQLAlchemy "Query has no attribute 'whoosh_search" AttributeError in Flask + Whoosh + SQLAlchemy flask flask

"Query has no attribute 'whoosh_search" AttributeError in Flask + Whoosh + SQLAlchemy


I was getting the same error, and then when i re-read the docs, i noticed that creating a post is one of the steps to being able to whoosh_search:

For example, the table needs to be indexed by whoosh first (docs):

Let’s create a post:db.session.add(    BlogPost(title='My cool title', content='This is the first post.')); db.session.commit()

After the session is committed, our new BlogPost is indexed. Similarly, if the post is deleted, it will be removed from the Whoosh index.

Is there a way to add existing db.table to a whoosh index? One solution is to re-insert all rows; this post seems to give directions, but also claims that whooshalchemy is not maintained.


I have always just used Flask-SQLAlchemy, but not SQLAlchemy directly.

With Flask-SQLAlchemy I would query the Restaurant table like so:

  Restaurant.query.whoosh_search('foo')

From the SQLAlchemy docs, it looks like you need to do something like this:

  q = session.query(Restaurant)  result = q.whooshee_search(query).all()