I have experienced a problem that appears to be fairly common for newbie users of Hibernate Search (based on other posts).
In a nutshell... If for some reason, the entity being indexed (by calling the FullTextEntityManager#index method) is not properly annotated or otherwise indicated as a indexable entity, the symptoms are as follows:
1. The "indexes" directory contains only the two files:
segments.gen, segments_1
and both files are the same size (7, 8, or 20 bytes)
2. No logging messages are printed.
I stepped into the index() method below and the local variable 'builder' is null. A logging message (perhaps if "debug") where added for the case where 'builder' is null would really help alert users to what the problem is.
In my case, I had annotated my ContentItem class but called index() passing it an instance of Article (which extends ContentItem). There was an entry in the "builders map" for ContentItem but not Article, therefore the 'builder' variable was set to null.
--Phil
Code:
/**
* (re)index an entity.
* Non indexable entities are ignored
* The entity must be associated with the session
*
* @param entity The neity to index - must not be <code>null</code>.
*/
public void index(Object entity) {
if (entity == null) return;
Class clazz = Hibernate.getClass( entity );
//TODO cache that at the FTSession level
SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
//not strictly necessary but a small optimization
DocumentBuilder<Object> builder = searchFactoryImplementor.getDocumentBuilders().get( clazz );
if ( builder != null ) {
Serializable id = session.getIdentifier( entity );
Work work = new Work(entity, id, WorkType.INDEX);
searchFactoryImplementor.getWorker().performWork( work, eventSource );
}
//TODO
//need to add elements in a queue kept at the Session level
//the queue will be processed by a Lucene(Auto)FlushEventListener
//note that we could keep this queue somewhere in the event listener in the mean time but that requires
// a synchronized hashmap holding this queue on a per session basis plus some session house keeping (yuk)
//an other solution would be to subclass SessionImpl instead of having this LuceneSession delecation model
// this is an open discussion
}
Versions I am using...
-------------- hibernate-annotations.jar --------------
Implementation-Version: 3.3.1.GA
-------------- hibernate-commons-annotations.jar --------------
Version: 3.0.0.GA
-------------- hibernate-entitymanager.jar --------------
Implementation-Version: 3.3.2.GA
-------------- hibernate-search.jar --------------
Implementation-Version: 3.0.1.GA
-------------- hibernate3.jar --------------
Implementation-Version: 3.2.6.ga
-------------- lucene-core-2.3.0.jar --------------
Implementation-Version: 2.3.0 613715 - buschmi - 2008-01-21 01:30:48