Text search

With Yandex Search API's Yandex Cloud ML SDK and API interfaces, you can run queries to the Yandex search database and get a response in synchronous or deferred mode. The search results you get depend on the parameters specified in your query.

Queries can be submitted by a user or service account with the search-api.webSearch.user role.

Depending on the specified query parameters, you will get the result in XML or HTML format.

Note

For parameters and examples of search queries via the ML SDK, see the Yandex Search API guides.

API request body format

The names of the request body fields are different in REST API and gRPC API: the former uses CamelCase, while the latter, snake_case.

{
            "query": {
              "searchType": "<search_type>",
              "queryText": "<search_query_text>",
              "familyMode": "<result_filter_setting_value>",
              "page": "<page_number>",
              "fixTypoMode": "<typo_correction_mode_setting_value>"
            },
            "sortSpec": {
              "sortMode": "<result_sorting_rule>",
              "sortOrder": "<sort_order_of_results>"
            },
            "groupSpec": {
              "groupMode": "<result_grouping_method>",
              "groupsOnPage": "<number_of_groups_per_page>",
              "docsInGroup": "<number_of_documents_per_group>"
            },
            "maxPassages": "<maximum_number_of_passages>",
            "region": "<region_ID>",
            "l10N": "<notification_language>",
            "folderId": "<folder_ID>",
            "responseFormat": "<result_format>",
            "userAgent": "<User-Agent_header>"
        }
        

Where:

  • searchType: Search type. The possible values are:

    • SEARCH_TYPE_RU: For the Russian search type.
    • SEARCH_TYPE_TR: For the Turkish search type.
    • SEARCH_TYPE_COM: For the International search type.
    • SEARCH_TYPE_KK: For the Kazakh search type.
    • SEARCH_TYPE_BE: For the Belarusian search type.
    • SEARCH_TYPE_UZ: For the Uzbek search type.
  • queryText: Search query text. The maximum length is 400 characters.

  • familyMode: Results filtering. This is an optional parameter. The possible values are:

    • FAMILY_MODE_MODERATE: Moderate filter (default). Adult category documents are excluded from search results unless the query explicitly targets resources of this category.
    • FAMILY_MODE_NONE: Filtering is off. Search results include any documents regardless of their contents.
    • FAMILY_MODE_STRICT: Family filter. Regardless of the search query, Adult category documents and documents containing profanity are excluded from search results.
  • page: Requested page number. This is an optional parameter. By default, the first page with search results is returned. Page numbering starts from zero (0 stands for page one).

  • fixTypoMode: Search query typo correction setting. This is an optional parameter. The possible values are:

    • FIX_TYPO_MODE_ON: Typo correction enabled (default). Search query typos are corrected automatically.
    • FIX_TYPO_MODE_OFF: Typo correction disabled. Search query typos are not corrected. The search is performed strictly as per the query.
  • sortMode: Search results sorting mode rule. This is an optional setting. The possible values are:

    • SORT_MODE_BY_RELEVANCE: Sorting by relevance (default).
    • SORT_MODE_BY_TIME: Sorting by document update time.
  • sortOrder: Search results sorting order. This is an optional setting. The possible values are:

    • SORT_ORDER_DESC: Forward sorting order from most recent to oldest (default).
    • SORT_ORDER_ASC: Reverse sorting order from oldest to most recent.
  • groupMode: Result grouping method. This is an optional setting. The possible values are:

    • GROUP_MODE_DEEP: Grouping by domain. Each group contains documents from one domain (default).
    • GROUP_MODE_FLAT: Flat grouping. Each group contains a single document.
  • groupsOnPage: Maximum number of groups that can be returned per page. This is an optional setting. The default value is 20.

    When getting the result in XML format, the possible values range from 1 to 100; for HTML, the range is from 5 to 50.

  • docsInGroup: Maximum number of documents that can be returned per group. This is an optional setting. Allowed values range from 1 to 3. The default value is 1.

  • maxPassages: Maximum number of passages that can be used when generating a document snippet. This is an optional setting. Allowed values range from 1 to 5. By default, a maximum of four passages with search query text is returned per document.

  • region: Search country or region ID that affects the document ranking rules. Only supported for the Russian and Turkish search types.

    For a list of frequently used country and region IDs, see Search regions.

  • l10N: Search response notifications language. Affects the text in the found-docs-human tag and error messages. This is an optional setting. Possible values depend on the selected search type:

    • Russian:
      • LOCALIZATION_RU: Russian (default).
      • LOCALIZATION_BE: Belarusian.
      • LOCALIZATION_KK: Kazakh.
      • LOCALIZATION_UK: Ukrainian.
    • Turkish:
      • LOCALIZATION_TR: Turkish.
    • International:
      • LOCALIZATION_EN: English.
  • folderId: Folder ID of the user or service account you will use for queries.

  • responseFormat: Search results format. This is an optional setting. The possible values are:

    • FORMAT_XML: The results will be delivered in XML format (default).
    • FORMAT_HTML: The results will be delivered in HTML format.
  • userAgent: String containing the User-Agent header. Use this parameter to have your search results optimized for a specific device and browser, including mobile search results. This is an optional setting. If not specified, you will get the default output.

