AutoComplete

SearchBlox Indexed Data Based AutoComplete

  • Suggestions can be generated from either the content field or the title field of the indexed data.

Content-Based Autocompletes

  • Content-based autocomplete provides suggestions from the indexed content. To enable this feature, the user must turn it on in the Search Settings as shown below:

Title-Based Autocomplete

  • Title-based autocomplete gives suggestions from the indexed title field. To enable this in search, the user must turn it on in the Search Settings as shown:
  • Response of Title field suggestions:

🚧

Important Information

Kindly note that it is mandatory to select the Autocomplete field in search settings for the suggestions to be fetched from the title or content in Autocomplete API mentioned in the preceding section.

ParameterDescription
qThe search text (query)
limitHow many suggestions to show

SearchBlox Query-Based AutoComplete

  • Suggestions can come from the user’s previous search queries.
  • Query-based autocomplete shows suggestions from past queries stored in the querylogs index. To enable this in search, the user must turn it on in the Search Settings as shown.

🚧

Important Information

It is not mandatory to select the autocomplete field as the query in search settings as providing the cname as searchlogs will fetch suggestions from querylogs irrespective of the selection made in search settings Autocomplete field.

queryThe search text entered by the user
cnameMust be set to searchlogs to get suggestions from query logs
limitHow many suggestions to show
  • Autocomplete search for Querylogs (the cname for Querylogs is searchlogs).
    JSON Response:
    ["news", "news analysis and", "news and features", "news and video", "news breaking news"]

Autocomplete in Faceted Search

  • Autocomplete is turned on by default in faceted search.
  • You can turn it off by editing <SEARCHBLOX_INSTALLATION_PATH>/webapps/ROOT/search/facet.js and setting showAutoSuggest to false, like this:
    "showAutoSuggest": false,
  • In the default faceted search, the number of autosuggest results shown is 5.

AutoComplete Parameters

SearchBlox ParametersDescriptionGSA Equivalent
queryThe partial text the user types to get suggestionsq
limitMaximum number of suggestions to return (default is 10)max
colCollection numbersite
cnameCollection namesite

Custom AutoComplete

  • In SearchBlox, you can set up AutoComplete for specific fields other than content, title, or querylogs.
  • These fields can be built-in SearchBlox fields or custom fields that you have indexed.

Custom Autocomplete for Custom Fields

You can enable Autocomplete for a custom field by following these steps:

  1. Go to <SEARCHBLOX_INSTALLATION_PATH>/searchblox/webapps/ROOT/WEB-INF/.
  2. Edit mapping.json, jdbc.json, or csv.json based on the collection that uses the custom field.
  3. Add the required mapping for the custom field.
"author": {
        "type": "completion"
      },
  1. Clear the collection and reindex it.
  2. In settings, choose the Autocomplete Field as Title or Content.
  3. Test the autosuggestions using this URL and parameters in the Autocomplete API:
    https://localhost:8443/rest/v2/api/autocomplete?query=speaker&type=custom&field=author

Custom Autosuggest for SearchBlox Fields

Custom Autosuggest can also be used for SearchBlox fields by following these steps.

For example, if you want to use autosuggest for the description field, it can be done in two ways.

Providing Subfield within the Actual Field

  1. Go to <SEARCHBLOX_INSTALLATION_PATH>/searchblox/webapps/ROOT/WEB-INF/.
  2. Edit mapping.json, jdbc.json, or csv.json based on the collection that uses the field for AutoSuggest.
  3. Add the required mapping to the description field.
"description": {
         "type": "text",
        "store": true,
        "analyzer": "sb_analyzer"
        "fields": {
          "desc": {
            "type": "completion"
          }
        }
      },
  1. Clear the collection and reindex it.
  2. Choose the Autocomplete Field as Title or Content.
  3. Autosuggestions can be fetched based on description field using description.desc as in the following URL
    https://localhost:8443/rest/v2/api/autocomplete?limit=5&query=cnn&col=1&field=description.desc

Copying to a New Field

  1. Go to <SEARCHBLOX_INSTALLATION_PATH>/searchblox/webapps/ROOT/WEB-INF/.
  2. Update mapping.json, jdbc.json, or csv.json depending on the collection that uses the field for AutoSuggest. For more details, refer to Mapping Files for Collections.
  3. Add the required mapping to the description field and test field.
"description": {
         "type": "text",
        "store": true,
        "analyzer": "sb_analyzer"
        "copy_to": "test"
              },
        "test": {
            "type": "completion"
            },
  1. Clear the collection and reindex it.
  2. Choose Title or Content as the Autocomplete Field.
  3. Get autosuggestions from the description field using the test field in the URL.
    https://localhost:8443/rest/v2/api/autocomplete?limit=5&query=cnn&cname=test