I have SOLR 5.3.1 version. I want to show those documents at start which have more matching terms.
For this purpose, i have applied omitNorms= true on every field of schema. I have also implement Custom Similarity class. My similarity class look like this:
package org.apache.lucene.search.similarities;
import org.apache.lucene.index.FieldInvertState;
public class MyDefaultSimilarity extends DefaultSimilarity{
@Override
public float idf(long docFreq, long numDocs) {
return 0.5f;
}
@Override
public float lengthNorm(FieldInvertState arg0) {
return 0.5f;
}
@Override
public float tf(float freq) {
return 0.5f;
}
@Override
public float coord(int overlap, int maxOverlap) {
System.out.println("Coord:"+Math.pow(super.coord(overlap, maxOverlap),2));
return (float)Math.pow(super.coord(overlap, maxOverlap),2);
}
}
I have made following changes in schema.xml for similarity class
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<!-- in this example, we will only use synonyms at query time
<filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
-->
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
//define custom similarity class there
<similarity class="org.apache.lucene.search.similarities.MyDefaultSimilarity"> </similarity>
</fieldType>
//define global similarity class there
<similarity class="solr.SchemaSimilarityFactory"/>
I have made following changes in solrconfig.xml for similarity class
<lib dir="${solr.install.dir:../../../..}/dist/" regex="SimilaritySolr.*\.jar" />
I have debug the query. It is still showing score of every document equal to 1. Here is the debug query result shows that which parameter is effecting on score.
1.0 = *:*, product of:
1.0 = boost
1.0 = queryNorm
Please Let me know if any thing else which i have missed to boost the score of documents which have more matching terms?