mirror of https://github.com/apache/lucene.git
SOLR-2423 -- fixing DateField and adding test
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1086582 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c7c03f6c61
commit
b822bb427c
|
@ -181,6 +181,14 @@ public class DateField extends FieldType {
|
|||
}
|
||||
}
|
||||
|
||||
public Fieldable createField(SchemaField field, Object value, float boost) {
|
||||
// Convert to a string before indexing
|
||||
if(value instanceof Date) {
|
||||
value = toInternal( (Date)value ) + 'Z';
|
||||
}
|
||||
return super.createField(field, value, boost);
|
||||
}
|
||||
|
||||
public String toInternal(Date val) {
|
||||
return formatDate(val);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.apache.solr.schema;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.solr.schema.DateField;
|
||||
import org.apache.solr.util.DateMathParser;
|
||||
|
@ -114,4 +116,13 @@ public class DateFieldTest extends LuceneTestCase {
|
|||
|
||||
}
|
||||
|
||||
public void testCreateField() {
|
||||
int props = FieldProperties.INDEXED ^ FieldProperties.STORED;
|
||||
SchemaField sf = new SchemaField( "test", f, props, null );
|
||||
Fieldable out = (Field)f.createField(sf, "1995-12-31T23:59:59Z", 1.0f );
|
||||
assertEquals(820454399000l, f.toObject( out ).getTime() );
|
||||
|
||||
out = (Field)f.createField(sf, new Date(820454399000l), 1.0f );
|
||||
assertEquals(820454399000l, f.toObject( out ).getTime() );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue