I'm having issues getting pagination of search results to work with Elasticsearch, Tire, and Kaminari.
I am searching on all models in my application (news, paintings, books) as a general site search and therefore, need a block for the tire search, in my site controller for more fine grained control, such as showing more than the default of 10 entries:
class SiteController < ApplicationController
def search
# @results = Painting.search(params[:query])
query = params[:query]
@results = Tire.search ['news','paintings', 'books'], :page => (params[:page]||1), :per_page=> (params[:per_page] || 3) do
query { string query }
size 100
end
end
end
In my search results page, I have the following code:
- if @results
- @results.results.each do |result|
= result.title
#pagination
= paginate @results
and in all my models, I have the proper mapping and includes from tire:
# - - - - - - - - - - - - - - - -
# Elasticsearch
# - - - - - - - - - - - - - - - -
include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
indexes :id, index: :not_analyzed
indexes :title, boost: 100
indexes :slug, boost: 100, as: 'slug'
indexes :content
indexes :image, as: 'image.thumb.url'
indexes :tags, as: 'tags'
indexes :gallery_name, as: 'gallery.name'
indexes :created_at, :type => 'date'
end
I ensured all my entries are indexed properly in Elasticsearch.
The issue I'm having is I can't get it to work, the latest error is:
undefined method `current_page'
Any thoughts would be greatly appreciated. Thank you.