mirror of https://github.com/apache/lucene.git
SOLR-3178: add inc to updateable docs
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1338343 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
63f87a7bdb
commit
e42ebbcb93
|
@ -516,12 +516,41 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {
|
|||
oldDoc.addField( sif.getName(), fieldVal, sif.getBoost());
|
||||
} else if ("set".equals(key)) {
|
||||
oldDoc.setField(sif.getName(), fieldVal, sif.getBoost());
|
||||
} else if ("inc".equals(key)) {
|
||||
SolrInputField numericField = oldDoc.get(sif.getName());
|
||||
if (numericField == null) {
|
||||
oldDoc.setField(sif.getName(), fieldVal, sif.getBoost());
|
||||
} else {
|
||||
// TODO: fieldtype needs externalToObject?
|
||||
String oldValS = numericField.getFirstValue().toString();
|
||||
SchemaField sf = cmd.getReq().getSchema().getField(sif.getName());
|
||||
BytesRef term = new BytesRef();
|
||||
sf.getType().readableToIndexed(oldValS, term);
|
||||
Object oldVal = sf.getType().toObject(sf, term);
|
||||
|
||||
String fieldValS = fieldVal.toString();
|
||||
Number result;
|
||||
if (oldVal instanceof Long) {
|
||||
result = ((Long) oldVal).longValue() + Long.parseLong(fieldValS);
|
||||
} else if (oldVal instanceof Float) {
|
||||
result = ((Float) oldVal).floatValue() + Float.parseFloat(fieldValS);
|
||||
} else if (oldVal instanceof Double) {
|
||||
result = ((Double) oldVal).doubleValue() + Double.parseDouble(fieldValS);
|
||||
} else {
|
||||
// int, short, byte
|
||||
result = ((Integer) oldVal).intValue() + Integer.parseInt(fieldValS);
|
||||
}
|
||||
|
||||
oldDoc.setField(sif.getName(), result, sif.getBoost());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// normal fields are treated as a "set"
|
||||
oldDoc.put(sif.getName(), sif);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cmd.solrDoc = oldDoc;
|
||||
|
|
|
@ -159,6 +159,50 @@ public class TestUpdate extends SolrTestCaseJ4 {
|
|||
assertEquals(409, se.code());
|
||||
}
|
||||
|
||||
version = addAndGetVersion(sdoc("id","1", "val_i",5), null);
|
||||
afterUpdate.call();
|
||||
|
||||
version = addAndGetVersion(sdoc("id","1",
|
||||
"val_is",map("inc",1),
|
||||
"val2_i",map("inc","1"),
|
||||
"val2_f",map("inc",1),
|
||||
"val2_d",map("inc","1.0"),
|
||||
"val2_l",map("inc",1)
|
||||
),
|
||||
null);
|
||||
afterUpdate.call();
|
||||
|
||||
assertJQ(req("qt","/get", "id","1", "fl","id,val*")
|
||||
,"=={'doc':{'id':'1', 'val_i':5, 'val_is':[1], 'val2_i':1, 'val2_f':1.0, 'val2_d':1.0, 'val2_l':1}}"
|
||||
);
|
||||
|
||||
version = addAndGetVersion(sdoc("id","1",
|
||||
"val_is",map("inc","-5"),
|
||||
"val2_i",map("inc",-5),
|
||||
"val2_f",map("inc","-5.0"),
|
||||
"val2_d",map("inc",-5),
|
||||
"val2_l",map("inc","-5")
|
||||
),
|
||||
null);
|
||||
afterUpdate.call();
|
||||
|
||||
assertJQ(req("qt","/get", "id","1", "fl","id,val*")
|
||||
,"=={'doc':{'id':'1', 'val_i':5, 'val_is':[-4], 'val2_i':-4, 'val2_f':-4.0, 'val2_d':-4.0, 'val2_l':-4}}"
|
||||
);
|
||||
|
||||
version = addAndGetVersion(sdoc("id","1",
|
||||
"val_is",map("inc","2000000000"),
|
||||
"val2_i",map("inc",-2000000000),
|
||||
"val2_f",map("inc","1e+20"),
|
||||
"val2_d",map("inc",-1.2345678901e+100),
|
||||
"val2_l",map("inc","5000000000")
|
||||
),
|
||||
null);
|
||||
afterUpdate.call();
|
||||
|
||||
assertJQ(req("qt","/get", "id","1", "fl","id,val*")
|
||||
,"=={'doc':{'id':'1', 'val_i':5, 'val_is':[1999999996], 'val2_i':-2000000004, 'val2_f':1.0E20, 'val2_d':-1.2345678901e+100, 'val2_l':4999999996}}"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue