127 lines
4.3 KiB
Markdown
127 lines
4.3 KiB
Markdown
# solr部署说明文档
|
||
|
||
## 1、下载官方solr程序压缩包
|
||
|
||
> 下载链接:[https://solr.apache.org/downloads.html](https://solr.apache.org/downloads.html)
|
||
|
||
可根据项目需求下载对应版本
|
||
|
||
## 2、多java版本环境修改
|
||
|
||
当部署环境存在多个java版本时,部署solr时需要修改solr的启动文件。举个栗子,使用的是`jdk1.6`版本,假如我们准备部署`solr 8.x`以上版本,而`solr 8.x`需要`jdk1.8`以上版本的支持。若服务器上环境变量设置了`JAVA_HOME`指向`jdk1.6`版本的路径。那么我们就需要通过修改solr的启动批处理文件来进行1.8版本的指定。
|
||
|
||
修改方式如下:
|
||
|
||
- windows
|
||
|
||
修改`solr根目录/bin`下的`solr.cmd`文件
|
||
|
||
```cmd
|
||
@REM solr.cmd
|
||
@REM 在首行中增加一行如下语句
|
||
set "JAVA_HOME=JDK1.8版本的根路径"
|
||
```
|
||
|
||
- linux
|
||
|
||
修改`solr根目录/bin`下的`solr.sh`文件
|
||
|
||
```shell
|
||
JAVA_HOME="JDK1.8版本的根路径"
|
||
```
|
||
|
||
## 3、中文分词类库加载准备
|
||
|
||
> solr自身携带中文分词类库,但需要在solr程序启动前拉到对应位置进行类加载。
|
||
|
||
将`solr根目录/contrib/analysis-extras/lucene-libs/`目录下的`lucene-analyzers-smartcn-8.9.0.jar`(官方中文分词器)复制到`solr根目录/server/solr-webapp/webapp/WEB-INF/lib/`目录下。
|
||
|
||
## 4、启动服务进程
|
||
|
||
进入solr的`bin`目录,运行
|
||
|
||
```cmd
|
||
solr start -e schemaless
|
||
```
|
||
|
||
`-e`为启动模式,这里示例中使用无模式(单机)启动,solr支持一下模式启动
|
||
|
||
- cloud
|
||
- techproducts
|
||
- dih
|
||
- schemaless
|
||
|
||
这里只以schemaless模式作为示例,其他模式请自行查阅[官方文档](https://solr.apache.org/guide/8_9/solr-control-script-reference.html)
|
||
|
||
## 5、创建服务核心
|
||
|
||
进入solr的`bin`目录,运行
|
||
|
||
```cmd
|
||
solr create -c EntNameInfo
|
||
```
|
||
|
||
> 此处的`EntNameInfo`为核心名称
|
||
|
||
运行完成后看见返回`SUCCESS`字样即为创建成功
|
||
|
||
## 6、字段定义
|
||
|
||
进入`solr根目录/example/schemaless/solr/EntNameInfo/conf`目录,编辑器打开`managed-schema`文件。
|
||
|
||
> 注意:以上示例为8.x版本。在旧版本中,可能没有这个文件,取而代之的是`schema.xml`文件。
|
||
|
||
### 6.1、分词字段类型定义
|
||
|
||
在与其他`<fieldType></fieldType>`标签同级的位置上加入
|
||
|
||
```xml
|
||
<!-- ChineseAnalyzer 自带的中文分词器 -->
|
||
<fieldType name="solr_cnAnalyzer" 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>
|
||
```
|
||
|
||
定义一个进行分词的字段
|
||
|
||
### 6.2、字段定义
|
||
|
||
在与其他`<field></field>`标签同级的位置上加入
|
||
|
||
```xml
|
||
<field name="EntName" type="solr_cnAnalyzer" indexed="true" stored="true" tokenized="true"/>
|
||
<field name="EntNo" type="string" indexed="true" required="true" stored="true"/>
|
||
<field name="EntType" type="string" indexed="true" stored="true"/>
|
||
<field name="EstDate" type="plong" uninvertible="true" indexed="true" stored="true"/>
|
||
<field name="LeRep" type="solr_cnAnalyzer" indexed="true" stored="true" tokenized="true"/>
|
||
<field name="OpState" type="string" indexed="true" stored="true"/>
|
||
<field name="RegNO" type="string" indexed="true" stored="true"/>
|
||
<field name="RegOrg" type="string" indexed="true" stored="true"/>
|
||
<field name="corpKeywords" type="string" indexed="true" stored="true"/>
|
||
<field name="corpName" type="text_general"/>
|
||
<field name="datasourceKey" type="string" indexed="true" stored="true"/>
|
||
<field name="lauptime" type="plong" uninvertible="true" indexed="true" stored="true"/>
|
||
<field name="regCapital" type="pdoubles" multiValued="false" indexed="false" stored="true"/>
|
||
<field name="regCapitalCoin" type="string" indexed="true" stored="true"/>
|
||
<field name="smallMicroEnt" type="string" indexed="true" stored="true"/>
|
||
<field name="timestampBin" type="string" uninvertible="true" indexed="true" stored="true"/>
|
||
```
|
||
|
||
在以上常用的属性中
|
||
|
||
- `type` 指定字段类型
|
||
- `indexed` 指定字段是否被索引
|
||
- `stored` 指定字段的实际值是否被存储
|
||
- `tokenized` 指定字段是否进行分词
|
||
|
||
### 7、重载核心
|
||
|
||
进入SolrAdmin管理界面,进入`Core Admin`界面进行core重载,以便配置加载。
|
||
|
||

|