问题
I'm using flask-whooshalchemy on sqlite, and mannually imported a lot of data, now whoosh can search none of it. I think it's because whoosh haven't indexed any of the data, right? How could I add whoosh index on those data manually?
回答1:
Have a look at https://gist.github.com/davb5/21fbffd7a7990f5e066c
I've just written this to solve the same issue - rebuild search indices after a bulk data import.
It won't work out of the box for anyone else (my "lib" import contains all of my third party libraries, and you'll need to specify your Flask-SQLAlchemy models in the if name=="main" block), but it should be enough to get you started.
As stated in the file comments, you should consider deleting your search.db folder (WHOOSH_BASE) as this script doesn't remove deleted data, only re-indexes the current data set.
I've found it to be much quicker importing all of my data using SQLAlchemy core then running this script compared to importing my data via SQLAlchemy ORM with on-the-fly Whoosh index updates (44s vs 48m for my data set).
回答2:
you can try my fork https://github.com/Revolution1/Flask-WhooshAlchemyPlus
just
$ pip install flask_whooshalchemyplus
and
from flask_whooshalchemyplus import index_all
index_all(app)
回答3:
The code for the extension is pretty light you can view it on github. From looking at it, it does look as it just watches for changes when SQLAlchemy flushes the session, so externally entered data won't be indexed automatically.
Depending on the amount of data, and if this is a one off data-load, it might be easiest to just delete the Whoosh index (by default a directory called ‘whoosh_index’), as it looks like it will re-index everything if that index isn't found (see lines 154-165).
来源:https://stackoverflow.com/questions/23472161/how-flask-whooshalchemy-index-data-imported-manually