Solr学习总结(三)建立第一个索引
2017-05-11 16:46
441 查看
进入solr-5.5.4的文件夹。复制文件夹basic_configs命名为tmp_configs. 并将managed-schema文件重命名为schema.xml
然后修改solrconfig.xml中的schemaFactory字段,使用ClassicIndexSchemaFactory。这个配置让solr使用schema.xml配置,并允许手动修改,屏蔽了使用API修改schema的权限。
然后修改schema.xml文件,添加一个搜索域text。
重命名schema(非必要)
添加text域
文档中原来只存在id域。id是被配置为唯一键的,索引中每个文档都应有一个唯一id。所以id的配置中,required=true。
添加的text域,type配置成text_general。这个类在schema下面有配置,是用的一元分词。indexed=true表示这个域的内容会建立索引。stored=true表示内容会被储存。required=false表示不是必须存在的域。multiValued=false表示不是多值域。
结束配置后,使用脚本命令创建索引tmp_index:
create 表示建立索引。
<-c 索引名>
<-d 配置目录>
<-n 配置名>
<-P 端口>
运行结束后得到类似下面这段显示success的json就表示建立索引成功:
现在去浏览器打开:http://your_server:8983/solr/#/tmp_index 可以看到建立的索引。
9d8a
-bash-3.2$ cp -r server/solr/configsets/basic_configs server/solr/configsets/tmp_configs -bash-3.2$ mv server/solr/configsets/tmp_configs/conf/managed-schema server/solr/configsets/tmp_configs/conf/schema.xml
然后修改solrconfig.xml中的schemaFactory字段,使用ClassicIndexSchemaFactory。这个配置让solr使用schema.xml配置,并允许手动修改,屏蔽了使用API修改schema的权限。
vi server/solr/configsets/tmp_configs/conf/solrconfig.xml
<!-- To disable dynamic schema REST APIs, use the following for <schemaFactory>: <schemaFactory class="ClassicIndexSchemaFactory"/> When ManagedIndexSchemaFactory is specified instead, Solr will load the schema from the resource named in 'managedSchemaResourceName', rather than from schema.xml. Note that the managed schema resource CANNOT be named schema.xml. If the managed schema does not exist, Solr will create it after reading schema.xml, then rename 'schema.xml' to 'schema.xml.bak'. Do NOT hand edit the managed schema - external modifications will be ignored and overwritten as a result of schema modification REST API calls. When ManagedIndexSchemaFactory is specified with mutable = true, schema modification REST API calls will be allowed; otherwise, error responses will be sent back for these requests. --> <!-- <schemaFactory class="ManagedIndexSchemaFactory"> <bool name="mutable">true</bool> <str name="managedSchemaResourceName">managed-schema</str> </schemaFactory> --> <schemaFactory class="ClassicIndexSchemaFactory"/>
然后修改schema.xml文件,添加一个搜索域text。
vi server/solr/configsets/tmp_configs/conf/schema.xml
重命名schema(非必要)
<schema name="tmp" version="1.5">
添加text域
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> <field name="text" type="text_general" indexed="true" stored="true" required="false" multiValued="false" />
文档中原来只存在id域。id是被配置为唯一键的,索引中每个文档都应有一个唯一id。所以id的配置中,required=true。
添加的text域,type配置成text_general。这个类在schema下面有配置,是用的一元分词。indexed=true表示这个域的内容会建立索引。stored=true表示内容会被储存。required=false表示不是必须存在的域。multiValued=false表示不是多值域。
<!-- A general text field that has reasonable, generic cross-language defaults: it tokenizes with StandardTokenizer, removes stop words from case-insensitive "stopwords.txt" (empty by default), and down cases. At query time only, it also applies synonyms. --> <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100"> <analyzer type="index"> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" /> <!-- in this example, we will only use synonyms at query time <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/> --> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> <analyzer type="query"> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" /> <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> </fieldType>
结束配置后,使用脚本命令创建索引tmp_index:
./bin/solr create -c tmp_index -d tmp_configs -n tmp_configs -p 8983
create 表示建立索引。
<-c 索引名>
<-d 配置目录>
<-n 配置名>
<-P 端口>
运行结束后得到类似下面这段显示success的json就表示建立索引成功:
{ "responseHeader":{ "status":0, "QTime":3699}, "success":{"192.168.0.123:8983_solr":{ "responseHeader":{ "status":0, "QTime":861}, "core":"tmp_index"}}}
现在去浏览器打开:http://your_server:8983/solr/#/tmp_index 可以看到建立的索引。
9d8a
相关文章推荐
- Solr4.6.1配置与建立索引——搜索引擎学习(一)
- Solr学习总结(四)索引配置schema.xml & solrconfig.xml
- Solr4.6.1配置与建立索引——搜索引擎学习(一)
- Solr学习总结-命令行添加索引
- Solr学习三与mysql集成建立索引
- Solr学习笔记之3、Solr dataimport - 从SQLServer导入数据建立索引
- 索引的建立过程学习总结
- 2.myql数据导入到solr,并建立solr索引(学习笔记)
- Lucene学习总结之三:Lucene的索引文件格式(2)
- Lucene学习总结之四:Lucene索引过程分析(1)
- Lucene学习总结之四:Lucene索引过程分析(2)
- Lucene学习总结之三:Lucene的索引文件格式(2)
- Lucene学习总结之三:Lucene的索引文件格式(1)
- 索引视图的学习总结
- Lucene学习总结之四:Lucene索引过程分析(1)
- lucene3.0学习ing——建立索引
- 数据库建模工具PowerDesigner建立索引总结
- 数据库建模工具PowerDesigner建立索引总结
- Bugnet学习总结(1) 前言&索引
- Lucene学习总结之四:Lucene索引过程分析(4)