QueryTermMatchCount

更新时间:
复制 MD 格式

Introduction

QueryTermMatchCount calculates the number of term groups in a search query that are hit in a document. An OpenSearch index can contain multiple fields, and a document is returned if the search query hits a term in any of these fields. This allows QueryTermMatchCount to calculate the number of hits in two ways: across all fields in an index or within a specific field. For example, consider an index named `default` that contains `title` and `body` fields. If the search query is `default:'user manual'`, you can calculate the number of term groups hit across both the `title` and `body` fields. You can also calculate the number of term groups hit only in the `title` field or only in the `body` field.

Function list

Function prototype

Description

QueryTermMatchCount create(OpsScorerInitParams params)

Creates an object to count hits across all fields in all searched indexes.

QueryTermMatchCount create(OpsScorerInitParams params, CString indexName)

You can use `QueryTermMatchCount` to calculate the count of term groups from a search query that hit a specific field in an index.

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

Creates an object to count hits in a specific field of a specified index.

void setGroupScoreMergeOp(CString opName)

Sets the merge method for scores from multiple query groups. Supported methods: sum, max. Default: sum.

double evaluate(OpsScoreParams params)

Calculates the number of hit term groups in the search query.

Function details

QueryTermMatchCount create(OpsScorerInitParams params)

Creates a QueryTermMatchCount object. This object calculates the number of term groups in the search query that are hit across all fields of all searched indexes.

QueryTermMatchCount create(OpsScorerInitParams params, CString indexName)

Creates a QueryTermMatchCount object. This object calculates the number of term groups in the search query that are hit across all fields of a specified index. Parameters: indexName - The name of the index. This parameter must be a constant.

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

Creates a QueryTermMatchCount object. This object calculates the number of term groups in the search query that are hit in a specific field of a specified index. Parameters: indexName - The name of the index. This parameter must be a constant. fieldName - The name of the field. The field type must be TEXT or SHORT_TEXT. The tokenizer for the field must be Basic Chinese Tokenizer, Custom Tokenizer, Single-word Tokenizer, English Tokenizer, or Fuzzy Tokenizer. This parameter must be a constant.

void setGroupScoreMergeOp(CString opName)

Sets the rule to combine scores from multiple query groups. The supported rules are max and sum. If you do not set a rule, the scores from all groups are summed by default. Call this function during the initialization phase of the scoring plug-in. A query group is an extension of the original search query that is created after query analysis. By default, only one query group exists.

Parameters: opName - The rule to combine scores from multiple query groups. The supported values are max and sum.

double evaluate(OpsScoreParams params)

Calculates the number of hit term groups in the search query. Parameters: params - The input parameters for scoring. For more information, see the OpsScoreParams manual. Return value: The number of hit term groups in the search query. Code example:

package users.scorer;
import com.aliyun.opensearch.cava.framework.OpsScoreParams;
import com.aliyun.opensearch.cava.framework.OpsScorerInitParams;
import com.aliyun.opensearch.cava.features.similarity.querymatch.QueryTermMatchCount;

class BasicSimilarityScorer {
    QueryTermMatchCount _f1;
    boolean init(OpsScorerInitParams params) {
        _f1 = QueryTermMatchCount.create(params, "pack_index2", "text_field1");
        return true;
    }

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