List of supported parameters:

Note

The list of supported request parameters depends on the required output format, XML or HTML.

Parameter Supported in XML response Supported in HTML response
searchType yes yes
queryText yes yes
familyMode yes yes
page yes yes
fixTypoMode yes no
sortMode yes no
sortOrder yes no
groupMode yes no
groupsOnPage yes yes
docsInGroup yes no
maxPassages yes no
region yes yes
l10N yes no
folderId yes yes
responseFormat yes yes
userAgent yes yes
{
            "query": {
              "search_type": "<search_type>",
              "query_text": "<search_query_text>",
              "family_mode": "<result_filter_setting_value>",
              "page": "<page_number>",
              "fix_typo_mode": "<typo_correction_mode_setting_value>"
            },
            "sort_spec": {
              "sort_mode": "<result_sorting_rule>",
              "sort_order": "<sort_order_of_results>"
            },
            "group_spec": {
              "group_mode": "<result_grouping_method>",
              "groups_on_page": "<number_of_groups_per_page>",
              "docs_in_group": "<number_of_documents_per_group>"
            },
            "max_passages": "<maximum_number_of_passages>",
            "region": "<region_ID>",
            "l10n": "<notification_language>",
            "folder_id": "<folder_ID>",
            "response_format": "<result_format>",
            "user_agent": "<User-Agent_header>"
        }
        

Where:

  • search_type: Search type. The possible values are:

    • SEARCH_TYPE_RU: For the Russian search type.
    • SEARCH_TYPE_TR: For the Turkish search type.
    • SEARCH_TYPE_COM: For the International search type.
    • SEARCH_TYPE_KK: For the Kazakh search type.
    • SEARCH_TYPE_BE: For the Belarusian search type.
    • SEARCH_TYPE_UZ: For the Uzbek search type.
  • query_text: Search query text. The maximum length is 400 characters.

  • family_mode: Results filtering. This is an optional parameter. The possible values are:

    • FAMILY_MODE_MODERATE: Moderate filter (default). Adult category documents are excluded from search results unless the query explicitly targets resources of this category.
    • FAMILY_MODE_NONE: Filtering is off. Search results include any documents regardless of their contents.
    • FAMILY_MODE_STRICT: Family filter. Regardless of the search query, Adult category documents and documents containing profanity are excluded from search results.
  • page: Requested page number. This is an optional parameter. By default, the first page with search results is returned. Page numbering starts from zero (0 stands for page one).

  • fix_typo_mode: Search query typo correction setting. This is an optional parameter. The possible values are:

    • FIX_TYPO_MODE_ON: Typo correction enabled (default). Search query typos are corrected automatically.
    • FIX_TYPO_MODE_OFF: Typo correction disabled. Search query typos are not corrected. The search is performed strictly as per the query.
  • sort_mode: Search results sorting mode rule. This is an optional setting. The possible values are:

    • SORT_MODE_BY_RELEVANCE: Sorting by relevance (default).
    • SORT_MODE_BY_TIME: Sorting by document update time.
  • sort_order: Search results sorting order. This is an optional setting. The possible values are:

    • SORT_ORDER_DESC: Forward sorting order from most recent to oldest (default).
    • SORT_ORDER_ASC: Reverse sorting order from oldest to most recent.
  • group_mode: Result grouping method. This is an optional setting. The possible values are:

    • GROUP_MODE_DEEP: Grouping by domain. Each group contains documents from one domain (default).
    • GROUP_MODE_FLAT: Flat grouping. Each group contains a single document.
  • groups_on_page: Maximum number of groups that can be returned per page. This is an optional setting. The default value is 20.

    When getting the result in XML format, the possible values range from 1 to 100, while for HTML format, from 5 to 50.

  • docs_in_group: Maximum number of documents that can be returned per group. This is an optional setting. Allowed values range from 1 to 3. The default value is 1.

  • max_passages: Maximum number of passages that can be used when generating a document snippet. This is an optional setting. Allowed values range from 1 to 5. By default, a maximum of four passages with search query text is returned per document.

  • region: Search country or region ID that affects the document ranking rules. Only supported for the Russian and Turkish search types.

    For a list of frequently used country and region IDs, see Search regions.

  • l10n: Search response notifications language. Affects the text in the found-docs-human tag and error messages. This is an optional setting. Possible values depend on the selected search type:

    • Russian:
      • LOCALIZATION_RU: Russian (default).
      • LOCALIZATION_BE: Belarusian.
      • LOCALIZATION_KK: Kazakh.
      • LOCALIZATION_UK: Ukrainian.
    • Turkish:
      • LOCALIZATION_TR: Turkish.
    • International:
      • LOCALIZATION_EN: English.
  • folder_id: Folder ID of the user or service account you will use for queries.

  • response_format: Search results format. This is an optional setting. The possible values are:

    • FORMAT_XML: The results will be delivered in XML format (default).
    • FORMAT_HTML: The results will be delivered in HTML format.
  • user_agent: String containing the User-Agent header. Use this parameter to have your search results optimized for a specific device and browser, including mobile search results. This is an optional setting. If not specified, you will get the default output.

