Query suggestions on mavention.nl
SharePoint 2013 ships with a rich search experience. One part of that experience is providing search query suggestions. Unfortunately those suggestions are not available for anonymous users. So what to do if you want query suggestions on your public facing website?

SharePoint 2013 search query suggestions – it’s not for anonymous

One of the biggest improvements in SharePoint 2013 is the fact that SharePoint Search and FAST Search are now one, so whenever you install SharePoint 2013 you get the best-in-class search experience. FAST has been known for its advanced capabilities for years now and with SharePoint 2013 all of that is available as a part of the SharePoint platform.

SharePoint Search contains many features that you can leverage when building productivity solutions as well as public-facing websites. One of those capabilities are query suggestions.

Query suggestions in SharePoint 2013

Query suggestions, often referred to as autocomplete, make it easier for the users to use search functionality. First of all they act as an autocomplete where they save time by “guessing” what the user is about to type. Secondly they increase efficiency by preventing users from entering typos. Finally they can help them discover new content or get easier to what the users are looking for by suggesting more detailed queries. Query suggestions are quite popular in public search engines so it’s not really surprising to have them available as a part of the SharePoint platform as well.

If you’re building solutions on the SharePoint platform, as long as your users as authenticated, you can leverage the query suggestions capability that is a part of SharePoint. If your users are anonymous, like they might be on a public-facing website, no query suggestions will be displayed.

No query suggestions displayed for anonymous users in SharePoint 2013

Search Query Suggestions with Mavention Query Suggestions

If you’re looking for implementing query suggestions for anonymous users on a public-facing website, Mavention Query Suggestions is exactly what you’ve been looking for. Mavention Query Suggestions is a SharePoint 2013 Farm Solution that allows you to provide query suggestions for anonymous users in SharePoint 2013.

Search Query Suggestions displayed to anonymous users by Mavention Query Suggestions

Managing query suggestions

The Mavention Query Suggestions Solution doesn’t reuse the same query suggestions that are used for authenticated users and served by SharePoint Search. Instead it keeps its own list of query suggestions that can be managed on a per-Site Collection basis so that you can ensure that no internal data is published to your visitors and that all query suggestions are approved for your audience.

Because query suggestions are stored in a List you can use the User Interface that you are already used to to manage them. Additionally you have the full control of deciding who has the access to the suggestions.

Mavention Query Suggestions’ query suggestions stored in the Query Suggestions List

Defining query suggestions

When defining query suggestions you want to ensure that the suggestions presented to the users are meaningful and that they will actually help them. All of the query suggestions that are used by Mavention Query Suggestions are stored in a List so you can easily add and remove new suggestions yourself as your website evolves. When managing query suggestions you can use your knowledge of your audience combined perhaps with web analytics data from your analytics service to ensure that users will be provided with relevant and helpful suggestions.

Another interesting possibility that Mavention Query Suggestions offers you is gathering query suggestions from successful search queries. In this approach you add the Suggestion Processor Web Part, which is provided as a part of the Mavention Query Suggestions Solution, to your search results page and configure it to use same Query Group Name as the Search Results Web Part (which is set to Default by default).

Every single time a visitor performs a search on your site and some search results are found, the Suggestion Processor Web Part will add that search query to the Query Suggestions List. To prevent your website from displaying undesired suggestions, the automatically added query suggestion will have to be approved by you first in order to be displayed to visitors as a query suggestion.

New query suggestions still to be approved in the ‘Query Suggestions’ List

If the same query has been executed multiple times, the counter for that query suggestion will be increased after every search query and as a result that particular suggestion will be shown more often and higher in the list of suggestions than other suggestions.

Suggesting search queries

Mavention Query Suggestions provides you with a mechanism for discovering and managing query suggestions. It is however up to you to integrate them with your website.

If you’re using jQuery on your website, probably the easiest way to integrate Mavention Query Suggestions is by using the jQuery UI Autocomplete widget. Following is a sample script that you could use to wire Mavention Query Suggestions with the jQuery UI Autocomplete widget:

var Mavention = Mavention || {};

