Revolution1 / Flask-WhooshAlchemyPlus

Whoosh indexing capabilities for Flask-SQLAlchemy, Flask-WhooshAlchemy plus some improvement

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: 'BaseQuery' object has no attribute 'whoosh_search'

RoseOu opened this issue · comments

Hello, I install Flask-WhooshAlchemyPlus and config according to your QuickStart,
but when I run my app and visit my route,it raise the error:
AttributeError: 'BaseQuery' object has no attribute 'whoosh_search'

My code:

app/Init.py:

import flask_whooshalchemyplus as whooshalchemyplus

def create_app(config_name=None, main=True):
    if config_name is None:
        config_name = 'default'
    app = Flask(__name__)
    app.config.from_object(config[config_name])

    config[config_name].init_app(app)
    db.init_app(app)
    moment.init_app(app)
    toolbar.init_app(app)
    login_manager.init_app(app)
    whooshalchemyplus.init_app(app)

app/models.py:

class BlogPost(db.Model):
    __tablename__ = 'blogpost'
    __searchable__ = ['title', 'content']  # these fields will be indexed by whoosh
    __analyzer__ = SimpleAnalyzer()        # configure analyzer; defaults to
                                         # StemmingAnalyzer if not specified

    id = app.db.Column(app.db.Integer, primary_key=True)
    title = app.db.Column(app.db.Unicode)  # Indexed fields are either String,
    content = app.db.Column(app.db.Text)   # Unicode, or Text
    created = db.Column(db.DateTime, default=datetime.datetime.utcnow)

you need index all post first. run index_all() first. Read readme for more details