Uploaded image for project: 'Jackrabbit Content Repository'
  1. Jackrabbit Content Repository
  2. JCR-3539

NotQuery#advance (and for older versions skipTo) violates Lucene advance contract in case a Filter is used

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 0.9, 2.4.4, 2.6.1, 2.7
    • jackrabbit-core
    • None

    Description

      Plain jackrabbit does not directly suffer from the issue in the NotQuery, but it surfaces when searching with a org.apache.lucene.search.Filterorg.apache.lucene.search.Filter.

      The following happens when calling JackrabbitIndexSearcher#search(Query,Filter,int) (or any other search method containing a filter). In Lucene 3.6.0 (older Lucene version in older jackrabbit versions similar issue) at FilterQuery#getFilterScorer, there is

      @Override
      public void score(Collector collector) throws IOException {
      int filterDoc = filterIter.nextDoc();
      int scorerDoc = scorer.advance(filterDoc);

      The scorer gets advanced with 'scorer.advance(filterDoc)' : If the scorer contains a Jackrabbit NotQuery, this results in NotQuery#advance being invoked. At this time, NotQuery#nextDoc() has not yet ever been invoked.

      The NotQuery#advance results in that docNo becomes some positive number (0 or larger). After this, when NotQuery#nextDoc() gets invoked, the docNo is not -1 any more, and the contextScorer.nextDoc(); is never called any more, ever. Hence, when a FIlter gets applied, the NotQuery is completely skipped.

      Fix is simply to replace the

      if (docNo == -1) {

      with a

      if (firstTime) {
      firstTime = false;

      (in older lucene versions the problem results in false 'more' for IndexSearcher in this line: boolean more = filterDocIdIterator.next() && scorer.skipTo(filterDocIdIterator.doc()); )

      Attachments

        Activity

          People

            aschrijvers Ard Schrijvers
            aschrijvers Ard Schrijvers
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: