Sunspot support #47

Closed
lda opened this Issue Mar 3, 2011 · 18 comments
@lda
lda commented Mar 3, 2011

Do you have any plans to support not ORM solutions like sunspot ?

@brstp

+1

@lacco

+1

@medihack

+1 ... Sunspot support would be great.

@amatsuda amatsuda added a commit that referenced this issue Apr 22, 2011
@amatsuda refs #47, #68, #74 generic pagination support for Array object
this enables you to paginate through any Arrayish object in this way:
  Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)
e04f65a
@amatsuda
Owner

Thanks for the request and +1s!

Just added an initial implementation of generic Arrayish object support e04f65a.
Can you bundle '>= 0.12.0' gem and try something like this?

Kaminari.paginate_array(search_result).page(params[:page])

I haven't tested with Sunspot myself, but hope this works.

@lacco

I just tested your code:

MyModel.search do
  keywords(params[:search])
  #paginate(:page => params[:page])
end
Kaminari.paginate_array(result.hits.map(&:result)).page(params[:page])

I works fine, but this way Sunspot can't perform the pagination itself on database level (as far as I see). I would like to leave out the Kaminari::PaginatableArray#page to avoid the offset like this:

MyModel.search do
  keywords(params[:search])
  paginate(:page => params[:page])
end
Kaminari.paginate_array(result.hits.map(&:result))#.page(params[:page])

Now I am getting the following error:
undefined method `current_page' for #<Kaminari::PaginatableArray:0x00000104a47e78>

I am not sure if I am doing something wrong, or if you have to extend Kaminari?

@tejo

+1 for sunspot support

@danoph

+1

@dhiemstra

Because sunspot handles the pagination I modified the Kaminari paginate helper so it can accept and handle a sunspot search result object. Could someone please test it out in his project before i enter a pull request?
dhiemstra@b9e868f
gem 'kaminari', :git => 'git@github.com:dhiemstra/kaminari.git', :branch => :sunspot_support

@medihack

I wonder that when Sunspot handles the pagination, why we all vote here for integration?! Wouldn't it be better to clean up this pull request and vote there? Or at least open up a Sunspot ticket?

@dhiemstra

Medihack, the reason is that sunspot handles the pagination of the results but not the actual view helper of the pagination.
For example most of the models of our project is normal AR and pagination goes via kaminari, because we have a search function for 3 models we would have to write our own pagination helper next to kaminari's helper or use will_paginate for those results.
This is duplication and forces you to maintain two views for the pagination of your project.

@lardawge

@dhiemstra, Why do you have to write pagination helpers for each model that has a search? In the view all your doing is passing an array to paginate and as long as the specified methods are defined on it, it just works. That is what medihack is referring to and I agree with.

Anyway, here is a pull request I submitted with tests to sunspot. Can you guys test and report your findings? https://github.com/outoftime/sunspot/pull/63

Thanks.
~Larry

@lardawge

For anyone looking for a quick and dirty fix until support gets added to sunspot, drop this in config/initializer folder:
https://gist.github.com/1045196

Also, test and +1 to the pull request here:
https://github.com/outoftime/sunspot/pull/64

~Larry

@dhiemstra

Thanks lardawge!

@lardawge

Kaminari support added to Sunspot here: outoftime/sunspot@08dc66b

Please test so we can get a release.

@lda

it works

@yuki24
Collaborator

It looks like Sunspot has support for generic pagination and there is no additional implementation needed on kaminari-side. Thanks @lardawge for your great work!
Open this issue again if there is any problem with sunspot integration.

@yuki24 yuki24 closed this Jul 3, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment