添加新实体后的 Django haystack 索引
Django haystack indexing after new entity added
我想知道在将新实体添加到数据库后应该调用什么操作才能使这个实体可以用 haystack 搜索:
- 我应该只更新索引吗?
- 我应该重建整个索引吗?
有问题的是,新实体会被频繁添加,并且数据库中可能存在大量实体。
如果您要向数据库中添加新行,那么 update_index
应该就足够了。
The conventional method is to use SearchIndex
in combination with cron
jobs. Running a ./manage.py update_index
every couple hours will keep
your data in sync within that timeframe and will handle the updates in
a very efficient batch.
如果您在搜索索引中添加了一个新的 字段,那么您需要 运行 rebuild_index
:
If you have an existing SearchIndex
and you add a new field to it,
Haystack will add this new data on any updates it sees after that
point. However, this will not populate the existing data you already
have.
In order for the data to be picked up, you will need to run
./manage.py rebuild_index
. This will cause all backends to rebuild the
existing data already present in the quickest and most efficient way.
我想知道在将新实体添加到数据库后应该调用什么操作才能使这个实体可以用 haystack 搜索:
- 我应该只更新索引吗?
- 我应该重建整个索引吗?
有问题的是,新实体会被频繁添加,并且数据库中可能存在大量实体。
如果您要向数据库中添加新行,那么 update_index
应该就足够了。
The conventional method is to use
SearchIndex
in combination with cron jobs. Running a./manage.py update_index
every couple hours will keep your data in sync within that timeframe and will handle the updates in a very efficient batch.
如果您在搜索索引中添加了一个新的 字段,那么您需要 运行 rebuild_index
:
If you have an existing
SearchIndex
and you add a new field to it, Haystack will add this new data on any updates it sees after that point. However, this will not populate the existing data you already have.In order for the data to be picked up, you will need to run
./manage.py rebuild_index
. This will cause all backends to rebuild the existing data already present in the quickest and most efficient way.