solr multivalue的实现分析
public class SolrInputField implements Iterable, Serializable{
String name;
Object value = null;
float boost = 1.0f;
public SolrInputField( String n )
{
this. name = n;
}
public void setValue(Object v, float b) {
boost = b;
if( v instanceof Object[] ) {// Arrays will be converted to a collection.如果传入的value是个list,会转换为collection
Object[] arr = (Object[])v;
Collection c = new ArrayList( arr.length );
for( Object o : arr ) {
c.add( o );
}
value = c;
}
else {
value = v;
}
}
public void addValue(Object v, float b) { //可以看到同样会判断是否为collection
if( value == null ) {
if ( v instanceof Collection ) {
Collection c = new ArrayList( 3 );
for ( Object o : (Collection)v ) {
c.add( o );
}
setValue(c, b);
} else {
setValue(v, b);
}
return;
}
页:
[1]