使用 kaminari 进行太阳黑子分页

发布于 2024-12-13 02:22:06 字数 1147 浏览 4 评论 0原文

我最近决定将我的索引引擎从 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

我是使用最新版本的 sunspot,据我所知,这应该使我能够使用 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 设置完美配合,那么我做错了什么?

I recently decided to port my indexing engine from sphinx to solr. Having used kaminari with thinking_sphinx I decided to try making use of generic pagination in sunspot https://github.com/sunspot/sunspot/pull/64 / https://github.com/sunspot/sunspot/pull/67, in order to use avoid moving to will_paginate.

My search is handled as follows:

@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

My view is unchanged from what I had when I was using thinking_sphinx:

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

My problem is that after the change I continually get the following error when trying to perform a search:

undefined method `current_page' for []:Array

I am using the latest version of sunspot, which to my knowledge should enable me to use 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) 

This worked perfectly with my old thinking_sphinx setup, so what am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红墙和绿瓦 2024-12-20 02:22:06

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

@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 %>

This is how I have used and it works great

@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

And in views I have this

<%= paginate @search.hits %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文