All Products
Search
Document Center

Popularity

Last Updated: Sep 09, 2021

Overview

Popularity is a basic sort feature provided by OpenSearch to measure the popularity of items. Before you use the popularity feature, you must create and deploy a popularity model in OpenSearch. To implement the popularity feature, create a popularity object when you initialize a score calculation object. Then, during score calculation, call the `double evaluate(OpsScoreParams params)` function to calculate the popularity score for each document.

Functions

Function

Description

Popularity create(OpsScorerInitParams params, CString modelName)

Creates a popularity object.

Popularity create(OpsScorerInitParams params, CString modelName, float defaultValue)

Creates a popularity object and specifies the default popularity score.

double evaluate(OpsScoreParams params)

Obtains the popularity score of a document.

Function details

Popularity create(OpsScorerInitParams params, CString modelName)

Creates a popularity object. You must specify the name of the popularity model. Parameters: params: the parameters that are used for score calculation. For more information, see OpsScoreParams. modelName: the name of the popularity model that is created and deployed in the OpenSearch console. The name must be a constant.

Popularity create(OpsScorerInitParams params, CString modelName, float defaultValue)

Creates a popularity object. You must specify the name of the popularity model and the default popularity score. New documents may have no popularity score. To ensure that the new documents can be displayed in the search results, you can specify a default popularity score for the new documents. The value range of the popularity score is [0,1]. The default value must also be within this value range. Parameters: params: the parameters that are used for score calculation. For more information, see OpsScoreParams. modelName: the name of the popularity model that is created and deployed in the OpenSearch console. The name must be a constant. defaultValue: the default popularity score. The value must be a constant.

double evaluate(OpsScoreParams params)

Calculates the popularity score of a document. Parameter: params: the parameters that are used for score calculation. For more information, see OpsScoreParams. Return value: the popularity score of a document. Valid values: [0,1]. Sample code:

package users.scorer;
import com.aliyun.opensearch.cava.framework.OpsScoreParams;
import com.aliyun.opensearch.cava.framework.OpsScorerInitParams;
import com.aliyun.opensearch.cava.framework.OpsRequest;
import com.aliyun.opensearch.cava.framework.OpsDoc;
import com.aliyun.opensearch.cava.features.algo.Popularity;

class IntelligenceAlgorithmScorer {
    Popularity _pop;
    boolean init(OpsScorerInitParams params) {
        _pop = Popularity.create(params, "pop1", 0.123F); // pop1 is the name of the popularity model.
        return true;
    }

    double score(OpsScoreParams params) {
        return _pop.evaluate(params);
    }
}