[infinispan-dev] new Infinispan Query API - ISPN-194

Sanne Grinovero sanne at hibernate.org
Mon Apr 4 12:23:43 EDT 2011


Infinispan 4.0 contained an integration with Hibernate Search to index
stored POJOs using the well-known Hibernate Search annotations; but
the configuration was tricky and the API quite limited.
With the latest changes in H.Search, we could now make a better integration.

Quick recap on configuration/usage on Infinispan 4:
1) indexing must be enabled in Infinispan configuration
2) a queryHelper class must be started and pointed to known types to
be indexed, passing it HS configuration properties
 - this would start a Hibernate Search engine
 - modifications done on the grid before the queryHelper was started
are ignored by the indexing engine
 - list of "known entities" could not be changed
3) use a queryFactory to create queries, which needs to be hooked up
the previously started queryHelper
 - the query options where a bit limited

What's coming in Infinispan 5:
1) indexing is still be enabled in Infinispan configuration
  - Hibernate Search configuration properties are embedded in the
Infinispan configuration

<infinispan>
   <default>
      <indexing enabled="true" indexLocalOnly="true">
         <properties>
            <property
name="hibernate.search.default.directory_provider" value="ram" />
         </properties>
      </indexing>
   </default>
</infinispan>


2) no queryHelper is needed
 - lifecycle of the indexing engine is managed by Infinispan
 - new entity types are autodiscovered
   (each time a previously unseen class is put/removed it's annotation
scanned and HS is potentially reconfigured)

3) you still use a QueryFactory, like in the examples linked below
 - exposes all features of Hibernate Search query builder DSL
 - Faceting
 - projections, etc..

API, most significant classes:
https://github.com/Sanne/infinispan/blob/eafe084a2ffa7e539768c838334ad42da3e8e565/query/src/main/java/org/infinispan/query/CacheQuery.java
https://github.com/Sanne/infinispan/blob/eafe084a2ffa7e539768c838334ad42da3e8e565/query/src/main/java/org/infinispan/query/QueryFactory.java

Two usage examples:
https://github.com/Sanne/infinispan/blob/eafe084a2ffa7e539768c838334ad42da3e8e565/query/src/test/java/org/infinispan/query/queries/faceting/SimpleFacetingTest.java
https://github.com/Sanne/infinispan/blob/eafe084a2ffa7e539768c838334ad42da3e8e565/query/src/test/java/org/infinispan/query/indexedembedded/CollectionsIndexingTest.java

there's one catch:
when searching for a class type, it will only include results from
known subtypes. The targeted type is automatically added to the known
classes, but eventually existing subtypes are not discovered.

Bringing this issue to an extreme, if the query is not targeting any
type, and no indexed types where added to the grid (even if some exist
already as they might have been inserted by other JVMs or previous
runs), all queries will return no results.
How to solve this?
 - class scanning?
 - explicitly list indexed entities in Infinispan configuration?
 - a metadata cache maintaining a distributed&stored copy of known types
 - search for types in the index :)  would be nice, but the current
design in Search mandates to know the entities first to know how the
indexes are named. without name I can't open the index, but maybe we
could have the user specify the index names instead of all entity
classtypes.

Feedback on the API is more urgent than to solve this, so it could
make it for Infinispan 5 Beta1.

Cheers,
Sanne


More information about the infinispan-dev mailing list