moremore0812 / cqengine

Automatically exported from code.google.com/p/cqengine
0 stars 0 forks source link

Add ability to limit number of results #20

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
See discussion in forum: 
https://groups.google.com/forum/#!topic/cqengine-discuss/o4oUCc-PGOA

It would be nice if CQEngine had an explicit way to limit the number of results 
returned. Currently, the application can just stop iterating when it has enough 
results. But built-in support might be useful as an alternative.

Possible approach:

ResultSet<Car> results = cars.retrieve(equal(Car.MANUFACTURER, "Ford"), 
queryOptions(limit(20)));

However, then support for pagination would seem like a good idea, but the limit 
approach would be inefficient as it would require re-starting the query for the 
second page.

Efficient pagination approach:

ResultSet<Car> results = cars.retrieve(equal(Car.MANUFACTURER, "Ford")); // 
cache this
for (Car car : Pagination.limit(results, 20)) { // Advances through the first 
20 cars
    // Process the first 20 cars
}
for (Car car : Pagination.limit(results, 20)) { // Advances through the next 20 
cars
    // Process the next 20 cars
}

Original issue reported on code.google.com by ni...@npgall.com on 28 Aug 2013 at 1:38

GoogleCodeExporter commented 9 years ago

Original comment by ni...@npgall.com on 28 Aug 2013 at 4:57

GoogleCodeExporter commented 9 years ago
Pagination would be a common requirement for large collection. In addition to 
sequential paging as shown in the example, arbitrary start positions should be 
supported: Pagination(results, 20, 20) [ start at position 20 (1 based) and 
return 20 records).
Guava's Iterable and FluentIterable interfaces support such pagination and 
could be used to wrap a ResultSet.

Original comment by wilson.k...@gmail.com on 22 Jan 2015 at 9:51