无法在弹性搜索相似性实现中覆盖 ClassicSimilarity 中的 scorePayload 函数

not able to override scorePayload function in ClassicSimilarity in elasticsearch similarity implementation

我正在尝试在 Elasticsearch 中实现相似性。我想将有效负载与 TF 和 IDF 值一起用于分数计算。当我检查 ClassicSimilarity 文档(https://lucene.apache.org/core/7_4_0/core/org/apache/lucene/search/similarities/ClassicSimilarity.html)时,存在一个可以重载的 scorePayload 函数。当我扩展 ClassicSimilarity class 时,它在 scorePayload 函数上显示错误。我也检查了导入的 class ,并且不存在有效负载功能。 我做错了什么?

package org.elasticsearch.index.similarity;

import org.apache.lucene.analysis.payloads.PayloadHelper;
import org.apache.lucene.search.similarities.ClassicSimilarity;
import org.apache.lucene.util.BytesRef;

public class CustomTFIDFScorer extends ClassicSimilarity{

    @Override
    protected float scorePayload(int doc, int start, int end, BytesRef payload) {

        if (payload != null) {
            return PayloadHelper.decodeFloat(payload.bytes, payload.offset);
            } 
        else {
            return 1.0F;
            }
      }

    @Override
      public float tf(float freq) {
        return freq;
      }

    @Override
      public float idf(long docFreq, long docCount) {
        return (float)(Math.log((docCount+1)/(double)(docFreq+1)) + 1.0);
      }

    @Override
    public float lengthNorm(int length) {
        // TODO Auto-generated method stub
        return 1;
    }
}

这是我的 maven 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>CustomPayloadSimilarity</groupId>
  <artifactId>ElasticseachCustomSimilarity</artifactId>
  <version>0.0.1</version>

  <dependencies>  
  <!-- https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch -->
<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>7.4.0</version>
</dependency>
</dependencies>

</project>

弹性 7.4 uses Lucene 8.2 where method you are trying to override 不存在