lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1380812 - in /lucene/dev/trunk/lucene: CHANGES.txt core/src/java/org/apache/lucene/document/Field.java core/src/test/org/apache/lucene/document/TestDocument.java
Date Tue, 04 Sep 2012 19:01:04 GMT
Author: rmuir
Date: Tue Sep  4 19:01:04 2012
New Revision: 1380812

URL: http://svn.apache.org/viewvc?rev=1380812&view=rev
Log:
LUCENE-4218: restore stringValue for numeric fields

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

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1380812&r1=1380811&r2=1380812&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Tue Sep  4 19:01:04 2012
@@ -138,6 +138,10 @@ Bug Fixes
 * LUCENE-4333: Fixed NPE in TermGroupFacetCollector when faceting on mv fields.
   (Jesse MacVicar, Martijn van Groningen)
 
+* LUCENE-4218: Document.get(String) and Field.stringValue() again return
+  values for numeric fields, like Lucene 3.x and consistent with the documentation.
+  (Jamie, Uwe Schindler, Robert Muir)
+
 * NRTCachingDirectory was always caching a newly flushed segment in
   RAM, instead of checking the estimated size of the segment
   to decide whether to cache it. (Mike McCandless)

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/document/Field.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/document/Field.java?rev=1380812&r1=1380811&r2=1380812&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/document/Field.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/document/Field.java Tue Sep  4
19:01:04 2012
@@ -267,7 +267,11 @@ public class Field implements IndexableF
    * getBinaryValue() must be set.
    */
   public String stringValue() {
-    return fieldsData instanceof String ? (String) fieldsData : null;
+    if (fieldsData instanceof String || fieldsData instanceof Number) {
+      return fieldsData.toString();
+    } else {
+      return null;
+    }
   }
   
   /**

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/document/TestDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/document/TestDocument.java?rev=1380812&r1=1380811&r2=1380812&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/document/TestDocument.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/document/TestDocument.java Tue
Sep  4 19:01:04 2012
@@ -324,4 +324,25 @@ public class TestDocument extends Lucene
       // expected
     }
   }
+  
+  public void testNumericFieldAsString() throws Exception {
+    Document doc = new Document();
+    doc.add(new IntField("int", 5, Field.Store.YES));
+    assertEquals("5", doc.get("int"));
+    assertNull(doc.get("somethingElse"));
+    doc.add(new IntField("int", 4, Field.Store.YES));
+    assertArrayEquals(new String[] { "5", "4" }, doc.getValues("int"));
+    
+    Directory dir = newDirectory();
+    RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
+    iw.addDocument(doc);
+    DirectoryReader ir = iw.getReader();
+    StoredDocument sdoc = ir.document(0);
+    assertEquals("5", sdoc.get("int"));
+    assertNull(sdoc.get("somethingElse"));
+    assertArrayEquals(new String[] { "5", "4" }, sdoc.getValues("int"));
+    ir.close();
+    iw.close();
+    dir.close();
+  }
 }



Mime
View raw message