List of supported parameters:

Note

The list of supported request parameters depends on the required output format, XML or HTML.

Parameter Supported in XML response Supported in HTML response
search_type yes yes
query_text yes yes
family_mode yes yes
page yes yes
fix_typo_mode yes no
sort_mode yes no
sort_order yes no
group_mode yes no
groups_on_page yes yes
docs_in_group yes no
max_passages yes no
region yes yes
l10n yes no
folder_id yes yes
response_format yes yes
user_agent yes yes

Synchronous search mode

You can run queries in synchronous mode using the Yandex Cloud ML SDK, REST API, and gRPC API.

In response to a synchronous mode query, depending on the query parameters you provide, Yandex Search API will return the result in XML or HTML format. The result is returned in the rawData response field as a Base64-encoded string.

Note

The response contains no required fields. It may not return a field if there is no relevant data.

Deferred (asynchronous) search mode

You can run queries in deferred mode using the Yandex Cloud ML SDK, REST API, and gRPC API.

In response to a deferred query, Yandex Search API returns an Operation object containing the operation info: status, ID, call time, etc.

With the Operation object ID, you can track the query execution status and get the results once the processing is complete. For more information, see Performing text search queries in deferred mode.

Depending on the specified query parameters, you will get the result in the response.rawData response field in XML or HTML format.

Response format for asynchronous search

In response to a deferred query, the Yandex Search API returns an Operation object in the following format:

Note

The response contains no required fields. It may not return a field if there is no relevant data.

{
         "done": true,
         "response": {
          "@type": "type.googleapis.com/yandex.cloud.searchapi.v2.WebSearchResponse",
          "rawData": "<Base64_encoded_XML_response_body>"
         },
         "id": "<operation_object_ID>",
         "description": "WEB search async",
         "createdAt": "2024-10-03T08:07:07Z",
         "createdBy": "<subject_ID>",
         "modifiedAt": "2024-10-03T08:12:09Z"
        }
        
{
          "id": "<operation_object_ID>",
          "description": "WEB search async",
          "createdAt": "2024-10-03T08:07:07Z",
          "createdBy": "<subject_ID>",
          "modifiedAt": "2024-10-03T08:12:09Z",
          "done": true,
          "response": {
            "@type": "type.googleapis.com/yandex.cloud.searchapi.v2.WebSearchResponse",
            "rawData": "<Base64_encoded_XML_response_body>"
          }
        }
        

The response object within the Operation object becomes available only after the query is executed on the Yandex Search API side and the done (operation status) field value changes to true.

The rawData value in the response object contains a Base64-encoded response in XML or HTML format, depending on the query parameters.

See also