• 【solr】schemaFactory配置相关schema.xml


    schemaFactory配置相关schema.xml

       关于schemaFactory的配置困扰我半天啦,下面来总结一下。

      话说,好像是从5.0以后就已经没有schema.xml啦,这是由于Solr5以后增加了一个新的功能,提供schema API修改分词字段类型,通过schemaFactory来配置选择方式。

      可以通过solr下面的conf文件夹中solrConfig.xml可以找到schemaFactory配置,在Solr5之前都是配置ClassicIndexSchemaFactory,

    <schemaFactory class="ClassicIndexSchemaFactory"/>

      Solr5以后包括Solr6,默认使用的是ManagedIndexSchemaFactory

    <schemaFactory class="ManagedIndexSchemaFactory">
        <bool name="mutable">true</bool>
        <str name="managedSchemaResourceName">managed-schema</str>
      </schemaFactory>

       这里我们就好好聊一聊他们的区别。

    1. ClassicIndexSchemaFactory配置后,只能手动编辑schema.xml文件来修改FieldType、Field等等信息,因此这种情况下需要特别的注意在定义模式小心出现漏定义的错误。有人也称这种模式为经典模式。

    2. ManagedIndexSchemaFactory配置被称为manage-schema模式,不支持用户通过修改manage-schema文件去进行FieldType、Field的修改(但实际上是可以manage-schema文件进行修改,并且重启Solr后可以生效)。manage-schema提供一套schema api去创建、修改、删除FieldType、Field等。

    3. 使用ManagedIndexSchemaFactory后,如果删除conf下面的manage-schema,系统会将conf下面的schema.xml重命名为schema.xml.bak,并重新生成一个manage-schema,此时manage-schema中的内容是schema.xml内容格式化得东东。
    4. managedSchemaResourceName属性定义了schema.xml文件的路径,这里使用的是相对路径,因此managed-schema文件跟solrconfig.xml文件在同一个目录中。

    注意:本人就是没有太理解,一直认为manage-schema模式下,manage-schema中的配置不能修改,就是修改也能不生效的,其实不然,就算你修改了也可以生效,重启后和通过API修改效果一样。不过如果正的使用这种模式的话也没比较修改,通过web页面添加编辑更加方便。

    下面介绍一下managed-schema模式下的Schema API

    Schema API是一套REST风格的API,用户可以通过浏览器,或者使用某种语言中的HTTPClient对象进行访问。

    HTTP Method:POST; Content-type:json,则定义新默认的Java代码为:

    public void addField() throws IOException  
        {  
            String urlStr="http://192.98.219.12:8983/solr/techproducts/schema";  
            URL url=new URL(urlStr);  
            HttpURLConnection connection=(HttpURLConnection) url.openConnection();  
            connection.setRequestMethod("POST");  
            connection.setRequestProperty("Content-type", "application/json");  
            connection.setDoOutput(true);  
            connection.setDoInput(true);  
            BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));  
            JSONObject field=new JSONObject();  
            field.put("name", "test");  
            field.put("type", "text_general");  
            field.put("stored", true);  
            JSONObject addDoc=new JSONObject();  
            addDoc.put("add-field",field);  
            System.out.println(addDoc.toString());  
            writer.write(addDoc.toString());  
            writer.flush();  
            writer.close();  
            //  
            BufferedReader reader=new BufferedReader(new InputStreamReader(connection.getInputStream()));  
            while(reader.ready())  
            {  
                System.out.println(reader.readLine());  
            }  
            reader.close();  
        }  
  • 相关阅读:
    题解 CF171G 【Mysterious numbers
    题解 P1157 【组合的输出】
    题解 P3955 【图书管理员】
    题解 P2036 【Perket】
    题解 CF837A 【Text Volume】
    题解 CF791A 【Bear and Big Brother】
    题解 CF747A 【Display Size】
    题解 P1332 【血色先锋队】
    题解 P2660 【zzc 种田】
    题解 P4470 【[BJWC2018]售票】
  • 原文地址:https://www.cnblogs.com/gaoxu007/p/7214626.html
Copyright © 2020-2023  润新知