lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r644406 - in /lucene/java/branches/lucene_2_3/src: java/org/apache/lucene/index/CheckIndex.java java/org/apache/lucene/index/DocumentsWriter.java java/org/apache/lucene/index/IndexWriter.java test/org/apache/lucene/index/TestIndexWriter.java
Date Thu, 03 Apr 2008 17:01:04 GMT
Author: mikemccand
Date: Thu Apr  3 10:01:02 2008
New Revision: 644406

URL: http://svn.apache.org/viewvc?rev=644406&view=rev
Log:
LUCENE-1255: if position is negative, silently change it to 0

Modified:
    lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/CheckIndex.java
    lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/DocumentsWriter.java
    lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/CheckIndex.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/CheckIndex.java?rev=644406&r1=644405&r2=644406&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/CheckIndex.java (original)
+++ lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/CheckIndex.java Thu Apr
 3 10:01:02 2008
@@ -203,7 +203,7 @@
               final int pos = termPositions.nextPosition();
               if (pos < 0)
                 throw new RuntimeException("term " + term + ": doc " + doc + ": pos " + pos
+ " is out of bounds");
-              if (pos <= lastPos)
+              if (pos < lastPos)
                 throw new RuntimeException("term " + term + ": doc " + doc + ": pos " + pos
+ " < lastPos " + lastPos);
             }
           }

Modified: lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/DocumentsWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/DocumentsWriter.java?rev=644406&r1=644405&r2=644406&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/DocumentsWriter.java
(original)
+++ lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/DocumentsWriter.java
Thu Apr  3 10:01:02 2008
@@ -1518,11 +1518,13 @@
 
           try {
             offsetEnd = offset-1;
-            Token token;
             for(;;) {
-              token = stream.next(localToken);
+              Token token = stream.next(localToken);
               if (token == null) break;
               position += (token.getPositionIncrement() - 1);
+              // LUCENE-1255: don't allow negative positon
+              if (position < 0)
+                position = 0;
               addPosition(token);
               if (++length >= maxFieldLength) {
                 if (infoStream != null)

Modified: lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java?rev=644406&r1=644405&r2=644406&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/index/IndexWriter.java Thu
Apr  3 10:01:02 2008
@@ -1260,8 +1260,11 @@
       throw oom;
     } finally {
       synchronized(this) {
-        if (!closed)
+        if (!closed) {
           closing = false;
+          if (infoStream != null)
+            message("hit exception while closing");
+        }
         notifyAll();
       }
     }

Modified: lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=644406&r1=644405&r2=644406&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java
(original)
+++ lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/index/TestIndexWriter.java
Thu Apr  3 10:01:02 2008
@@ -29,6 +29,7 @@
 import org.apache.lucene.analysis.WhitespaceAnalyzer;
 import org.apache.lucene.analysis.WhitespaceTokenizer;
 import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.SinkTokenizer;
 import org.apache.lucene.analysis.TokenFilter;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
@@ -39,6 +40,9 @@
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Hits;
 import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.spans.SpanTermQuery;
+import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.store.RAMDirectory;
@@ -2989,5 +2993,46 @@
     assertEquals(1, ir.maxDoc());
     assertEquals(0, ir.numDocs());
     ir.close();
+  }
+
+  // LUCENE-1255
+  public void testNegativePositions() throws Throwable {
+    SinkTokenizer tokens = new SinkTokenizer();
+    Token t = new Token();
+    t.setTermText("a");
+    t.setPositionIncrement(0);
+    tokens.add(t);
+    t.setTermText("b");
+    t.setPositionIncrement(1);
+    tokens.add(t);
+    t.setTermText("c");
+    tokens.add(t);
+
+    MockRAMDirectory dir = new MockRAMDirectory();
+    IndexWriter w = new IndexWriter(dir, false, new WhitespaceAnalyzer(), true);
+    Document doc = new Document();
+    doc.add(new Field("field", tokens));
+    w.addDocument(doc);
+    w.close();
+
+    IndexSearcher s = new IndexSearcher(dir);
+    PhraseQuery pq = new PhraseQuery();
+    pq.add(new Term("field", "a"));
+    pq.add(new Term("field", "b"));
+    pq.add(new Term("field", "c"));
+    Hits hits = s.search(pq);
+    assertEquals(1, hits.length());
+
+    Query q = new SpanTermQuery(new Term("field", "a"));
+    hits = s.search(q);
+    assertEquals(1, hits.length());
+    TermPositions tps = s.getIndexReader().termPositions(new Term("field", "a"));
+    assertTrue(tps.next());
+    assertEquals(1, tps.freq());
+    assertEquals(0, tps.nextPosition());
+
+    assertTrue(_TestUtil.checkIndex(dir));
+    s.close();
+    dir.close();
   }
 }



Mime
View raw message