2011-10-28 47 views
7

我最近決定將我的索引引擎從sphinx移植到solr。在使用kaminari和think_sphinx之後,我決定嘗試在太陽黑子https://github.com/sunspot/sunspot/pull/64/https://github.com/sunspot/sunspot/pull/67中使用通用分頁,以避免移動到will_paginate。與kaminari的太陽黑子分頁

我的搜索爲如下處理:

@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 

我使用的是最新版本的黑子,這給我的知識應該使我能夠用雷:

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設置完美地工作,所以我究竟做錯了什麼?

+0

好吧,我厭倦了,不想讓它工作,並切換到will_paginate,偉大工程現在。 – maecro

+2

有一個太陽黑子kaminari寶石,這使得kaminari和太陽黑子很好地一起玩[https://github.com/richardiux/sunspot_with_kaminari](https://github.com/richardiux/sunspot_with_kaminari)絕對適合我們。 –

+0

我曾經看過那顆寶石,但當時忽略了,因爲那裏似乎沒有很多活動。也許我認爲它有點苛刻,我會再看看它。歡呼建議。 – maecro

回答

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 %> 
+0

你爲我節省了很多時間!謝謝! – 23tux