ncbo / goo

Graph Oriented Objects (GOO) for Ruby. A RDF/SPARQL based ORM.
http://ncbo.github.io/goo/
Other
15 stars 6 forks source link

Pagination in search (count and sorting) #26

Closed msalvadores closed 7 years ago

msalvadores commented 11 years ago

Offset limit and some kind of ordering when retrieving Goo objects.

Project.all(:limit=> 10, :offset => 100, :sort => { :with => [:name, :asc] )
Project.find(:attribute => "value" :limit=> 10, :offset => 100, :sort => { :with => [:name, :asc] )
Project.count({})

This should be done accordingly to the issue about changing the API for search

palexander commented 11 years ago

ActiveModel has a decent api for this:

User.find_each(:start => 2000, :batch_size => 5000) do |user|
  # do something with `user`
end
palexander commented 11 years ago

There's a good one for iterating over arrays of responses too:

# Give add_invoices an array of 1000 invoices at a time
Invoice.find_in_batches(:include => :invoice_lines) do |invoices|
  # invoices is an array with 1000 invoice objects
  export.add_invoices(invoices)
end
msalvadores commented 11 years ago

:+1: I like it.

@palexander how Active Model does to know the number of pages in find_in_batches ?

palexander commented 11 years ago

It doesn't know the number of pages, you just keep iterating until all records are found. I guess this isn't really pagination, more a convenient way to work with groups of results when getting back Invoice.all would be too much data.

Here's more info: http://apidock.com/rails/ActiveRecord/Batches/ClassMethods/find_in_batches

msalvadores commented 11 years ago

As discussed we do not worry about this now. We only need pagination for mappings and classes (in the ontology linked data API). It can wait.