1

我正在尝试使用 Solr、SolrNet 及其使用 asp.net MCV 3 构建的产品目录应用程序实现分面。到目前为止,我设法列出了所有产品结果,但没有列出分面。我可以打印如下所示的方面。

<ul>
    @foreach (var facet in Model.Products.FacetFields["brand"])
    {
      <li>@facet.Key (@facet.Value)</li>
    }
</ul>

上面的代码有两个问题,

1)如果搜索结果不包含品牌的方面,则抛出此错误给定的键不在字典中。

System.Collections.Generic.KeyNotFoundException:给定的键不在字典中。在 System.Collections.Generic.Dictionary

2)我需要将构面键和值显示为链接。所以点击那个方面我应该能够列出这个方面的产品。

这是schema.xml,如果您知道上述问题的答案,请帮助我。

<field name="product_id" type="string" indexed="true" stored="true" required="true" /> 
<field name="name" type="string" indexed="true" stored="true"/>
<field name="merchant" type="string" indexed="true" stored="true"/>
<field name="merchant_id" type="string" indexed="true" stored="true"/>
<field name="brand" type="string" indexed="true" stored="true"/>
<field name="brand_id" type="string" indexed="true" stored="true"/>
<field name="categories" type="string" multiValued="true" indexed="true" stored="true"/>
4

1 回答 1

1

1)如果搜索结果不包含品牌的方面,则抛出此错误给定的键不在字典中。

如果您没有对该字段进行构面字段查询,请不要在结果中要求它。

2)我需要将构面键和值显示为链接。所以点击那个方面我应该能够列出这个方面的产品。

基本上,您需要将单击的构面值转换为过滤器查询。根据您的特定应用程序需求,有很多方法可以实现这一点。请参阅SolrNet 示例应用程序以了解一种方法,使用其源代码作为指导。

于 2011-04-23T23:08:49.497 回答