Class: Builder

Constructor

Builder

new Builder()

Example

// Builds a search box.
function onload() {
  gapi.client.init({
    &#x27;apiKey&#x27;: &#x27;<your api key>&#x27;,
    &#x27;clientId&#x27;: &#x27;<your client id>&#x27;,
    // Add additional scopes if needed
    &#x27;scope&#x27;: &#x27;https://www.googleapis.com/auth/cloud_search.query',
    &#x27;hosted_domain&#x27;: &#x27;<your G Suite domain>&#x27;,
  });

  const searchBox &#x3D; new gapi.cloudsearch.widget.searchbox.Builder()
    .setInput(document.getElementById(&#x27;input&#x27;))
    .setAnchor(document.getElementById(&#x27;input&#x27;).parentElement)
    .build();
}
gapi.load(&#x27;client:cloudsearch-widget&#x27;, onload);

Methods

build

build() returns SearchBox

Returns

non-null SearchBox 

setAdapter

setAdapter(adapter) returns Builder

Required. Customize the user's search experience with this adapter.

Parameter

adapter

SearchBoxAdapter

You can override part of the methods.

Value must not be null.

Returns

non-null Builder this

Example

const adapter &#x3D; {
 interceptSuggestRequest: function(request) {
    // Change the request
  }
}

builder.setAdapter(adapter).build();

setAnchor

setAnchor(anchor) returns Builder

Required. Must to be a valid HTMLElement that can contain child nodes. Anchor of the search overlay. The overlay is added as the last child in anchor. The position of the overlay is the bottom of anchor.

Parameter

anchor

HTMLElement

Value must not be null.

Deprecated
Use `setAnchorElement` instead
Returns

non-null Builder this

setAnchorElement

setAnchorElement(anchorElement) returns Builder

Required. Must to be a valid HTMLElement that can contain child nodes. Anchor of the search overlay. The overlay is added as the last child in anchor. The position of the overlay is the bottom of anchor.

Parameter

anchorElement

HTMLElement

Value must not be null.

Returns

non-null Builder this

setHints

setHints(hints) returns Builder

Optional. The hints on the search box when input is empty. When the input is empty, a random hint is picked from the array.

Parameter

hints

Array of string

Value must not be null.

Returns

non-null Builder this

setInput

setInput(input) returns Builder

Required. An HTMLElement that the user inputs the query. Must be <input> or <textarea>

Parameter

input

HTMLElement

Value must not be null.

Deprecated
Use `setInputElement` instead
Returns

non-null Builder this

setInputElement

setInputElement(inputElement) returns Builder

Required. An HTMLElement that the user inputs the query. Must be <input> or <textarea>

Parameter

inputElement

HTMLElement

Value must not be null.

Returns

non-null Builder this

setResultsContainer

setResultsContainer(resultsContainer) returns Builder

Optional. Container for displaying search results. If set, the results are rendered in the search results container. If not set, the results are shown in cloudsearch.google.com.

Parameter

resultsContainer

gapi.cloudsearch.widget.resultscontainer.ResultsContainer

Value must not be null.

See also
ResultsContainer
Returns

non-null Builder this

setSearchApplicationId

setSearchApplicationId(searchApplicationId) returns Builder

Optional. Sets the search application ID to use for requests. Must be prefixed with 'searchapplications/'.

Parameter

searchApplicationId

string

Returns

non-null Builder this

setThrottleInterval

setThrottleInterval(throttleInterval) returns Builder

Optional. The throttle interval in ms on firing request. The search box sends less than one request every throttleInterval milliseconds. If throttleInternal is less than 200, search box ignores the value and uses 200 as interval instead.

Parameter

throttleInterval

number

Returns

non-null Builder this