solr

solr官方教程,领悟书生教程网提供solr教程,solr视频教程,solr学习笔记,solr电子书等系列教程

自定义solr core

2016-06-13| 发布: | 浏览: 1172 |保存PDF

在tomcat中部署solr

1、对apache-tomcat-7.0.53.zip解压,并将E:\dev\solr\solr-4.10.4\dist\solr-4.10.4.war拷贝到Tomcatwebapp目录下改名为solr.war,解压solr.war为solr,把solr.war删除



2、创建solrhome2,将solr-4.10.4\example\solr下的solr.xml拷贝到solrhome2目录下


3、在solrhome2目录下创建mysolr目录,并且在mysolr创建conf和data目录


4、将solr-4.10.4\example\solr\collection1\core.properties拷贝到solrhome2/mysolr目录下,并且修改core.properties

name=mysolr

5、将solr-4.10.4\example\solr\collection1\conf下的schema.xml、solrconfig.xml拷贝到solrhome2/mysolr/conf目录下


6、修改solrhome2/mysolr/conf/schema.xml,内容如下


<?xml version="1.0" encoding="UTF-8" ?>
<schema name="example" version="1.5">
    <field name="_version_" type="long" indexed="true" stored="true"/>
    <field name="_root_" type="string" indexed="true" stored="false"/>
    <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
    <field name="name" type="string" indexed="true" stored="true"/>
    <field name="title" type="text_general" indexed="true" stored="true" multiValued="true"/>
    <field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>
    <uniqueKey>id</uniqueKey>
    <fieldType name="string" class="solr.StrField" sortMissingLast="true" />
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
    <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>
</schema>
把solr-4.10.4\example\solr\collection1\conf目录下的 stopwords.txt和 synonyms.txt拷贝到solrhome2/mysolr/conf目录下

7、修改solrhome2/mysolr/conf/ solrconfig.xml ,修改以下内容,其他的保持默认

a、把所有lib标签注释掉

<!--
  <lib dir="${solr.install.dir:../../..}/contrib/extraction/lib" regex=".*\.jar" />
  <lib dir="${solr.install.dir:../../..}/dist/" regex="solr-cell-\d.*\.jar" />
  <lib dir="${solr.install.dir:../../..}/contrib/clustering/lib/" regex=".*\.jar" />
  <lib dir="${solr.install.dir:../../..}/dist/" regex="solr-clustering-\d.*\.jar" />
  <lib dir="${solr.install.dir:../../..}/contrib/langid/lib/" regex=".*\.jar" />
  <lib dir="${solr.install.dir:../../..}/dist/" regex="solr-langid-\d.*\.jar" />
  <lib dir="${solr.install.dir:../../..}/contrib/velocity/lib" regex=".*\.jar" />
  <lib dir="${solr.install.dir:../../..}/dist/" regex="solr-velocity-\d.*\.jar" />
-->
b、搜索 <str name="df">text</str>替换成 <str name="df">title</str>

c、注释掉以下代码

<!-- <searchComponent name="elevator" class="solr.QueryElevationComponent" > -->
    <!-- pick a fieldType to analyze queries -->
    <!-- <str name="queryFieldType">string</str>
    <str name="config-file">elevate.xml</str>
  </searchComponent> -->


8、修改Tomcat目录 下webapp\solr\WEB-INF\web.xml文件,设置 solr home

<env-entry>
   <env-entry-name>solr/home</env-entry-name>
   <env-entry-value>E:/dev/solr/solrhome2</env-entry-value>
   <env-entry-type>java.lang.String</env-entry-type>
</env-entry>


9、拷贝example\lib\ext 目录下所有jar包到Tomcatwebapp\solr\WEB-INF\lib目录下

10、启动Tomcat,并访问http://localhost:8080/solr


系列教程

大家都在看

热门访问