设为首页 收藏本站
查看: 890|回复: 0

[经验分享] Solr4.5.1+tomcat8.0安装配置

[复制链接]

尚未签到

发表于 2015-11-12 09:21:15 | 显示全部楼层 |阅读模式

  • 下载tomcat和solr:wget http://mirror.esocc.com/apache/tomcat/tomcat-8/v8.0.0-RC5/bin/apache-tomcat-8.0.0-RC5.tar.gz
    -O tomcat.tgz; wget
    http://mirror.bit.edu.cn/apache/lucene/solr/4.5.1/solr-4.5.1.tgz -O solr.tgz
  • 解压缩tomcat和solr:tar xzvf tomcat.tgz; tar xzvf solr.tgz
  • 拷贝solr到tomcat的webapps目录: cp solr/example/webapps/solr.war tomcat/webapps
  • 启动tomcat,解压缩solr.wartomcat/bin/startup.sh
  • solr/example/multicore拷贝到tomcat/webapps/conf目录下
  • 在tomcat/webapps/solr/WEB-INF/下新建一个classes目录,将example/resources下的文件复制到该classes目录中
  • 将solr/example/lib/ext/下的所有jar包复制到tomcat/webapps/solr/WEB-INF的lib目录中
  • 修改web.xml文件,为:
    <env-entry>
    <env-entry-name>solr/home</env-entry-name>
    <env-entry-value>${TOMCAT_HOME}/webapps/conf/multicore</env-entry-value>
    <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
  • 配置分词,使用的是mmseg4j和搜狗词库:wget http://mmseg4j.googlecode.com/files/mmseg4j-1.9.1.zip -O mmseg4j; cp mmseg4j/dist/*.jar tomcat/webapps/solr/WEB-INF/lib
  • 配置core0下面的schema.xml的types节点:
    <fieldtype name=&quot;textComplex&quot; class=&quot;solr.TextField&quot; positionIncrementGap=&quot;100&quot;>
    <analyzer>
    <tokenizer class=&quot;com.chenlb.mmseg4j.solr.MMSegTokenizerFactory&quot; mode=&quot;complex&quot; dicPath=&quot;dic&quot;></tokenizer>
    </analyzer>
    </fieldtype>
    <fieldtype name=&quot;textMaxWord&quot; class=&quot;solr.TextField&quot; positionIncrementGap=&quot;100&quot;>
    <analyzer>
    <tokenizer class=&quot;com.chenlb.mmseg4j.solr.MMSegTokenizerFactory&quot; mode=&quot;max-word&quot; dicPath=&quot;dic&quot;></tokenizer>
    </analyzer>
    </fieldtype>
    <fieldtype name=&quot;textSimple&quot; class=&quot;solr.TextField&quot; positionIncrementGap=&quot;100&quot;>
    <analyzer>
    <tokenizer class=&quot;com.chenlb.mmseg4j.solr.MMSegTokenizerFactory&quot; mode=&quot;simple&quot; dicPath=&quot;dic&quot;></tokenizer>
    </analyzer>
    </fieldtype>
  • 在 tomcat\webapps\conf\multicore\core0\conf\schema.xml  文件的  fields 节点里 添加如下节点 :
    <field name=&quot;simple&quot; type=&quot;textSimple&quot; indexed=&quot;true&quot; stored=&quot;true&quot; multiValued=&quot;true&quot; />
    <field name=&quot;complex&quot; type=&quot;textComplex&quot; indexed=&quot;true&quot; stored=&quot;true&quot; multiValued=&quot;true&quot; />
    <field name=&quot;max&quot; type=&quot;textMaxWord&quot; indexed=&quot;true&quot; stored=&quot;true&quot; multiValued=&quot;true&quot; />
  • 因为 solr4.5 里有两个 core , 所以针对 core1 重复 10,11 两步
  • 对分词进行测试 , 访问  http://localhost:8080/solr/#/core0/analysis
  • Field[Name]   输入:  complex
  • Field Value(index)   输入:   中国银行第一分行  ,   Field Value(index)  下面的 verbose outpu 点选
  • 点击Analyze  按钮 ,  查看分词结果    :  中国银行 |  第一 |  分行
  • 此时 Solr3.5 已经可以进行 分词 , 接下来配置 solr 3.5 连接  mysql 数据库 , 生成索引 , 进行分词


  • 每个core中都有两个文件,conf和data

    conf:主要用于存放core的配置文件,

    (1)、schema.xml用于定义索引库的字段及分词器等,这个配置文件是核心文件

    (2)、solrconfig.xml定义了这个core的配置信息,比如:


    <autoCommit>
    <maxTime>15000</maxTime>
    <openSearcher>false</openSearcher>
    </autoCommit>


    定义了什么时候自动提交,提交后是否开启一个新的searcher等等。

    data:主要用于存放core的数据,即index-索引文件和log-日志记录。

  • 下载 java 的 mysql 驱动 , 本机解压 mysql-connector-java-5.1.18-bin.jar,  然后拷贝到 tomcat\webapps\solr\WEB-INF\lib  目录下
  • 在 \Tomcat 6.0\webapps\solr  目录下 新建  db  文件夹
  • 在 \Tomcat 6.0\webapps\solr\db 文件夹下面新建一个  db-data-config.xml 文件 , 内容如下 :


