Autocomplete

As the name suggests Autocomplete can be used to get auto-completion suggestions for terms entered by the user.

  • Therefore, a range of different types of suggesters are available that can be used.

  • Results can be prefetched for the suggested terms (therefore an additional search is triggered)

Usage

The default auto-complete endpoint is /suggest. The single mandatory parameter is:

  • term / q: This parameter contains the so far entered search term(s) for which suggestions should be returned. (The parameter q, if present, is treated as a synonym to term.)

Optional parameters:

  • Filter parameters (specifically for the auto-complete calls) need to be explicitly managed by the frontend, unlike what is the case of normal search. In other words, the search server defaults to not applying filters in the context of auto-complete calls. The filter parameters that can be used are identical to those of the normal search, and frontend developers can adjust the corresponding action URLs for the auto-completion calls as necessary. Note that auto-complete responses do again contain filtering capabilities (see the Example below for details).

Configuration

In the properties section of the configuration file the following properties are used to control the behavior of the Autocomplete search:

Name Type Default value Description Overridden by searchtime parameter

search.config.autocomplete

String

autocomplete

Response section name for autocomplete

search.config.autocomplete.maxsuggestions

Integer

5

Max. number of suggestions in autocomplete

search.config.autocomplete.lasttermquery

Boolean

false

Get suggestions only for the last term when the suggesters do not return results

search.config.autocomplete.config

String

autocomplete

Name of the configuration that is used for prefetching of results

autocomplete.config

search.config.autocomplete.spellcheckresults

Boolean

false

Spellcheck results are added as suggestions when the suggesters do not return results

search.config.autocomplete.sortsuggestions

String

natural

Available options: natural (based on string length), hits (based on number of hits)

search.config.autocomplete.prefetchedResults

String

prefetchedResults

Response section name for prefetched results

search.config.autocomplete.prefetchResults

Boolean

true

En-/Disables prefetching of results.

search.config.autocomplete.highlight

Boolean

false

En-/Disables highlighting of results.

search.config.spellchecker (v1.6.5+)

List

default

List of the types of spellchecker to be used

spellchecker

search.config.slsuggester.version (v2.0.0+)

classic or advanced

classic

advanced enables the advanced suggester

search.config.suggest.prefix

String

sem_text_suggest

Name of the field that is used for facet prefix suggester

search.config.suggest.prefix.fq

List

-

Filter queries that should be applied when using the facet prefix suggester (e.g. sem_record_type:wine)

suggest.prefix.fq (v1.6.5+)

search.config.suggester

List

prefix

The name(s) of the suggester that are used (e.g. prefix, suggest, or sem_suggest_phrase)

suggester (v1.6.5+)

Response

The autocomplete response differs from the search response, it writes information to the section autocomplete and prefetchedResults.

Elements of the Response

The main sections of the response are:

  • autocomplete:

    • suggestions: This section contains the suggestions for the term(s) that can be used to “complete” the thus far user-entered query. The structure of the individual suggestions in this case is identical to the structure used for spelling suggestions – please refer to section Spelling suggestions for details.

  • prefetchedResults: This section contains “prefetched” documents that match the top suggestion, grouped by a predefined grouping field. The fields inside this section are:

    • term: This is the actual suggestion for which documents were prefetched

    • sem_action: The action URL that selects the term

    • response or grouped: Contains the prefetched documents either as document list or grouped. These sections correspond to the sections in the chapter The search response.

  • responseHeader: Same as for the search response.

Example

The overall structure of a search response is shown in the example below calling suggestion for "brune": https://search-features.demos.contexity.ch/sl/suggest?q=brune

