All Products
Search
Document Center

CategoryScore

Last Updated: Sep 09, 2021

Overview

Category prediction is a basic feature in e-commerce search scenarios. This feature is used to predict the relevance of a query term to a commodity category. For example, the query term is "apple". In the category of fruits, the search results need to contain fruit brands. In the category of mobile phones, the search results need to contain iPhones. For more information about how to use the category prediction feature, see Overview of category prediction. The CategoryScore class is used to obtain the score that indicates the relevance of a query term to a category in a document during score calculation. To implement the category prediction feature, create a CategoryScore object when you initialize a score calculation object. Then, during score calculation, call the `double evaluate(OpsScoreParams params)` function to calculate the score that indicates the relevance of a query term to a category in a document. The score can be 0, 1, or 2. A greater value indicates higher relevance.

Functions

Function

Description

CategoryScore create(OpsScorerInitParams params, CString fieldName)

Creates a CategoryScore object.

double evaluate(OpsScoreParams params)

Obtains the score that indicates the relevance of a query term to a category in a document.

Function details

CategoryScore create(OpsScorerInitParams params, CString fieldName)

Creates a CategoryScore object. Parameters: params: the parameters that are used for score calculation. For more information, see OpsScoreParams. fieldName: the name of the category field in the document. The field must be an attribute field. The name must be a constant.

double evaluate(OpsScoreParams params)

Calculates the score that indicates the relevance of a query term to a category in a document. This function is called in the score function of score calculation objects. Parameter: params: the parameters that are used for score calculation. For more information, see OpsScoreParams. Return value: the score that indicates the relevance of a query term to a category in a document. The score can be 0, 1, or 2. A value of 0 indicates that the query term is irrelevant to the category in the document. A greater value indicates higher relevance. Sample code:

package users.scorer;
import com.aliyun.opensearch.cava.framework.OpsScoreParams;
import com.aliyun.opensearch.cava.framework.OpsScorerInitParams;
import com.aliyun.opensearch.cava.features.CategoryScore;

class BasicSimilarityScorer {
    CategoryScore _categoryScore;
    boolean init(OpsScorerInitParams params) {
        _categoryScore = CategoryScore.create(params, "category_field");
        return true;
    }

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