-->
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: Best way to search...
PostPosted: Sat Feb 02, 2008 12:56 pm 
Newbie

Joined: Mon Dec 18, 2006 2:39 am
Posts: 16
I currently have an app that searches through data and returns a max number of results per page to the user. It also returns the total number of results for the query. I also return subcategories from the query where a user can narrow their search.

The problem is, I want to show how many results are for each subcategory as well, but i don't want to have to do a projections.rowCount for each subcategory to get the total number of results for each of them, which to me seems like an expensive task.


Basically i want it similar to how a job site works...first you enter a keyword and location, and you get the results, and then you can click on a number of categories to narrow down your search with hte number of results per category listed.

Any know how sites like that typically do it?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 02, 2008 2:26 pm 
Newbie

Joined: Tue Jan 22, 2008 9:53 am
Posts: 18
In hibernate the best way to know how many records a query will result is counting them before you get them paginated.
Use the same query you are going to use to retrieve the data. but make this change

Long count = (Long) session.createQuery("select count(*) from ... where...").uniqueResult();

this is not so expensive task depending on your database. It's not unexpensive, but is much better than retrieve all ate to count them.
Hibernate manual recomends this to count data in you db


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 02, 2008 7:19 pm 
Newbie

Joined: Mon Dec 18, 2006 2:39 am
Posts: 16
Ya, i had a feeling it might be better just to do a count on all the elements i needed a count for.

thx


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.