简体   繁体   中英

Ruby on Rails - SunSpot doesn't return anything

When I search a model, sunspot doesn't return anything:

routes.rb

get 'product/:q' => 'store#product'

store_controller.rb

if (!!(params[:q] =~ /^[-+]?[0-9]+$/)) == false #if no number
  @note = "hello"
  @search = Product.search do
    fulltext params[:q]
  @note2 = "hello2"
  end
@food_input = @search.results

else #if number
  @food_input = params[:q]
end

product.rb

class Product < ActiveRecord::Base
  searchable do
    text :name
  end
end

product.html.erb

<% if @search.present? %>
<% @food_input.each do |product| %>
<%= link_to product.name, product.barcode_number %>
<% end %>
<p>is number?: <%= !!(params[:q] =~ /^[-+]?[0-9]+$/) %></p>
<p>param q: <%= params[:q] %></p>
<p>empty?: <%= @food_input.empty? %></p>
<p>note: <%= @note %></p>
<p>note2: <%= @note2 %></p>

Browser output when searching for Kat:

is number?: false
param q: Kat
empty?: true
note: hello
note2:

As you can see, no results, no @note2 variable. Does anyone know why?

根据我的评论: rake sunspot:reindex ,现在您可以将问题标记为已回答;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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