-->
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: Multiple values fields bug
PostPosted: Mon Sep 20, 2010 5:36 am 
Beginner
Beginner

Joined: Thu Feb 25, 2010 11:33 am
Posts: 36
Hi there,
Maybe the title is not very cleaver. I didn't found any that should be very explicit.
Here is my problem:
I've a class diagram like this

BusinessUnit --1--------*-- Category

I would like to index this relation. So I found a sample index code to re-index objects in the Hibernate Search book. I've updated that code to make it work in my environment and I'm a little frustrated : sometimes, the relation is succesfully translated in my index, sometimes only one category is written in my indexes (but more are present in the database!).

As a beginning, I put here the update index code, let me know if you need anything else ...

Thanks for the help, I've no idea what can be wrong here ...

Code:
    @RequestMapping("updateindex")
    public ModelAndView luceneIndex(HttpServletRequest req) {
   logger.debug("Re-Building Lucene index");
   Session session = sessionFactory.openSession();
   session.beginTransaction();
   FullTextSession fts = org.hibernate.search.Search.getFullTextSession(session);
   fts.setFlushMode(FlushMode.MANUAL);
   fts.setCacheMode(CacheMode.IGNORE);
   if (logger.isDebugEnabled()) {
       logger.debug("Beginning transaction ...");
   }
   Transaction tx = fts.beginTransaction();
   // Read the data from the database - Page 154 Hibernate search
   List<Class> reindexClasses = new ArrayList<Class>();
   reindexClasses.add(EnterpriseLang.class);
   reindexClasses.add(Categories.class);
   reindexClasses.add(Province.class);
   reindexClasses.add(Commune.class);
   reindexClasses.add(BusinessUnit.class);
   try {
       int index = 0;
       for (Class c : reindexClasses) {
      if (logger.isDebugEnabled()) {
          logger.debug("Starting reindex of " + c);
      }
      ScrollableResults results = fts.createCriteria(c).scroll(ScrollMode.FORWARD_ONLY);
      while (results.next()) {
          index++;
          fts.index(results.get(0));
          if (index % 100 == 0) {
         if (logger.isDebugEnabled()) {
             logger.debug("Flushing to index");
         }
         fts.flushToIndexes();
         fts.clear();
          }
      }
      fts.flushToIndexes();
      fts.clear();
       }
       tx.commit();
   } catch (Exception e) {
       tx.rollback();
       logger.warn("Unable to update indexes", e);
   }
   return new ModelAndView("indexok");
    }


Some more info : I've set the log4j debug mode and in the logs I can now see the SQL executed to get my categories. This sql is correct and returns the right data. So the problem is somewhere between the returned data and the index writing. The most amazing thing is that with some data, everything is fine, and other, only one category is indexed even if there are more than one ...


Top
 Profile  
 
 Post subject: Re: Multiple values fields bug
PostPosted: Mon Sep 20, 2010 8:20 am 
Beginner
Beginner

Joined: Thu Feb 25, 2010 11:33 am
Posts: 36
Ok, we found the solution.

Apparently, the line ScrollableResults results = fts.createCriteria(c).scroll(ScrollMode.FORWARD_ONLY); was not correct. It returns multiple times the same record, and the index flushing destroy the collections. Why? I don't know.

Replacing the wrong line by this one ScrollableResults results = session.createQuery("select t from " + c.getSimpleName() + " t").scroll(ScrollMode.FORWARD_ONLY); fix the problem.


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.