Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Where would you add Whoosh Indexes? #8

Closed
Siecje opened this Issue · 4 comments

2 participants

@Siecje

I'm trying to add fulltext search with Flask-Whoosh and I added searchable but when I try to use .whoose_search I get an error and saw this issue.
gyllstromk/Flask-WhooshAlchemy#13

So I assume I need to add the indexes but where do I add them?

I added the following to manage.py but I get a RuntimeError

from flask.ext.migrate import Migrate, MigrateCommand
import flask.ext.whooshalchemy as whooshalchemy

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)
whooshalchemy.whoosh_index(app, Post)

raise RuntimeError('application not registered on db '
RuntimeError: application not registered on db instance and no application bound to current context

@miguelgrinberg

Could you please post the complete stack trace of the error?

@Siecje
Traceback (most recent call last):
  File "manage.py", line 26, in <module>
    whooshalchemy.whoosh_index(app, Lab)
  File "/home/siecje/Desktop/flaskbook/flasky/venv/local/lib/python2.7/site-packages/flask_whooshalchemy.py", line 168, in whoosh_index
    _create_index(app, model))
  File "/home/siecje/Desktop/flaskbook/flasky/venv/local/lib/python2.7/site-packages/flask_whooshalchemy.py", line 199, in _create_index
    model.query = _QueryProxy(model.query, primary_key,
  File "/home/siecje/Desktop/flaskbook/flasky/venv/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 428, in __get__
    return type.query_class(mapper, session=self.sa.session())
  File "/home/siecje/Desktop/flaskbook/flasky/venv/local/lib/python2.7/site-packages/sqlalchemy/orm/scoping.py", line 70, in __call__
    return self.registry()
  File "/home/siecje/Desktop/flaskbook/flasky/venv/local/lib/python2.7/site-packages/sqlalchemy/util/_collections.py", line 864, in __call__
    return self.registry.setdefault(key, self.createfunc())
  File "/home/siecje/Desktop/flaskbook/flasky/venv/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 136, in __init__
    self.app = db.get_app()
  File "/home/siecje/Desktop/flaskbook/flasky/venv/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 809, in get_app
    raise RuntimeError('application not registered on db '
RuntimeError: application not registered on db instance and no application bound to current context
@miguelgrinberg

Try creating doing the association under an application context:

from flask.ext.migrate import Migrate, MigrateCommand
import flask.ext.whooshalchemy as whooshalchemy

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)
with app.app_context():
    whooshalchemy.whoosh_index(app, Post)
@Siecje

Yes, that works!

@Siecje Siecje closed this
@samzhang111 samzhang111 referenced this issue in gyllstromk/Flask-WhooshAlchemy
Open

“Query has no attribute 'whoosh_search” #25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.