Java – How to index rows dependent on column values with Hibernate Search / Lucene

full-text-searchhibernate-searchjavalucene

Is it possible to use hibernate search/lucene to index some entity based on values of some fields?

For example, let's take the following example: A product has several properties with values.
e.g. property names could be color, amount, order-date, price, whatever…

PRODUCT (
   name
   description
   ...
)

PROPERTY (
    id
    name
    value
    fk_product
 )

And I only want to index PRODUCTS that have a property COLOR, but I never want to search on property SIZE.

Also, Is it possible to index my products with hibernate search and be able to query only on specific property names (like they where fields on a project)?

Some query like this: color:blue that would return me all products that have a property name=color with the value=blue.

From the reference doc I don't find anything, but maybe should I use Filters to restrict the querying depending on the values of some fields!

Best Answer

After rereading the reference documentation I realized I had to use a ClassBridge. (section 4.2.2.3 in the documentation) This solves exactly my problem!

The example of the documentation is straight forward.

Related Topic