我正在使用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中设置)
答案 0 :(得分:0)
如果更改架构(“可搜索”块),则必须重新索引所有模型:
rake sunspot:solr:reindex
或重新索引具有给定批量大小(此处为500)的特定模型:
rake sunspot:solr:reindex[500,Style]
根据太阳黑子doco on Github(搜索“重新索引对象”)。
仅供参考,要使用Style.reindex
进行非架构更改,您必须致电Sunspot.commit
以保存更改。