gpt4 book ai didi

java - 在elasticsearch相似性实现中无法覆盖ClassicSimilarity中的scorePayload函数

转载 作者:行者123 更新时间:2023-12-01 18:06:19 26 4
gpt4 key购买 nike

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

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您正在尝试的方法override不存在

关于java - 在elasticsearch相似性实现中无法覆盖ClassicSimilarity中的scorePayload函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60551626/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com