ruby - Query always the same with Sunspot/Solr on rails -
i have problem sunspot. when solr request have same query.
solr request (3.7ms) [ path=select parameters={fq: ["type:tag"], start: 0, rows: 30, q: "*:*"} ]
no matter type in search field , it's same query
here code :
tag.rb
class tag < activerecord::base belongs_to :pictogram searchable text :name end end
searchs_controller.rb
class searchscontroller < applicationcontroller def index if params[:search] pictograms = array.new @term = params[:query] search = tag.search fulltext @term end index = 0 search.results.each |t| if !pictograms.include? t.pictogram pictograms[index] = t.pictogram index = index + 1 end end @results = pictograms.group_by { |p| p.category } @search_mode = true end end end
index.html
<%= form_tag result_search_path %> <div class="input-group input-group-lg"> <%= search_field_tag :term,"#{@term}", class: 'form-control' %> <span class="input-group-btn"> <%= submit_tag "search", :class => 'btn btn-primary btn' %> </span> </div> <% end %>
i think params using search not correct.
<%= search_field_tag :term,"#{@term}", class: 'form-control' %>
means params passing controller [:term],
so code should like:
if params[:term].present? pictograms = array.new @term = params[:term] search = tag.search fulltext params[:term] end
and not params[:search] , params[:query] have tried.
Comments
Post a Comment