简体   繁体   English

@ sun.pot_rails时,@ search.results = []

[英]@search.results = [] when using sunspot_rails

It seems that view's search form can certainly cast the search word, but @search.results equals []. 似乎view的搜索形式可以强制转换搜索词,但是@ search.results等于[]。 And when I check Solr admin, reindex looks go well but I cannot search here, too. 当我检查Solr admin时,重新索引的外观看起来不错,但我也无法在此处搜索。 Please give me your advice. 请给我您的建议。

Showing relevant files below. 在下面显示相关文件。

messages_controller.rb messages_controller.rb

def index
   @search = Message.all.search do
     fulltext params[:search]
   end
   @messages = @search.results
end

message.rb message.rb

class Message < ActiveRecord::Base
  belongs_to :user
  scope :recent, -> { order(created_at: :desc) }
  validates :content, presence: true, length: { maximum: 200 }
  validates :user_id, presence: true

  searchable do
    string :content
  end
end

home.html.erb home.html.erb

<%= form_tag messages_path, :method => :get do %>
        <p>
          <%= text_field_tag :search, params[:search] %>
          <%= submit_tag "Search", :name => nil %>
          <% end %>

routes.rb routes.rb

  resources :messages, only: [:index, :new, :create, :destroy]

Thanks, 谢谢,

Change: 更改:

searchable do
  string :content
end

To: 至:

searchable do
  text :content
end

From the doc: text fields will be full-text searchable. 从doc:文本字段将是全文搜索的。 Other fields (eg, integer and string) can be used to scope queries. 其他字段(例如,整数和字符串)可用于范围查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM