This release will hopefully be the last before Hibernate Search 4.1 final. If you want to give feedback, now is the time :) We are simultaneously releasing Hibernate Search 3.4.2 as a minor bug fix release.

The main improvement in this candidate for release is the ability to intercept indexing operations and change them. In the team we nicknamed it the Soft Delete feature even if it can do much more. At first look, it seems like a barbarian feature but it enables a lot of interesting use cases.

Indexing interception

In some situations, you do not want to index all the entities (of a given type). For example, I want my readers to search my blog entries only when they are in PUBLISHED state. If they are in DRAFT, they should not appear in the results. Of course, to do that you can use a boolean query restriction or even better a declarative filter. Nevertheless, these DRAFT blogs are still indexed. The situation is even more critical if the majority of your entities should not be searchable. An example is invoices that should not be searchable when put in archive mode.

Indexing interception lets you decide if an entity is worthy of being indexed. The big benefits are:

  • less work at runtime: no bridge conversion, no analyzer phase, and no writes in the index
  • a smaller and more manageable index: smaller indexes makes faster queries, fit better in memory and are easier to backup and copy

Alright so how do I do this?

  • write an EntityIndexingInterceptor
  • Mark the entity as being intercepted using @Indexed.interceptor
 * Only index blog when it is in published state
 * @author Emmanuel Bernard <>
public class IndexWhenPublishedInterceptor implements EntityIndexingInterceptor<Blog> {
    public IndexingOverride onAdd(Blog entity) {
        if (entity.getStatus() == BlogStatus.PUBLISHED) {
            return IndexingOverride.APPLY_DEFAULT;
        return IndexingOverride.SKIP;

    public IndexingOverride onUpdate(Blog entity) {
        if (entity.getStatus() == BlogStatus.PUBLISHED) {
            return IndexingOverride.UPDATE;
        return IndexingOverride.REMOVE;

    public IndexingOverride onDelete(Blog entity) {
        return IndexingOverride.APPLY_DEFAULT;

    public IndexingOverride onCollectionUpdate(Blog entity) {
        return onUpdate(entity);
public class Blog {
    public Integer getId() { return id; }
    public void setId(Integer id) { = id; }
    private Integer id;

    public String getTitle() { return title; }
    public void setTitle(String title) {  this.title = title; }
    private String title;

    public BlogStatus getStatus() { return status; }
    public void setStatus(BlogStatus status) {  this.status = status; }
    private BlogStatus status;


If you look at IndexWhenPublishedInterceptor, you will see that we only index the entity when it is in PUBLISHED state and we skip or remove it from the index otherwise.

This feature is still experimental as we might add more transitions depending on your feedback.

Get the release

This release is (hopefully) the last of the 4.1 series before 4.1 final. Try it out:

Hibernate Search 3.4.2

This release fixed a few bugs in particular a regression on how collections are indexed. Thanks to Guillaume Smet for his work. We encourage users stuck with the 3.4 series to upgrade. You can get the release on SourceForge and it should be available on our Maven repository within the next few hours or days.

05. Mar 2012, 23:33 CET | Link

This is a very helpful feature as you frequently have entities which still exist in the DB but that you do not want included in the search. Inactive or Deleted Users retired products, etc..

It could also be useful to simply have an annotation which could be placed on a boolean @NotIndexed for example.

12. Mar 2012, 20:43 CET | Link

This is interesting. I noticed that the documentation for the IndexingOverride.UPDATE mentions that it is safe to call when the index item doesn't exist yet (or anymore). This is crucial for me. Because, it can happen that using the interceptor, I don't index an item (yet) but with a future update of the entity (e.g. activation) I will.

28. Mar 2012, 15:13 CET | Link

This is great, thank you!

16. Apr 2012, 12:37 CET | Link

When using the mass indexer, the EntityIndexingInterceptor doesen't seem to get called. What could be wrong? It works properly on regular updates/inserts though.

Here's my mass indexer code: getFullTextEntityManager().createIndexer() .batchSizeToLoadObjects(25) .threadsToLoadObjects(1) .threadsForSubsequentFetching(2) .optimizeOnFinish(true) .startAndWait();

Upon calling this code, all rows, including the ones that were removed by the interceptor are added back to index.

Is this a bug or am I missing something here? Please help, without possibility to reindex the data this funconality is practically useless.



21. Jun 2014, 16:39 CET | Link

Generational lows aside, market timing for dividend stocks doesnt all yield the best results which is why dollar-cost-averaging still makes sense to me Dividend Investing There are also affiliate opportunities to those web developers, bloggers, and internet marketers who have traffic, eyeballs, and in general, an audience. Since many sellers are willing to shave their margins and pay referrals for buying customers e-commerce

16. Jul 2014, 10:04 CET | Link

happy husband is the first thing that needs to be done in the home, harmony married couples tend to rely on the relationship in bed. With convenience in dealing requires an intimate rgan healthy condition both male sex organs and female sex organs Herbastamin is supporting stamina and vitality of a man who is able to improve the quality of your virility and herbal Natural Crytsal x is specially designed for your feminine which has many benefits for couples harmony couple

29. Aug 2014, 06:09 CET | Link
Obat Herbal Kanker Paru Paru

The world is transforming fast. people are also having by day time we are becoming more dependant on degital're making me think of this really.You have a nice technique of sharing your thoughts. obat herbal kanker paru paru

26. Sep 2014, 09:27 CET | Link
Obat Kolesterol

Pusat Penjualan Obat Tradisional Penyakit Kolesterol Tinggi amazon - obat kolesterol

30. Sep 2014, 10:33 CET | Link

There are so many web, but only that I think your website helpful, thank you My Link

30. Sep 2014, 10:35 CET | Link

There are so many web, but only that I think your website helpful, thank you My Link

20. Oct 2014, 12:11 CET | Link

This is a great article thanks for sharing this informative information. HD mxf files conversion software mxf converter pdf conversion to Office pdf to word v

Post Comment