All Products
Search
Document Center

OpsDoc

Last Updated: Sep 09, 2021

Overview

During score calculation, different scores are given to documents based on the values of the fields in the documents. The scores are used to sort search results. The OpsDoc class encapsulates specific interfaces that you can use to obtain fields in documents. You can use an OpsDoc object to obtain only attribute fields that are configured in the OpenSearch console and declared in advance. The fields can be declared by invoking the requireAttribute function of the OpsDoc class in the init function of a sort plug-in. OpsDoc objects are automatically created by the system, and you can directly use them.

Unlike sort expressions, sort scripts written by using Cava require you to manually invoke trace functions to display trace information. The OpsDoc class encapsulates a series of trace functions that allow you to generate various types of trace information. You cannot change the parameters that are used by the trace functions encapsulated by the OpsDoc class. If you need to display the results of multiple variables, you must call the trace method multiple times. You can view trace information only on the Search Test page. Regular search requests do not support the trace feature. The memory for processing a single request by using Cava is limited, and a large number of traces occupy a large amount of runtime memory. Therefore, we recommend that you invoke trace functions only when necessary.

Functions

Function

Description

boolean requireAttribute(CString fieldName)

Declares an attribute field that needs to be used during score calculation.

long docFieldLong(CString fieldName)

Obtains the value of a field of the INT type.

float docFieldFloat(CString fieldName)

Obtains the value of a field of the FLOAT type.

double docFieldDouble(CString fieldName)

Obtains the value of a field of the DOUBLE type.

CString docFieldLiteral(CString fieldName)

Obtains the value of a field of the LITERAL type.

long[] docFieldLongArray(CString fieldName)

Obtains the value of a field of the INT_ARRAY type.

float[] docFieldFloatArray(CString fieldName)

Obtains the value of a field of the FLOAT_ARRAY type.

double[] docFieldDoubleArray(CString fieldName)

Obtains the value of a field of the DOUBLE_ARRAY type.

CString[] docFieldLiteralArray(CString fieldName)

Obtains the value of a field of the LITERAL_ARRAY type.

OpsGeoPoint docFieldGeoPoint(CString fieldName)

Obtains the value of a field of the GEO_POINT type.

OpsTimestamp docFieldTimestamp(CString fieldName)

Obtains the value of a field of the TIMESTAMP type.

boolean declareLongVariable(CString variableName, boolean needSeraialize)

Declares a variable of the LONG type. The variable can be used in score calculation plug-ins or returned in documents.

boolean declareDoubleVariable(CString variableName, boolean needSeraialize)

Declares a variable of the DOUBLE type. The variable can be used in score calculation plug-ins or returned in documents.

void setLongVariable(CString variableName, long value)

Sets the value of a variable of the LONG type. The variable must have been declared.

void setDoubleVariable(CString variableName, double value)

Sets the value of a variable of the DOUBLE type. The variable must have been declared.

long getLongVariable(CString variableName)

Obtains the value of a variable of the LONG type. The value of the variable must have been set.

double getDoubleVariable(CString variableName)

Obtains the value of a variable of the DOUBLE type. The value of the variable must have been set.

void trace(byte value)

Displays trace information of the BYTE type during score calculation.

void trace(CString prefix, byte value)

Displays trace information of the BYTE type during score calculation.

void trace(short value)

Displays trace information of the SHORT type during score calculation.

void trace(CString prefix, short value)

Displays trace information of the SHORT type during score calculation.

void trace(int value)

Displays trace information of the INT type during score calculation.

void trace(CString prefix, int value)

Displays trace information of the INT type during score calculation.

void trace(long value)

Displays trace information of the LONG type during score calculation.

void trace(CString prefix, long value)

Displays trace information of the LONG type during score calculation.

void trace(float value)

Displays trace information of the FLOAT type during score calculation.

void trace(CString prefix, float value)

Displays trace information of the FLOAT type during score calculation.

void trace(double value)

Displays trace information of the DOUBLE type during score calculation.

void trace(CString prefix, double value)

Displays trace information of the DOUBLE type during score calculation.

void trace(CString value)

Displays trace information of the CString type during score calculation.

