Google logo
Google Search Appliance Documentation

Search Protocol Reference
PDF Previous Next
Query Suggestion Service /suggest Protocol

Query Suggestion Service /suggest Protocol

The query suggestion service provides suggestions that complete a user’s search query. As a user enters a query in the search box, a drop-down menu appears with suggestions to complete the query. The search appliance uses the most popular search queries of its users to determine the top suggestions that list for a query.

Only queries that returned results are used to build the database of query suggestions. Queries with special terms, such as inmeta:, info:, link:, daterange:, etc are excluded when building the database of query suggestions.

In addition, if activated, the search appliance adds user-added results to the list of suggestions.

For information on retrieving and updating the suggestion blacklist using Java and the Google Data API, see Query Suggestion Blacklist in the Administrative API Developer’s Guide: Java. For information on user-added results, see Providing User Results in Creating the Search Experience.

The following example shows query suggestions:

You can use the query suggestion feature to:

Enable the query suggestion client for a front end from Search > Search Features > Front Ends > Output Format > Search Box > Query suggestions.

The query suggestion service adds latest query data to its list of suggestions once every 24 hours. However you can force the service to pick up changes immediately by disabling and enabling the Query Suggestions checkbox. When you enable the checkbox, the suggest service is sent a HUP signal so that it updates its data structure from the latest query logs.

Queries with Special Query Terms, such as inmeta, are excluded from the Query Suggestion database. So if this type of query is used extensively, then a possible solution is to use the equivalent Search Parameters, such as partialfields and requiredfields.

After enabling query suggestions:

<xsl:variable name="show_suggest">1</xsl:variable>
2.
The search appliance provides access to the http://Search_Appliance/ss.js JavaScript file. The ss.js file is for version 6.2 and later only, the version 6.0 uses the suggest_js.js file.

For more information, see Providing Query Suggestions in Creating the Search Experience.

Back to top

Query Suggestion JavaScript Variables

After enabling query suggestion, the show_suggest XSLT variable is set to 1 and the JavaScript variables become usable in the XSLT stylesheet.

<xsl:variable name="show_suggest">1</xsl:variable>

The query suggestion features supports the following JavaScript variables in the XSLT stylesheet.

ss_allow_non_query

A true or false flag used by the os (OpenSearch) and rich output formats to suppress user-added results. This variable eliminates user-added results from the suggestions, while retains those based on popularity among other users’ queries.

Default value: true

ss_form_element

The value of the attribute id of the <form> used for the search box. This variable must be overwritten with the correct value when using suggest in a custom form outside of the search appliance, but still using the existing JavaScript client. If this parameter is incorrect, AJAX calls aren’t sent.

The XSLT spreadsheet sets this variable as:

var ss_form_element = ’suggestion_form’;

The form request occurs under the following XSLT condition (wrapped for readability):

<xsl:when test="$show_suggest = ’1’ and (($type = ’home’) 
  or ($type = ’std_top’))">
  <xsl:text disable-output-escaping="yes">&lt;form id="suggestion_form" 
    name="gs" method="GET" action="search" 
    onsubmit="return (this.q.value == ’’) ? false : true;"</xsl:text>
</xsl:when>

Default value: suggestion_form

ss_g_max_to_display

The maximum number of query suggestions to show from the suggest server. If set to 0, allows an unlimited number of suggestion types.

Default value: 10

ss_g_more_names_to_display

A literal string that displays for multiple suggestions. This value appears to the right of the query suggestion box. The default value listed in the next column is for the English language version. The value is internationalized and the actual value depends on the current language setting.

Default value: Suggestions

ss_g_one_name_to_display

A literal string that displays for a single suggestion. This value appears to the right of the query suggestion box. The default value listed in the next column is for the English language version. The value is internationalized and the actual value depends on the current language setting.

Default value: Suggestion

ss_max_to_display

The total number of rows allowed in the suggestion box. The smaller of ss_max_to_display and ss_g_max_to_display takes effect in limiting the number of suggestions.

Default value: 12

ss_non_query_empty_title

If a user-added results entry’s title is missing or is an empty string, this value is used. This is a token that you can internationalize in the XSLT stylesheet. Set this value to Unknown, Noname, --- , or anything that can be visually shown. Otherwise, the empty string becomes an element that introduces confusion, as the user may not know whether it is a suggestion or just a separation line. The default value listed in the next column is for the English language version. The value is internationalized and the actual value depends on the current language setting.

Default value: No Title

ss_popup_element

The value of the attribute id of the <table> as the placeholder for search suggestions. The <table> initially is empty, and is positioned beneath the search box, aligned to the left. If the <table> HTML code is incorrect, suggestion results do not display. The default value is:

var ss_popup_element = ’search_suggest’;

For an example of the search_suggest in a table, see Query Suggestion Table Class.

Default value: search_suggest

ss_protocol

The three values are:

 

legacy

Provides backward compatibility with the version 6.0 query suggestion feature for the token and max_matches variables. This setting excludes user-added results from the response. If an unknown format is set, legacy is assumed.

os

Supports the OpenSearch format.

rich

Rich text format (default for version 6.2 and later).

Default value: rich

Back to top

Query Suggestion CSS Classes in the XSLT Stylesheet

Programs can change the following areas of the suggestion display using CSS:

Google Suggest provides the following CSS classes that correspond to the numbers in the illustration:

 

1

.ss_gac_a

Suggestion box table row <tr> when an entry is not selected.

1

.ss_gac_b

Suggestion box table row <tr> when an entry is selected.

2

.ss_gac_c

Suggestion box table cell <td>. This class affects all suggestion entries.

3

.ss_gac_d

Suggestion box table cell <td>. This class is defined by the ss_g_more_names_to_display and ss_g_one_name_to_display XSLT variables.

