Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-5307

Inconsistency between Weight.scorer documentation and ConstantScoreQuery on top of a Filter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 4.6, 6.0
    • core/search
    • None
    • New

    Description

      Weight.scorer states that if topScorer == true, Scorer.collect will be called and that otherwise Scorer.nextDoc/advance will be called.

      This is a problem when ConstantScoreQuery is used on top of a QueryWrapperFilter:
      1. ConstantScoreWeight calls getDocIdSet on the filter to know which documents to collect.
      2. QueryWrapperFilter.getDocIdSet returns a Scorer created with topScorer == false so that nextDoc/advance are supported.
      3. But then ConstantScorer.score(Collector) has the following optimization:

          // this optimization allows out of order scoring as top scorer!
          @Override
          public void score(Collector collector) throws IOException {
            if (docIdSetIterator instanceof Scorer) {
              ((Scorer) docIdSetIterator).score(wrapCollector(collector));
            } else {
              super.score(collector);
            }
          }
      

      So the filter iterator is a scorer which was created with topScorer = false but ParentScorer ends up using its score(Collector) method, which is illegal. (I found this out because AssertingSearcher has some checks to make sure Scorers are used accordingly to the value of topScorer.)

      I can imagine several fixes, including:

      • removing this optimization when working on top of a filter
      • relaxing Weight documentation to allow for using score(Collector) when topScorer == false

      but I'm not sure which one is the best one. What do you think?

      Attachments

        1. LUCENE-5307.patch
          7 kB
          Uwe Schindler
        2. LUCENE-5307.patch
          8 kB
          Uwe Schindler
        3. LUCENE-5307-test.patch
          4 kB
          Adrien Grand

        Activity

          People

            uschindler Uwe Schindler
            jpountz Adrien Grand
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: