在Solr 4.*中,假设我有字段"mytext"。
mytext“中的第一个记录是"working at ABC”。mytext“中的第二个记录是"working at ABC project ABC”。现在,当我搜索"Working at ABC“时,文档序列是
Doc.1:"Working at ABC project ABC“
Doc2:"Working at ABC“
尽管根据计算,第二个文档应该位于顶部,因为它包含了两次"ABC“(对于第二个文档,TF更高)。
但是从用户的角度来看,当查询输入“在ABC工作”时,结果应该是
"Working at ABC"
"Working at ABC project ABC"。
我该如何处理这种情况。此项目只有在“公司”和“项目”有重叠数据时才会发生。就像这个例子中的"ABC"。
谢谢
阿米特·阿加瓦尔
发布于 2015-03-04 12:41:54
您可以为字段设置omitTermFreqsAndPositions=true。只要包含规范,内容较短的字段的排名将高于内容较长的字段。
发布于 2015-03-05 18:41:41
而不是改变schema.xml。我覆盖TF函数,它总是返回1。因此,术语频率没有影响。
如果有人在短字段上使用Solr,那么下面是我的自定义类
private static float ARR[] = { 0.0f, 1.5f, 1.25f, 1.0f, 0.875f, 0.75f, 0.625f, 0.5f, 0.4375f, 0.375f, 0.3125f};
/**
* Implemented as a lookup for the first 10 counts, then
* <code>1/sqrt(numTerms)</code>. This is to avoid term counts below
* 11 from having the same lengthNorm after being stored encoded as
* a single byte.
*/
public float lengthNorm(FieldInvertState state) {
int numTerms = state.getLength();
String fieldName = state.getName();
System.out.println("field is " + fieldName + " number of terms are " + numTerms);
if( numTerms <= 10 ) {
// this shouldn't be possible, but be safe.
if( numTerms < 0 ) { numTerms = 0; }
return ARR[numTerms];
}
//else
return (float)(1.0 / Math.sqrt(numTerms));
}
// For short fields , term frequency does not always lead to relevancy so returning 1.0
@Override
public float tf(float freq) {
return (float) 1.0;
}https://stackoverflow.com/questions/28850689
复制相似问题