O'Reilly logo

Hibernate Search by Example by Steve Perkins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Conditional indexing

There are specialized ways to go about indexing fields, such as using a class bridge or the programmatic mapping API. Generally speaking, though, a property is indexed when it is annotated with @Field. Therefore, one obvious way to avoid indexing a field is to simply not apply the annotation.

However, what if we want an entity class to be searchable in general, but we need to exclude certain instances of that class, based on the state of their data at runtime?

The @Indexed annotation has an experimental second element, interceptor , that gives us the ability to index conditionally. When this element is set, the normal indexing process will be intercepted by custom code, which can prevent an entity from being indexed based on ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required