As stated in the search hibernate guide, section 3.6.1, if you use annotations (now the default), listeners that start indexing in the repository are registered by default:
Hibernate Search is turned on when using Hibernate Annotations or Hibernate EntityManager. If for some reason you need to disable it, set hibernate.search.autoregister_listeners to false.
An example of how to enable them manually:
hibConfiguration.setListener("post-update", new FullTextIndexEventListener()); hibConfiguration.setListener("post-insert", new FullTextIndexEventListener()); hibConfiguration.setListener("post-delete", new FullTextIndexEventListener());
All you have to do is annotate the objects you want to index with
@Indexed(index = "fulltext")
and then make a fine-grained annotation in the fields as described in the user guide.
Thus, you should not start indexing manually during storage, do not restart indexing when the application starts, unless you have objects that were saved before indexing.
You may experience performance issues when storing an object that has an "attachment", and therefore you index it in the same transaction area that stores the object. See here:
Hibernate Search and offline text extraction
for a solution that solves this problem.
source share