简体   繁体   English

太阳黑子Solr-使用构面

[英]Sunspot Solr - working with facets

I have setup faceted search using Sunspot, SOLR. 我已经使用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. 现在根据with(:facet_id,params [:facet_id])条件来计算构面计数。 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. 还是有一种方法可以在一个SOLR查询中做到这一点。

Thanks 谢谢

Hamish 哈米什

Solr has (and Sunspot supports) a concept called "multiselect facets", which is what you need here. Solr具有(并且受Sunspot支持)一个称为“多选面”的概念,这是您在这里需要的。 Essentially you can tell Solr to ignore a condition (or multiple conditions) just for the purposes of calculating a certain facet. 本质上,您可以告诉Solr仅出于计算某个方面的目的而忽略一个条件(或多个条件)。 So what you'd want to do here is: 因此,您想要在这里做的是:

Sunspot.search(MyModel) do
  facet_restriction = with(:facet_id, params[:facet_id])
  facet(:facet_id, :exclude => facet_restriction)
end

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM