All Products
Search
Document Center

FieldLength

Last Updated: Sep 09, 2021

Overview

The FieldLength class is used to obtain the number of terms after the analysis of a field in an index.

Functions

Function

Description

FieldLength create(OpsScorerInitParams params, CString indexName, CString fieldName)

Creates a FieldLength object.

double evaluate(OpsScoreParams params)

Returns the number of terms after the analysis of a field in an index.

Function details

FieldLength create(OpsScorerInitParams params, CString indexName, CString fieldName)

Creates a FieldLength object.

Parameters: params: the parameters that are used for score calculation. For more information, see OpsScoreParams. indexName: the name of an index. The name must be a constant. fieldName: the name of a field in the specified index. The name must be a constant. The field must be of the TEXT or SHORT_TEXT type. The analyzer can be the general analyzer for Chinese, a custom analyzer, the single character analyzer for Chinese, the analyzer for English, or the analyzer for fuzzy searches.

double evaluate(OpsScoreParams params)

Returns the number of terms after the analysis of a field in an index. Parameter: params: the parameters that are used for score calculation. For more information, see OpsScoreParams. 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.similarity.fieldmatch.FieldLength;

class BasicSimilarityScorer {
    FieldLength _fieldLength;
    boolean init(OpsScorerInitParams params) {
        _fieldLength = FieldLength.create(params, "text_index1", "text_field");
        return true;
    }   

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