BasicSimilarityScore computes a relevance score for a document and exposes it as a component that IntelligenceAlgorithmScorer can consume during query-time scoring.
Constructor
| Signature | Description |
|---|---|
BasicSimilarityScore create(OpsScorerInitParams params) | Factory method that creates a BasicSimilarityScore instance. params carries the initialization parameters passed from the scoring framework. For parameter details, see OpsScorerInitParams. |
Methods
| Signature | Description |
|---|---|
double evaluate(OpsScoreParams params) | Calculates and returns the relevance score for a document. |
Method details
BasicSimilarityScore create(OpsScorerInitParams params)
A factory method that creates a BasicSimilarityScore object.
Parameter
| Name | Type | Description |
|---|---|---|
params | OpsScorerInitParams | Initialization parameters provided by the scoring framework. |
double evaluate(OpsScoreParams params)
Calculates the relevance score for a document. Call this method from the score() method of your scorer class. The returned double is the document's score, which IntelligenceAlgorithmScorer uses directly as its output.
Parameter
| Name | Type | Description |
|---|---|---|
params | OpsScoreParams | Score calculation parameters provided by the scoring framework. For details, see OpsScoreParams. |
Return value
The relevance score of the document as a double.
Example
The example shows two classes working together: BasicSimilarityScorer wraps a BM25F field-match scorer, and IntelligenceAlgorithmScorer delegates to BasicSimilarityScore to produce the final document score.
package users.scorer;
import com.aliyun.opensearch.cava.framework.OpsScoreParams;
import com.aliyun.opensearch.cava.framework.OpsScorerInitParams;
import com.aliyun.opensearch.cava.features.similarity.fieldmatch.BM25F;
import com.aliyun.opensearch.cava.features.BasicSimilarityScore;
class BasicSimilarityScorer {
BM25F _f1;
boolean init(OpsScorerInitParams params) {
CString[] fields1 = {"title"};
_f1 = BM25F.create(params, "default", fields1);
_f1.setFieldAvgLength("title", 10);
_f1.setFieldWeight("title", 10D);
_f1.setFieldParamB("title", 0.6);
return true;
}
double score(OpsScoreParams params) {
return _f1.evaluate(params);
}
};
class IntelligenceAlgorithmScorer {
BasicSimilarityScore _f1;
boolean init(OpsScorerInitParams params) {
_f1 = BasicSimilarityScore.create(params);
return true;
}
double score(OpsScoreParams params) {
return _f1.evaluate(params);
}
};该文章对您有帮助吗?