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>

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?

  • those can be excluded in code level before returning suggestedlist
    – Abhay Dhar
    Apr 20, 2020 at 13:21
  • Can you plz elaborate it? or share more details
    – Rajasekar
    Apr 21, 2020 at 2:31
  • as you have a select statement to get only .Term property, you can also add a LINQ query to select items from a selected template
    – Abhay Dhar
    Apr 21, 2020 at 5:14
  • 1
    Could you explain a scenario what do want to achive? Suggester is just a dictionary with words and, if needed, with catagory for each word (contextField). And that is all. You can NOT exclude something, you can only find suggestions in specific category (with contextField). If you don`t want to see some results - skip them while indexing and they will not be in suggester.
    – x3mxray
    Apr 26, 2020 at 13:03
  • 1
    If you need information about items, use usual search functionality, not suggester.
    – x3mxray
    Apr 26, 2020 at 13:06


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.