我正在尝试使用 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"/>