【问题标题】:What is wrong with this Sunspot Solr setup?这个 Sunspot Solr 设置有什么问题?
【发布时间】:2013-05-08 05:26:51
【问题描述】:

我正在使用sunspot 搜索我的本地数据库。添加 gems、运行 generate 命令并启动 solr 服务器后,我执行以下操作:

class Style < ActiveRecord::Base
  attr_accessible :full_name, :brand_name
  searchable do
    text :full_name
    text :brand_name
  end
end

将以上内容添加到我的 Style 模型中并重新编制索引(我在创建这篇文章之前已经编制了索引,这就是我重新编制索引并将其放在这里的原因)

funkdified@vizio ~/rails_projects/goodsounds.org $ rake sunspot:solr:reindex
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
*Note: the reindex task will remove your current indexes and start from scratch.
If you have a large dataset, reindexing can take a very long time, possibly weeks.
This is not encouraged if you have anywhere near or over 1 million rows.
Are you sure you want to drop your indexes and completely reindex? (y/n)
y
[#######################################] [14/14] [100.00%] [00:00] [00:00] [53.19/s]

然后我尝试搜索并没有得到任何东西

1.9.3p392 :003 > Style.search { fulltext 'Monkey' }.results
  SOLR Request (10.4ms)  [ path=#<RSolr::Client:0x0000000685ab28> parameters={data: fq=type%3AStyle&q=Monkey&fl=%2A+score&qf=full_name_text+brand_name_text&defType=dismax&start=0&rows=30, method: post, params: {:wt=>:ruby}, query: wt=ruby, headers: {"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}, path: select, uri: http://localhost:8982/solr/select?wt=ruby, open_timeout: , read_timeout: , retry_503: , retry_after_limit: } ]
 => [] 

但是,等一下,它不应该起作用并把它捡起来吗?

Style.first
  Style Load (1.3ms)  SELECT "styles".* FROM "styles" LIMIT 1
 => #<Style id: 54, brand_name: "Monkey", full_name "Monkey Chicken", created_at: "2013-02-01 23:25:58", updated_at: "2013-02-16 03:02:16"> 

这里还有一个线索。我看到 brand_name 的“未知字段”(在 Style.rb 中设置)

【问题讨论】:

    标签: ruby-on-rails solr sunspot


    【解决方案1】:

    如果您更改架构(“可搜索”块),您必须重新索引所有模型:

    rake sunspot:solr:reindex
    

    或使用给定的批量大小(此处为 500)重新索引该特定模型:

    rake sunspot:solr:reindex[500,Style]
    

    根据太阳黑子doco on Github(搜索“重新索引对象”)。

    仅供参考,要将Style.reindex 用于非架构更改,您必须调用Sunspot.commit 来保存更改。

    【讨论】:

    • 这很奇怪——我实际上构建了一个 Style 模型来匹配你上面的模型,它在默认生成的配置下工作得很好。我假设您使用的是 Mac 或 Linux - sunspot_solr 通常比 PC 上的失败更严重。如果您创建一个仅包含样式模型的新应用程序并使用rails g sunspot_rails:install 生成设置,它会起作用吗?
    • 是的,我正在运行 Mint 14 (ubuntu quantal)
    • 我怀疑存在 gem 冲突,但我只能找到一个冲突的 gem.. 那是我没有使用的活动管理员 mrdanadams.com/2012/…
    • 是否需要将可搜索逻辑放置在我的 style.rb 文件中的任何特定位置?我在belongs_to关联逻辑之后就有了它
    • 我讨厌事情变得像那样奇怪,但很高兴你的项目正在运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-12
    • 1970-01-01
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    • 2016-02-11
    相关资源
    最近更新 更多