samedi 30 janvier 2016

whoosh search after database migration

I migrated my database from sqlite3 to postgresql with the following three steps

  1. I create a sqlite dump file with

    sqlite3 app.db .dump > app_dump.sql

  2. I create a postgresql database and initialized it with my models.py file as

    python manage.py db init

where manage.py is

SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://appuser:777@localhost/app_db' 
migrate = Migrate(app, db)

manager = Manager(app)
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manager.run()

  1. I used only the insert lines in the dump file to populate the new database.

This worked well, however I do want to have a whoosh search in my User table.

My models.py looks like this

if sys.version_info >= (3, 0):
    enable_search = False
else:
    enable_search = True
    import flask.ext.whooshalchemy as whooshalchemy

class User(db.Model):
    __searchable__ = ['username','id'] 

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100), index=True)

if enable_search:
    whooshalchemy.whoosh_index(app, User)

However, the search does not seem to work at all. I fear that the table has not been properly indexed? Anybody know how I can fix this? thanks carl

Aucun commentaire:

Enregistrer un commentaire