Lucene - Core
  1. Lucene - Core
  2. LUCENE-4477

Boolean query composed of spanqueries can return ArrayIndexOutOfBoundsException if one of the subqueries doesn't have a match

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 4.0-BETA
    • Fix Version/s: 4.0-BETA
    • Component/s: core/search
    • Labels:
    • Environment:

      Windows 7

    • Lucene Fields:
      New

      Description

      When building a boolean query of two spanqueryies, if one of the spanqueries does not have a hit, an ArrayIndexOutOfBoundsException is thrown.

      This does not happen when building a boolean query of two TermQuery(ies), nor does it happen if all of the terms have a hit.

      @Test
      public void testBooleanSpanQuery() {
      boolean failed = false;
      int hits = 0;
      try{
      CharArraySet stops = CharArraySet.EMPTY_SET;
      Analyzer indexerAnalyzer = new StandardAnalyzer(LuceneProjectVersion.LUCENE_VERSION, stops);
      Directory directory = new RAMDirectory();

      IndexWriterConfig config = new IndexWriterConfig(LuceneProjectVersion.LUCENE_VERSION, indexerAnalyzer);
      IndexWriter writer = new IndexWriter(directory, config);
      String FIELD = "content";
      Document d = new Document();
      d.add(new TextField(FIELD, "clockwork orange", Field.Store.YES));
      writer.addDocument(d);
      writer.close();

      IndexReader indexReader = DirectoryReader.open(directory);
      IndexSearcher searcher = new IndexSearcher(indexReader);

      BooleanQuery query = new BooleanQuery();
      SpanQuery sq1 = new SpanTermQuery(new Term(FIELD, "clockwork"));
      SpanQuery sq2 = new SpanTermQuery(new Term(FIELD, "clckwork"));
      query.add(sq1, BooleanClause.Occur.SHOULD);
      query.add(sq2, BooleanClause.Occur.SHOULD);
      TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true);
      searcher.search(query, collector);
      hits = collector.topDocs().scoreDocs.length;
      for (ScoreDoc scoreDoc : collector.topDocs().scoreDocs)

      { System.out.println(scoreDoc.doc); }

      } catch (java.lang.ArrayIndexOutOfBoundsException e)

      { failed = true; }

      catch (IOException e)

      { e.printStackTrace(); }

      assertEquals("Bug in boolean query composed of span queries", failed, false);
      assertEquals("Bug in boolean query composed of span queries", hits, 1);
      }

      1. LUCENE-4477.patch
        4 kB
        Michael McCandless

        Activity

        Hide
        Robert Muir added a comment -

        Maybe try the patch on LUCENE-4401 ? I'm on the phone but it might be the same bug (fixed in the final release: coming out tomorrow)

        Show
        Robert Muir added a comment - Maybe try the patch on LUCENE-4401 ? I'm on the phone but it might be the same bug (fixed in the final release: coming out tomorrow)
        Hide
        Michael McCandless added a comment -

        This test passes now on trunk (I stuffed it into analysis module...).

        Show
        Michael McCandless added a comment - This test passes now on trunk (I stuffed it into analysis module...).
        Hide
        Michael McCandless added a comment -

        Dup of LUCENE-4401, but I committed this nice test case (thanks Timothy!).

        Show
        Michael McCandless added a comment - Dup of LUCENE-4401 , but I committed this nice test case (thanks Timothy!).
        Hide
        Commit Tag Bot added a comment -

        [branch_4x commit] Michael McCandless
        http://svn.apache.org/viewvc?view=revision&revision=1397323

        LUCENE-4477/LUCENE-4401: remove dup test

        Show
        Commit Tag Bot added a comment - [branch_4x commit] Michael McCandless http://svn.apache.org/viewvc?view=revision&revision=1397323 LUCENE-4477 / LUCENE-4401 : remove dup test
        Hide
        Commit Tag Bot added a comment -

        [branch_4x commit] Michael McCandless
        http://svn.apache.org/viewvc?view=revision&revision=1397284

        LUCENE-4477/LUCENE-4401: add test case

        Show
        Commit Tag Bot added a comment - [branch_4x commit] Michael McCandless http://svn.apache.org/viewvc?view=revision&revision=1397284 LUCENE-4477 / LUCENE-4401 : add test case

          People

          • Assignee:
            Unassigned
            Reporter:
            Tim Allison
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development