solr learning (a) Installation and Deployment

After testing, data synchronization MongoDB to Solr when the connection is not the error appears to Solr version 8.4.0 will be, I do not know 8.3.0 untested, bloggers test is easy to use a version 8.2.0, but have been under official website not, so I'll download link on the end of the text, students need self-created, not to under 8.3.0 / 8.4.0! ! !

Dragged more than a month, the company's busy with a new project, the contact period to a new thing, and that is Solr , what is solr, I understood as a full-text search, he can achieve full-text search database and highlighted realized, I believe you the mind has emerged out of the way when similar shopping platform Taobao search goods, yes, very similar to solr with him, when we need a full-text search can be used solr, let's start building solr environment.

Download and install Apache Solr

We have to solr official website to download the installation package solr

solr official website

Download a zip format, directly extract to a local can. solr built jetty server, so we can run, of course, we can also deploy solr to tomcat server such as running, here we use the built-in server.

Start solr service

We enter into solr installation directory bin folder, shift + right to open a command line window, win10 is powershell window, so we open to execute cmdthe command to switch to the cmd window (solr command of the executed are executed in this directory, not repeat them), then execute solr startto start solr, which is solr successful start screen.

solr starts successfully

We open the browser input localhost:8983(solr default start port is 8983) will be able to see solr interface.

solr interface

Add core

core project is equivalent to a solr instance, you enter the commandsolr create -c mycore

After successfully created, you can solr-8.2.0/server/solr/see the automatically generated default configuration file directory

Profiles

Once created, re-enter the backstage control page, you can find the newly created core

core

配置中文分词器 IK-Analyzer-Solr8

分词器就是能把我们输入的一个短语分成几个单词的形式,例如我爱中国,会被分为 我,爱,中国,三个。

为什么需要分词器?全文检索的意义就是当我们输入一个词语的时候能把相关涵盖的全都搜出来,比如我们搜索笔记本电脑,会把笔记本电脑拆成,笔记本,电脑,也就是说笔记本和电脑都会被查出来,这才是我们所需要的。

下载solr8版本的ik分词器,下载地址:https://search.maven.org/search?q=com.github.magese

ik word breaker

将下载好的jar包放入solr-8.2.0\server\solr-webapp\webapp\WEB-INF\lib目录中

然后到solr-8.2.0\server\solr\mycore\conf目录中打开managed-schema文件

managed-schema

打开managed-schema文件在文件末尾添加以下代码

<!-- ik分词器 -->
    <fieldType name="text_ik" class="solr.TextField">
    <analyzer type="index">
    <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false" conf="ik.conf"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
    <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true" conf="ik.conf"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    </fieldType>

Add word configuration

然后我们输入solr restart -port 8983来重启solr,回到后台管理页面

选择mycore -> Analysis -> 选择分词器 text_ik 输入 "我爱中国"

点击"Analyse Values"按钮可以看到结果已经分词成功了。

Word success

Solr后台管理

solr的安装与部署已经结束了,接下来带大家熟悉solr管理界面的各种功能。

Dashboard

仪表盘,显示了该Solr实例开始启动运行的时间、版本、系统资源、jvm等信息。

Logging

Solr运行日志信息

Core Admin

Solr Core的管理界面。Solr Core 是Solr的一个独立运行实例单位,它可以对外提供索引和搜索服务,一个Solr工程可以运行多个SolrCore(Solr实例),一个Core对应一个索引目录。

java properties

Solr在JVM 运行环境中的属性信息,包括类路径、文件编码、jvm内存设置等信息。

Tread Dump

显示Solr Server中当前活跃线程信息,同时也可以跟踪线程运行栈信息。

Core selector

选择一个SolrCore进行详细操作,如下:

Select the core

Analysis

分词器,在上面已经讲过了,通过此界面可以测试索引分析器和搜索分析器的执行情况。

Dataimport

可以定义数据导入处理器,从关系数据库将数据导入 到Solr索引库中。

Document

通过此菜单可以创建索引、更新索引、删除索引等操作,界面如下:

document

/update表示更新索引,solr默认根据id(唯一约束)域来更新Document的内容,如果根据id值搜索不到id域则会执行添加操作,如果找到则更新。

Query

solr的条件查询操作

query

Request-Handler

/select为一个URI。solr服务在接受到这个请求的时候,就会根据”/select”这段URI来选择对应的RequestHandler。

common

参数 描述 用法
q 这是Apache Solr的主要查询参数,文档根据它们与此参数中的术语的相似性来评分。 * : *
fq 这个参数表示Apache Solr的过滤器查询,将结果集限制为与此过滤器匹配的文档。
sort 这个参数指定由逗号分隔的字段列表,根据该列表对查询的结果进行排序。 id desc,price asc
start start参数表示页面的起始偏移量,此参数的默认值为0。若为1,表示从第二条记录中检索记录 1
rows 这个参数表示每页要检索的文档的数量。此参数的默认值为10。例如,可以通过将值2传递到参数行(row),将查询结果中的记录总数限制为2。 2
fl 这个参数为结果集中的每个文档指定返回的字段列表。如果想在结果文档中显示指定字段,则需要传递必填写的字段列表,用逗号分隔,作为属性fl的值。 id,content
df
Raw Query Parameters
wt 这个参数表示要查看响应结果的写入程序的类型。选择一个来获取所需文档类型的响应。 json、xml
indent Whether the results returned indent, off by default, use indent = true | on open, general debugging json, php, ruby ​​output only need to use this parameter. indent=true | on
debugQuery The results show whether Debug is set to return information.
dismax
edismax
hl Highlight open
hl.fl To highlight the field
hl.simple.pre Highlighted prefix
hl.simple.post Suffix highlighted
spatial
spellcheck

At this point, solr installation and deployment on the finish, and I think you also have some knowledge of solr, this is the first study solr, I intend to write a total of three articles to explain solr, respectively [solr installation and deployment] [solr mongodb data synchronization] [ssm project to integrate solr], to use the experience I have solr share out the project.

[reply]

  • Solr8.2.0 download link: link: https://pan.baidu.com/s/19HQOeXmYAesYH0UfNDwFgA extraction code: a3qs
    [/ Reply]

Guess you like

Origin www.cnblogs.com/zouwangblog/p/12171015.html