solr7.7.0搜索引擎使用(三)(添加文件索引)
众所周知,solr与es的最大区别是,solr可以对pdf,txt,doc等文件生成索引
那我们如何添加文件索引呢?
步骤1.添加core,取名暂且为 coreFile 在bin下执行命令 ./solr create -c coreFile
步骤2.准备要搜索的文件

步骤3.添加搜索的数据源 注意,此时使用的class是solr.DataimportHandler

步骤4.添加数据源文件,注意更换 baseDir为你自己的文件路径
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="BinFileDataSource"/>
<document>
<entity name="file" processor="FileListEntityProcessor" dataSource="null"
baseDir="/Users/sunpeizhen/Desktop/file" fileName=".(doc)|(pdf)|(docx)|(txt)|(csv)|(json)|(xml)|(pptx)|(pptx)|(ppt)|(xls)|(xlsx)"
rootEntity="false"> <field column="file" name="id"/>
<field column="fileSize" name="fileSize"/>
<field column="fileLastModified" name="fileLastModified"/>
<field column="fileLastModified" name="fileLastModified"/>
<field column="fileAbsolutePath" name="fileAbsolutePath"/>
<entity name="pdf" processor="TikaEntityProcessor"
url="${file.fileAbsolutePath}" format="text"> <field column="Author" name="author" meta="true"/>
<!-- in the original PDF, the Author meta-field name is upper-cased,
but in Solr schema it is lower-cased
--> <field column="title" name="title" meta="true"/>
<field column="text" name="text"/> </entity>
</entity>
</document> </dataConfig>
步骤5.添加字段索引
在managed-schema 文件下添加字段索引:
<field name="title" type="text_cn" indexed="true" stored="true"/>
<field name="text" type="text_cn" indexed="true" stored="true" omitNorms ="true"/>
<field name="author" type="string" indexed="true" stored="true"/>
<field name="fileSize" type="plong" indexed="true" stored="true"/>
<field name="fileLastModified" type="pdate" indexed="true" stored="true"/>
<field name="fileAbsolutePath" type="string" indexed="true" stored="true"/>
步骤6.添加中文分词
solr默认没有开启中文分词,许压迫我们添加中文分词的配置
在managed-schema 文件下添加:
<fieldType name="text_cn" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>
</analyzer>
</fieldType>
此时中文分词开启。
文件搜索已经添加完毕
测试中文分词:
我们添加的分词名称为 text_cn
进入solrUI操作界面,选择coreFIle,点击 Analys

输入中文语句,进行分词,测试如下:

文件搜索:
点击query,进入查询页面。 可以看到文件内容也已经可以搜索到

solr7.7.0搜索引擎使用(三)(添加文件索引)的更多相关文章
- solr7.7.0搜索引擎使用(二)(添加搜索)
一.安装完毕之后,需要为solr添加core,每一个搜索server就是一个core,solr可以有很多core,我们需要创建一个core用于我们的搜索 添加core的方式有两种: 第一种进入solr ...
- solr7.7.0搜索引擎使用(四)(搜索语法)
solr搜索语法 参数defType 指定用于处理查询语句(参数q的内容)的查询解析器,eg:defType=lucenesort 指定响应的排序方式:升序asc或降序desc.同时需要指定 ...
- solr7.7.0搜索引擎使用(一)(下载安装)
一.下载安装 可以直接在官网下载地址:https://lucene.apache.org/solr/ 解压之后,目录结构如下图,bin里边提供部署的文件,contrib提供额外的jar包,docs提供 ...
- (二)部署solr7.1.0到tomcat
solr7.1.0部署到tomcat8 官方表示solr5之后的版本不再提供对第三方容器的支持(不提供war包了). "旧式"solr.xml格式不再支持,核心必须使用core.p ...
- CentOS7.5 Linux搭建全文检索--Solr7.4.0单机服务
一.Solr安装环境 1.官方参考文档 Solr教程参考指南:http://lucene.apache.org/solr/guide/7_4/solr-tutorial.html 2.Solr运行环境 ...
- CentOS7.5搭建Solr7.4.0单机服务
一.Solr安装环境 1.官方参考文档 Solr教程参考指南:http://lucene.apache.org/solr/guide/7_4/solr-tutorial.html 2.Solr运行环境 ...
- VC++6.0一些常见问题解决方法(打开多个窗口、行号、添加文件无响应、更改.exe图标及名称等等)
背景: 最近使用VC++6.0做一个界面,供测试CAN通信使用.由于客户希望我们提供简单方便的函数接口让其最快速使用CAN,DLL(动态链接库)是不二之选.做DLL需要两个VC窗口进行测试才方便.可是 ...
- 解决VC++6.0打开文件或添加文件到工程出错的问题
相信很多朋友在安装VC++6.0之后,发现无法使用打开文件命令.同时,打开了工程,却无法实现文件添加到工程的问题.一旦进行如此操作,便会出现应用程序错误,需要关闭应用程序.为此,不胜其烦.更有甚者,以 ...
- Servlet3.0学习总结(三)——基于Servlet3.0的文件上传
在Servlet2.5中,我们要实现文件上传功能时,一般都需要借助第三方开源组件,例如Apache的commons-fileupload组件,在Servlet3.0中提供了对文件上传的原生支持,我们不 ...
随机推荐
- Spring Boot-基础教程
一.关于RESTfull API风格 import java.util.Date; /** * 实体类 */public class User { private int id; private St ...
- kafka partition(分区)与 group(转)
原文 https://www.cnblogs.com/liuwei6/p/6900686.html 一. 1.原理图 2.原理描述 一个topic 可以配置几个partition,produce发送 ...
- 几种流行Webservice框架
一. 几个比较流行的Webservice框架: Apache Axis1.Apache Axis2.Codehaus XFire.Apache CXF.Apache Wink.Jboss RESTE ...
- Linux报错:bash: pip: command not found
$ wget https://bootstrap.pypa.io/get-pip.py$ python get-pip.py$ pip -V #查看pip版本 接下来就可以随便pip安装东西了
- SYSAUX表空间清理
最近zabbix告警某业务sysaux表空间使用率超过95%,使用sql查看sysaux表空间设置了32G,32G的表空间竟然使用了95%.一般来讲除开业务数据存放的表空间,DBA要着重关注SYSTE ...
- 黑色背景下 vs把{}括号变黑问题
最近喜欢把VS的背景搞成黑色,据说这样可以对眼睛好一点,然后就蛋疼的碰到点击括号中的内容,括号就变黑的问题,这样黑色背景下就什么看不到了. 原因是装了番茄助手导致的,解决办法,把选中行VA Brace ...
- docker 在windows7 、8下的安装
这里说明一下这种安装方式适合win7 win8的系统环境下安装的,当然win10也可以,但是win10有更好的方式 即安装Docker Toolbox,同时还附加安装 Docker Client fo ...
- 概念吓死人的webservice
前倾提要:这是我七拼八凑,自己用手打出来的头一篇了!都是别人的想法,我抄袭的,我坦白,我这只是总结一下觉得有用的 本来题目想叫(1)REST API 和WebService(2)REST 样式和 SO ...
- thinkphp5 与 endroid 二维码生成
windows compser安装endroid/qrcode,自己安装好composer工具; 1. 项目目录 文件 composer.json require 里添加 "endroid/ ...
- Python中的正则表达式(re)
import re re.match #从开始位置开始匹配,如果开头没有则无 re.search #搜索整个字符串 re.findall #搜索整个字符串,返回一个list 举例: r(raw)用在p ...