Revolution1 / Flask-WhooshAlchemyPlus

Whoosh indexing capabilities for Flask-SQLAlchemy, Flask-WhooshAlchemy plus some improvement
Other
68 stars 17 forks source link

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

Closed RoseOu closed 6 years ago

RoseOu commented 7 years ago

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)
cqzhao commented 7 years ago

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