Related Searches API


SearchStax® provides an API that retrieves the Related Searches defined for a specific search phrase in the SearchStudio App.

Related Searches allows users to manually define Search terms that are related, and augments them from search terms learned using Artificial Intelligence using Analytics data. For the AI augmented related searches, Analytics should be connected with your Search page and there should be enough searches with clicks available.

This page describes how to retrieve a Json document of related-search strings for display on your search page.

The API can be accessed through any tool that assembles HTTP requests and dispatch them to a server. Among these would be the Python coreapi package, the Postman tool, and cURL. For Windows, use PowerShell Core 6.1+.

Symbols enclosed in carets (< and >) such as <username> are metavariables. Substitute your local values when you encounter them in the examples.

Related Search

This method returns a list of Related Searches from a SearchStudio App.

GET <related-searches-URL>?search=<search-phrase>

where <related-searches-URL> is an endpoint from the Search API Tab of the App Settings screen, and <search-phrase> is the base query that has related searches defined on the Related Searches screen.

This method uses SearchAPIKey authorization. The Search API key is displayed on the Search API Tab. It must be passed in the header of the request.

When invoked from Linux (Bash script):

URL="https://app.searchstax.com/api/v1/nn/related-search/"
APIKEY="456cwe54sasb8e5lu5y6k48j55u86546slas"
KEYWORD="sitecore"

SEARCHES=$(curl -H "Authorization: $APIKEY" "$URL?search=$KEYWORD") 

When invoked from Windows Powershell:

# Removes TLS obstacles from connection. Otherwise connections fail. 
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12

$URL = "https://app.searchstax.com/api/v1/nn/related-search/"
$APIKEY = "81c09977fedb7e89310c87df81d7bc787301155e"
$KEYWORD = "Sitecore"

# Set up HTTP header for authorization token
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $APIKEY)

$RESPONSE = Invoke-RestMethod -Method Get -ContentType 'application/json' -Headers $headers `
              -uri $($URL+"?search=$KEYWORD") 
$RESPONSE = $RESPONSE | ConvertTo-Json -Depth 3

Write-Host $RESPONSE

The response is a JSON document containing a list of related searches.

{
  "responseHeader": {
    "zkConnected": true,
    "status": 0,
    "QTime": 0,
    "params": {
      "q": "search_term:\"Sitecore\"",
      "sort": "related_score desc"
    }
  },
  "response": {
    "numFound": 5,
    "start": 0,
    "numFoundExact": true,
    "docs": [
      {
        "search_term": "sitecore",
        "related_search": "sitecore 10",
        "related_score": "1",
        "id": "9f5d7e9e-9623-4dc9-b936-86de9c675c94",
        "_version_": 1719414068933033984
      },
      {
        "search_term": "sitecore",
        "related_search": "sitecore plugin",
        "related_score": "1",
        "id": "3831f631-68e4-4e3f-8b1c-036279c293b0",
        "_version_": 1719414068934082560
      },
      {
        "search_term": "sitecore",
        "related_search": "sitecore replace azure",
        "related_score": "1",
        "id": "ca4e9edc-950f-46ae-8063-a9c78da1f6b3",
        "_version_": 1719414068935131136
      },
      {
        "search_term": "sitecore",
        "related_search": "site search for sitecore",
        "related_score": "1",
        "id": "14ab5cbb-942a-4f25-a47d-ddfd49c27a8e",
        "_version_": 1719414068936179712
      },
      {
        "search_term": "sitecore",
        "related_search": "managed solr for sitecore",
        "related_score": "1",
        "id": "c84be92b-2e61-4a04-a4f2-444b678280da",
        "_version_": 1719414068937228288
      }
    ]
  }
}

The fields of each related search have the following meanings:

  • search_term: This is the search string that keys to the Related Searches.
  • related_search: Each entry contains the string of a single Related Search.
  • related_score: A measure of similarity to the search_term. The range of values is 0 to 1. Higher values are more similar.

The other fields are Solr internal values.