【问题标题】:Sunspot not working properly in Ruby on RailsSunspot 在 Ruby on Rails 中无法正常工作
【发布时间】:2015-05-04 10:15:35
【问题描述】:

我正在使用以下宝石

gem 'sunspot_rails'
gem 'sunspot_solr'

在模型中,我也提到并且我也重新索引了太阳黑子,所有都已尝试但不知道它没有返回任何结果是什么问题:

searchable do
  text :email
end

对于搜索,当我按照它的文档进行搜索时,一切正常,没有错误但没有结果。它也总是返回这样的输出:

<Sunspot::Search:{:fq=>["type:User"], :q=>"talentuser1", :fl=>"* score", :qf=>"email_text", :defType
=>"edismax", :start=>0, :rows=>30}>

如果有人遇到过这类问题,请帮我解决这个问题。

谢谢

【问题讨论】:

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


    【解决方案1】:

    根据文档,首先我们应该配置 SOLR,示例(Inside Post 模型):

    searchable do
      integer :blog_id
      integer :category_id
    end
    
    self.search(options) do
      any_of do
        with(:blog_id, options[:blog_id])
        with(:category_id, options[:category_id])
      end
    end
    

    然后,我们必须做rake sunspot:solr:reindex
    然后,得到结果

    post = Post.search(:blog_id => 1, :category_id => 2)
    results = post.results
    

    这些步骤应该会为您提供搜索结果

    【讨论】:

    • 兄弟,我已经这样做了,就像:searchable do text :email end
    • @user3436543 在那之后你要重新索引吗?而且,您在问题中提到的输出是标准 solr 输出,唯一需要做的就是获取结果
    • 是的,我做到了,我正在尝试获取记录它显示为零的记录,但表中有记录
    • 这对我来说似乎是一个重新索引问题,尝试重新启动 solr rake sunspot:solr:stop 然后 rake sunspot:solr:start 并重新索引它 rake sunspot:solr:reindex
    • 嘿,兄弟,它工作正常实际上没有问题,只需重新启动我的电脑,它工作正常,但你能帮我,我们如何获取多条记录,因为当我搜索它与用户 ID 相关但我希望基于特定文件搜索所有用户而不是特定用户
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-04
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多