Giter Club home page Giter Club logo

Comments (8)

npgall avatar npgall commented on August 19, 2024 1

Actually what you probably need is a NavigableIndex on price (i.e. not a HashIndex), and to request CQEngine to use the "index" ordering strategy. Take a look at: OrderingStrategies.md

If you need more help with this, feel free to open a new issue and we can continue discussing there. Hope that helps for now!

from cqengine.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 19, 2024

Original comment by [email protected] on 28 Aug 2013 at 4:57

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

from cqengine.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 19, 2024
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 [email protected] on 22 Jan 2015 at 9:51

from cqengine.

npgall avatar npgall commented on August 19, 2024

Closing this issue as this problem is best solved by combining other libraries with CQEngine.

CQEngine's ResultSet implements the java.lang.Iterable interface, therefore results can be limited or paginated as follows:

  • Guava's Iterables.limit()
  • Convert the CQEngine ResultSet into a Java 8 Stream and call Stream.limit()
  • Consider using a variety of open source pagination libraries.

from cqengine.

DuskoV avatar DuskoV commented on August 19, 2024

Please open this issue. Here is the reasoning:

Records: 100k

SQL:
SELECT * FROM Cars ORDER BY price LIMIT 10

cqengine will sort and return all 100k records (2+ seconds), and then other libraries should paginate.

If SQL parser considers LIMIT keyword and finds defined index (HashIndex on price), it would be natural to optimize response to top 10 results by HashIndex.

As a result, query will be in a ms instead of sec.

from cqengine.

ale3hs avatar ale3hs commented on August 19, 2024

Create a limitBy option, add it to the queryOptions. Create your own version of MaterializedOrderedResultSet that only sorts the top n of the resultSet and just appends the rest to the bottom of the data structure. Upon iterator(), read that limit and sort accordingly. This way you'll have a "list" of resultset.size where the top n are sorted (given that you don't care about n+1...) rather than using the treeSet to sort the entire result set. Any item that compares > to the nth item is just added to the bottom of the semi-sorted structure. You could also use a variation of the binary search to reduce the complexity of finding where to insert an item in the top n. Try it out by sloppily overriding MaterializedOrderedResultSet in your project path with hard-coded limits, if it works out for you build your own queryEngine etc

from cqengine.

ale3hs avatar ale3hs commented on August 19, 2024

great work btw @ npgall

from cqengine.

muhdkhokhar avatar muhdkhokhar commented on August 19, 2024

please someone give me a example how to achieve pagination

from cqengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.