[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
How can I get the total count when I set the maxResults(1000) in the query?  XML
Forum Index -> BigMemory
Author Message
lijie

journeyman

Joined: 09/04/2012 23:10:13
Messages: 19
Offline

I use Aggregators.count() to get the total count. But when I set maxResults(1000), the Aggregators.count() result is 1000.
How can I get the 1000 results and total count in one query?
Thanks.
rajoshi

seraphim

Joined: 07/04/2011 04:36:10
Messages: 1491
Offline

Can you please specify how you are using Aggregators.count() to get the total count. Can you share the source.

Rakesh Joshi
Senior Consultant
Terracotta.
lijie

journeyman

Joined: 09/04/2012 23:10:13
Messages: 19
Offline

The code snippet:
Code:
public void testTotalCount(Cache cache) {
 		List<Person> personList = new ArrayList<Persion>();
 		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
 		Attribute<Date> create_time = cache.getSearchAttribute("create_time");
 		
 		//get the first 1000 results
 		Query q = cache.createQuery();
 		q.maxResults(1000);
 		q.includeKeys();
 		q.includeValues();
 		Criteria c1 = create_time.between(df.parse("2012-09-01"),df.parse("2012-09-31"));
 		q.addCriteria(c1).addOrderBy(create_time, Direction.ASCENDING);
 		Results rs = q.execute();
 		for(Result r : rs.all()) {
 			personList.add((Person)r.getValue());
 		}
 		
 		//get the total count
 		Query qC = cache.createQuery();
 		qC.addCriteria(c1);
 		qC.includeAggregator(Aggregators.count());
 		Results cRs = qC.execute();
 		int count = (Integer) cRs.all().get(0).getAggregatorResults().get(0);
 }


So,I execute the query twice. I can't sure whether it is right or not?
ericm

jedi

Joined: 01/27/2011 17:23:34
Messages: 117
Offline

I would avoid Hobo Bags....just a thought.

@ lijie
The way you are running your queries is very normal. It will be two queries. One for the total count of objects which could be 10M, but then you bring back only 1K in a second query.

I hope this helps.

Eric

Eric Mizell (Terracotta Engineer)
 
Forum Index -> BigMemory
Go to:   
Powered by JForum 2.1.7 © JForum Team