Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

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

Daniel Naberf242e1b5643e
diff --git a/src/java/org/apache/lucene/index/MultipleTermPositions.java b/src/java/org/apache/lucene/index/MultipleTermPositions.java
index e31bca6d3d1..2536d9b9e5b 100644
--- a/src/java/org/apache/lucene/index/MultipleTermPositions.java
+++ b/src/java/org/apache/lucene/index/MultipleTermPositions.java
@@ -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();
diff --git a/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java b/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
index 227cf3c636e..1cc97cc40f4 100644
--- a/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
+++ b/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
@@ -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);
+ }
}