0

I'm trying to implement the Sitecore SXA auto suggest search functionality, below is the setup

<searchComponent name="suggest" class="solr.SuggestComponent"> 
 <lst name="suggester"> 
  <str name="name">sxaSuggester</str> 
  <str name="dictionaryImpl">DocumentDictionaryFactory</str>
  <str name="field">sxacontent_txm</str> 
  <str name="suggestAnalyzerFieldType">text_suggester</str> 
  <str name="buildOnStartup">true</str> 
 </lst> 
</searchComponent>

<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy" > 
 <lst name="defaults"> 
  <str name="suggest.dictionary">sxaSuggester</str>
  <str name="suggest">true</str> 
  <str name="suggest.count">10</str> 
 </lst> 
 <arr name="components"> 
  <str>suggest</str> 
 </arr> 
</requestHandler>

enter image description here

My Sitecore instance is throwing the below error.

Error:

    "Message": "An error has occurred.", "ExceptionMessage":"The given key was not present in the
dictionary.","ExceptionType":"System.Collections.Generic.KeyNotFoundException","StackTrace":"at
System.ThrowHelper.ThrowKeyNotFoundException()\r\n at System.Collections.Generic.Dictionary`2.get_Item(TKey key)\r\n at
Sitecore.XA.Foundation.Search.Providers.Solr.Services.SolrSuggester.GetSuggestions(SuggesterModel model, Timer&
queryTimer, String& indexName)\r\n at
Sitecore.XA.Feature.Search.Controllers.SearchController.SearchSuggestions(SuggesterModel model)\r\n at
lambda_method(Closure, Object, Object[])\r\n at
System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_1.<GetExecutor>b__3(Object
        instance, Object[] methodParameters)\r\n at
        System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext,
        IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location
        where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at
        System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at
        System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of
            stack trace from previous location where exception was thrown ---\r\n at
            System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at
            System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at
            System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack
                trace from previous location where exception was thrown ---\r\n at
                System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at
                System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of
                    stack trace from previous location where exception was thrown ---\r\n at
                    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at
                    System.Runtime.CompilerServices.TaskAwaiter.

Sitecore : 9.2 Solr : 7.5

Please let me know if I'm missing something here.

3

You should use the AnalyzingInfixLookupFactory , see below section.

Please note the lookupImpl and dictionaryImpl fields. The AnalyzingInfixLookupFactory is currently supported by SOLR 7.5 - Context filtering lets you filter suggestions by a separate context field, such as category, department or any other token. The AnalyzingInfixLookupFactory and BlendedInfixLookupFactory currently support this feature, when backed by DocumentDictionaryFactory. https://lucene.apache.org/solr/guide/8_1/suggester.html

<searchComponent name="suggest" class="solr.SuggestComponent">
  <lst name="suggester">
    <str name="name">sxaSuggester</str>
    <str name="lookupImpl">AnalyzingInfixLookupFactory</str>
    <str name="dictionaryImpl">DocumentDictionaryFactory</str>
    <str name="field">sxacontent_txm</str>
    <str name="contextField">_template</str> 
    <str name="suggestAnalyzerFieldType">text_general</str>
    <str name="buildOnStartup">false</str>
  </lst>
</searchComponent>

Shameless Plug - https://sitecorejumpstart.wordpress.com/2019/10/06/sitecore-solr-autosuggest-with-template-and-language-filters/

Hope this helps!.

  • Hi @Abhay I tried you suggestion but no luck same error. – Mrunal Brahmbhatt Oct 29 at 10:18
  • Ok, Did u restart SOLR ? – Abhay Dhar Oct 29 at 11:38
  • Reload the core – Mrunal Brahmbhatt Oct 29 at 18:56
  • After restart, it started working. thanks. – Mrunal Brahmbhatt Oct 29 at 23:00
  • Glad it worked out for you!. Please accept the answer as well – Abhay Dhar Oct 30 at 5:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.