Mavention.initSearchSuggestions = function() {
    jQuery('#searchbox').autocomplete({
        source: function(request, response) {
            jQuery.ajax({
                url: '/_layouts/15/mavention/querysuggestions.ashx',
                data: { query: request.term },
                dataType: "json",
                success: function( data ) {
                    response( data );
                },
                error: function() {
                    response( [] );
                }
            });
        },
        minLength: 2,
        select: function(event, ui) {
            var $this = jQuery(this);
            $this.val(ui.item.value);
            $this.parents('form').submit();
        }
    });
}

jQuery(function () {
    Mavention.initSearchSuggestions();
});

Although the exact implementation may vary depending on how your website is built, the above snippet could give you a good picture of how to connect Mavention Query Suggestions with your website. The entry point, to receive query suggestions from Mavention Query Suggestions, is the querysuggestions.ashx HTTP Handler deployed to the SharePoint Root (line 7). The string typed by the user is sent using the query query string parameter (line 8). The user has to type at least two chars to get a query suggestion (line 18). After selecting a suggestion from the list of query suggestions the search form is being submitted (lines 19-23).

The great thing about using the jQuery UI Autocomplete widget is that it’s really easy to integrate with your website and it’s accessible as it implements WAI-ARIA attributes.

You can see live implementation of Mavention Query Suggestions using the jQuery UI Autocomplete widget on both mavention.nl and mavention.com. Try searching for example for a name of one of the Mavens and you will get query suggestions provided by Mavention Query Suggestions.

Query suggestions provided by Mavention Query Suggestions when searching for one of the Mavens on mavention.com

Installing and configuring Mavention Query Suggestions

Mavention Query Suggestions is a SharePoint 2013 Farm Solution so the first step is to add the Solution Package file (WSP) to the Farm Solution Store (using the Add-SPSolution PowerShell cmdlet) and deploying it to one or more Web Applications (using the Install-SPSolution PowerShell cmdlet). During this process Mavention Query Suggestions will automatically activate the Mavention Query Suggestions Farm Configuration Farm Feature that installs custom logging category which you can use to monitor Mavention Query Suggestions.

The ‘Mavention Query Suggestions’ logging category on the ‘Diagnostic Logging’ page in SharePoint 2013 Central Administration

If you want to make use of query suggestions gathering based on successful search queries you also need to activate the Mavention Query Suggestions Web Application Configuration Web Application Feature. Upon activation this Feature will install the Mavention Query Suggestions Timer Job that is responsible for processing gathered query suggestions and writing them to the Query Suggestions List. By default it runs every 5 minutes but you can tweak this schedule to make it fit your requirements.

The details of the ‘Mavention Query Suggestions’ Timer Job in Central Administration

To use Mavention Query Suggestions in a site you have to activate the Mavention Query Suggestions Site Collection Feature. This Feature creates the Query Suggestions List that is used for storing query suggestions.

Configuring Mavention Query Suggestions

Upon installation Mavention Query Suggestions allows you to change the number of suggestions that are returned at maximum and how the suggestions are matched. Both settings are stored in the Property Bag of the Root Web of your Site Collection and can be changed for example using PowerShell. Both settings are cached and after changing them you have to recycle the Application Pool to refresh the settings stored in the cache.

By default Mavention Query Suggestions returns up to 5 query suggestions. You can change the number of suggestion to for example 3 by running the following PowerShell script:

$web = Get-SPWeb http://www.mavention.nl.local
$web.SetProperty('MaventionQuerySuggestions_NumberOfSuggestions', 3)
$web.Update()

By default Mavention Query Suggestions matches query suggestions using the BeginsWith operator. Another way to match suggestions is using the Contains operator. This could be set as follows:

$web = Get-SPWeb http://www.mavention.nl.local
$web.SetProperty('MaventionQuerySuggestions_SuggestionsOperator', 'Contains')
$web.Update()

Summary

SharePoint 2013 ships with a rich search experience. One part of that experience is providing search query suggestions. Unfortunately those suggestions are not available for anonymous users. Mavention Query Suggestions is a free Solution for SharePoint 2013 that allows you to easily implement query suggestions on your public-facing website.

Download: Mavention Query Suggestions (13KB, WSP)