void trace(CString prefix, CString value)

Displays trace information of the CString type during score calculation.

Function details

boolean requireAttribute(CString fieldName)

Declares an attribute field that needs to be used during score calculation. This function can be invoked only during the initialization of score calculation. If the field is not declared during the initialization, the value of the field cannot be correctly retrieved from a document during score calculation.
Parameter:
fieldName: the name of an attribute field. The name must be a constant.
Return value:
If the field is declared, true is returned. Otherwise, false is returned. In most cases, false is returned because the declared field is not an attribute field.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        CString field1;
        boolean ret = params.getDoc().requireAttribute(field1); // field1 must be a constant.
        ret = params.getDoc().requireAttribute("price"); //ok
          return ret;
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        float floatValue = doc.docFieldFloat("price");
        return floatValue;
    }
}

long docFieldLong(CString fieldName)

Obtains the value of a field of the INT type. The return value is a long integer. If the field is of the FLOAT or DOUBLE type, the return value is the nearest integer to which the value of the field is rounded. If the field is of the LITERAL or ARRAY type, 0 is returned.
Parameter:
fieldName: the name of an attribute field. The name must be a constant.
Return value:
The value of the field is returned.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        boolean ret = params.getDoc().requireAttribute("count"); 
          return ret;
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        long count = doc.docFieldLong("count");
        return (double)count;
    }
}

float docFieldFloat(CString fieldName)

Obtains the value of a field of the FLOAT type. The return value is a floating-point number.
Parameter:
fieldName: the name of an attribute field. The name must be a constant.
Return value:
The value of the field is returned.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        boolean ret = params.getDoc().requireAttribute("count"); 
          return ret;
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        float count = doc.docFieldFloat("count");
        return (double)count;
    }
}

double docFieldDouble(CString fieldName)

Obtains the value of a field of the DOUBLE type. The return value is a double-precision floating-point number.
Parameter:
fieldName: the name of an attribute field. The name must be a constant.
Return value:
The value of the field is returned.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        boolean ret = params.getDoc().requireAttribute("count"); 
          return ret;
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        double count = doc.docFieldDouble("count");
        return count;
    }
}

CString docFieldLiteral(CString fieldName)

Obtains the value of a field of the LITERAL type. The return value is of the CString type.
Parameter:
fieldName: the name of an attribute field. The name must be a constant.
Return value:
The value of the field is returned.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        boolean ret = params.getDoc().requireAttribute("tag"); 
          return ret;
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        CString tag = doc.docFieldLiteral("tag");
        if (tag.equals("abc")) {
            return 100.0;
        }
        return 0;
    }
}

long[] docFieldLongArray(CString fieldName)

Obtains the value of a field of the INT_ARRAY type.
Parameter:
fieldName: the name of an attribute field. The name must be a constant.
Return value:
The value of the field is returned. If the field does not exist, the type of the field cannot be converted, or the field is not of the ARRAY type, null is returned.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        boolean ret = params.getDoc().requireAttribute("tags"); 
          return ret;
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        long[] tags = doc.docFieldLongArray("tags");
        if (tags != null) {
            if (tags.length > 0) {
                return (double)tags[0];
            }
        }
        return 0;
    }
}

float[] docFieldFloatArray(CString fieldName)

Obtains the value of a field of the FLOAT_ARRAY type.
Parameter:
fieldName: the name of an attribute field. The name must be a constant.
Return value:
The value of the field is returned. If the field does not exist, the type of the field cannot be converted, or the field is not of the ARRAY type, null is returned.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        boolean ret = params.getDoc().requireAttribute("tags"); 
          return ret;
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        float[] tags = doc.docFieldFloatArray("tags");
        if (tags != null) {
            if (tags.length > 0) {
                return (double)tags[0];
            }
        }
        return 0;
    }
}

double[] docFieldDoubleArray(CString fieldName)

