1.Solr简介

Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口。用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引;也可以通过Http Get操作提出查找请求,并得到XML格式的返回结果。

特点:Solr是一个高性能,采用Java5开发,基于Lucene的全文搜索服务器。同时对其进行了扩展,提供了比Lucene更为丰富的查询语言,同时实现了可配置、可扩展并对查询性能进行了优化,并且提供了一个完善的功能管理界面,是一款非常优秀的全文搜索引擎

2.Solr的安装配置

1)下载solr安装包(以solr-5.5.4为例)

http://archive.apache.org/dist/lucene/solr/

2)安装:

解压后将solr-5.5.4\server\solr-webapp下的webapp拷贝到LinuxTomcat(版本:apache-tomcat-8.0.44)webapps下并改名为solr

 solr搜索服务器

 

将解压包solr-5.5.4\server\lib\ext下的jar文件拷到Linuxapache-tomcat-8.0.44/webapps/solr/WEB-INF/lib下:

solr搜索服务器

3)配置solrhome

打开apache-tomcat-8.0.44/webapps/solr/WEB-INFweb.xml文件,找到如下所示去掉注释,将value值设置成你的Linux分词库路径(要先创建好分词库的文件夹index):

 

<env-entry>

   <env-entry-name>solr/home</env-entry-name>

   <env-entry-value>/mysoft/index</env-entry-value>

   <env-entry-type>java.lang.String</env-entry-type>

</env-entry>

 

 

solr-5.5.4\solr-5.5.4\server\solr下的文件和文件夹拷贝到上面web.xml中配置的分词库index下:

 solr搜索服务器

 

 

在上面已经配好的分词库下创建目录core(core1),将分词库index/configsets/basic_configs下的conf文件夹拷到core1下:

 solr搜索服务器

 

 

 

开启Tomcat并访问(ipLinux上的IP):http://192.168.6.128:8080/solor/index.html  或者 http://192.168.6.128:8080/solr/admin.html  

 solr搜索服务器

 

 

 

 

 

 

4配置corecore类似于数据库可以插入多个document(数据库表行)每个document拥有多个 field 数据库的列)

 solr搜索服务器

 

 

检查 mycore目录 发现多了 core.properties和data两个资源

 solr搜索服务器



登陆solr管理网站发现 列表中多了core1

 solr搜索服务器



5)解析配置文件

 solr搜索服务器


managed-schema 主要用于配置 可以提交到该core的所有field定义,field的类型定义,唯一标识符等

 solr搜索服务器


 solrconfig.xml 主要用于配置solor的主要配置信息 比如lucene版本 缓存 数据目录 请求路径映射 等

 solr搜索服务器



6)solr界面添加和查询数据(添加时要根据配置文件中已有的数据类型添加:foodname_ik)

 solr搜索服务器




 

solr搜索服务器




3.添加IK分词器(solr版本5.5.4,IK最高支持4.7.2,所以要修改源码)

新建一个maven项目,配置pom文件如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>cn.et</groupId>

<artifactId>IK</artifactId>

<version>0.0.1-SNAPSHOT</version>

<dependencies>

<dependency>

<groupId>com.janeluo</groupId>

<artifactId>ikanalyzer</artifactId>

<version>2012_u6</version>

<!-- 排除IK4.7.2重新引Lucene5.5.4 -->

<exclusions>

<exclusion>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-core</artifactId>

</exclusion>

<exclusion>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-queryparser</artifactId>

</exclusion>

<exclusion>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-queries</artifactId>

</exclusion>

<exclusion>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-sandbox</artifactId>

</exclusion>

<exclusion>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-analyzers-common</artifactId>

</exclusion>

</exclusions>

</dependency>

<dependency>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-core</artifactId>

<version>5.5.4</version>

</dependency>

<dependency>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-queryparser</artifactId>

<version>5.5.4</version>

</dependency>

<dependency>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-queries</artifactId>

<version>5.5.4</version>

</dependency>

<dependency>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-sandbox</artifactId>

<version>5.5.4</version>

</dependency>

<dependency>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-analyzers-common</artifactId>

<version>5.5.4</version>

</dependency>

</dependencies>

</project>


 

solr搜索服务器 



创建跟源码一样的包名和类名并进行修改:

 solr搜索服务器

 


solr搜索服务器

 

用修改好的文件替换源码:

 solr搜索服务器



先拷贝ikanalyzer-2012_u6.jar,解压后将上面两个文件替换

 solr搜索服务器

 

 solr搜索服务器


 

将改好的jar包放到Linux中的/mysoft/apache-tomcat-8.0.44/webapps/solr/WEB-INF/lib

 solr搜索服务器

 

 

managed-schema 中配置:

 solr搜索服务器

 

添加数据,查询数据后分词结果:

 solr搜索服务器



相关文章:

  • 2021-09-25
  • 2021-09-25
  • 2021-09-25
  • 2021-09-25
  • 2021-09-25
  • 2021-09-25
  • 2021-10-05
  • 2018-02-22
猜你喜欢
  • 2021-09-25
  • 2021-05-09
  • 2018-12-13
  • 2021-08-17
  • 2022-01-07
  • 2021-10-12
  • 2021-06-30
  • 2021-09-25
相关资源
相似解决方案