lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From busc...@apache.org
Subject svn commit: r1558877 - in /lucene/dev/branches/lucene_solr_4_6/lucene: CHANGES.txt core/src/java/org/apache/lucene/document/Field.java core/src/test/org/apache/lucene/document/TestDocument.java
Date Thu, 16 Jan 2014 18:45:01 GMT
Author: buschmi
Date: Thu Jan 16 18:45:01 2014
New Revision: 1558877

URL: http://svn.apache.org/r1558877
Log:
LUCENE-5401: Field.StringTokenStream#end() calls super.end() now.

Modified:
    lucene/dev/branches/lucene_solr_4_6/lucene/CHANGES.txt
    lucene/dev/branches/lucene_solr_4_6/lucene/core/src/java/org/apache/lucene/document/Field.java
    lucene/dev/branches/lucene_solr_4_6/lucene/core/src/test/org/apache/lucene/document/TestDocument.java

Modified: lucene/dev/branches/lucene_solr_4_6/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_6/lucene/CHANGES.txt?rev=1558877&r1=1558876&r2=1558877&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_6/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_4_6/lucene/CHANGES.txt Thu Jan 16 18:45:01 2014
@@ -27,6 +27,10 @@ Bug fixes
   when the parent query incorrectly returns child documents, and throw
   a clear exception saying so. (Dr. Oleg Savrasov via Mike McCandless)
 
+* LUCENE-5401: Field.StringTokenStream#end() calls super.end() now,
+  preventing wrong term positions for fields that use
+  StringTokenStream. (Michael Busch)
+
 ======================= Lucene 4.6.0 =======================
 
 New Features

Modified: lucene/dev/branches/lucene_solr_4_6/lucene/core/src/java/org/apache/lucene/document/Field.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_6/lucene/core/src/java/org/apache/lucene/document/Field.java?rev=1558877&r1=1558876&r2=1558877&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_6/lucene/core/src/java/org/apache/lucene/document/Field.java
(original)
+++ lucene/dev/branches/lucene_solr_4_6/lucene/core/src/java/org/apache/lucene/document/Field.java
Thu Jan 16 18:45:01 2014
@@ -586,7 +586,8 @@ public class Field implements IndexableF
     }
 
     @Override
-    public void end() {
+    public void end() throws IOException {
+      super.end();
       final int finalOffset = value.length();
       offsetAttribute.setOffset(finalOffset, finalOffset);
     }

Modified: lucene/dev/branches/lucene_solr_4_6/lucene/core/src/test/org/apache/lucene/document/TestDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_6/lucene/core/src/test/org/apache/lucene/document/TestDocument.java?rev=1558877&r1=1558876&r2=1558877&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_6/lucene/core/src/test/org/apache/lucene/document/TestDocument.java
(original)
+++ lucene/dev/branches/lucene_solr_4_6/lucene/core/src/test/org/apache/lucene/document/TestDocument.java
Thu Jan 16 18:45:01 2014
@@ -30,6 +30,7 @@ import org.apache.lucene.index.Term;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.TermQuery;
@@ -101,28 +102,31 @@ public class TestDocument extends Lucene
    */
   public void testRemoveForNewDocument() throws Exception {
     Document doc = makeDocumentWithFields();
-    assertEquals(8, doc.getFields().size());
+    assertEquals(10, doc.getFields().size());
     doc.removeFields("keyword");
-    assertEquals(6, doc.getFields().size());
+    assertEquals(8, doc.getFields().size());
     doc.removeFields("doesnotexists"); // removing non-existing fields is
                                        // siltenlty ignored
     doc.removeFields("keyword"); // removing a field more than once
-    assertEquals(6, doc.getFields().size());
+    assertEquals(8, doc.getFields().size());
     doc.removeField("text");
-    assertEquals(5, doc.getFields().size());
+    assertEquals(7, doc.getFields().size());
     doc.removeField("text");
-    assertEquals(4, doc.getFields().size());
+    assertEquals(6, doc.getFields().size());
     doc.removeField("text");
-    assertEquals(4, doc.getFields().size());
+    assertEquals(6, doc.getFields().size());
     doc.removeField("doesnotexists"); // removing non-existing fields is
                                       // siltenlty ignored
-    assertEquals(4, doc.getFields().size());
+    assertEquals(6, doc.getFields().size());
     doc.removeFields("unindexed");
-    assertEquals(2, doc.getFields().size());
+    assertEquals(4, doc.getFields().size());
     doc.removeFields("unstored");
-    assertEquals(0, doc.getFields().size());
+    assertEquals(2, doc.getFields().size());
     doc.removeFields("doesnotexists"); // removing non-existing fields is
                                        // siltenlty ignored
+    assertEquals(2, doc.getFields().size());
+    
+    doc.removeFields("indexed_not_tokenized");
     assertEquals(0, doc.getFields().size());
   }
   
@@ -198,10 +202,33 @@ public class TestDocument extends Lucene
                  doc.getValues("nope"));
   }
   
+  public void testPositionIncrementMultiFields() throws Exception {
+    Directory dir = newDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
+    writer.addDocument(makeDocumentWithFields());
+    IndexReader reader = writer.getReader();
+    
+    IndexSearcher searcher = newSearcher(reader);
+    PhraseQuery query = new PhraseQuery();
+    query.add(new Term("indexed_not_tokenized", "test1"));
+    query.add(new Term("indexed_not_tokenized", "test2"));
+    
+    ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
+    assertEquals(1, hits.length);
+    
+    doAssert(searcher.doc(hits[0].doc), true);
+    writer.close();
+    reader.close();
+    dir.close();    
+  }
+  
   private Document makeDocumentWithFields() {
     Document doc = new Document();
     FieldType stored = new FieldType();
     stored.setStored(true);
+    FieldType indexedNotTokenized = new FieldType();
+    indexedNotTokenized.setIndexed(true);
+    indexedNotTokenized.setTokenized(false);
     doc.add(new StringField("keyword", "test1", Field.Store.YES));
     doc.add(new StringField("keyword", "test2", Field.Store.YES));
     doc.add(new TextField("text", "test1", Field.Store.YES));
@@ -212,6 +239,8 @@ public class TestDocument extends Lucene
         .add(new TextField("unstored", "test1", Field.Store.NO));
     doc
         .add(new TextField("unstored", "test2", Field.Store.NO));
+    doc.add(new Field("indexed_not_tokenized", "test1", indexedNotTokenized));
+    doc.add(new Field("indexed_not_tokenized", "test2", indexedNotTokenized));
     return doc;
   }
   



Mime
View raw message