Sunspot Solr - 使用方面
我已经使用 Sunspot、SOLR 设置了多面搜索。像这样:
for row in @search.facet(:facet_id).rows
link_to row.instance.name, :url_for(:search => params[:q], :facet_id => row.value)
我的问题是,当我在控制器中执行分面搜索时,如下所示:
@search = Sunspot.search(MyModel) do
keywords search_text
facet :facet_id
with(:facet_id, params[:facet_id]) if params[:facet_id].present?
end
分面计数现在是根据 with(:facet_id, params[:facet_id]) 条件计算的。我希望在没有这种条件的情况下始终计算构面计数。
我需要执行两次搜索吗?一种用于不带条件的搜索(以计算构面计数),另一种用于带条件的搜索以检索结果。或者有没有一种方法可以在一个 SOLR 查询中执行此操作。
谢谢哈米什
I have setup faceted search using Sunspot, SOLR. Like this:
for row in @search.facet(:facet_id).rows
link_to row.instance.name, :url_for(:search => params[:q], :facet_id => row.value)
My issue is that when I execute the faceted search in the controller like this:
@search = Sunspot.search(MyModel) do
keywords search_text
facet :facet_id
with(:facet_id, params[:facet_id]) if params[:facet_id].present?
end
The facet counts are now calculated based on the with(:facet_id, params[:facet_id]) condition. I want the facet counts to ALWAYS be calculated without this condition.
Do I need to execute two searches? One for the search without the conditions (to calculate the facet counts) and one with the condition to retrieve the results. Or is there a way to do this in one SOLR query.
Thanks
Hamish
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Solr 有(并且 Sunspot 支持)一个称为“多选方面”的概念,这正是您在这里所需要的。本质上,您可以告诉 Solr 忽略一个条件(或多个条件),只是为了计算某个方面。所以你在这里想做的是:
希望有帮助。
Solr has (and Sunspot supports) a concept called "multiselect facets", which is what you need here. Essentially you can tell Solr to ignore a condition (or multiple conditions) just for the purposes of calculating a certain facet. So what you'd want to do here is:
Hope that helps.