<dataConfig>

    <dataSource type=&quot;JdbcDataSource&quot; driver=&quot;com.mysql.jdbc.Driver&quot; url=&quot;jdbc:mysql://localhost:3306/test&quot; user=&quot;root&quot; password=&quot;123&quot; />

    <document name=&quot;messages&quot;>

        <entity name=&quot;message&quot; transformer=&quot;ClobTransformer&quot; query=&quot;select * from test1&quot;>

            <field column=&quot;ID&quot; name=&quot;id&quot; />

            <field column=&quot;Val&quot; name=&quot;text&quot; />

        </entity>

    </document>

</dataConfig>


url=&quot;jdbc:mysql://localhost:3306/test&quot; user=&quot;root&quot; password=&quot;123&quot;  这里配置了 mysql 的连接路径 , 用户名 , 密码


<field column=&quot;ID&quot; name=&quot;id&quot; /><field column=&quot;Val&quot; name=&quot;text&quot; />  这里配置的是 数据库里要索引的字段 , 注意name 是 11 步配置的


14.4   在 Tomcat 6.0\webapps\solr\conf\multicore\core0\conf 目录下的 solrconfig.xml 文件里 , 添加如下代码 :


<requestHandler name=&quot;/dataimport&quot; class=&quot;org.apache.solr.handler.dataimport.DataImportHandler&quot;>

    <lst name=&quot;defaults&quot;>

      <str name=&quot;config&quot;>E:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/solr/db/db-data-config.xml</str>

    </lst>

  </requestHandler>


“E:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/solr/db/db-data-config.xml” 是 14.3 配置文件的绝对路径


14.5  在Tomcat 6.0\webapps\solr\conf\multicore\core1\conf\solrconfig.xml   路径里重复 14.4


14.6  把本地下载解压的 solr3.5 文件里 , dist 目录下的  apache-solr-dataimporthandler-3.5.0.jar 和 apache-solr-dataimporthandler-extras-3.5.0.jar  Tomcat 6.0\webapps\solr\WEB-INF\lib  目录下


14.7   solr3.5 连接 mysql 已经配置完成 , 测试读取 mysql 生成 索引 , 访问 :   http://localhost:8180/solr/core0/dataimport?command=full-import


14.8   测试分词查询 , 访问  http://localhost:8180/solr/core0/admin/  查询数据库里索引列里有的词


注意 , 这仅仅是配置 solr3.5 连接 mysql 生成索引 , 可以执行正常 词语  的查询 , 但是不能执行  对搜索短语的分词 查询


multicore  目录下面多个 core 文件夹 , 每一个都是一个接口 , 有独立的配置文件 , 处理某一类数据 。


multicore/core0/conf/  目录下的  schema.xml  文件 相当于数据表配置文件 , 它定义了加入索引的数据的数据类型 。文件里有一个 <uniqueKey>id</uniqueKey> 的配置 , 这里将 id 字段作为索引文档的唯一标示符 , 非常重要 。




FieldType 类型 , name 是这个 FieldType 的名称 , class 指向了 org.apache.solr.analysis 包里面对应的 class 名称 , 用来定义这个类型的定义 。在 FieldType 定义的时候最重要的就是定义这个类型的数据在建立索引和进行查询的时候要使用的分析器analyzer,包括分词和过滤 。


Fields 字段 :  结点内定义具体的字段(类&#20284;数据库中的字段) , 就是 field , 包含 name , type(为之前定义过的各种FieldType) , indexed(是否被索引) , stored(是否被存储) , multiValued(是否有多个&#20540;)


copeField(赋&#20540;字段): 建立一个拷贝字段 , 将所有的全文字段复制到一个字段中 , 以便进行统一的检索 。


版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-138183-1-1.html 上篇帖子: Windows下安装配置Solr (tomcat7.0) 下篇帖子: 使用Solr快速实现Django的全文搜索[转]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表