我正在使用此代码查询Solr,我可以看到从Solr返回的facet但由于某种原因它们没有通过。
public class HomeController : Controller
{
private readonly ISolrReadOnlyOperations<Product> _solr;
public HomeController(ISolrReadOnlyOperations<Product> solr)
{
_solr = solr;
}
public ActionResult Index()
{
var queryOptions = new QueryOptions()
{
Rows = 5,
Facet = new FacetParameters
{
Queries = new[] { new SolrFacetFieldQuery("brand") }
}
};
SolrQueryByField query = new SolrQueryByField("category", "phones-tablets/mobile-phones");
SolrQueryResults<Product> results = _solr.Query(query, queryOptions);
return View();
}
}
当我粘贴网址时,我可以按预期看到方面部分。但是results.FacetQueries.Count为零。我错过了什么吗?
答案 0 :(得分:1)
FacetQueries使用for returning the result的explicit facet queries。您正在进行定期分面。可以通过results.FacetFields
访问该结果。来自the documentation:
var r = solr.Query(...);
foreach (var facet in r.FacetFields["category"]) {
Console.WriteLine("{0}: {1}", facet.Key, facet.Value);
}