Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to limit number of results #20

Open
GoogleCodeExporter opened this issue Jun 15, 2015 · 2 comments
Open

Add ability to limit number of results #20

GoogleCodeExporter opened this issue Jun 15, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant