solr学习笔记-入门

solr学习笔记
一、安装前准备

solr依赖java 8 运行环境,因此咱们先安装java。若是没有java环境没法启动solr服务,而且会看到以下提示:php

[root@localhost solr-6.1.0]# ./bin/solr start -e cloud -noprompt /*运行solr服务*/
Java not found, or an error was encountered when running java.
A working Java 8 is required to run Solr!
Please install Java 8 or fix JAVA_HOME before running this script.
Command that we tried: 'java -version'
[root@localhost ~]# java -version /*检测是否已安装java*/
[root@localhost ~]#  yum install -y java /*安装java*/

二、下载&安装&启动&中止
1.一、下载&安装:下载安装包,而后直接解压到指定目录便可。
html

[root@localhost ~]# wget http://ftp.meisei-u.ac.jp/mirror/apache/dist/lucene/solr/6.1.0/solr-6.1.0.tgz
[root@localhost ~]# tar zxvf solr-6.1.0.tgz -C /usr/local/
[root@localhost ~]# cd /usr/local/solr-6.1.0
[root@localhost solr-6.1.0]# ls
bin  CHANGES.txt  contrib  dist  docs  example  licenses  LICENSE.txt  LUCENE_CHANGES.txt  NOTICE.txt  README.txt  server
[root@localhost solr-6.1.0]# ./bin/solr -help /*查看solr命令帮助*/
[root@localhost solr-6.1.0]# ./bin/solr status /*查看solr服务启动状态*/

1.二、启动solr服务
[root@localhost solr-6.1.0]# ./bin/solr start -e cloud -noprompt /*启动solr服务*/
Welcome to the SolrCloud example!
Starting up 2 Solr nodes for your example SolrCloud cluster.
/*省略中间部分*/
SolrCloud example running, please visit: http://localhost:8983/solr /*浏览器打开这个url能够看到solr的运行状况*/
[root@localhost solr-6.1.0]# ps aux | grep solr /*能够看到solr服务进程*/
[root@localhost solr-6.1.0]# ./bin/solr start -help /*查看启动命令帮助*/

1.三、中止solr服务
[root@localhost solr-6.1.0]# ./bin/solr stop -all
[root@localhost solr-6.1.0]# ./bin/solr start -help /*查看中止命令帮助*/

三、生成索引数据
solr使用./bin/post命令生成索引数据。支持多种生成方式:
3.一、指定文件生成索引数据,支持格式:xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted filename.json

3.二、指定目录生成索引数据
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted ~/docdir

3.三、网络爬虫
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted http://lucene.apache.org/solr -recursive 1 -delay 1

3.四、标准输入/输出管道
[root@localhost solr-6.1.0]# echo '{commit: {}}' | ./bin/post -c gettingstarted -type application/json -out yes -d

3.五、字符串
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted -type text/csv -out yes -d $'id,value\n1,0.47'

注:文件内容格式能够参考solr安装目录内的/usr/local/solr-6.1.0/example/exampledocs/*下文件。

四、删除索引数据
咱们能够指定要删除记录的主键值来删除指定记录,或者在文档中定义指定记录的值批量删除
4.一、删除主键ID值为SP2514N的记录,-d参数是能够是其余solr支持的格式或文件
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted -d "<delete><id>SP2514N</id></delete>"

五、搜索
Solr支持多种搜索渠道,如:REST clients, cURL, wget, Chrome POSTMAN等等.理论上支持全部语言。
5.一、CURL方式:
[root@localhost solr-6.1.0]# curl "http://localhost:8983/solr/gettingstarted/select?q=*:*&wt=json&indent=true"
5.二、搜索API经常使用参数说明 5.2.一、参数[q=keyword|field:value|keyword1+keyword2|keyword1+-keyword2]:搜索关键字|包含value的字段field|同时包含keyword1和keyword2|包含keyword1,但不包含keyword2。 5.2.二、参数[wt=json]:结果返回格式:json、xml、python、ruby、php、csv等。 5.2.三、参数[start=0]:分页偏移量,即从第几条开始。 5.2.四、参数[rows=10]:每页数量,默认10。 5.2.五、参数[fl=id[,field2,field3,...]]:结果只返回指定的字段,多个用“,”隔开。 5.2.六、参数[indent=false|true]:返回结果个否格式化(缩进)。 5.2.七、参数[fq=field:value]:过滤结果 5.2.八、参数[facet=true|false|on|off]:开始/关闭分组,统计分组数量 5.2.八、参数[facet.field=field]:以field字段分组统计 更多参数说明:https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing
相关文章
相关标签/搜索