検索結果のページネーションを Elasticsearch、Tire、Kaminari で動作させるのに問題があります。
一般的なサイト検索としてアプリケーション (ニュース、絵画、書籍) のすべてのモデルを検索しているため、タイヤ検索用のブロックが必要です。 10 エントリ:
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
私の検索結果ページには、次のコードがあります。
- if @results
- @results.results.each do |result|
= result.title
#pagination
= paginate @results
私のすべてのモデルで、適切なマッピングがあり、タイヤから含まれています:
# - - - - - - - - - - - - - - - -
# 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
すべてのエントリが Elasticsearch で適切にインデックス化されていることを確認しました。
私が抱えている問題は、それを機能させることができないことです。最新のエラーは次のとおりです。
未定義のメソッド「current_page」
どんな考えでも大歓迎です。ありがとうございました。