I was tasked to create a facet component for our solution on top of an already existing search functionality - which is an API controller.
The code snippet I added is the use of .FacetOn(x => x[key])
and .GetResults()
but this returns an empty set:
//queryResults is an IQueryable<SearchResultItem>
//searchparams is the JSON request body
//fl is the list of facet titles from JSON request body
//e.g. "Tag List","Action"
var facets = searchparams.fs.Split(','); //["Tag List","Action"]
//Converts facet titles to index keys (info stored as item in Sitecore)
//["tag_list_sm","action_sm"]
var keyList = this.GetFacetKeys(facets);
foreach (var key in keyList)
{
queryResults.FacetOn(x => x[key] != null);
//also tried
//queryResults.FacetOn(x => x[key]);
}
var results = queryResults.GetResults(); //shows result items, but no facets
The tags are stored as a TreeList on the target pages, and are filled up.
Am I missing something? Do I have to add something in the defaultSolrIndexConfiguration
node of Sitecore? I also tried creating a model that contains the fields that I need but it still won't show.
public class SearchPage: SearchResultItem
{
[IndexField("action_sm")]
public string Action{ get; set; }
[IndexField("tag_list_sm")]
public string TagList{ get; set; }
}
facet=on
andfacet.fields
are not included in the query. How is that possible? @_@