我们在schema.xml中有以下设置:
<field name="last_modified" type="date" indexed="true" stored="true" multiValued="false" omitTermFreqAndPositions="true"/>
...
<field name="prefix" type="string" indexed="true" stored="true" omitTermFreqAndPositions="true"/>
我们的目标是按
对文档进行排序我们的代码:
{!boost b=recip(ms(NOW,last_modified),3.16e11,1,1)}prefix:9999^1000000 OR {!boost b=recip(ms(NOW,last_modified),3.16e-11,1,1)}prefix:1004^600000 OR {!boost b=recip(ms(NOW,last_modified),3.16e-11,1,1)}prefix:1005^600000
结果: 上面的查询无法按预期工作!
我们认为omitTermFreqAndPositions = true会强制阻止ITF并且评分应该有效。但它似乎并非如此! 请帮助我们: - )
答案 0 :(得分:2)
So we found a solution!
The class we used
package com.luxactive;
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;
}
}
SOLRFOLDER/solr-4.8.0/example/solr/dih
The next steps need to be done to every collection you have!
SOLRFOLDER/solr-4.8.0/example/solr/collection/conf/solrconfig.xml
<lib dir="../dih" regex=".*\.jar" />
to import the custom jarAdd the following
<!-- DEFAULT Factory for custom com.luxactive.MyNewSimilarityClass -->
<similarity class="solr.SchemaSimilarityFactory"/>
<!-- TYPE String -->
<fieldType name="no_term_frequency_string" class="solr.StrField" sortMissingLast="true" >
<similarity class="com.luxactive.MyNewSimilarityClass"/>
</fieldType>
<!-- TYPE Date -->
<fieldType name="no_term_frequency_date" class="solr.TrieDateField" sortMissingLast="true" >
<similarity class="com.luxactive.MyNewSimilarityClass"/>
</fieldType>
<!-- TYPE Int-->
<fieldType name="no_term_frequency_int" class="solr.TrieIntField" sortMissingLast="true" >
<similarity class="com.luxactive.MyNewSimilarityClass"/>
</fieldType>
Here you define your own field types (int, string and date) that use the new Similarity class which will return a boost value like defined in the MyNewSimilarityClass.
<field name="last_modified" type="date" indexed="true" stored="true" multiValued="false" />
<field name="last_modified" type="no_term_frequency_date" indexed="true" stored="true" multiValued="false" />