A flask extension that adds full text search capabilites to your SQLAlchemy models using the Whoosh search engine
Project description
Flask-SQLAlchemy-Whoosh
A simple and easy to use Flask extension to add full text search to your SQLAlchemy models using the Whoosh search engine.
Installing
$ pip install Flask-SQLAlchemy-Whoosh
Setup
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from Flask_SQLalchemy_Whoosh.searcher import WhooshSearcher
from Flask_SQLalchemy_Whoosh.mixin import SearchableMixin
app = Flask(__name__)
db = SQLAlchemy(app)
search = WhooshSearcher(app)
# If you want to use the SearchableMixin
SearchableMixin.init_search(search, db)
Documentation
You can find some documentation here
Example
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from Flask_SQLalchemy_Whoosh.searcher import WhooshSearcher
from Flask_SQLalchemy_Whoosh.mixin import SearchableMixin
from whoosh.fields import ID, TEXT, NUMERIC
app = Flask(__name__)
db = SQLAlchemy(app)
search = WhooshSearcher(app)
SearchableMixin.init_search(search, db)
class Product(SearchableMixin, db.Model):
__tablename__ = "product"
# __searchable__ is needed to tell the searcher what to index
# For documentation on the specifics of each field, refer to the Whoosh documentation
# https://whoosh.readthedocs.io/en/latest/schema.html
__searchable__ = {
"id": ID(stored=True, unique=True),
"name": TEXT(stored=True),
"desc": TEXT,
"price": NUMERIC
}
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String),
desc = db.Column(db.String),
price = db.Column(db.Integer)
# If you want to index a table that already has entries, use the reindex method
# It will index all entries in the table
Product.reindex()
# Use the search method to search a table
results, total = Product.search("name", "nails", 1)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for flask_sqlalchemy_whoosh-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa6c1e7ef5a423de08c6a86264fdff4f6136dd91d3446ca7c53aa192b5726723 |
|
MD5 | bf07f72bc0cf77854bdeeb72aa03e265 |
|
BLAKE2b-256 | 413474409fdc193d47c12554479768de1addced9f4d283b626f1dbbb6bba82d0 |
Close
Hashes for flask_sqlalchemy_whoosh-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3501a6b8927b7806a1747e22e9a79cbd31d6664f4ee9084d519f7b98f3810012 |
|
MD5 | f2652d43ec5a1b96283df77344b93252 |
|
BLAKE2b-256 | da5733191298260e491d1d4fea7e6a10fac124b6fc90b5fdbe368d32d31ee6a7 |