lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dor...@apache.org
Subject svn commit: r608367 - in /lucene/java/trunk: CHANGES.txt src/test/org/apache/lucene/index/TestDocumentWriter.java
Date Thu, 03 Jan 2008 07:32:39 GMT
Author: doronc
Date: Wed Jan  2 23:32:38 2008
New Revision: 608367

URL: http://svn.apache.org/viewvc?rev=608367&view=rev
Log:
LUCENE-766: test added for adding two fields with same 
            name but different term vector setting.

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/test/org/apache/lucene/index/TestDocumentWriter.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=608367&r1=608366&r2=608367&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Wed Jan  2 23:32:38 2008
@@ -375,6 +375,9 @@
 
 Test Cases
 
+ 1. LUCENE-766: Test adding two fields with the same name but different 
+    term vector setting.  (Nicolas Lalevée via Doron Cohen)  
+    
 ======================= Release 2.2.0 2007-06-19 =======================
 
 Changes in runtime behavior

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestDocumentWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestDocumentWriter.java?rev=608367&r1=608366&r2=608367&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestDocumentWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestDocumentWriter.java Wed Jan  2
23:32:38 2008
@@ -18,11 +18,13 @@
  */
 
 import org.apache.lucene.analysis.*;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
 import org.apache.lucene.document.Field.TermVector;
 import org.apache.lucene.document.Fieldable;
-import org.apache.lucene.search.Similarity;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.LuceneTestCase;
 
@@ -49,7 +51,6 @@
     Document testDoc = new Document();
     DocHelper.setupDoc(testDoc);
     Analyzer analyzer = new WhitespaceAnalyzer();
-    Similarity similarity = Similarity.getDefault();
     IndexWriter writer = new IndexWriter(dir, analyzer, true);
     writer.addDocument(testDoc);
     writer.flush();
@@ -105,7 +106,6 @@
       }
     };
 
-    Similarity similarity = Similarity.getDefault();
     IndexWriter writer = new IndexWriter(dir, analyzer, true);
 
     Document doc = new Document();
@@ -191,7 +191,6 @@
 
 
   public void testPreAnalyzedField() throws IOException {
-    Similarity similarity = Similarity.getDefault();
     IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(), true);
     Document doc = new Document();
     
@@ -231,5 +230,34 @@
     assertEquals(1, termPositions.freq());
     assertEquals(2, termPositions.nextPosition());
 
+  }
+
+  /**
+   * Test adding two fields with the same name, but 
+   * with different term vector setting (LUCENE-766).
+   */
+  public void testMixedTermVectorSettingsSameField() throws Exception {
+    Document doc = new Document();
+    // f1 first without tv then with tv
+    doc.add(new Field("f1", "v1", Store.YES, Index.UN_TOKENIZED, TermVector.NO));
+    doc.add(new Field("f1", "v2", Store.YES, Index.UN_TOKENIZED, TermVector.WITH_POSITIONS_OFFSETS));
+    // f2 first with tv then without tv
+    doc.add(new Field("f2", "v1", Store.YES, Index.UN_TOKENIZED, TermVector.WITH_POSITIONS_OFFSETS));
+    doc.add(new Field("f2", "v2", Store.YES, Index.UN_TOKENIZED, TermVector.NO));
+
+    RAMDirectory ram = new RAMDirectory();
+    IndexWriter writer = new IndexWriter(ram, new StandardAnalyzer(), true);
+    writer.addDocument(doc);
+    writer.close();
+
+    IndexReader reader = IndexReader.open(ram);
+    // f1
+    TermFreqVector tfv1 = reader.getTermFreqVector(0, "f1");
+    assertNotNull(tfv1);
+    assertEquals("the 'with_tv' setting should rule!",2,tfv1.getTerms().length);
+    // f2
+    TermFreqVector tfv2 = reader.getTermFreqVector(0, "f2");
+    assertNotNull(tfv2);
+    assertEquals("the 'with_tv' setting should rule!",2,tfv2.getTerms().length);
   }
 }



Mime
View raw message