All Products
Search
Document Center

OpenSearch:Top searches and hints

Last Updated:May 11, 2022

Overview

Top searches and hints are essential features of a complete search engine. They are often displayed in prominent positions in or near the search box and provide indispensable business value.

In a search engine, top searches and hints are provided to users in the first step of the search process. Better top searches and hints facilitate subsequent steps by reducing the difficulties in optimizing these steps, including query analysis, sorting, and operational intervention. In addition, top searches and hints can be used with operational strategies to ensure that business goals are achieved. The business value of top searches and hints can be analyzed from different perspectives.

From the perspective of users, top searches and hints can meet the following requirements:

Note

  1. Users who do not know what to search for want to check the recommended high-quality queries.

  2. Users want to know what everyone is searching for.

  3. Users want diverse queries that are recommended based on their interests. This way, these users can search for what they are interested in and explore content beyond their interests.

From the perspective of operators, top searches and hints can provide the following business value:

Note
  1. Operators can obtain queries that have been searched most. Hot queries indicate the interests of users. Operators can analyze hot queries to grasp the interest trend and formulate operational strategies, such as promotions, replenishment, and campaigns.

  2. Operators can use drop-down suggestions to guide the intents of users when they enter something in the search box. For users who have not entered anything, operators can use top searches and hints to recommend high-quality queries to these users.

  3. Top searches and hints ensure that diverse queries, instead of only the hottest queries, are recommended to users. This ensures user experience and increases the chance that popular queries, but not the hottest queries, are displayed to users.

  4. Operators can analyze the behavior of users to recommend queries based on their preference. This improves user experience and the precision of recommendations.

Procedure

Procedure of using top searches and hints

  1. Create and train models.

  2. Obtain the top searches and hints.

1. Create and train models

1.1 Creation methods

  • Create models in the OpenSearch console. Note: You can select a method as required.

Usage notes

  • The system trains the top search and hint models by using the queries that are labeled as raw_query in historical search requests. If the historical search requests do not contain queries that are labeled as raw_query, the models may fail to be created.

  • The models rely only on statistics that are collected from search logs based on specific algorithms. Other training goals are not supported. Therefore, the models need to be created only once.

  • After the models are created, the system automatically retrains the models every day and no human intervention is needed.

  • After the models are created and trained, you can query the top searches and hints in a period within the past half-year. By default, the data in the past 14 days is returned.

Create the top search and hint models in the OpenSearch console

Step 1: Enable training of the top search and hint models Log on to the OpenSearch console. In the left-side navigation pane, choose Search Algorithm Center > Search guide. On the Drop-down Suggestions page, click Top Searches and Hints in the left-side pane. On the Top Searches and Hints page, select an application and enable training of the top search and hint models.1

Step 2: Wait for the system to complete training2

Step 3: Preview the top searches and hints

Top search preview3Hint preview4

Create the top search and hint models by using the SDK

Management and Control SDK dependencies

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-opensearch</artifactId>
    <version>0.7.0</version>
</dependency>
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>4.5.0</version>
</dependency>

