Skip to main content

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")

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

flask_sqlalchemy_whoosh-0.1.5.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

flask_sqlalchemy_whoosh-0.1.5-py2.py3-none-any.whl (4.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file flask_sqlalchemy_whoosh-0.1.5.tar.gz.

File metadata

File hashes

Hashes for flask_sqlalchemy_whoosh-0.1.5.tar.gz
Algorithm Hash digest
SHA256 283174c20ed6bbfb66276ca65b98ae714992a15d7170da1cc9d2933ed44e25ae
MD5 af314377aa889a605748699057ab64ba
BLAKE2b-256 c0390b3048e73970481ac8c7f87d30e69ad8d63aff9c3d1c0a3d5a3ee3bafabe

See more details on using hashes here.

File details

Details for the file flask_sqlalchemy_whoosh-0.1.5-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for flask_sqlalchemy_whoosh-0.1.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9814181dd753e7713731d1c931df5de34519afdc35bc4d121ca3f0119c98be2d
MD5 62548ac7f63e067b349543f1ef6c52fc
BLAKE2b-256 2e0e7f9e486cf7bcdbd4930bd716d150cc0276d126607eb7120bca7557159fca

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page