mirror of https://github.com/apache/lucene.git
SOLR-9838: 'inc' atomic update doesn't respect default field value
This commit is contained in:
parent
d5181ec8e5
commit
a06c39f3e5
|
@ -227,6 +227,8 @@ Bug Fixes
|
|||
|
||||
* SOLR-10226: add back "totalTime" metric to all handlers. See also the back-compat note. (ab)
|
||||
|
||||
* SOLR-9838: "inc" atomic update doesn't respect default field value (hoss, Amrit Sarkar, Ishan Chattopadhyaya)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -316,12 +316,11 @@ public class AtomicUpdateDocumentMerger {
|
|||
|
||||
protected void doInc(SolrInputDocument toDoc, SolrInputField sif, Object fieldVal) {
|
||||
SolrInputField numericField = toDoc.get(sif.getName());
|
||||
if (numericField == null) {
|
||||
toDoc.setField(sif.getName(), fieldVal);
|
||||
} else {
|
||||
SchemaField sf = schema.getField(sif.getName());
|
||||
if (numericField != null || sf.getDefaultValue() != null) {
|
||||
// TODO: fieldtype needs externalToObject?
|
||||
String oldValS = numericField.getFirstValue().toString();
|
||||
SchemaField sf = schema.getField(sif.getName());
|
||||
String oldValS = (numericField != null) ?
|
||||
numericField.getFirstValue().toString(): sf.getDefaultValue().toString();
|
||||
BytesRefBuilder term = new BytesRefBuilder();
|
||||
sf.getType().readableToIndexed(oldValS, term);
|
||||
Object oldVal = sf.getType().toObject(sf, term.get());
|
||||
|
@ -340,6 +339,8 @@ public class AtomicUpdateDocumentMerger {
|
|||
}
|
||||
|
||||
toDoc.setField(sif.getName(), result);
|
||||
} else {
|
||||
toDoc.setField(sif.getName(), fieldVal);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1204,7 +1204,6 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {
|
|||
|
||||
}
|
||||
|
||||
@AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/SOLR-9838")
|
||||
public void testAtomicUpdateOfFieldsWithDefaultValue() {
|
||||
// both fields have the same default value (42)
|
||||
for (String fieldToUpdate : Arrays.asList("intDefault", "intDvoDefault")) {
|
||||
|
@ -1254,7 +1253,7 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {
|
|||
, "count(//doc/*)=6"
|
||||
);
|
||||
// do atomic update
|
||||
assertU(adoc(sdoc("id", "7", fieldToUpdate, ImmutableMap.of("inc", -555))));
|
||||
assertU(adoc(sdoc("id", "8", fieldToUpdate, ImmutableMap.of("inc", -555))));
|
||||
assertQ(fieldToUpdate + ": RTG after atomic update"
|
||||
, req("qt", "/get", "id", "8")
|
||||
, "count(//doc)=1"
|
||||
|
|
Loading…
Reference in New Issue