All Products
Search
Document Center

QueryMinSlideWindow

Last Updated: Sep 09, 2021

Overview

The QueryMinSlideWindow class is used to calculate the ratio of the number of terms that a search query hits in a specified field to the minimum window of the search query in the field. After a field is analyzed, OpenSearch assigns an ID for each term. The IDs start from 0. For example, after the title field is analyzed, the terms are Open, Search, User, and Manual. The IDs of the terms are 0, 1, 2, and 3. A search query contains the following terms after analysis: Search and Manual. In this case, the number of terms that the search query hits is 2. The minimum window of the search query in the title field is 3.

Functions

Function

Description

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

Creates a QueryMinSlideWindow object.

QueryMinSlideWindow create(OpsScorerInitParams params, CString indexName, CString fieldName, boolean inOrder)

Creates a QueryMinSlideWindow object. The inOrder parameter specifies whether to preserve the term order during the calculation of the minimum window.

double evaluate(OpsScoreParams params)

Calculates the ratio of the number of terms that a search query hits in a specified field to the minimum window of the search query in the field.

Function details

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

Creates a QueryMinSlideWindow object that calculates the ratio of the number of terms that a search query hits in a specified field to the minimum window of the search query in the field. Parameters: params: the parameters that are used for score calculation. For more information, see OpsScorerInitParams. indexName: the name of an index. The name must be a constant. 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. 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.

QueryMinSlideWindow create(OpsScorerInitParams params, CString indexName, CString fieldName, boolean inOrder)

Creates a QueryMinSlideWindow object that calculates the ratio of the number of terms that a search query hits in a specified field to the minimum window of the search query in the field. The inOrder parameter specifies whether to preserve the term order during the calculation of the minimum window. Parameters: params: the parameters that are used for score calculation. For more information, see OpsScorerInitParams. indexName: the name of an index. The name must be a constant. 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. 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. inOrder: specifies whether to preserve the term order during the calculation of the minimum window. Valid values: true and false.

double evaluate(OpsScoreParams params)

Calculates the ratio of the number of terms that a search query hits in a specified field to the minimum window of the search query in the field. Parameter: params: the parameters that are used for score calculation. For more information, see OpsScoreParams. Return value: the ratio of the number of terms that the search query hits in the specified field to the minimum window of the search query in the field. 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.similarity.distribution.QueryMinSlideWindow;

class BasicSimilarityScorer {
    QueryMinSlideWindow _f1;
    QueryMinSlideWindow _f2;
    boolean init(OpsScorerInitParams params) {
        _f1 = QueryMinSlideWindow.create(params, "pack_index1", "text_field");
        _f2 = QueryMinSlideWindow.create(params, "pack_index1", "text_field", true);
        return true;
    }

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