Red Hat

Hibernate Search 4.4.0.Alpha1

Posted by    |       |    Tagged as Hibernate Search

It has been quite some time since I have done my last Hibernate Search release announcement, so I am especially happy to get the 4.4 release train rolling. Hibernate Search 4.4.0.Alpha1 is now out and ready for download, either from the JBoss Maven Repository under the GAV org.hibernate:hibernate-search:4.4.0.Alpha1 or via SourceForge. The release contains fixes for 16 issues which you can closer inspect in the Jira release notes.

Next to the usual bug fixes and internal changes I want to highlight the latest new feature of Hibernate Search, the Metadata API (HSEARCH-436). Looking at SearchFactory you will find two new methods:

public interface SearchFactory {

    // ...

    /**
     * Returns the set of currently indexed types.
     *
     * @return the set of currently indexed types. If no types are indexed the empty set is returned.
     */
     Set<Class<?>> getIndexedTypes();

     /**
      * Returns a descriptor for the specified entity type describing its indexed state.
      *
      * @param entityType the entity for which to retrieve the descriptor
      *
      * @return a non {@code null} {@code IndexedEntityDescriptor}. This method can also be called for non indexed types.
      *         To determine whether the entity is actually indexed {@link org.hibernate.search.metadata.IndexedTypeDescriptor#isIndexed()} can be used.
      *
      * @throws IllegalArgumentException in case {@code entityType} is {@code null}
      */
     IndexedTypeDescriptor getIndexedTypeDescriptor(Class<?> entityType);
}

The former, getIndexedTypes(), allows you to determine which indexed types the SearchFactory knows about. The latter, getIndexedTypeDescriptor(Class<?>), is the entry point into a descriptor based meta model API. It allows you to determine the configuration aspects of a given type. Amongst other things the type descriptor contains information about the static and dynamic class boost, whether the index is sharded and of course which properties of the type are indexed and which Lucene fields they produce. The property and field information is contained - surprise, surprise - in Property- and FieldDescriptors. Access to these descriptors is via getters in IndexedTypeDescriptor.

Last but not least, there are a couple of things worth noticing around FieldDescriptor. First, there are really two field related descriptors, namely FieldSettingsDescriptor and FieldDescriptor (extending FieldSettingsDescriptor). The split might not seem obvious at first glance, but it allows to separate the actual Lucene Field information from additional Search specific field configuration options (for example whether null values should be indexed or not).

Secondly, there are multiple subtypes of FieldSettingsDescriptor, for example NumericFieldSettingsDescriptor. This allows to keep information specific for a given field type contained in a single class. In the case of NumericFieldSettingsDescriptor it is the precisionStep. To access type sub-type specific information a type check followed by an unwrap is needed. Something like:

// ...
IndexedTypeDescriptor typeDescriptor = searchFactory.getIndexedTypeDescriptor( Foo.class );
FieldDescriptor fieldDescriptor = typeDescriptor.getIndexedField( "snafu" );
if( FieldSettingsDescriptor.Type.NUMERIC.equals( fieldDescriptor.getType() ) ) {        
    NumericFieldSettingsDescriptor numericFieldSettingsDescriptor = fieldDescriptor.as(NumericFieldSettingsDescriptor.class);
    int precisionStep = numericFieldSettingsDescriptor.precisionStep();
    // ...
}
// ...

Feedback related to this API is much welcome. It helps us fine tuning the API prior to final Search 4.4 release. Just contact us via the mailing list or on IRC.

Enjoy!

back to top