Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where would you add Whoosh Indexes? #8

Closed
Siecje opened this issue May 5, 2014 · 4 comments
Closed

Where would you add Whoosh Indexes? #8

Siecje opened this issue May 5, 2014 · 4 comments

Comments

@Siecje
Copy link

Siecje commented May 5, 2014

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
Copy link
Owner

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

@Siecje
Copy link
Author

Siecje commented May 5, 2014

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
Copy link
Owner

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
Copy link
Author

Siecje commented Jun 6, 2014

Yes, that works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants