London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Navigation [hide] [expand]
Area: Optimizely Search & Navigation
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Introduction

EPiServer Find's Search Statistics provide additional tracking and statistics functionality. Refer to the EPiServer 8 Find user guide for a description of the user interface.

Overview

Search Statistics provide an HTTP API for tracking and retrieving statistical data for completed searches. Based on aggregated statistics, the API exposes functions that you can use to enhance the search functionality: autocomplete, spelling suggestions and related queries.

Although you can interact with the Search Statistics API using any programming language that can make HTTP requests, API usage is typically done from JavaScript.

Tracking

To gather statistics for later analysis, use the Track() method in the search query:

C#
SearchClient.Instance.Search<IContent>()
  .For("banana")
  .Track()
  .GetResult();

Autocomplete

Search Statistics support autocomplete suggestions by returning previous queries filtered on a prefix. A simple jQuery-example is shown below:

C#
<script type="text/javascript">
$.get('/find_v2/_autocomplete?prefix=c&size=3', function (data) {
    $.each(data.Hits, function(index, value)
    {
        $('#autocomplete').append("<p>"+"Autocomplete for 'c': <a href=/Search/?q=" + value.Query + ">" + value.Query + "</a></p>");
    }
    )}, "jsonp");
</script>
<div id="autocomplete"></div>

Autocomplete accepts the following parameters:

  • prefix (mandatory): the prefix to filter all returned query suggestions.
  • size (optional): the number of autocomplete suggestions to return.

Spellchecking

Based on what other users have searched for, Search Statistics can provide spellchecks, popular queries similar to the one passed to the spellchecker. A simple jQuery-example is shown below.

C#
<script type="text/javascript">
$.get('/find_v2/_spellcheck?query=camonix?size=1', function (data) {
    $.each(data.Hits, function(index, value)
    {
        $('#spellcheck').append("<p>"+"Spellcheck for 'camonix': <a href=/Search/?q=" + value.Suggestion + ">" + value.Suggestion + "</a></p>");
    }
    )}, "jsonp");
</script>
<div id="spellcheck"></div>

The spellchecker accepts these parameters:

  • query (mandatory): the query to return spellchecks for.
  • size (optional): the number of spellchecks to return.

Related queries

Sometimes, it is valuable to discover relationships, for example people who search for a also search for b.Search Statistics calls this related queries. They can be requested using jQuery, as shown below.

C#
<script type="text/javascript">
$.get('/find_v2/_didyoumean?query=chamoni&size=1', function (data) {
    
$.each(data.Hits, function(index, value)
    
{
        $('#didyoumean').append("<p>"+"Didyoumean for 'chamonix': <a href=/Search/?q=" + value.Suggestion + ">" + value.Suggestion + "</a></p>");
    
}
    
)}, "jsonp");
</script>
<div id="didyoumean"></div>

Related queries accept these  parameters:

  • query (mandatory): the query for which to return related queries.
  • size (optional): the number of related queries to return.

Last updated: Jun 10, 2014