Solr Custom The similarity class is loaded but does not affect the ranking result. Why is the override not working?

My affinity class has PercentageSimilarityClass

been added to the classloader, but the results are ranked the same as before.

This is my code. What am I doing wrong?

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

public class PercentageSimilarityClass extends DefaultSimilarity {

  @Override
  public float coord(int overlap, int maxOverlap) {
    return ((overlap /(float)maxOverlap)*(overlap/(float)maxOverlap));
  }

  @Override
  public float queryNorm(float sumOfSquaredWeights) {
    return (float) 1.0;
  }

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

  @Override
  public float sloppyFreq(int distance) {
    return (float) 1.0;  
  }

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

      

I also tried to add

public PercentageSimilarityClass(){
    super();
}

      

but it did not help.

Any help would be greatly appreciated!

Edit

I want Solr to evaluate documents based on how many query words are found in the document; the more words, the higher the rating.

So I'm trying to increase the weighting of the factor coord()

(by squaring) and decrease the other factors (by returning them (float) 1.0

).

I calculated what percentage of each document returned is made up of query words, and before and after I added my usual similarity, my dozens of ranked documents got a percentage of

21.74%

12.5%

15.38%

27.59%

10.34%

44.44%

37.5%

14.29%

19.3%

20.0%

A document that is 44.44% composed of query words should have ranked first in this case, and when I expand my search to more than 10 documents, to 100 or 500 documents, I get many documents that are 70% + consisting of words in the query that was not ranked first.

+3


source to share





All Articles