我们只能在初始设置时只创建一次Lucene索引吗? [英] Can we create Lucene indexes only once at for initial set up only?

查看:143
本文介绍了我们只能在初始设置时只创建一次Lucene索引吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Hibernate Search 中的新手。根据文件

I am an newbie in Hibernate Search. According to Documentation


对象时,Hibernate Search都会更新相应的Lucene
索引。 / p>

By default, every time an object is inserted, updated or deleted through Hibernate, Hibernate Search updates the according Lucene index.

在我学习到现在为止,我知道我们可以通过编程方式构建lucene索引,如下所示:(如果我错了,请纠正我)

As I learn till now I come to know that we can build the lucene index through programmatically like this :( correct me if I am wrong)

FullTextSession fullTextSession = Search.getFullTextSession(session);
fullTextSession.createIndexer().startAndWait();

但是,让我惊讶的是,是否有任何方式(可能)在初始设置时创建索引只有一次只有一次。

But what makes me surprise if is there is any way (and possible) to create indexes at initial set up only for once only.

推荐答案

如果您使用空数据库启动应用程序(最初),则无需构建指数。
当您重新启动应用程序时,索引(默认情况下)存储在文件系统中,因此不需要重建索引。

If you start your application with an empty database (initially) there is no need to build the index. When you restart the application, the index is (by default) stored on filesystem so there is no need to rebuild the index.

此操作旨在仅在丢失索引时(磁盘崩溃?),更新Hibernate Search或Lucene版本时,还原其他数据库备份或更改实体映射时使用它:只有当它失去索引时才会自动检测应该运行,所以你应该明确地调用该方法。

This operation is meant to be used only when you lost the index (disk crash?), when you update the Hibernate Search or Lucene versions, when you restore a different database backup, or when you change the mapping of your entities: it can't detect automatically when it should run, so you're supposed to invoke the method explicitly.

MassIndexer 也可以作为JMX操作使用,这使得它非常易于由管理员调用,无需编写代码,或者在某些情况下,我只是在我的Web应用程序中创建了一个管理面板,以便人们在需要时进行操作。

The MassIndexer is also available as a JMX operation, which makes it very easy to invoke by an administrator without writing code, or in some cases I've simply created an "admin panel" in my web applications for people to operate when needed.

这篇关于我们只能在初始设置时只创建一次Lucene索引吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