SolrNet 方面正在从 Solr 但不是通过 SolrNet 客户端返回
SolrNet facets are being returned from Solr but not through the SolrNet client
我正在使用此代码查询 Solr,我可以看到 facet 正在从 Solr 返回,但由于某些原因它们没有通过。
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();
}
}
上面的代码最终生成了这个 url 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
当我粘贴 URL 时,我可以按预期看到构面部分。但是 results.FacetQueries.Count 为零。我错过了什么吗?
使用了 FacetQueries for returning the result of explicit facet queries. You're performing regular faceting. That result can be accessed through results.FacetFields
. From the documentation:
var r = solr.Query(...);
foreach (var facet in r.FacetFields["category"]) {
Console.WriteLine("{0}: {1}", facet.Key, facet.Value);
}
我正在使用此代码查询 Solr,我可以看到 facet 正在从 Solr 返回,但由于某些原因它们没有通过。
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();
}
}
上面的代码最终生成了这个 url 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
当我粘贴 URL 时,我可以按预期看到构面部分。但是 results.FacetQueries.Count 为零。我错过了什么吗?
使用了 FacetQueries for returning the result of explicit facet queries. You're performing regular faceting. That result can be accessed through results.FacetFields
. From the documentation:
var r = solr.Query(...);
foreach (var facet in r.FacetFields["category"]) {
Console.WriteLine("{0}: {1}", facet.Key, facet.Value);
}