lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Timothy Allison (JIRA)" <j...@apache.org>
Subject [jira] [Created] (LUCENE-4477) Boolean query composed of spanqueries can return ArrayIndexOutOfBoundsException if one of the subqueries doesn't have a match
Date Thu, 11 Oct 2012 17:49:22 GMT
Timothy Allison created LUCENE-4477:
---------------------------------------

             Summary: Boolean query composed of spanqueries can return ArrayIndexOutOfBoundsException
if one of the subqueries doesn't have a match 
                 Key: LUCENE-4477
                 URL: https://issues.apache.org/jira/browse/LUCENE-4477
             Project: Lucene - Core
          Issue Type: Bug
          Components: core/search
    Affects Versions: 4.0-BETA
         Environment: Windows 7
            Reporter: Timothy Allison
             Fix For: 4.0-BETA


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);
	}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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


Mime
View raw message