我为 solr 制作了一个非常简单的自定义相似性类。它主要用于测试。
public class StaticNormSimilarity extends DefaultSimilarity {
private static final Logger LOG = LoggerFactory.getLogger(StaticNormSimilarity.class);
private float norm = 0.1f;
public void setNorm(float norm) {
this.norm = norm;
//TODO: not working how can I access parameters
LOG.info("##gyk: StaticNormSimilarity norm = {}", norm);
System.out.println(String.format("##gyk: StaticNormSimilarity: %f",norm));
}
public float getNorm() {
return this.norm;
}
@Override
public float queryNorm(float sumOfSquaredWeights) {
return this.norm;
}
}
在 schema.xml 我执行以下操作:
<fieldType name="text_en" class="solr.TextField" positionIncrementGap="100">
<similarity class="gyk.solr.similarity.StaticNormSimilarity">
**HOW CAN I SEE THIS VALUE FROM MY CODE**
<float name="norm">0.1</float>
</similarity>
<analyzer type="index">
...
</analyzer>
<analyzer type="query">
...
</analyzer>
</fieldType>
和
<similarity class="solr.SchemaSimilarityFactory" />
我的问题是如何从代码中看到norm
schema.xml 文件中指定的值?提前致谢。