Solr Custom Similarity

房东的猫 提交于 2019-12-28 03:06:09

问题


i want to set my own custom similarity in my solr schema.xml but i have a few problems with understanding this feature. I want to completely deactivate solr scoring (tf,idf,coord and fieldNorm).

I dont know where to start. Things i know

  1. I have to write my own DefaultSimilarity implementation.
  2. Override the (tf,idf,coord and fieldNorm) - methods.
  3. Load the class in schem.xml

Where to store the class ? Are there any working examples in the web ? I cant find one!

THANKS


回答1:


I figured it out on my own. I have stored my own implementation of DefaultSimilarity under /dist/ folder in solr. Then i add <lib dir="../../../dist/org/apache/lucene/search/similarities/" regex=".*\.jar"/> to my solrconfig.xml and everything works fine.

package org.apache.lucene.search.similarities;
import org.apache.lucene.index.FieldInvertState;
import org.apache.lucene.search.similarities.DefaultSimilarity;

public class MyNewSimilarityClass extends DefaultSimilarity {

@Override
public float coord(int overlap, int maxOverlap) {
    return 1.0f;
}

@Override
public float idf(long docFreq, long numDocs) {
    return 1.0f;
}

@Override
public float lengthNorm(FieldInvertState arg0) {
    return 1.0f;
}

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

}

Gist: https://gist.github.com/FabianKoestring/7846845



来源:https://stackoverflow.com/questions/20428709/solr-custom-similarity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!