Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
6.4.1
-
None
Description
When sending a JSON POST to the Schema API to replace a field type, the following JSON does not pass the SolrParameters properly to the BM25SimilarityFactory.
{"replace-field-type":{"name":"tint","class":"solr.TrieIntField","positionIncrementGap":"0","precisionStep":"8","similarity":{"class":"solr.BM25SimilarityFactory","k1":1.25,"b":0.75}}}
The `appendAttrs` function in the FieldTypeXmlAdapter parses k1 and b into attributes instead of children. https://github.com/apache/lucene-solr/blob/master/solr/core/src/java/org/apache/solr/rest/schema/FieldTypeXmlAdapter.java#L155
<similarity b="0.75" class="org.apache.lucene.search.similarities.BM25Similarity" k1="1.25"/>
Based on the XML examples for similarity, this should actually be the following :
<similarity class="org.apache.lucene.search.similarities.BM25Similarity"> <float name=“k1”>0.1</float> <float name=“b”>0.1</float> </similarity>
The similarities block in JSON should be handled differently so that the XML is generated appropriately.
protected static Element appendSimilarityAttrs(Document doc, Element elm, Map<String,?> json) { String clazz = (String) json.get("class"); elm.setAttribute("class", clazz); json.remove("class"); for (Map.Entry<String,?> entry : json.entrySet()) { Object val = entry.getValue(); if (val != null && !(val instanceof Map)) { Element element = doc.createElement(val.getClass().getSimpleName().toLowerCase()); element.setAttribute("name", entry.getKey()); element.setTextContent(entry.getValue().toString()); elm.appendChild(element); } } return elm; }