-->
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.  [ 7 posts ] 
Author Message
 Post subject: EntityIndexingInterceptor and Mass Indexer
PostPosted: Mon Apr 16, 2012 7:17 am 
Newbie

Joined: Mon Apr 16, 2012 6:49 am
Posts: 1
There seems to be an issue with this combination. I've set up the application as described here:http://in.relation.to/Bloggers/HibernateSearch41CR1SoftDeletes. The thing works exactly as advertised and properly removes the documents with unproper status from index. The problem is when I try to reindex the entire database using the mass indexer. It seems that the EntityIndexingInterceptor get's completely ignored as it's not called even once.
I have the most trivial possible implementation of this. Just a boolean field called active. If true, document should get added to index, otherwise not.

Here's my code.
Interceptor:
Code:
public class IndexWhenActiveInterceptor implements EntityIndexingInterceptor<IndexWhenActive> {
    @Override
    public IndexingOverride onAdd(IndexWhenActive entity) {
        System.out.println("IndexingOverride onAdd");
        if (entity.getActive()==null || entity.getActive()) {
            return IndexingOverride.APPLY_DEFAULT;
        }
        return IndexingOverride.SKIP;
    }

    @Override
    public IndexingOverride onUpdate(IndexWhenActive entity) {
        System.out.println("IndexingOverride onUpdate: ");
        if (entity.getActive()==null || entity.getActive()) {
            return IndexingOverride.UPDATE;
        }
        return IndexingOverride.REMOVE;
    }

    @Override
    public IndexingOverride onDelete(IndexWhenActive entity) {
        return IndexingOverride.APPLY_DEFAULT;
    }

    @Override
    public IndexingOverride onCollectionUpdate(IndexWhenActive entity) {
        return onUpdate(entity);
    }

}


The interface used in interceptor:
Code:
public interface IndexWhenActive {
    Boolean getActive();
}


The Entity (partial)
Code:
@Entity
@Table(name="make")
@Indexed(interceptor = IndexWhenActiveInterceptor.class)
public class Make extends BasicEntity implements Serializable, IndexWhenActive {
    @Field
    private Boolean active = true;
....

}


BasicEntity is a mapped superclass that should not be relevant here.

and finally, the mass indexer code:
Code:
            fullTextEntityManager.createIndexer()
                    .batchSizeToLoadObjects(25)
                    .threadsToLoadObjects(1)
                    .threadsForSubsequentFetching(2)
                    .optimizeOnFinish(true)
                    .startAndWait();


I'm using this:
Code:
      <dependency>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-entitymanager</artifactId>
         <version>4.1.0.Final</version>
      </dependency>




Am I missing something or is there a problem with my implementation.

Please help.

regards.

Jure


Top
 Profile  
 
 Post subject: Re: EntityIndexingInterceptor and Mass Indexer
PostPosted: Thu May 03, 2012 11:15 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi Jure,

interception should also work with the mass indexer. I just added a new test case to our harness and it worked for me.
Have a look at IndexingActionInterceptorTest

Maybe you could create a minimal testcase for your example. This would help to localize your problem.

--Hardy


Top
 Profile  
 
 Post subject: Re: EntityIndexingInterceptor and Mass Indexer
PostPosted: Fri May 04, 2012 7:05 am 
Newbie

Joined: Thu May 03, 2012 4:55 am
Posts: 3
It would not work in case if old approach is used:
Code:
            ScrollableResults results = fullTextSession.createCriteria(persistentClass)
                    .setFetchSize(BATCH_SIZE)
                    .scroll(ScrollMode.FORWARD_ONLY);

            while (results.next()) {
                index++;
                T entity = (T) results.get(0);
                fullTextSession.index(HibernateHelper.unproxy(entity)); //index each element


because of TransactionalWorker code is following:
Code:
   private <T> Work<T> interceptWork(EntityIndexBinder indexBindingForEntity, Work<T> work) {
      if (indexBindingForEntity == null) {
         return work;
      }
      EntityIndexingInterceptor<? super T> interceptor = (EntityIndexingInterceptor<? super T> ) indexBindingForEntity.getEntityIndexingInterceptor();
      if (interceptor == null) {
         return work;
      }
      IndexingOverride operation;
      switch ( work.getType() ) {
         case ADD:
            operation = interceptor.onAdd( work.getEntity() );
            break;
         case UPDATE:
            operation = interceptor.onUpdate( work.getEntity() );
            break;
         case DELETE:
            operation = interceptor.onDelete( work.getEntity() );
            break;
         case COLLECTION:
            operation = interceptor.onCollectionUpdate( work.getEntity() );
            break;
         case PURGE:
         case PURGE_ALL:
         case INDEX:
            operation = IndexingOverride.APPLY_DEFAULT;
            break;




it means, that work.getType() equals to INDEX and interceptor code not called.


Top
 Profile  
 
 Post subject: Re: EntityIndexingInterceptor and Mass Indexer
PostPosted: Tue May 08, 2012 3:38 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

thanks for the update. I need to have a closer look at the code. However, didn't you say you used the mass indexer? Now you are saying the "old style" approach is broken.


Top
 Profile  
 
 Post subject: Re: EntityIndexingInterceptor and Mass Indexer
PostPosted: Fri May 11, 2012 11:53 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi Jure,

turns out you are right with your analysis. FulltextSesion#index does not apply the interceptor. Turns out this is a "feature". Personally I think the interceptor should be applied. I started a discussion on the hibernate-dev mailing list.

--Hardy


Top
 Profile  
 
 Post subject: Re: EntityIndexingInterceptor and Mass Indexer
PostPosted: Tue May 15, 2012 5:56 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
FYI, here is a link to the discussion on the Hibernate Dev mailing list - http://lists.jboss.org/pipermail/hibern ... 08365.html
I think we will add some additional methods to FulltextSession to ensure that #index and #purge also apply the interceptor unless this behavior is explicitly turned off.

--Hardy


Top
 Profile  
 
 Post subject: Re: EntityIndexingInterceptor and Mass Indexer
PostPosted: Mon Jun 25, 2012 10:17 am 
Newbie

Joined: Mon Jun 25, 2012 10:03 am
Posts: 1
Hi,

I'm facing the same issue even using the mass indexer startAndWait() method. Also I noticed that the TransactionWorker isn't used at all when using the mass indexer, so your suggestion won't fix or allow a customization for this problem.

I haven't tested it yet but apparently it's possible to use a custom Worker by setting the hibernate.search.worker.scope property. Also, using flushToIndexes it's possible to use a custom query prefiltering the data to be indexed instead of using the interceptor which could be more efficient.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.