Создатель окна поиска. Используйте построитель и не вызывайте напрямую конструктор поля поиска.
Конструктор
Строитель
новый строитель()
Пример
// Builds a search box.functiononload(){gapi.client.init({'apiKey':'<your api key>','clientId':'<your client id>',// Add additional scopes if needed'scope':'https://www.googleapis.com/auth/cloud_search.query','hosted_domain':'<your G Suite domain>',});constsearchBox = newgapi.cloudsearch.widget.searchbox.Builder().setInput(document.getElementById('input')).setAnchor(document.getElementById('input').parentElement).build();}gapi.load('client:cloudsearch-widget',onload);
Методы
строить
build() возвращает SearchBox
Возврат
non-null SearchBox
установитьАдаптер
setAdapter(адаптер) возвращает Builder
Необходимый . Настройте поиск пользователя с помощью этого адаптера.
constadapter = {interceptSuggestRequest:function(request){// Change the request}}builder.setAdapter(adapter).build();
setAnchor
setAnchor(anchor) возвращает Builder
Необходимый . Должен быть действительным HTMLElement, который может содержать дочерние узлы. Привязка наложения поиска. Наложение добавляется как последний дочерний элемент привязки. Положение наложения — нижняя часть якоря.
Необходимый . Должен быть действительным HTMLElement, который может содержать дочерние узлы. Привязка наложения поиска. Наложение добавляется как последний дочерний элемент привязки. Положение наложения — нижняя часть якоря.
Параметр
якорьЭлемент
HTMLЭлемент
Значение не должно быть нулевым.
Возврат
non-null Builder это
setHints
setHints(hints) возвращает Builder
Необязательный . Подсказки в поле поиска, когда ввод пуст. Когда входные данные пусты, из массива выбирается случайная подсказка.
Параметр
намеки
Массив строк
Значение не должно быть нулевым.
Возврат
non-null Builder это
setInput
setInput(input) возвращает Builder
Необходимый . HTMLElement, который пользователь вводит в запрос. Должно быть <input> или <textarea>.
Параметр
вход
HTMLЭлемент
Значение не должно быть нулевым.
Устарело
Вместо этого используйте `setInputElement`
Возврат
non-null Builder это
SetInputElement
setInputElement(inputElement) возвращает Builder
Необходимый . HTMLElement, который пользователь вводит в запрос. Должно быть <input> или <textarea>.
Необязательный . Контейнер для отображения результатов поиска. Если установлено, результаты отображаются в контейнере результатов поиска. Если этот параметр не установлен, результаты отображаются на сайте Cloudsearch.google.com.
Необязательный . Интервал газа в мс при запросе на запуск. Поле поиска отправляет менее одного запроса каждые миллисекунды throttleInterval. Если throttleInternal меньше 200, поле поиска игнорирует это значение и вместо этого использует 200 в качестве интервала.
[[["Прост для понимания","easyToUnderstand","thumb-up"],["Помог мне решить мою проблему","solvedMyProblem","thumb-up"],["Другое","otherUp","thumb-up"]],[["Отсутствует нужная мне информация","missingTheInformationINeed","thumb-down"],["Слишком сложен/слишком много шагов","tooComplicatedTooManySteps","thumb-down"],["Устарел","outOfDate","thumb-down"],["Проблема с переводом текста","translationIssue","thumb-down"],["Проблемы образцов/кода","samplesCodeIssue","thumb-down"],["Другое","otherDown","thumb-down"]],["Последнее обновление: 2025-07-24 UTC."],[],[],null,["# Class: Builder\n\ngapi.cloudsearch.widget.[searchbox](/workspace/cloud-search/docs/reference/widget/js/gapi.cloudsearch.widget.searchbox).Builder\n===============================================================================================================================\n\nclass static\n\nBuilder of a search box. Use a builder and do not directly call\nthe searchbox constructor.\n\nConstructor\n-----------\n\n### Builder\n\nnew\nBuilder()\n\n#### Example\n\n // Builds a search box.\n function onload() {\n gapi.client.init({\n 'apiKey': '\u003cyour api key\u003e',\n 'clientId': '\u003cyour client id\u003e',\n // Add additional scopes if needed\n 'scope': 'https://www.googleapis.com/auth/cloud_search.query',\n 'hosted_domain': '\u003cyour G Suite domain\u003e',\n });\n\n const searchBox = new gapi.cloudsearch.widget.searchbox.Builder()\n .setInput(document.getElementById('input'))\n .setAnchor(document.getElementById('input').parentElement)\n .build();\n }\n gapi.load('client:cloudsearch-widget', onload);\n\nMethods\n-------\n\n### build\n\nbuild() returns SearchBox\n\nReturns\n\n: `non-null SearchBox`\n\n### setAdapter\n\nsetAdapter(adapter) returns Builder\n\n**Required**. Customize the user's search experience with this adapter.\n\n| #### Parameter ||\n|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------|\n| adapter | [SearchBoxAdapter](/workspace/cloud-search/docs/reference/widget/js/SearchBoxAdapter) You can override part of the methods. Value must not be null. |\n\nReturns\n\n: `non-null Builder` this\n\n#### Example\n\n const adapter = {\n interceptSuggestRequest: function(request) {\n // Change the request\n }\n }\n\n builder.setAdapter(adapter).build();\n\n### setAnchor\n\nsetAnchor(anchor) returns Builder\n\n**Required**. Must to be a valid HTMLElement that can contain child\nnodes.\nAnchor of the search overlay. The overlay is added\nas the last child in anchor. The position of the overlay is the\nbottom of anchor.\n\n| #### Parameter ||\n|--------|-------------------------------------|\n| anchor | HTMLElement Value must not be null. |\n\nDeprecated\n: Use \\`setAnchorElement\\` instead\n\nReturns\n\n: `non-null Builder` this\n\n### setAnchorElement\n\nsetAnchorElement(anchorElement) returns Builder\n\n**Required**. Must to be a valid HTMLElement that can contain child\nnodes.\nAnchor of the search overlay. The overlay is added\nas the last child in anchor. The position of the overlay is the\nbottom of anchor.\n\n| #### Parameter ||\n|---------------|-------------------------------------|\n| anchorElement | HTMLElement Value must not be null. |\n\nReturns\n\n: `non-null Builder` this\n\n### setHints\n\nsetHints(hints) returns Builder\n\n**Optional**. The hints on the search box when input is empty.\nWhen the input is empty, a random hint is picked from the array.\n\n| #### Parameter ||\n|-------|-----------------------------------------|\n| hints | Array of string Value must not be null. |\n\nReturns\n\n: `non-null Builder` this\n\n### setInput\n\nsetInput(input) returns Builder\n\n**Required**. An HTMLElement that the user inputs the query.\nMust be \\\u003cinput\\\u003e or \\\u003ctextarea\\\u003e\n\n| #### Parameter ||\n|-------|-------------------------------------|\n| input | HTMLElement Value must not be null. |\n\nDeprecated\n: Use \\`setInputElement\\` instead\n\nReturns\n\n: `non-null Builder` this\n\n### setInputElement\n\nsetInputElement(inputElement) returns Builder\n\n**Required**. An HTMLElement that the user inputs the query.\nMust be \\\u003cinput\\\u003e or \\\u003ctextarea\\\u003e\n\n| #### Parameter ||\n|--------------|-------------------------------------|\n| inputElement | HTMLElement Value must not be null. |\n\nReturns\n\n: `non-null Builder` this\n\n### setResultsContainer\n\nsetResultsContainer(resultsContainer) returns Builder\n\n**Optional**. Container for displaying search results.\nIf set, the results are rendered in the search results container.\nIf not set, the results are shown in cloudsearch.google.com.\n\n| #### Parameter ||\n|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| resultsContainer | [gapi.cloudsearch.widget.resultscontainer.ResultsContainer](/workspace/cloud-search/docs/reference/widget/js/gapi.cloudsearch.widget.resultscontainer.ResultsContainer) Value must not be null. |\n\nSee also\n: [ResultsContainer](/workspace/cloud-search/docs/reference/widget/js/gapi.cloudsearch.widget.resultscontainer.ResultsContainer)\n\nReturns\n\n: `non-null Builder` this\n\n### setSearchApplicationId\n\nsetSearchApplicationId(searchApplicationId) returns Builder\n\n**Optional**. Sets the search application ID to use for requests. Must\nbe prefixed with 'searchapplications/'.\n\n| #### Parameter ||\n|---------------------|--------|\n| searchApplicationId | string |\n\nReturns\n\n: `non-null Builder` this\n\n### setThrottleInterval\n\nsetThrottleInterval(throttleInterval) returns Builder\n\n**Optional**. The throttle interval in ms on firing request.\nThe search box sends less than one request every throttleInterval\nmilliseconds. If throttleInternal is less than 200, search box ignores\nthe value and uses 200 as interval instead.\n\n| #### Parameter ||\n|------------------|--------|\n| throttleInterval | number |\n\nReturns\n\n: `non-null Builder` this"]]