Creating EnumType Solr using SolrJ

前端 未结 1 1363
失恋的感觉
失恋的感觉 2021-01-24 23:28

I need to create a schema which will containt few enums. I\'m trying to do that using SolrJ. I\'ve found this link DefininganEnumFieldinschema but I couldn\'t find any examples

相关标签:
1条回答
  • 2021-01-24 23:41

    First you need to specify your enum field in schema, like in the documentation:

    <fieldType name="myEnumField" class="solr.EnumField" enumsConfig="enumsConfig.xml" enumName="attribute"/>
    

    in the enumsConfig.xml you will specify all your enum values, like:

    <?xml version="1.0" ?>
    <enumsConfig>
      <enum name="attribute">
        <value>sponsored</value>
        <value>generic</value>
      </enum>
    </enumsConfig>
    

    Alternatively, you could create this fieldType dynamically via Schema API as follows:

    curl -X POST -H 'Content-type:application/json' --data-binary '{
      "add-field-type" : {
         "name":"myEnumField",
         "class":"solr.EnumField",
         "enumsConfig":"enumsConfig.xml",
         "enumName" : "attribute"}
    }' http://localhost:8983/solr/demo/schema
    

    You could do this as well in SolrJ fashion, by using org.apache.solr.client.solrj.request.schema.SchemaRequest.AddFieldType, you need to specify FieldTypeDefinition, method setAttributes(Map<String,Object> attributes) will be helpful

    0 讨论(0)
提交回复
热议问题