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 ...