Introduction
Category prediction is a basic feature in E-commerce search scenarios. It predicts the relevance between a search query and a product's category. For example, for the search query "apple", products in the fruit category are returned in a fresh food scenario. In a mobile phone scenario, Apple iPhones are returned. For more information about how to use category prediction, see Category Prediction User Guide. CategoryScore retrieves the category score of a search query for a document during the scoring procedure. You can create a CategoryScore object during the initialization phase of the scoring plugin. Then, you can call the scoring interface of CategoryScore to calculate the category score of the search query for the document during the scoring phase. The category score has three levels: 0, 1, and 2, where a higher score indicates higher relevance.
Function list
Function prototype | Function description |
CategoryScore create(OpsScorerInitParams params, CString fieldName) | A factory function that constructs a CategoryScore object. |
double evaluate(OpsScoreParams params) | Gets the category score of a search query for a document. |
Function details
CategoryScore create(OpsScorerInitParams params, CString fieldName)
A factory function that constructs a CategoryScore object. The `params` parameter specifies the input parameters for scoring. For more information, see OpsScoreParams User Guide. The `fieldName` parameter specifies the name of the category field in the document. This field must be a property field and a constant.
double evaluate(OpsScoreParams params)
This function is the scoring interface of CategoryScore. You can use it in the `score` function of the scoring plugin to return the category score of the search query for the document. The `params` parameter specifies the input parameters for scoring. For more information, see OpsScoreParams User Guide. Return value: The relevance score between the search query and the category in the document. The relevance score has three levels: 0, 1, and 2. A score of 0 indicates not relevant, 1 indicates relevant, and 2 indicates most relevant. Example:
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);
}
}