【问题标题】:Query always the same with Sunspot/Solr on rails使用轨道上的 Sunspot/Solr 查询始终相同
【发布时间】:2015-06-10 13:16:45
【问题描述】:

我有太阳黑子的问题。当我执行 SOLR 请求时,我总是有相同的查询。

SOLR Request (3.7ms) [ path=select parameters={fq: ["type:Tag"], start: 0, rows: 30, q: "*:*"} ]

无论我在搜索字段中输入什么,它总是相同的查询

这是我的代码:

tag.rb

class Tag < ActiveRecord::Base
    belongs_to :pictogram
    searchable do
        text :name
    end
end

searchs_controller.rb

class SearchsController < ApplicationController
    def index
        if params[:search]
            pictograms = Array.new
            @term = params[:query]
            search = Tag.search do
                fulltext @term
            end


            index = 0
            search.results.each do |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 do %>
    <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 %>

【问题讨论】:

    标签: ruby-on-rails ruby solr sunspot sunspot-rails


    【解决方案1】:

    我认为您用于搜索的参数不正确。

    <%= search_field_tag :term,"#{@term}", class: 'form-control' %>
    

    表示您传递回控制器的参数是 [:term],

    所以代码应该是这样的:

    if params[:term].present?
                pictograms = Array.new
                @term = params[:term]
                search = Tag.search do
                    fulltext params[:term]
                end
    

    而不是你尝试过的 params[:search] 和 params[:query]。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-08
      • 1970-01-01
      • 2012-07-31
      • 2014-09-25
      相关资源
      最近更新 更多