Where would you add Whoosh Indexes? #8

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

Comments

Projects
None yet
2 participants
@Siecje

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

This comment has been minimized.

Show comment
Hide comment
@miguelgrinberg

miguelgrinberg May 5, 2014

Owner

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

Owner

miguelgrinberg commented May 5, 2014

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

@Siecje

This comment has been minimized.

Show comment
Hide comment
@Siecje

Siecje 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

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

This comment has been minimized.

Show comment
Hide comment
@miguelgrinberg

miguelgrinberg Jun 1, 2014

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

miguelgrinberg commented Jun 1, 2014

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

This comment has been minimized.

Show comment
Hide comment
@Siecje

Siecje Jun 6, 2014

Yes, that works!

Siecje commented Jun 6, 2014

Yes, that works!

@Siecje Siecje closed this Jun 6, 2014

@samzhang111 samzhang111 referenced this issue in gyllstromk/Flask-WhooshAlchemy Jul 3, 2014

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