Obtains the value of a field of the DOUBLE_ARRAY type.
Parameter:
fieldName: the name of an attribute field. The name must be a constant.
Return value:
The value of the field is returned. If the field does not exist, the type of the field cannot be converted, or the field is not of the ARRAY type, null is returned.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        boolean ret = params.getDoc().requireAttribute("tags"); 
          return ret;
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        double[] tags = doc.docFieldDoubleArray("tags");
        if (tags != null) {
            if (tags.length > 0) {
                return (double)tags[0];
            }
        }
        return 0;
    }
}

CString[] docFieldLiteralArray(CString fieldName)

Obtains the value of a field of the LITERAL_ARRAY type.
Parameter:
fieldName: the name of an attribute field. The name must be a constant.
Return value:
The value of the field is returned. If the field does not exist, the type of the field cannot be converted, or the field is not of the ARRAY type, null is returned.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        boolean ret = params.getDoc().requireAttribute("tags"); 
          return ret;
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        CString[] tags = doc.docFieldLiteralArray("tags");
        if (tags != null) {
            if (tags.length > 0 && tags[0].equals("abc")) {
                return 100.0;
            }
        }
        return 0;
    }
}

OpsGeoPoint docFieldGeoPoint(CString fieldName)

Obtains the value of a field of the GEO_POINT type. An OpsGeoPoint object must be referenced.
Parameter:
fieldName: the name of an attribute field. The name must be a constant.
Return value:
The value of the field is returned. If the field does not exist, or the type of the field is invalid, null is returned.

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.OpsDoc;
import com.aliyun.opensearch.cava.framework.OpsGeoPoint;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        boolean ret = params.getDoc().requireAttribute("location"); 
          return ret;
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        OpsGeoPoint location = doc.docFieldGeoPoint("location");
        double longitude = location.getLongitude();
        if (longitude < 0 || longitude > 180.0) {
            return 0;
        }
        return 1.0;
    }
}

OpsTimestamp docFieldTimestamp(CString fieldName)

Obtains the value of a field of the TIMESTAMP type. An OpsTimestamp object must be referenced.
Parameter:
fieldName: the name of an attribute field. The name must be a constant.
Return value:
The value of the field is returned. If the field does not exist, or the type of the field is invalid, null is returned.

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.OpsDoc;
import com.aliyun.opensearch.cava.framework.OpsTimestamp;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        boolean ret = params.getDoc().requireAttribute("timestamp"); 
          return ret;
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        OpsTimestamp timestamp = doc.docFieldTimestamp("timestamp");
        return (double)timestamp.getValue();
    }
}

boolean declareLongVariable(CString variableName, boolean needSeraialize)

Declares a variable of the LONG type, which is used for multiple plug-ins to pass information or return the value of the variable in the result. This function can be invoked only during the initialization of score calculation. A maximum of 30 variables can be declared in a plug-in. If the limit is exceeded, an error is returned.

Parameters:

variableName: the name of the variable. The name must be a constant.

needSeraialize: specifies whether to return the variable in the document. The value must be a constant. Valid values: true and false.

Return value:

If the variable is declared, true is returned. Otherwise, false is returned.

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.framework.OpsGeoPoint;
import com.aliyun.opensearch.cava.framework.OpsTimestamp;

class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return params.getDoc().declareLongVariable("v_int64", true);
    }

    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        doc.setLongVariable("v_int64", 100);
        
        long longValue = doc.getLongVariable("v_int64");
        doc.trace("long value1: ", longValue);
        return 0;
    }
}

boolean declareDoubleVariable(CString variableName, boolean needSeraialize)

Declares a variable of the DOUBLE type. The variable is used when you need to pass information among multiple plug-ins or return the value of the variable in the result. This function can be invoked only during the initialization of score calculation. A maximum of 30 variables can be declared in a plug-in. If the limit is exceeded, an error is returned.

Parameters:

variableName: the name of the variable. The name must be a constant.

needSeraialize: specifies whether to return the variable in the document. The value must be a constant. Valid values: true and false.

Return value:

If the variable is declared, true is returned. Otherwise, false is returned.

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.framework.OpsGeoPoint;
import com.aliyun.opensearch.cava.framework.OpsTimestamp;

class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return params.getDoc().declareDoubleVariable("v_double", true);
    }

    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        doc.setDoubleVariable("v_double", 100);
        
        long doubleValue = doc.getDoubleVariable("v_double");
        doc.trace("double value1: ", doubleValue);
        return 0;
    }
}

