You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "jainankitk (via GitHub)" <gi...@apache.org> on 2023/05/16 02:02:07 UTC

[GitHub] [lucene] jainankitk commented on issue #12297: Unnecessary BM25Scorer allocations for non-scoring queries

jainankitk commented on issue #12297:
URL: https://github.com/apache/lucene/issues/12297#issuecomment-1548859574

   I also came across [this discussion](https://lists.apache.org/thread/nrlkswkqh1bp80owb9yd9zzotcz81soj). Maybe I am missing some context, but could not understand why this is not an issue. Seems like regression to me, for specific customer use case. I also tried quick hack patch (always returning non-scoring similarity) just to confirm, and the float[] did not appear in the histogram / heap dump anymore.
   
   ```
    public class IndexSearcher {
    
   +  /** A search-time {@link Similarity} that does not make use of scoring factors
   +   *  and may be used when scores are not needed. */
   +  private static final Similarity NON_SCORING_SIMILARITY = new Similarity() {
   + 
   +    @Override
   +    public long computeNorm(FieldInvertState state) {
   +      throw new UnsupportedOperationException("This Similarity may only be used for searching, not indexing");
   +    }
   + 
   +    @Override
   +    public SimScorer scorer(float boost, CollectionStatistics collectionStats, TermStatistics... termStats) {
   +      return new SimScorer() {
   +        @Override
   +        public float score(float freq, long norm) {
   +          return 0f;
   +        }
   +      };
   +    }
   + 
   +  };
   +
      private static QueryCache DEFAULT_QUERY_CACHE;
      private static QueryCachingPolicy DEFAULT_CACHING_POLICY = new UsageTrackingQueryCachingPolicy();
      static {
   @@ -314,7 +336,7 @@ public class IndexSearcher {
       *  {@link Similarity} that has been set through {@link #setSimilarity(Similarity)}
       *  or the default {@link Similarity} if none has been set explicitly. */
      public Similarity getSimilarity() {
   -    return similarity;
   +    return NON_SCORING_SIMILARITY;
      }
    
      /**
   ```
   
   @jpountz - Can you check once and confirm if I am missing something?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org