Book Image

Flask Framework Cookbook

By : Shalabh Aggarwal
Book Image

Flask Framework Cookbook

By: Shalabh Aggarwal

Overview of this book

Table of Contents (19 chapters)
Flask Framework Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 can be absolute or relative.

Next...