Fix for NPE (bug #35626). Fix by Hans Hjelm, test case by Scotty Allen.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@219387 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Daniel Naber 2005-07-17 10:47:14 +00:00
parent d6ee6c0845
commit f242e1b564
2 changed files with 33 additions and 1 deletions

View File

@ -175,7 +175,7 @@ public class MultipleTermPositions
public final boolean skipTo(int target)
throws IOException
{
while (target > _termPositionsQueue.peek().doc())
while (_termPositionsQueue.peek() != null && target > _termPositionsQueue.peek().doc())
{
TermPositions tp = (TermPositions)_termPositionsQueue.pop();

View File

@ -23,6 +23,7 @@ import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@ -164,5 +165,36 @@ public class TestMultiPhraseQuery extends TestCase
assertEquals("Wrong number of hits", 2, hits.length());
searcher.close();
}
public void testPhrasePrefixWithBooleanQuery() throws IOException {
RAMDirectory indexStore = new RAMDirectory();
IndexWriter writer = new IndexWriter(indexStore, new StandardAnalyzer(new String[]{}), true);
add("This is a test", "object", writer);
add("a note", "note", writer);
writer.close();
IndexSearcher searcher = new IndexSearcher(indexStore);
// This query will be equivalent to +type:note +body:"a t*"
BooleanQuery q = new BooleanQuery();
q.add(new TermQuery(new Term("type", "note")), BooleanClause.Occur.MUST);
MultiPhraseQuery trouble = new MultiPhraseQuery();
trouble.add(new Term("body", "a"));
trouble.add(new Term[] { new Term("body", "test"), new Term("body", "this") });
q.add(trouble, BooleanClause.Occur.MUST);
// exception will be thrown here without fix for #35626:
Hits hits = searcher.search(q);
assertEquals("Wrong number of hits", 0, hits.length());
searcher.close();
}
private void add(String s, String type, IndexWriter writer) throws IOException {
Document doc = new Document();
doc.add(new Field("body", s, Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("type", type, Field.Store.YES, Field.Index.UN_TOKENIZED));
writer.addDocument(doc);
}
}