-->
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: fulltextquery is slow to load data from db
PostPosted: Tue Oct 09, 2007 4:37 pm 
Newbie

Joined: Mon Oct 08, 2007 3:13 pm
Posts: 6
Hi

Below is my method and it's output.

Based on output seems like Lucene is working fast but hibernate is taking time to load data from db.

Any idea how to reduce time taken by hibernate? I know we can use pagination, but any other idea? like loading data from db in batch like that?


public void dbuserFullTextQuery(){
try {
long start1 = System.currentTimeMillis();

Session session = getHibernateTemplate().getSessionFactory().openSession();
FullTextSession fullTextSession = Search.createFullTextSession(session);
Transaction tx = fullTextSession.beginTransaction();

MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{"title"}, new StandardAnalyzer());
Query query = parser.parse("chapel");
org.hibernate.search.FullTextQuery hibQuery = fullTextSession.createFullTextQuery( query, Mediafile.class );

long end1 = System.currentTimeMillis();
System.out.println("time for Lucene:-->" + (end1-start1));

long start2 = System.currentTimeMillis();
List result = hibQuery.list();
long end2 = System.currentTimeMillis();
System.out.println("time for hibernate:-->" + (end2-start2));

System.out.println("dbuserFullTextQuery result size is:--->" + result.size());

tx.commit();
}catch(Exception e) {
e.printStackTrace();
}
}


-----------------------------

output


time for Lucene:-->31
time for hibernate:-->11719
dbuserFullTextQuery result size is:--->2969


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 09, 2007 6:30 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
First of all you measure for the Lucene time is wrong, there is no call to Lucene at that stage :)

Second, if you are using the latest Hibernate Search version, such a query should be batched for you (how many SQL queries are fired?)

There are several things that might influence the time:
- you have EAGER associations to the object loader, this might trigger some addiitional and useless queries => don't use EAGER, and if you have, check the fullTextQuery.setCriteriaQuery
- you retrieve a lot of objects => use pagination (or potentially scroll), note that you can still retrieve the total number of matching objects using fillTextQuery.getResultSize()

In any case check the SQL queries generated by Hibernate and see what's going on.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 10, 2007 1:03 pm 
Newbie

Joined: Mon Oct 08, 2007 3:13 pm
Posts: 6
Hi

You were right. Hibernate loads data in batch only.
Problem was in my mapping file for few associations i had Outer Join = "auto", that's the reason it was trying to load all other objects unnecessary.


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.