簡體   English   中英

你如何在Rails 3上使用Thinking Sphinx排序?

[英]How do you sort Using Thinking Sphinx on Rails 3?

我正在嘗試使用傳遞給我的控制器的參數來完成一個簡單的排序。 我正在關注Searching&Thinking Sphinx網站上的文檔 ,我遇到了以下錯誤。 我究竟做錯了什么?

以下@places對象是think Sphinx類的一個實例。

 @places = Place.search(params[:q], :order => :created_at)

ThinkingSphinx::SphinxError (index place_core: sort-by attribute 'created_at' not found):

您需要添加要搜索的字段。 然后,通過一個字段進行排序,你需要將其標記為可排序的模型,或者您需要在define_index方法添加屬性為這里解釋

對於您的模型,這樣的事情:

class Place < ActiveRecord::Base
  # ...

  define_index do
    # fields
    indexes subject, :sortable => true
    indexes content
    indexes author.name, :as => :author, :sortable => true

    # attributes
    has created_at
  end

  # ...
end

在該示例中,subject,author和created_at是可排序的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM