Help

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 <emmanuel@hibernate.org>
 */
public class IndexWhenPublishedInterceptor implements EntityIndexingInterceptor<Blog> {
    @Override
    public IndexingOverride onAdd(Blog entity) {
        if (entity.getStatus() == BlogStatus.PUBLISHED) {
            return IndexingOverride.APPLY_DEFAULT;
        }
        return IndexingOverride.SKIP;
    }

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

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

    @Override
    public IndexingOverride onCollectionUpdate(Blog entity) {
        return onUpdate(entity);
    }
}
@Entity
@Indexed(interceptor=IndexWhenPublishedInterceptor.class)
public class Blog {
    @Id
    @GeneratedValue
    public Integer getId() { return id; }
    public void setId(Integer id) {  this.id = id; }
    private Integer id;

    @Field
    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.

24 comments:
 
05. Mar 2012, 23:33 CET | Link
Cody

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
MoDo

This is great, thank you!

 
16. Apr 2012, 12:37 CET | Link
Jure

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.

Regards.

Jure

 
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 altered.day by day time we are becoming more dependant on degital system.you'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
tomu

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

 
11. Nov 2014, 09:36 CET | Link
jack

I wish to show thanks to you just for bailing me out cosmetic dentist fort lauderdale of this particular trouble.As a result of checking through the the net and meeting techniques that were not productive, I was thinking my life was done.

 
20. Nov 2014, 12:27 CET | Link
Bellewaters

it is right beside Punggol Waterfront. Entertainment for your loved ones and friends are therefore at your fingertips with the full condo facilities as well as the amenities near Bellewaters EC.Bellewaters

 
24. Nov 2014, 04:53 CET | Link

Permission to visit his website, hopefully more prosperous and successful ... Asam Lambung

25. Nov 2014, 05:35 CET | Link

There are abounding replicas that are actual agnate to the absolute accoutrements so it is capital to apprentice how to atom a affected so they do not end up accident your money. A lot of counterfeits are harder to analyze from the absolute accord to pay absorption to specific data is capital to actuate whether a bag is authentic.With the acceptance of Fendi Replica Handbags at a acme of all time, a lot of apish accoutrements are go alfresco and online auctions. Do not be bamboozled into affairs a Louis Vuitton Sacs bag that claims to be the absolute thing, if in actuality it is not. Sometimes it can be difficult to analyze a affected from a real, but there are several agency to analyze the aberration amid a absolute and accurate Louis Vuitton Replica Designer Handbags.As the afterward features.Louis Vuitton handbags are expensive. They are fabricated of big-ticket abstracts such as top superior leather, boa, crocodile, lamb and biscuit skin. The fakes are fabricated of bogus covering and vinyl, can feel asperous and rugged.

harga obat kutil kelamin cara mengobati kutil kelamin obat kutil kelamin alami cara mengobati kutil kelamin secara alami obat kutil kelamin manjur cara mengobati kutil kelamin secara herbal obat kutil kelamin ampuh cara mengobati kutil kelamin tanpa operasi obat kutil kelamin wanita cara mengobati kutil kelamin pada ibu hamil obat kutil kelamin tanpa operasi cara mengobati kutil kelamin bagaimana ya obat kutil kelamin apa ya bagaimana cara mengobati kutil kelamin obat kutil kelamin ibu hamil cara mengobati kutil kelamin dengan cepat obat kutil kelamin terbaik cara mengobati kutil kelamin pada wanita obat kutil kelamin yang paling manjur cara mengobati kutil kelamin pada pria

 
29. Nov 2014, 05:29 CET | Link
obat ejakulasi dini | irpan.maulana1997(AT)gmail.com

menjual obat ejakulasi dini paling ampuh yang sudah terbukti dan teruji dapat mengobati ejakulasi dini anda dengan cepat dan hasilnya permanen. bila anda ingin tahan lama di ranjang bisa menggunakan tricajus . setelah anda mengkonsumsinya anda akan kuat tahan lama saat bercinta hingga berjam jam

 
01. Dec 2014, 14:40 CET | Link
jack

Absolutely fantastic posting! Lots of useful cosmetic dentist fort lauderdale information and inspiration, both of which we all need!

 
04. Dec 2014, 04:19 CET | Link

Thank you for the information, Obat Penyakit Herpes di Kulit

 
08. Dec 2014, 04:10 CET | Link

Sangat berkualitas tampilan websitenya, Ulasannya juga sangat informatif, Obat Jantung Bocor

 
09. Dec 2014, 04:16 CET | Link

sukses untuk websitenya, mohon izin nih untuk berkunjung, terima kasih... Obat Polip Hidung

09. Dec 2014, 05:30 CET | Link

I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles.

 
10. Dec 2014, 03:59 CET | Link

bagus websitenya, semoga makin sukses... Obat Sakit Limpa Bengkak

 
11. Dec 2014, 03:56 CET | Link

jaya selalu untuk websitenya, dan semoga semakin sukses, Obat Alami untuk Hipertensi