Float fval = new Float( 10.01f );
Boolean bval = Boolean.TRUE;
String sval = "12qwaszx";
// Set up a simple document
SolrDocument doc = new SolrDocument();
doc.addField( "f", fval );
doc.addField( "b", bval );
doc.addField( "s", sval );
doc.addField( "f", 100 ); // again, but something else
// make sure we can pull values out of it
assertEquals( fval, doc.getFirstValue( "f" ) );
assertEquals( fval, doc.getFieldValues( "f" ).iterator().next() );
assertEquals( fval, ((Collection<Object>)doc.getFieldValue( "f" )).iterator().next() );
assertEquals( bval, doc.getFieldValue( "b" ) );
assertEquals( sval, doc.getFieldValue( "s" ) );
assertEquals( 2, doc.getFieldValues( "f" ).size() );
assertNull( doc.getFieldValue( "xxxxx" ) );
assertNull( doc.getFieldValues( "xxxxx" ) );
List<String> keys = new ArrayList<String>();
for( String s : doc.getFieldNames() ) {
keys.add( s );
}
Collections.sort( keys );
assertEquals( 3, keys.size() );
assertEquals( "[b, f, s]", keys.toString() );
// set field replaced existing values:
doc.setField( "f", fval );
assertEquals( 1, doc.getFieldValues( "f" ).size() );
assertEquals( fval, doc.getFieldValue( "f" ) );
doc.setField( "n", null );
assertEquals( null, doc.getFieldValue( "n" ) );
// now remove some fields
assertEquals( true, doc.removeFields( "f" ) );
assertEquals( false, doc.removeFields( "asdgsadgas" ) );
assertNull( doc.getFieldValue( "f" ) );
assertNull( doc.getFieldValues( "f" ) );
}