Rails 4 アプリに Tire gem と ElasticSearch の実装を始めたところです。Tire gemのホームページには、次のように記載されています。
Note that Tire search results are fully compatible with WillPaginate and Kaminari, so you can pass all the usual parameters to the search method in the controller:
@articles = Article.search params[:q], :page => (params[:page] || 1)
私はほとんどまったく同じ設定をしています:
@projects = Project.search params[:query], :load => true, :page => (params[:page] || 1)
検索しようとすると、次のようになります。
undefined method `total_pages' for #<ActiveRecord::Relation []>
Project.rb:
include Tire::Model::Search
include Tire::Model::Callbacks
settings :analysis => {
:filter => {
:ngram_filter => {
:type => "nGram",
:min_gram => 2,
:max_gram => 12
}
},
:analyzer => {
:index_ngram_analyzer => {
:type => "custom",
:tokenizer => "standard",
:filter => ["lowercase", "ngram_filter"]
},
:search_ngram_analyzer => {
:type => "custom",
:tokenizer => "standard",
:filter => ["standard", "lowercase", "ngram_filter"]
}
}
} do
mapping do
indexes :id, :type => 'integer'
indexes :title
indexes :description
end
end
WillPaginate を使用して検索結果を適切にページ付けするにはどうすればよいですか? どんな助けでも大歓迎です。