Autocomplete response section
{
  "autocomplete": {
    "suggestions": [
      {
        "suggestion": "brunet",
        "hits": 2,
        "sem_action": {
          "sem_url": "?q=brunet",
          "sem_url_action": "?q=brunet&ot.et=search&ot.est=suggest-term-select&ot.es=source_autocomplete&ot.orig=Brune&ot.sg=brunet&ot.sgidx=0&ot.sse=05ddaa43-de52-4363-9d16-1bf4e1d0915f"
        }
      },
      {
        "suggestion": "brunet jehanne",
        "hits": 1,
        "sem_action": {
          "sem_url": "?q=brunet+jehanne",
          "sem_url_action": "?q=brunet+jehanne&ot.et=search&ot.est=suggest-term-select&ot.es=source_autocomplete&ot.orig=Brune&ot.sg=brunet+jehanne&ot.sgidx=1&ot.sse=05ddaa43-de52-4363-9d16-1bf4e1d0915f"
        }
      },
      {
        "suggestion": "brunet jehanne de",
        "hits": 1,
        "sem_action": {
          "sem_url": "?q=brunet+jehanne+de",
          "sem_url_action": "?q=brunet+jehanne+de&ot.et=search&ot.est=suggest-term-select&ot.es=source_autocomplete&ot.orig=Brune&ot.sg=brunet+jehanne+de&ot.sgidx=2&ot.sse=05ddaa43-de52-4363-9d16-1bf4e1d0915f"
        }
      },
      {
        "suggestion": "brunet jehanne de chantal",
        "hits": 1,
        "sem_action": {
          "sem_url": "?q=brunet+jehanne+de+chantal",
          "sem_url_action": "?q=brunet+jehanne+de+chantal&ot.et=search&ot.est=suggest-term-select&ot.es=source_autocomplete&ot.orig=Brune&ot.sg=brunet+jehanne+de+chantal&ot.sgidx=3&ot.sse=05ddaa43-de52-4363-9d16-1bf4e1d0915f"
        }
      }
    ]
  }
}

Advanced Suggester

Available since version 2.0.

The advanced suggester extends the potential of the suggester to use various fields in various ways for the suggestion. Furthermore, the response of the advanced suggester reveals more useful details.

Configuration

In the properties section of the configuration file setting properties search.config.slsuggester.version to advanced enables the advanced suggester

Note that when in advanced mode the other suggester related fields are ignored:

  • search.config.suggest.prefix.fq

  • search.config.suggest.prefix

  • search.config.suggester

  • search.config.autocomplete.lasttermquery

  • search.config.autocomplete.maxsuggestions

Instead of that the advanced suggester is defined in the new section suggester_configurations of configuration file where various suggesters that consists in several suggester components can be added.

Every single suggester component is described by these field:

  • name: The name of the suggester as defined in your solrconfig.xml (in case of prefix suggester it is the field name)

  • weight: The factor to be applied, higher weight will bring up the results of this suggester component

  • maxResults: The maximum number of results returned by the suggester component (replaces search.config.autocomplete.maxsuggestions)

  • lastTermQuery: Get suggestions only for the last term when the suggesters do not return results (replaces search.config.autocomplete.lasttermquery)

  • prefix: true if it a prefix suggester

  • filterQueries: Filter queries that should be applied when using the facet prefix suggester (replaces search.config.suggest.prefix.fq)

Example of an advanced suggester configuration
"suggester_configurations": {
    "default": {
        "components": [
            {
                "name": "sem_text_suggest",
                "weight": 1,
                "maxResults": 5,
                "lastTermQuery": true,
                "prefix": true,
                "filterQueries": ["sem_record_type:wine"]
            },
            {
                "name": "suggest_prefix",
                "weight": 1,
                "maxResults": 5,
                "lastTermQuery": true,
                "prefix": false
            }
        ]
    }
}

Response of the advanced suggester

In its response the advanced suggester outprints more detailed information about the source of the suggestions and its relevance (hits)

In order to take advantage of the enhanced response of the advanced suggester, you can still enable it setting search.config.slsuggester.version to advanced. In that case the properties are translated to the new format of the advanced suggester!

The example below shows the autocomplete section for the advanced suggester for the example configuration above

