ruby-on-rails – 非关键字搜索的Solr(太阳黑子)查询时间提升
鉴于我想找到20个相关结果,我将如何提升any_of中的第一个条件(使用(:id).any_of(co_author_ids)),这样如果有20个符合所述条件的结果,它将返回而不是尝试根据第二个标准进行匹配?
@solr_search = User.solr_search do paginate(:per_page => 20) with(:has_email,true) any_of do with(:id).any_of(co_author_ids) with(:hospitals_id).any_of(hopital_ids) end end 最初我并不认为增强是必要的,因为我认为any_of会产生级联效应,但它看起来并不像那样.我知道在查询关键字和全文搜索时会对查询时间进行提升,但却无法使用with()方法. 解决方法
由于co_author_ids是一个多值密钥,我有足够的理由相信没有办法实现这一点.虽然使用单值键,但可以通过使用函数查询使用solr排序来实现此级联效果.
http://wiki.apache.org/solr/FunctionQuery#Sort_By_Function aong with adjust_solr-params
http://sunspot.github.io/docs/Sunspot/DSL/Adjustable.html
例: @solr_search = User.solr_search do paginate(:per_page => 20) with(:has_email,true) any_of do with(:id,author_id) #assuming author id is a solr index with(:hospitals_id).any_of(hopital_ids) end end 现在在这种情况下你想要一个级联效果,并希望更多地优先考虑与author_id完全匹配,你可以这样做 @solr_search = User.solr_search do paginate(:per_page => 20) with(:has_email,author_id) #assuming author id is a solr index with(:hospitals_id).any_of(hopital_ids) end adjust_solr_params do |p| p["sort"] = "if(author_id_i = #{id},1,0) desc" #note author_id_i solr eq of author_id end end 因此,这将基于if(author_id_i =#{id},0)的值进行排序,并且作为回报,将把auhtor_id的所有记录与用户的顶部相同. 我不知何故使用IF函数遇到问题所以我改为使用(实际上它们都是相同的): @solr_search = User.solr_search do paginate(:per_page => 20) with(:has_email,author_id) #assuming author id is a solr index with(:hospitals_id).any_of(hopital_ids) end adjust_solr_params do |p| p[:sort] = "min(abs(sub(author_id_i,#{id})),1) asc" end end 我也偶然发现了http://wiki.apache.org/solr/SpatialSearch,同时寻找一个解决方案,如果你想按距离排序,你可以这样做: @solr_search = User.solr_search do paginate(:per_page => 20) with(:has_email,author_id) #assuming author id is a solr index with(:hospitals_id).any_of(hopital_ids) end adjust_solr_params do |p| p[:pt] = "#{latitude_of_your_interest},#{longitude_of_your_interest}" p[:sfield] = :author_location #your solr index which stores location of the author p[:sort] = "geodist() asc" end end 总的来说,我会说你可以用p [“sort”]做很多很酷的事情但是在这种特殊情况下它不能完成(imho)因为它是一个多值字段 我希望他们可以为多值字段提供一个包含函数,我们可以写 但截至目前,这是不可能的(再次imho). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ruby-on-rails – Rails自动加载完全大写的名称,如API
- c# – 使用ASP.NET Boilerplate将ValueObject存储在数据库中
- OK6410烧写裸机程序到nandflash,不使用jlink,支持大文件烧
- .net – 调用XmlReader :: ReadStartElement时抛出InvalidO
- Error parsing XML: mismatched tag
- ruby-on-rails – Rails关系表,来自同一个表的多个id
- ios – 无法在我的XCode项目中找到Cordova.plist
- 05-Swift循环
- Swift Mailer ——Comprehensive mailing tools for PHP
- C:声明“返回A ||”当A> 1时,1’返回?