SolrNet facet从Solr返回,但不通过SolrNet客户端返回

时间:2018-05-04 18:48:43

标签: solr solrnet

我正在使用此代码查询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();
    }

}

以上代码最终会生成此网址http://localhost:8983/solr/new_core/select?q=category%3a(phones%5c-tablets%5c%2fmobile%5c-phones)&rows=5&facet=true&facet.field=brand&version=2.2&wt=xml

当我粘贴网址时,我可以按预期看到方面部分。但是results.FacetQueries.Count为零。我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

FacetQueries使用for returning the resultexplicit 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);
}