I have a scenario that, I want to exclude some templates(Items that are based on these templates are need to be excluded) from solr Suggestion/autocomplete results.
I did set a context field as _template.
<!-- Solr Auto Suggest starts -->
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">default</str>
<str name="lookupImpl">AnalyzingInfixLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">_name</str>
<str name="contextField">_template</str>
<str name="suggestAnalyzerFieldType">text_general</str>
<str name="buildOnStartup">true</str>
</lst>
</searchComponent>
In code, I passed a template ID and I'm getting results based on that template.
But now, I need to remove the result items based on some template ID's(multi-list of excluding templates). How I can achieve this? Any help on this.
my code:
public static List<string> GetSuggestions(IProviderSearchContext context, string term, ID template, int numberResults)
{
var suggestedList = new List<string>();
SolrSuggestQuery query = term;
var options = new SuggestHandlerQueryOptions
{
Parameters = new SuggestParameters
{
Count = numberResults
}
};
if (!template.IsNull)
{
options.Parameters.ContextFilterQuery = template.Guid.ToString("N");
}
var result = context.Suggest(query, options);
suggestedList = result.Suggestions["default"].Suggestions.Select(a => a.Term).ToList();
return suggestedList;
}
or Do I need to add a new field to the solrconfig.xml(sitecore_master_index) file? if so, please attach an example for this?