Search code examples
curlsolrfiltertokenizefieldtype

Only one tokenizer filter is added when creating/replacing a new field type


I'm adding my field type using Curl:

curl -X POST -H 'Content-type:application/json' --data-binary '{
    "add-field-type" :  {
        "name":"valueWithSubFields",
        "class":"solr.TextField",
        "positionIncrementGap":"100",
        "indexAnalyzer":{
            "tokenizer": { "class":"solr.KeywordTokenizerFactory" },
            "filters": [{ "class":"solr.LowerCaseFilterFactory"}],
            "filters": [{ "class":"solr.ASCIIFoldingFilterFactory" }],  
            "filters": [{ "class":"solr.ReversedWildcardFilterFactory" }]           
        },
        "queryAnalyzer": {
            "tokenizer": { "class":"solr.KeywordTokenizerFactory" },
            "filters": [{ "class":"solr.LowerCaseFilterFactory" }],
            "filters": [{ "class":"solr.ASCIIFoldingFilterFactory" }]
        }
    }
}' http://localhost:8983/solr/myMainCore/schema

here's my created field type

<fieldType name="valueWithSubFields" class="solr.TextField"  positionIncrementGap="100">
    <analyzer type="index">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.ReversedWildcardFilterFactory"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.ASCIIFoldingFilterFactory"/>
    </analyzer>
</fieldType>

The problem is that only the last tokenizer filters are actually added. I don't really get why this is happening. I tried to change my tokenizer class but still get the same result.

Any help will be greatly appreciated.


Solution

  • The array of filters should be this way

    "filters": [
                  {
                     "class":"solr.LowerCaseFilterFactory"
                  },
                  {
                     "class":"solr.ASCIIFoldingFilterFactory"
                  },
                  {
                     "class":"solr.ReversedWildcardFilterFactory"
                  }
              ],
    

    and the full curl command would be

    curl -X POST -H 'Content-type:application/json' --data-binary '{
        "add-field-type" :  {
            "name":"valueWithSubFields",
            "class":"solr.TextField",
            "positionIncrementGap":"100",
            "indexAnalyzer":{
                "tokenizer": { "class":"solr.KeywordTokenizerFactory" },
                "filters": [
                        {
                            "class":"solr.LowerCaseFilterFactory"
                        },
                        {
                            "class":"solr.ASCIIFoldingFilterFactory"
                        },
                        {
                            "class":"solr.ReversedWildcardFilterFactory"
                        }
                    ]           
            },
            "queryAnalyzer": {
                "tokenizer": { "class":"solr.KeywordTokenizerFactory" },
                "filters": [
                        {
                            "class":"solr.LowerCaseFilterFactory"
                        },
                        {
                            "class":"solr.ASCIIFoldingFilterFactory"
                        }
                    ]
            }
        }
    }' http://localhost:8983/solr/myMainCore/schema