7

我最近决定将我的索引引擎从 sphinx 移植到 solr。将 kaminari 与 thinking_sphinx 一起使用后,我决定尝试在 sunspot https://github.com/sunspot/sunspot/pull/64 / https://github.com/sunspot/sunspot/pull/67中使用通用分页,按顺序使用避免移动到 will_paginate。

我的搜索处理如下:

@search = Address.search do
  fulltext params[:search]
  with(:updated_at).greater_than(1.week.ago)
  order_by :updated_at, :desc
  paginate :page => params[:page], :per_page => 7
end

我的观点与我使用thinking_sphinx时的观点不同:

<%= render :partial => 'address' %>
<%= paginate @addresses %>

我的问题是,更改后我在尝试执行搜索时不断收到以下错误:

undefined method `current_page' for []:Array

我正在使用最新版本的太阳黑子,据我所知,这应该使我能够使用 kaminari:

Using sunspot (1.3.0.rc3) from git://github.com/sunspot/sunspot.git (at master) 
Using sunspot_rails (1.3.0.rc3) from git://github.com/sunspot/sunspot.git (at master) 

这与我的旧thinking_sphinx 设置完美配合,那么我做错了什么?

4

1 回答 1

13

这就是我使用的方式,效果很好

@search = Sunspot.search(Listing) do
      if params[:category].present?
        with :category_id, params[:category]
      end
      if params[:subcategory].present?
        with :subcategory_id, params[:subcategory]
      end
      if params[:q].present?
        keywords params[:q]  do 
          fields :title, :description
        end
      end
      paginate :page => params[:page], :per_page => SEARCH_RESULT_PER_PAGE
    end

在意见中我有这个

<%= paginate @search.hits %>
于 2012-01-17T14:09:59.127 回答