Autocomplete response section
{
  "autocomplete": {
    "suggestions": [
      {
        "suggestion": "brunet",
        "hits": 2,
        "hitsWeighted": 2.0,
        "suggesters": [
          "sem_text_suggest",
          "suggest_prefix"
        ],
        "sem_action": {
          "sem_url": "?q=brunet",
          "sem_url_action": "?q=brunet&ot.et=search&ot.est=suggest-term-select&ot.es=source_autocomplete&ot.orig=brune&ot.sg=brunet&ot.sgidx=0&ot.sse=8d63a572-a52c-43f7-ab5e-c0b4e9720445"
        }
      },
      {
        "suggestion": "brunet jehanne",
        "hits": 1,
        "hitsWeighted": 1.0,
        "suggesters": [
          "suggest_prefix"
        ],
        "sem_action": {
          "sem_url": "?q=brunet+jehanne",
          "sem_url_action": "?q=brunet+jehanne&ot.et=search&ot.est=suggest-term-select&ot.es=source_autocomplete&ot.orig=brune&ot.sg=brunet+jehanne&ot.sgidx=1&ot.sse=8d63a572-a52c-43f7-ab5e-c0b4e9720445"
        }
      },
      {
        "suggestion": "brunet jehanne de",
        "hits": 1,
        "hitsWeighted": 1.0,
        "suggesters": [
          "suggest_prefix"
        ],
        "sem_action": {
          "sem_url": "?q=brunet+jehanne+de",
          "sem_url_action": "?q=brunet+jehanne+de&ot.et=search&ot.est=suggest-term-select&ot.es=source_autocomplete&ot.orig=brune&ot.sg=brunet+jehanne+de&ot.sgidx=2&ot.sse=8d63a572-a52c-43f7-ab5e-c0b4e9720445"
        }
      },
      {
        "suggestion": "brunet jehanne de chantal",
        "hits": 1,
        "hitsWeighted": 1.0,
        "suggesters": [
          "suggest_prefix"
        ],
        "sem_action": {
          "sem_url": "?q=brunet+jehanne+de+chantal",
          "sem_url_action": "?q=brunet+jehanne+de+chantal&ot.et=search&ot.est=suggest-term-select&ot.es=source_autocomplete&ot.orig=brune&ot.sg=brunet+jehanne+de+chantal&ot.sgidx=3&ot.sse=8d63a572-a52c-43f7-ab5e-c0b4e9720445"
        }
      }
    ],
    "suggestions_detail": {
      "sem_text_suggest": [
        {
          "suggestion": "brunet",
          "hits": 1,
          "suggesters": [
            "sem_text_suggest"
          ],
          "sem_action": {
            "sem_url": "?q=brunet",
            "sem_url_action": "?q=brunet&ot.et=search&ot.est=suggest-term-select&ot.es=source_autocomplete&ot.orig=brune&ot.sg=brunet&ot.sgidx=0&ot.sse=8d63a572-a52c-43f7-ab5e-c0b4e9720445"
          }
        }
      ],
      "suggest_prefix": [
        {
          "suggestion": "brunet",
          "hits": 2,
          "suggesters": [
            "suggest_prefix"
          ],
          "sem_action": {
            "sem_url": "?q=brunet",
            "sem_url_action": "?q=brunet&ot.et=search&ot.est=suggest-term-select&ot.es=source_autocomplete&ot.orig=brune&ot.sg=brunet&ot.sgidx=0&ot.sse=8d63a572-a52c-43f7-ab5e-c0b4e9720445"
          }
        },
        {
          "suggestion": "brunet jehanne",
          "hits": 1,
          "suggesters": [
            "suggest_prefix"
          ],
          "sem_action": {
            "sem_url": "?q=brunet+jehanne",
            "sem_url_action": "?q=brunet+jehanne&ot.et=search&ot.est=suggest-term-select&ot.es=source_autocomplete&ot.orig=brune&ot.sg=brunet+jehanne&ot.sgidx=1&ot.sse=8d63a572-a52c-43f7-ab5e-c0b4e9720445"
          }
        },
        {
          "suggestion": "brunet jehanne de",
          "hits": 1,
          "suggesters": [
            "suggest_prefix"
          ],
          "sem_action": {
            "sem_url": "?q=brunet+jehanne+de",
            "sem_url_action": "?q=brunet+jehanne+de&ot.et=search&ot.est=suggest-term-select&ot.es=source_autocomplete&ot.orig=brune&ot.sg=brunet+jehanne+de&ot.sgidx=2&ot.sse=8d63a572-a52c-43f7-ab5e-c0b4e9720445"
          }
        },
        {
          "suggestion": "brunet jehanne de chantal",
          "hits": 1,
          "suggesters": [
            "suggest_prefix"
          ],
          "sem_action": {
            "sem_url": "?q=brunet+jehanne+de+chantal",
            "sem_url_action": "?q=brunet+jehanne+de+chantal&ot.et=search&ot.est=suggest-term-select&ot.es=source_autocomplete&ot.orig=brune&ot.sg=brunet+jehanne+de+chantal&ot.sgidx=3&ot.sse=8d63a572-a52c-43f7-ab5e-c0b4e9720445"
          }
        }
      ]
    }
  }
}