360SDN.COM

首页/Solr/列表

solr7.4 安装与使用【创建core ,配置IK分词】

来源:  2018-08-02 17:57:00    评论:0点击:

来源:http://www.cnblogs.com/tony-zt/p/9260017.html
1.solr7环境要求

solr7需要java8环境,且需要在环境变量中添加 JAVA_HOME变量。

2.solr 安装

下载地址 https://lucene.apache.org/solr/mirrors-solr-latest-redir.html  我下载为7.4版本

   在solr5以前solr的启动都有tomcat作为容器,但是从solr5以后solr内部集成jetty服务器,可以通过bin目录中脚本直接启动。就是从solr5以后跟solr4最大的区别是被发布成一个独立的应用。

   在solr5之后solr其实特别容易安装,有安装包,之后在解压,直接启动bin下solr,solr就这样完成的启动了。。

 运行命令:

solr.cmd start

 
重启solr
solr.cmd restart  -p 8983
 

注意:这里我直接启动会有报 log4j2.xml (文件名、目录名或卷标语法不正确。)  我暂时还没解决,不过不影响启动

ERROR StatusLogger Unable to access file:/D:/3d/solr-7.4.0/server/file:D:/3d/solr-7.4.0/server/resources/log4j2.xml
 java.io.FileNotFoundException: D:\3d\solr-7.4.0\server\file:D:\3d\solr-7.4.0\server\resources\log4j2.xml (文件名、目录 名或卷标语法不正确。)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(FileInputStream.java:195)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at java.io.FileInputStream.<init>(FileInputStream.java:93)
        at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
        at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
        at java.net.URL.openStream(URL.java:1038)
        at org.apache.logging.log4j.core.config.ConfigurationSource.fromUri(ConfigurationSource.java:247)
        at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:404)
        at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:346)
        at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:260)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:615)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
        at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
        at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:121)
        at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
        at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
        at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
        at org.eclipse.jetty.util.log.Slf4jLog.<init>(Slf4jLog.java:38)
        at org.eclipse.jetty.util.log.Slf4jLog.<init>(Slf4jLog.java:32)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at org.eclipse.jetty.util.log.Log.initialized(Log.java:178)
        at org.eclipse.jetty.util.log.Log.getLogger(Log.java:311)
        at org.eclipse.jetty.util.log.Log.getLogger(Log.java:301)
        at org.eclipse.jetty.xml.XmlConfiguration.<clinit>(XmlConfiguration.java:80)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.eclipse.jetty.start.Main.invokeMain(Main.java:220)
        at org.eclipse.jetty.start.Main.start(Main.java:486)
        at org.eclipse.jetty.start.Main.main(Main.java:77)

启动后直接访问  http://localhost:8983/solr/#/ 

 

 

 

出现这个页面就表示solr启动成功

 

3.创建core 

点击admin core 输入创建core名称  注意:创建的instanceDir和dataDir 需存在,就是我们需在solr-7.4.0\server\solr 目录下先去创建目录

 命令:
solr create -c vip_core
 

此目录下的conf文件我们可从solr\configsets\sample_techproducts_configs中复制

 

当创建与复制好后,我们在再页面上创建core  创建成功

 

 

 4.配置IK分词

下载地址:https://pan.baidu.com/s/1Dbma2vAepBSsCag_EztTTw

下载解压后 把两个jar文件复制到solr-7.4.0\server\solr-webapp\webapp\WEB-INF\lib中

在solr-7.4.0\server\solr-webapp\webapp\WEB-INF\classes目录下新建一个classes目录,把下面三个文件复制进去

进入之前创建的core   在solr-7.4.0\server\solr\newCore\conf下打开managed-schema.xml 添加如下代码:

 <fieldType name="text_ik" class="solr.TextField">  
        <analyzer type="index" useSmart="false"
            class="org.wltea.analyzer.lucene.IKAnalyzer" />
        <analyzer type="query" useSmart="true"
            class="org.wltea.analyzer.lucene.IKAnalyzer" />
</fieldType> 

 

重启solr 重新访问 选择刚之前创建的core 

 

 选择Analysis  输入要搜索的中文 选择FieldType为text_ik  可以发现分词成功

 

为您推荐

友情链接 |九搜汽车网 |手机ok生活信息网|ok生活信息网|ok微生活
 Powered by www.360SDN.COM   京ICP备11022651号-4 © 2012-2016 版权