-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Search: FullTextEntityManager#index() silently fails
PostPosted: Thu May 08, 2008 3:10 pm 
Newbie

Joined: Thu May 08, 2008 2:34 pm
Posts: 6
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


Top
 Profile  
 
 Post subject: Subclasses of an indexable object need @Indexed
PostPosted: Thu May 08, 2008 3:22 pm 
Newbie

Joined: Thu May 08, 2008 2:34 pm
Posts: 6
As soon as I added the following annotation to my Article object, it worked...

@Indexed(index = "Articles")

--Phil


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 3:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I've started a thread on the dev list to see what we should do.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.