【问题标题】:Rails 4 - Sunspot returning empty results on all queriesRails 4 - Sunspot 在所有查询中返回空结果
【发布时间】:2016-02-24 15:13:41
【问题描述】:

我有一个希望对其执行搜索的 Person 模型。

class Person < ActiveRecord::Base

  searchable do
    text :first_name, :last_name, :boost => 2
    text :email, :phone
  end

end

我已经从 people_controller 中移除了搜索功能,因为从长远来看,我希望扩大搜索所有模型的范围。这是搜索控制器

class SearchController < ApplicationController
  def index
    @people = Person.search do
      fulltext params[:search]
    end
    @results = @people.results
  end
end

我正在使用 UJS 在页面的搜索窗格中呈现搜索结果。目前 search/index.js.erb 附加了上述@results 变量的调试输出。

$('#search-results').empty();
$('#search-results').append('<%= j debug @results %>');

我尝试的每个查询都会返回以下结果。

--- !ruby/array:Sunspot::Search::PaginatedCollection
internal: []
ivars:
  :@current_page: 1
  :@per_page: 30
  :@total_count: 0

在 Rails 控制台中显示以下内容。

Parameters: {"utf8"=>"✓", "search"=>"Sabrina", "commit"=>"Go"}
  SOLR Request (4.7ms)  [ path=select parameters={fq: ["type:Person"], q: "Sabrina", fl: "* score", qf: "first_name_text last_name_text email_text phone_text", defType: "edismax", start: 0, rows: 30} ]

请务必注意,此查询是从数据库中的一个人那里复制/粘贴的。最初我担心容错性甚至不允许出现轻微的拼写错误。

这开始变得非常令人沮丧,到目前为止,我已经删除并重新安装了最新的 JDK,并重新启动了我的机器。在这一点上,我还没有看到任何错误或失败的依赖等。有一个可能的例外:当我运行 rake sunspot:solr:reindex 我在终端中只得到以下内容

Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile

我的问题是:我做错了什么?

【问题讨论】:

    标签: ruby-on-rails solr sunspot


    【解决方案1】:

    试试这个

    class SearchController < ApplicationController
     def index
      @people = Sunspot.search(Person) do
      fulltext params[:search]
     end
      @results = @people.results
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2015-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-18
      • 2021-11-20
      相关资源
      最近更新 更多