gpt4 book ai didi

ruby - 是否为 :include inside a sunspot/solr searchable method do anything?

转载 作者:数据小太阳 更新时间:2023-10-29 07:57:26 25 4
gpt4 key购买 nike

我首先使用以下包含语句对我的 solr 索引的 2 个版本进行了基准测试:

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 将:

allow ActiveRecord to load required associations when indexing.

您的基准测试无法正常工作,因为您在普通的 Ruby 迭代器中索引单个记录。当您为单个记录编制索引 50 次时,Sunspot 根本无法使用预先加载。相反,你应该这样做:

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

哦,你能测试下面是否比上面更快吗?我真的很想知道。

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

还有一个bug目前,STI 模型将忽略 :include

关于ruby - 是否为 :include inside a sunspot/solr searchable method do anything?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7287943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com