Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-16360: Atomic update on boolean fields doesn't reflect when value starts with "1", "t" or "T" #1816

Merged
merged 11 commits into from
Aug 9, 2023
3 changes: 2 additions & 1 deletion solr/core/src/java/org/apache/solr/schema/BoolField.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.lucene.util.mutable.MutableValue;
import org.apache.lucene.util.mutable.MutableValueBool;
import org.apache.solr.analysis.SolrAnalyzer;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.OrdFieldSource;
Expand Down Expand Up @@ -211,7 +212,7 @@ public List<IndexableField> createFields(SchemaField field, Object value) {
@Override
public Object toNativeType(Object val) {
if (val instanceof CharSequence) {
return Boolean.valueOf(val.toString());
return Boolean.valueOf(StrUtils.parseBoolean(val.toString()));
rahulgoswami marked this conversation as resolved.
Show resolved Hide resolved
}
return super.toNativeType(val);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
DO NOT ADD THINGS TO THIS CONFIG! -->
<config>
<luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion>
<updateHandler class="solr.DirectUpdateHandler2">
<updateLog enable="${enable.update.log:true}">
<str name="dir">${solr.ulog.dir:}</str>
</updateLog>
</updateHandler>
<dataDir>${solr.data.dir:}</dataDir>
<xi:include href="solrconfig.snippet.randomindexconfig.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
<directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.RAMDirectoryFactory}"/>
Expand Down
12 changes: 12 additions & 0 deletions solr/core/src/test/org/apache/solr/schema/BooleanFieldTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.solr.schema;

import java.util.Map;
import org.apache.solr.SolrTestCaseJ4;
import org.junit.BeforeClass;
import org.junit.Test;
rahulgoswami marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -108,5 +109,16 @@ public void testBoolField() {
"//lst[@name='bindsto']/int[@name='true'][.='2']",
"//lst[@name='bindstom']/int[@name='false'][.='2']",
"//lst[@name='bindstom']/int[@name='true'][.='3']");

// SOLR-16360
assertU(adoc("id", "7", "bindsto", "false"));
assertU(commit());
// do atomic update
assertU(adoc(sdoc("id", "7", "bindsto", Map.of("set", "1"))));
assertQ(
req("qt", "/get", "id", "7"),
"count(//doc)=1",
"//doc/str[@name='id'][.='7']",
"//doc/bool[@name='bindsto'][.='true']");
}
}