0

我正在使用太阳黑子搜索我的本地数据库。添加 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 中设置)

在此处输入图像描述

4

1 回答 1

0

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

rake sunspot:solr:reindex

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

rake sunspot:solr:reindex[500,Style]

根据 Github 上的 Sunspot doco(搜索“重新索引对象”)。

仅供参考,要Style.reindex用于非模式更改,您必须调用Sunspot.commit以保存更改。

于 2013-05-08T06:46:25.540 回答