做什么:在太阳黑子/ solr搜索方法中包含什么内容?

问题描述:

我基准2版我的Solr索引的第一个具有以下包括语句:做什么:在太阳黑子/ solr搜索方法中包含什么内容?

searchable(:auto_index => false, :auto_remove => true, 
      :include => { :account => true, 
      :user_practice_contact => [:city], 
      :user_professional_detail => [:specialty, :subspecialties]}) do 

第二:

searchable(:auto_index => false, :auto_remove => true) do 

我期待看到一个减速的版本包括但在这里是结果:

版本包括:

Benchmark.measure { User.limit(50).each do |u|; u.index; end; Sunspot.commit; } 
    => #<Benchmark::Tms:0x1130b34e8 @real=6.8079788684845, @utime=5.05, @cstime=0.0, @cutime=0.0, @total=5.2, @label="", @stime=0.149999999999999> 

和不包括:

Benchmark.measure { User.limit(50).each do |u|; u.index; end; Sunspot.commit; } 
=> #<Benchmark::Tms:0x112ef0fe8 @real=6.82465195655823, @utime=4.92, @cstime=0.0, @cutime=0.0, @total=5.07, @label="", @stime=0.15> 

有谁知道,如果包括应该工作?如果是这样,我做错了吗? 我看了一下文档:http://outoftime.github.com/sunspot/rails/docs/,并没有提到这一点。

根据the API:include将会:

允许的ActiveRecord当索引加载所需的关联。

您的基准测试无法正常工作,因为您正在将普通Ruby迭代器中的单个记录编入索引。当您将单个记录编入索引50次时,太阳黑子根本无法利用急切的加载。相反,你应该这样做:

Sunspot.index(User.limit(50)); 
Sunspot.commit 

哦,你可以测试,如果以下是比以上更快?我真的很想知道。

Sunspot.index(User.includes(:account).limit(50)); 
Sunspot.commit 

也有一个bug目前该STI车型将忽略:include

通过查看Rails日志中的SQL查询,您可以看到:include在可搜索的页面上导致在索引编制时进行加载。 #search上的:include在搜索时导致急切加载。