【问题标题】:Rails 3 - Solr doesn't search an itemsRails 3 - Solr 不搜索项目
【发布时间】:2012-03-07 17:24:19
【问题描述】:

在 Photo 模型中,我有以下简单规则:

  searchable do
    string :note
  end

我尝试使用 Solr 搜索一些字符串(同时在两个表中)。这是终端中 Solr query 的输出(第一个用于Articles,第二个用于Photos):

SOLR 请求(4.8 毫秒)[路径=# 参数={数据:fq=type%3A Article&q=searched_string&fl=%2A+score&qf=title+content&defType=dismax&start=0&rows=30,方法:post,参数:{:wt=>:ruby},查询:wt=ruby,标题: {"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}, 路径:选择,uri:http://localhost:8982/solr/select?wt=ruby, open_timeout: , read_timeout: } ]

还有这个

SOLR 请求(4.4 毫秒)[路径=# 参数={数据:fq=type%3A Photo&q=asgasg&fl=%2A+score&defType=dismax&start=0&rows=30,方法:post,参数:{:wt=>:ruby},查询:wt=ruby,标题: {"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}, 路径:选择,uri:http://localhost:8982/solr/select?wt=ruby, open_timeout: , read_timeout: } ]

控制器:

@articles = Article.search do
  fulltext params[:search]
end
@photos = Photo.search do
  fulltext params[:search]
end
## => searching ##
puts @articles.results #work fine
puts @photos.results #always 0

我完全不知道,为什么 SOLR 不在 Photo 模型中搜索...一切都应该指定和设置,但仍然不知道问题出在哪里。 ..

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 full-text-search sunspot-rails sunspot-solr


    【解决方案1】:

    我认为在照片模型中你必须将:note 定义为text 类型(而不是string)才能对其进行全文搜索:

    searchable do
      text :note
    end
    

    另外,您设置了@articles 和@photos,但在您的问题中检查@users 和@photos。

    更新

    根据sunspot readme:

    “文本字段将是全文搜索。其他字段(例如,整数和字符串)可用于范围查询”

    也就是说,要在该字段上运行fulltext 或keywords,它必须在可搜索块中声明为text。你有它作为string,它只能用于使用with()的精确匹配。

    祝你好运。

    【讨论】:

    • note 是varchar(255),而不是使用fulltext 我尝试在那里使用keywords,但仍然没有。
    • 感谢您的帮助,西蒙。我在单独的帖子中发布了解决方案。好吧...我也尝试将字符串与with clausule 一起使用,但这对我不起作用...我尝试在文本/字符串列上进行搜索,并且在没有设置with 部分的情况下运行良好。看起来总是需要重新索引 SOLR,如果在模型中的 searchable 部分进行了一些更改...
    【解决方案2】:

    我的问题的工作解决方案: 1.停止rails服务器 2. 耙太阳黑子:reindex 3. 运行rails服务器

    如果searchable 块中的所有内容都发生了变化,则需要重新索引数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多