void setLongVariable(CString variableName, long value)

Sets the value of a variable of the LONG type. This function must be invoked during score calculation. The variable must be declared during initialization.

Parameters:

variableName: the name of the variable.

value: the value of the variable.

void setDoubleVariable(CString variableName, long value)

Sets the value of a variable of the DOUBLE type. This function must be invoked during score calculation. The variable must be declared during initialization.

Parameters:

variableName: the name of the variable.

value: the value of the variable.

long getLongVariable(CString variableName)

Returns the value of a variable of the LONG type. This function must be invoked during score calculation. The variable must be declared during initialization.

Parameter:

variableName: the name of the variable.

Return value:

The value of the variable is returned. If the variable is not declared, or the value of the variable is not set, 0 is returned by default.

double getDoubleVariable(CString variableName)

Returns the value of a variable of the DOUBLE type. This function must be invoked during score calculation. The variable must be declared during initialization. If the variable is not declared, or the value of the variable is not set, 0 is returned by default.

Parameter:

variableName: the name of the variable.

Return value:

The value of the variable is returned. If the variable is not declared, or the value of the variable is not set, 0 is returned by default.

void trace(byte value)

Displays trace information of the BYTE type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameter:
value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           byte value = 1;
        doc.trace(value);
        return 0.0;
    }
}

void trace(CString prefix, byte value)

Displays trace information of the BYTE type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameters:
prefix: the trace prefix that facilitates searches. value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           byte value = 1;
        doc.trace("byte value: ", value);
        return 0.0;
    }
}

void trace(short value)

Displays trace information of the SHORT type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameter:
value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           short value = 1;
        doc.trace(value);
        return 0.0;
    }
}

void trace(CString prefix, short value)

Displays trace information of the SHORT type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameters:
prefix: the trace prefix that facilitates searches. value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           short value = 1;
        doc.trace("short value: ", value);
        return 0.0;
    }
}

void trace(int value)

Displays trace information of the INT type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameter:
value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           int value = 1;
        doc.trace(value);
        return 0.0;
    }
}

void trace(CString prefix, int value)

Displays trace information of the INT type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameters:
prefix: the trace prefix that facilitates searches. value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           int value = 1;
        doc.trace("int value: ", value);
        return 0.0;
    }
}

void trace(long value)

Displays trace information of the LONG type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameter:
value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           long value = 1;
        doc.trace(value);
        return 0.0;
    }
}

void trace(CString prefix, long value)

Displays trace information of the LONG type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameters:
prefix: the trace prefix that facilitates searches. value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           long value = 1;
        doc.trace("long value: ", value);
        return 0.0;
    }
}

void trace(float value)

Displays trace information of the FLOAT type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameter:
value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           float value = 1;
        doc.trace(value);
        return 0.0;
    }
}

void trace(CString prefix, float value)

Displays trace information of the FLOAT type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameters:
prefix: the trace prefix that facilitates searches. value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           float value = 1.0;
        doc.trace("float value: ", value);
        return 0.0;
    }
}

void trace(double value)

Displays trace information of the DOUBLE type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameter:
value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           double value = 1;
        doc.trace(value);
        return 0.0;
    }
}

void trace(CString prefix, double value)

Displays trace information of the DOUBLE type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameters:
prefix: the trace prefix that facilitates searches. value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           double value = 1.0;
        doc.trace("double value: ", value);
        return 0.0;
    }
}

void trace(CString value)

Displays trace information of the CString type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameter:
value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           CString value = "abc";
        doc.trace(value);
        return 0.0;
    }
}

void trace(CString prefix, CString value)

Displays trace information of the CString type. The trace information can be displayed for a document and can be displayed only during search tests.
Parameters:
prefix: the trace prefix that facilitates searches. value: the content to be displayed.

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.OpsDoc;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return true;
    }
    double score(OpsScoreParams params) {
           OpsDoc doc = params.getDoc();
           CString value = "abc";
        doc.trace("CString value: ", value);
        return 0.0;
    }
}