SDK for Java demo

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.opensearch.model.v20171225.*;
import com.aliyuncs.profile.DefaultProfile;
public class CreateModel {
    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);
        CreateModelRequest request = new CreateModelRequest();
        request.setAppGroupIdentity("app_name");
 // The type parameter specifies the model type. A value of hot indicates the top search model. A value of hint indicates the hint model. The modelName parameter specifies the model name. You can enter a custom name that consists of digits, letters, and underscores (_). The name cannot contain only digits and can be up to 30 characters in length.
        String content = "{\"type\": \"hot\",\"name\": \"model_name\"}";
        request.setHttpContent(content.getBytes(), "UTF-8", FormatType.JSON);
        try {
            HttpResponse response = client.doAction(request);
            System.out.println(response.getHttpContentString());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

2. Obtain the top searches and hints

After the top search and hint features are integrated into your product, you can obtain the recommended top searches and hints by calling API operations or using the SDK. For more information about the API operations, see the API document. For more information about how to use the SDK, see the following SDK demo code.

By default, 10 top searches and 3 hints are returned. The hints can be displayed in the search box in turn.

Usage notes

  • No API operation is provided for you to obtain the status of a model training task. You must check whether results are available by calling an API operation or using the SDK.

  • After the models are created, the system automatically runs model training tasks every day. You can obtain updated top searches and hints by calling an API operation or using the SDK.

  • When you use the SDK to call the API operations for obtaining top searches and hints, you can set the hit parameter to 30 at most for top searches and 10 at most for hints. The hit parameter specifies the number of top searches or hints that you want to obtain.

Traffic SDK dependencies

<dependency>
    <groupId>com.aliyun.opensearch</groupId>
    <artifactId>aliyun-sdk-opensearch</artifactId>
    <version>3.5.0</version>
</dependency>

SDK for Java demo

import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.aliyun.opensearch.OpenSearchClient;
import com.aliyun.opensearch.sdk.generated.OpenSearch;
import com.aliyun.opensearch.sdk.generated.commons.OpenSearchClientException;
public class Hot {
    private static final String accesskey = "Your AccessKey ID";
    private static final String secret = "Your AccessKey secret";
    private static final String host = "The endpoint of the OpenSearch API, such as http://opensearch-cn-hangzhou.aliyuncs.com";
    private static final String appName = "The name of your OpenSearch application";
    private static final String HOT_API_PATH = "/apps/{app_name}/actions/hot";
    public static void main(String[] args) {
        OpenSearch openSearch = new OpenSearch(accesskey, secret, host);
        // Create OpenSearchClient
        OpenSearchClient client = new OpenSearchClient(openSearch);
        String requestPath = HOT_API_PATH.replaceAll(("\\{app_name\\}"), appName);
        Map<String, String> params = new HashMap<>();
        params.put("model_name", "your_model_name");// Specify the model name.
        params.put("hit", "20");// Specify the number of top searches that you want to obtain.
        try {
            String response = client.call(requestPath, params, OpenSearchClient.METHOD_GET);
            System.out.println(JSON.toJSONString(response));
        } catch (OpenSearchClientException e) {
            e.printStackTrace();
        }
    }
}

Model optimization

User behavior data

The top searches and hints that are generated based on statistics collected from search logs can meet the requirements at the initial use of the top search and hint features. After the features are put into use, we recommend that you associate user behavior data with top searches and hints. The system collects user behavior data, including the from_request_id and user_id parameters. The user behavior data can be used to further optimize the models. The user behavior data has the following benefits:

Note

  1. You can obtain a variety of metrics, such as the page views (PVs), unique visitors (UV), and zero-result rate of searches guided by top searches and hints. These metrics allow you to evaluate the top search and hint features and improve the features.

  2. You can analyze the interest trend of your user group and formulate operational strategies based on the trend.

  3. You can recommend queries in a smart way. After you mark data based on user click behavior, you can train the models for different optimization goals. By default, models are optimized based on the click rate. Then, you can recommend queries generated by the models that have strong generalization ability.

  4. You can recommend personalized hot queries to users. After you obtain the queries initiated by users, you can customize the recommendations based on their preference.

Search traffic guided by top searches and hints

When you obtain top searches or hints by calling an API operation or using the SDK, the system returns the request_id parameter that contains an ID. The ID uniquely identifies the request. When a user clicks a top search or hint in your product, the system initiates a search request based on the top search or hint. You can allow the system to set the from_request_id parameter in the search request to the value of the request_id parameter. This way, the user click behavior is associated top searches and hints. After the system collects statistics from search logs and user behavior data, you can view the metrics of search traffic guided by hot searches and hints in business operation reports. If the user_id parameter is set in search requests, you can also view the UV metric of search traffic guided by hot searches and hints in business operation reports.

Usage notes

  • A page turning request after a search is also considered as an independent PV. Therefore, the from_request_id parameter must also be set for a page turning request that follows a search guided by a top search or hint.

  • For more information about the parameters of a search request, see from_request_id and user_id.

Business operation reports

View business operation reports in the OpenSearch console

Business operation report for top searches

Log on to the OpenSearch console. In the left-side navigation pane, choose Search Algorithm Center > Search guide. On the Drop-down Suggestions page, click Top Searches and Hints in the left-side pane. On the Top Searches and Hints page, click View Metrics for top searches. On the Hot search report page, view the business operation report for top searches.5

Alternatively, choose Report Statistics > Hot search report in the left-side navigation pane to view the business operation report for top searches.6

Business operation report for hints

Log on to the OpenSearch console. In the left-side navigation pane, choose Search Algorithm Center > Search guide. On the Drop-down Suggestions page, click Top Searches and Hints in the left-side pane. On the Top Searches and Hints page, click View Metrics for hints. On the Shading report page, view the business operation report for hints.7

Alternatively, choose Report Statistics > Shading report in the left-side navigation pane to view the business operation report for hints.8

Usage notes

  • For more information about the metrics in the business report for top searches, see Top search report.

  • For more information about the metrics in the business report for hints, see Hint report.