Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-10218

The Schema API commands "add-field-type" and "replace-field-type" improperly specify SimilarityFactory params

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 6.4.1
    • 6.5, 7.0
    • Schema and Analysis
    • 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;
          }
      

      Attachments

        1. SOLR-10218.patch
          8 kB
          Steven Rowe
        2. SOLR-10218.patch
          5 kB
          Troy Mohl

        Activity

          People

            sarowe Steven Rowe
            bdeininger Benjamin Deininger
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: