Full-text search with Whoosh
Whoosh is a fast, featureful, full-text indexing and searching library implemented in Python. It has a pure Pythonic API and allows developers to add search functionality to their applications easily and efficiently. In this recipe, we will use a package called Flask-WhooshAlchemy, which integrates the text-search functionality of Whoosh with SQLAlchemy for use in Flask applications.
Getting ready
The Flask-WhooshAlchemy package can be installed via pip
using the following command:
$ pip install flask_whooshalchemy
This will install the required packages and dependencies.
How to do it…
Integrating Whoosh with Flask using SQLAlchemy is pretty straightforward. First, we need to provide the path to the Whoosh base directory where the index for our models will be created. This should be done in the application's configuration, that is, my_app/__init__.py
:
app.config['WHOOSH_BASE'] = '/tmp/whoosh'
You can choose any path you prefer, and it...