-->
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.  [ 2 posts ] 
Author Message
 Post subject: Check if index already exists or is up to date
PostPosted: Wed May 18, 2011 3:45 am 
Beginner
Beginner

Joined: Thu Jan 06, 2011 6:19 am
Posts: 25
Hi!

I added hibernate search to my existing project. When I start the application I have to detect whether there is already an index or not. If not I have to re-index all entities. This could be the case when I upgrade my existing application with the new hibernate search project where already some entities are persisted in the database. I could re-index all entities by using the manual indexing code like this:

Code:
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(getEntityManager());
Session session = getSession();
session.setFlushMode(FlushMode.MANUAL);
session.setCacheMode(CacheMode.IGNORE);
      
Transaction tx = session.beginTransaction();
      
ScrollableResults results = session.createCriteria(ProjectEntityImpl.class)
    .setFetchSize(this.batchSize)
    .scroll(ScrollMode.FORWARD_ONLY);
      
int index = 0;
while(results.next()) {
    index++;
    fullTextEntityManager.index(results.get(0));
    if (index % this.batchSize == 0) {
        fullTextEntityManager.flushToIndexes();
        fullTextEntityManager.clear();
    }
}
         
tx.commit();
fullTextEntityManager.getSearchFactory().optimize(ProjectEntityImpl.class);


I would do this when starting my application but only in the case my index is not existing or not up to date.

How can I detect that? By checking if there is a sub-directory for this entity in the lucene target directory? If so, can I determine if the index is empty or not?

Regards, jacquipre


Top
 Profile  
 
 Post subject: Re: Check if index already exists or is up to date
PostPosted: Wed May 18, 2011 12:45 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
you could run a org.apache.lucene.search.MatchAllDocsQuery , and then use
org.hibernate.search.FullTextQuery.getResultSize()
(this won't load all data, just count it)

_________________
Sanne
http://in.relation.to/


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