4

.ss_gac_e

Suggestion box last table row <tr>.

Query Suggestion Table Class

The .ss_gac_m CSS class provides the style for the <table> element whose id value is referenced by the JavaScript ss_popup_element variable:

<table cellpadding="0" cellspacing="0" class="ss-gac-m" 
 style="width: 365px; visibility: hidden;" id="search_suggest"></table>

Back to top

Query Suggestion Requests and Responses

The output format controls the query suggestion request and response:

Legacy Format

The legacy format is similar to the suggest feature in the version 6.0 search appliance. The token and max_matches were in version 6.0, and the client, format, and site parameters were introduced in version 6.2.

 

callback

Provides a JSONP compatible response from suggest. If you set callback=test, it will return:

/* GSA Suggest Service JSONP Response. */test(<WHAT WAS SUPPOSED TO BE RETURNED>);

The prefix /* GSA Suggest Service JSONP Response. */ is hard-coded in the response to safeguard against cross-site scripting attacks on the JSONP callback name. You must remove the prefix before the response can be parsed by JavaScript.

client

Front end name.

default_frontend

format

The output format in which the client wants the results.

legacy

max_matches

The maximum number of results that the suggest server should return. The minimum is 0, which indicates that the server should return an empty set, however this result would not be meaningful.

The maximum is not defined. If this parameter is not set, then the default value is 10 possible matches. If fewer suggestions are configured, then they are returned.

10

site

Collection name.

default_collection

token

The partial query string that a user enters in the search box. The minimum size is one character. If set to 0, that is, if the search box is empty, then the suggest client side JavaScript doesn’t send a request to query suggestion. Even if an administrator implements a custom interface, sending an empty token returns an empty set as the result. The maximum size of the token parameter is not defined.

None

Request:

/suggest?token=<query>&max_matches=<num>&use_similar=0

Response:

[ "<term 1>", "<term 2>", ..., "<term n>" ]

Or, if no result:

[]

OpenSearch Format

The os format uses the OpenSearch protocol.

 

callback

Provides a JSONP compatible response from suggest. If you set callback=test, it will return:

/* GSA Suggest Service JSONP Response. */test(<WHAT WAS SUPPOSED TO BE RETURNED>);

The prefix /* GSA Suggest Service JSONP Response. */ is hard-coded in the response to safeguard against cross-site scripting attacks on the JSONP callback name. You must remove the prefix before the response can be parsed by JavaScript.

client

Front end name.

default_frontend

format

The output format in which the client wants the results.

os

max

The maximum number of results that the suggest server should return. The minimum is 0, which indicates that the server should return an empty set, however this result would not be meaningful.

The maximum is not defined. If this parameter is not set, then the default value is 10 possible matches. If fewer suggestions are configured, then they are returned.

10 (matches)

q

The partial query string that a user enters in the search box. The minimum size is one character. If set to 0, that is, if the search box is empty, then the suggest client side JavaScript doesn’t send a request to query suggestion. Even if an administrator implements a custom interface, sending an empty token returns an empty set as the result. The maximum size of the token parameter is not defined.

None

site

Collection name.

default_collection

Request:

/suggest?q=<query>&max=<num>&site=<collection>&client=<frontend>&
   format=os

Response:

[
  "<query>",
  [ "<term 1>", "<term 2>", ... "<term n>" ],
  [ "<content 1>", "<content 2>", ..., "<content n>" ],
  [ "<url 1>", "<url 2>", ..., "<url n>" ]
]

The client distinguishes between suggest and user-added results as follows:

A client can choose to display both suggest and user-added results or just one of them. The default front end provided in the Admin Console’s XSLT stylesheet, displays both results. User-added results display after suggest results and appear in italics.

If no result occurs, the OpenSearch format provides the following response:

[ <query>, [] ]

Rich Output Format

The rich format uses the rich protocol for search-as-you-type suggestions.

 

callback

Provides a JSONP compatible response from suggest. If you set callback=test, it will return:

/* GSA Suggest Service JSONP Response. */test(<WHAT WAS SUPPOSED TO BE RETURNED>);

The prefix /* GSA Suggest Service JSONP Response. */ is hard-coded in the response to safeguard against cross-site scripting attacks on the JSONP callback name. You must remove the prefix before the response can be parsed by JavaScript.

client

Front end name.

default_frontend

format

The output format in which the client wants the results.

rich

max

The maximum number of results that the suggest server should return. The minimum is 0, which indicates that the server should return an empty set, however this result would not be meaningful.

The maximum is not defined. If this parameter is not set, then the default value is 10 possible matches. If fewer suggestions are configured, then they are returned.

10 (matches)

q

The partial query string that a user enters in the search box. The minimum size is one character. If set to 0, that is, if the search box is empty, then the suggest client side JavaScript doesn’t send a request to query suggestion. Even if an administrator implements a custom interface, sending an empty token returns an empty set as the result. The maximum size of the token parameter is not defined.

None

site

Collection name.

default_collection

Request:

/suggest?q=<query>&max=<num>&site=<collection>&client=<frontend>&format=rich

Response (wrapped for readability):

{
  "query": "<query>",
  "results": [
  { "name": "<term 1>", "type": "suggest"},
  { "name": "<term 2>", "type": "suggest"},
  { "name": "<term 3>", "type": "uar", "content": "Title of UAR",
   "moreDetailsUrl": "URL of UAR"}
  ...,
  ]
}

Clients can distinguish between suggest and user-added results by looking at the type. The type can be suggest or uar (user-added result) to identify the type of suggestion.

The style value is reserved and not used in version 6.2. For suggest entries, a term must be present. For user-added results entries, moreDetailsUrl must be present.

If no result occurs, the rich format provides the following response:

{ "query": <query>, "results": [] }