SP2013 - Get Query Suggestions to work with your custom result source in the Search Center.

Hi Search Enthusiasts !

As a reminder about what Query Suggestions are in SP2013 Search:

Query suggestions help users find information quickly by showing queries that might be similar to the one they're typing. For example, as users start to type "sales", they may be able to pick common sales-related queries from a list below the Search Box.

The search system automatically creates suggestions for a query when users have clicked one or more of the results for that query at least six times. The query suggestions are generated daily for each result source and for each site collection, so the automatic query suggestions can be different for different result sources and site collections.

https://technet.microsoft.com/en-us/library/jj721441.aspx

One common question I received is why you don't have suggestions in my Search Center if you're using the non default "Local SharePoint Results".

Well the answer lies in how the default Search Box Web Part builds the Query Suggestions CSOM Query (client.svc/ProcessQuery) with method name "GetQuerySuggestionsWithResults".

 

There are 2 Search Box in the Search Center. One in the landing page and one in results page.

 

From the landing page, the Search Box WP by default sends a query to the hardcoded 8413CD39-2156-4E00-B54D-11EFD9ABDB89 source aka "Local SharePoint Results". 

To see the source in the CSOM query use any F12 or Fiddler to show the request sent to client.svc.  

<Request xmlns="https://schemas.microsoft.com/sharepoint/clientquery/2009" SchemaVersion="15.0.0.0" LibraryVersion="15.0.0.0" ApplicationName="Javascript Library"><Actions><ObjectPath Id="1" ObjectPathId="0" /><SetProperty Id="2" ObjectPathId="0" Name="QueryText"><Parameter Type="String">sha</Parameter></SetProperty><SetProperty Id="3" ObjectPathId="0" Name="Culture"><Parameter Type="Number">1033</Parameter></SetProperty><SetProperty Id="4" ObjectPathId="0" Name="ShowPeopleNameSuggestions"><Parameter Type="Boolean">false</Parameter></SetProperty><SetProperty Id="5" ObjectPathId="0" Name="SourceId"><Parameter Type="Guid"> {8413cd39-2156-4e00-b54d-11efd9abdb89} </Parameter></SetProperty><Method Name="GetQuerySuggestionsWithResults" Id="6" ObjectPathId="0"><Parameters><Parameter Type="Number">5</Parameter><Parameter Type="Number">3</Parameter><Parameter Type="Boolean">true</Parameter><Parameter Type="Boolean">true</Parameter><Parameter Type="Boolean">false</Parameter><Parameter Type="Boolean">false</Parameter></Parameters></Method></Actions><ObjectPaths><Constructor Id="0" TypeId="{80173281-fffd-47b6-9a49-312e06ff8428}" /></ObjectPaths></Request>

The SBWP attribute used for setting the SourceId in the CSOM Query is called QuerySuggestionsSourceID !

        <property name="QuerySuggestionsSourceID" type="string">8413CD39-2156-4E00-B54D-11EFD9ABDB89</property>

Hence to change it, export the landing Search Box web part, adapt it and re-upload it.

 

The second Search Box Web Part is located in the search results page.

The default value on that Search Box is null meaning the suggestions will be fetched against the "Local SharePoint Results" Result Source.

<property name="QuerySuggestionsSourceID" type="string" null="true" />

Important about the possible values of the source id

  • A specific GUID to point to your custom result source

<property name="QuerySuggestionsSourceID" type="string">06c3729e-eb18-499b-ad9f-649f392bb4e1</property>

  • An empty GUID Source Id shall return query suggestions for all Result Sources (Site Collection filter still applies though)

        <property name="QuerySuggestionsSourceID" type="string">00000000-0000-0000-0000-000000000000</property>

  • A null Source Id shall return Query suggestions from the "Local SharePoint Results"

<property name="QuerySuggestionsSourceID" type="string" null="true" />

 

I hope this can help improving the Query Suggestions in our SP2013.

 

Stay tuned.