All Products
Search
Document Center

OpenSearch:Usage of algorithm module parameters

Last Updated:Nov 07, 2024

When you use the algorithm feature of OpenSearch to implement the search feature, you need to upload necessary parameters to associate with the algorithm feature. The following sections describe how to add the necessary parameters of each algorithm module to a query request by using the SDK for Java. The parameters provided in the following examples are all in the form of pseudocode.

Query analysis

image

...
// Create a SearchParams object.
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'OpenSearch'"); // The search query is recommended by the drop-down suggestion feature.

// Add the from_request_id parameter.
Map<String, String> customParam =new HashMap<>();
customParam.put("raw_query","OpenSearch'");
searchParams.setCustomParam(customParam);


// Run the query and return the results in the form of a SearchResult object.
SearchResult execute = searcherClient.execute(searchParams);

...

Category prediction

image

...
// Create a SearchParams object.
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'Apple'"); // The search query is recommended by the drop-down suggestion feature.

// Add the from_request_id parameter.
Map<String, String> customParam =new HashMap<>();
customParam.put("raw_query","Apple");
searchParams.setCustomParam(customParam);


// Run the query and return the results in the form of a SearchResult object.
SearchResult execute = searcherClient.execute(searchParams);

...

Drop-down suggestions

  • raw_query: enables high-frequency search queries.

  • from_request_id: optimizes the sorting model of drop-down suggestions, improves the effects of drop-down suggestions to guide searches, and collects statistics on metrics used to assess the effects of drop-down suggestion-guided searches.

  • raw_query, user_id, and from_request_id: enable intelligent sorting.

image

...
// Create a SearchParams object.
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'Apple'"); // The search query is recommended by the drop-down suggestion feature.

// Add the from_request_id parameter.
Map<String, String> customParam =new HashMap<>();
customParam.put("raw_query","Apple");
customParam.put("user_id","12345");
customParam.put("from_request_id","159851481919726888064081");
searchParams.setCustomParam(customParam);


// Run the query and return the results in the form of a SearchResult object.
SearchResult execute = searcherClient.execute(searchParams);

...
  • Upload the raw_query parameter to a search request and upload the user_id parameter to a drop-down suggestion request to enable historical search queries.

...
// Create a SearchParams object.
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'Apple'"); // The search query is recommended by the drop-down suggestion feature.

// Add the from_request_id parameter.
Map<String, String> customParam =new HashMap<>();
customParam.put("raw_query","Apple");
searchParams.setCustomParam(customParam);


// Run the query and return the results in the form of a SearchResult object.
SearchResult execute = searcherClient.execute(searchParams);

...
    
    
// Create a suggestParams object.
SuggestParams suggestParams = new SuggestParams();
suggestParams.setUserId("12345");

Top searches and hints

  • raw_query: is used to train algorithm models such as top search models and hint models.

  • from_request_id and user_id: improve the effects of top searches and hints to guide searches, and collect statistics on metrics used to assess the effects of hot search- and hint-guided searches.

image

...
// Create a SearchParams object.
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'Apple'"); // The search query is recommended by the drop-down suggestion feature.

// Add the from_request_id parameter.
Map<String, String> customParam =new HashMap<>();
customParam.put("raw_query","Apple");
customParam.put("user_id","12345");
customParam.put("from_request_id","160851481919726888064913");
searchParams.setCustomParam(customParam);


// Run the query and return the results in the form of a SearchResult object.
SearchResult execute = searcherClient.execute(searchParams);

...

Cava-based plug-in

  • The name of the Cave script.

  • The sort type.

image

...
// Create a SearchParams object.
SearchParams searchParams = new SearchParams(config);
...

// Create a Rank object.
Rank rank=new Rank();
// Specify the Cava script that is to be called.
rank.setSecondRankName("test_cava");
// Specify the sort type by using the Cava script.
rank.setSecondRankType(RankType.CAVA_SCRIPT);
// Add the sort policy to the SearchParams object.
searchParams.setRank(rank);