lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dna...@apache.org
Subject svn commit: r219387 - in /lucene/java/trunk/src: java/org/apache/lucene/index/MultipleTermPositions.java test/org/apache/lucene/search/TestMultiPhraseQuery.java
Date Sun, 17 Jul 2005 10:47:15 GMT
Author: dnaber
Date: Sun Jul 17 03:47:14 2005
New Revision: 219387

URL: http://svn.apache.org/viewcvs?rev=219387&view=rev
Log:
Fix for NPE (bug #35626). Fix by Hans Hjelm, test case by Scotty Allen.

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/MultipleTermPositions.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/MultipleTermPositions.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/index/MultipleTermPositions.java?rev=219387&r1=219386&r2=219387&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/MultipleTermPositions.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/MultipleTermPositions.java Sun Jul
17 03:47:14 2005
@@ -175,7 +175,7 @@
     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();
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java?rev=219387&r1=219386&r2=219387&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java Sun Jul
17 03:47:14 2005
@@ -23,6 +23,7 @@
 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;
 
@@ -163,6 +164,37 @@
 
       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);
   }
 
 }



Mime
View raw message