title: how do I normalise a solr/lucene score?
body: <p>I am trying to work out how to improve the scoring of solr search results.  My application needs to take the score from the solr results and display a number of “stars” depending on how good the result(s) are to the query. 5 Stars = almost/exact down to 0 stars meaning not matching the search very well, e.g. only one element hits.  However I am getting scores from 1.4 to 0.8660254  both are returning results that I would give 5 stars to.  What I need to do is somehow turn these results in to a percentage so that I can mark these results, with the correct number of stars.</p>
  
  <p>The query that I run that gives me the 1.4 score is:</p>
  
  <p><strong>euallowed:true AND(grade:"2:1")</strong></p>
  
  <p>The query that gives me the 0.8660254 score is:</p>
  
  <p><strong>euallowed:true AND(grade:"2:1" OR grade:"1st")</strong></p>
  
  <p>I've already updated the Similarity so that the tf and idf return 1.0 as I am only interested if a document has a term, not the number of that term in the document.  This is what my similarity code looks like:</p>
  
  <pre><code>import org.apache.lucene.search.Similarity;
  
  public class StudentSearchSimilarity extends Similarity {
  
      @Override
      public float lengthNorm(String fieldName, int numTerms) {
          return (float) (1.0 / Math.sqrt(numTerms));
      }
  
      @Override
      public float queryNorm(float sumOfSquaredWeights) {
  
          return (float) (1.0 / Math.sqrt(sumOfSquaredWeights));
  
      }
  
      @Override
      public float sloppyFreq(int distance) {
          return 1.0f / (distance + 1);
      }
  
      @Override
      public float tf(float freq) {
          return (float) 1.0;
      }
  
      @Override
      public float idf(int docFreq, int numDocs) {
  
          //return (float) (Math.log(numDocs / (double) (docFreq + 1)) + 1.0);
          return (float)1.0;
  
      }
  
      @Override
      public float coord(int overlap, int maxOverlap) {
          return overlap / (float) maxOverlap;
      }
  }
  </code></pre>
  
  <p>So I suppose my questions are:</p>
  
  <ol>
  <li><p>How is the best way of normalising
  the score so that I can work out how
  many “stars” to give?</p></li>
  <li><p>Is there another way of scoring the
  results?</p></li>
  </ol>
  
  <p>Thanks </p>
  
  <p>Grant</p>