加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 太阳黑子与kaminari分页

发布时间:2020-12-17 04:29:45 所属栏目:百科 来源:网络整理
导读:我最近决定将我的索引引擎从sphinx移植到solr.使用kaminari和thinking_sphinx后,我决定尝试在太阳黑子 https://github.com/sunspot/sunspot/pull/64/ https://github.com/sunspot/sunspot/pull/67中使用泛型分页,以避免移动到will_paginate. 我的搜索处理如
我最近决定将我的索引引擎从sphinx移植到solr.使用kaminari和thinking_sphinx后,我决定尝试在太阳黑子 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)

这与我的旧think_sphinx设置完美配合,所以我做错了什么?

解决方法

这就是我使用的方式,效果很好
@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 %>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读