solr学习笔记

1、安装前准备

solr依赖java 8 运行环境,所以我们先安装java。如果没有java环境无法启动solr服务,并且会看到如下提示:

[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*/

2、下载&安装&启动&停止
1.1、下载&安装:下载安装包,然后直接解压到指定目录即可。

[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.2、启动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.3、停止solr服务

[root@localhost solr-6.1.0]# ./bin/solr stop -all
[root@localhost solr-6.1.0]# ./bin/solr start -help /*查看停止命令帮助*/

3、生成索引数据
solr使用./bin/post命令生成索引数据。支持多种生成方式:
3.1、指定文件生成索引数据,支持格式: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.2、指定目录生成索引数据

[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted ~/docdir

3.3、网络爬虫

[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted http://lucene.apache.org/solr -recursive 1 -delay 1

3.4、标准输入/输出管道

[root@localhost solr-6.1.0]# echo '{commit: {}}' | ./bin/post -c gettingstarted -type application/json -out yes -d

3.5、字符串

[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、删除索引数据
我们可以指定要删除记录的主键值来删除指定记录,或者在文档中定义指定记录的值批量删除
4.1、删除主键ID值为SP2514N的记录,-d参数是可以是其他solr支持的格式或文件

[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted -d "<delete><id>SP2514N</id></delete>"

5、搜索
Solr支持多种搜索渠道,如:REST clients, cURL, wget, Chrome POSTMAN等等.理论上支持所有语言。
5.1、CURL方式:

[root@localhost solr-6.1.0]# curl "http://localhost:8983/solr/gettingstarted/select?q=*:*&wt=json&indent=true"

5.2、搜索API常用参数说明
5.2.1、参数[q=keyword|field:value|keyword1+keyword2|keyword1+-keyword2]:搜索关键字|包含value的字段field|同时包含keyword1和keyword2|包含keyword1,但不包含keyword2。
5.2.2、参数[wt=json]:结果返回格式:json、xml、python、ruby、php、csv等。
5.2.3、参数[start=0]:分页偏移量,即从第几条开始。
5.2.4、参数[rows=10]:每页数量,默认10。
5.2.5、参数[fl=id[,field2,field3,...]]:结果只返回指定的字段,多个用“,”隔开。
5.2.6、参数[indent=false|true]:返回结果个否格式化(缩进)。
5.2.7、参数[fq=field:value]:过滤结果
5.2.8、参数[facet=true|false|on|off]:开始/关闭分组,统计分组数量
5.2.8、参数[facet.field=field]:以field字段分组统计
更多参数说明:https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing

solr学习笔记-入门的更多相关文章

  1. Solr学习笔记之3、Solr dataimport - 从SQLServer导入数据建立索引

    Solr学习笔记之3.Solr导入SQLServer数据建立索引 一.下载MSSQLServer的JDBC驱动 下载:Microsoft JDBC Driver 4.0 for SQL Server ...

  2. Solr学习笔记之2、集成IK中文分词器

    Solr学习笔记之2.集成IK中文分词器 一.下载IK中文分词器 IK中文分词器 此文IK版本:IK Analyer 2012-FF hotfix 1 完整分发包 二.在Solr中集成IK中文分词器 ...

  3. Solr学习笔记之1、环境搭建

    Solr学习笔记之1.环境搭建 一.下载相关安装包 1.JDK 2.Tomcat 3.Solr 此文所用软件包版本如下: 操作系统:Win7 64位 JDK:jdk-7u25-windows-i586 ...

  4. PHP学习笔记 - 入门篇(5)

    PHP学习笔记 - 入门篇(5) 语言结构语句 顺序结构 eg: <?php $shoesPrice = 49; //鞋子单价 $shoesNum = 1; //鞋子数量 $shoesMoney ...

  5. PHP学习笔记 - 入门篇(4)

    PHP学习笔记 - 入门篇(4) 什么是运算符 PHP运算符一般分为算术运算符.赋值运算符.比较运算符.三元运算符.逻辑运算符.字符串连接运算符.错误控制运算符. PHP中的算术运算符 算术运算符主要 ...

  6. PHP学习笔记 - 入门篇(3)

    PHP学习笔记 - 入门篇(3) 常量 什么是常量 什么是常量?常量可以理解为值不变的量(如圆周率):或者是常量值被定义后,在脚本的其他任何地方都不可以被改变.PHP中的常量分为自定义常量和系统常量 ...

  7. PHP学习笔记--入门篇

    PHP学习笔记--入门篇 一.Echo语句 1.格式 echo是PHP中的输出语句,可以把字符串输出(字符串用双引号括起来) 如下代码 <?php echo "Hello world! ...

  8. LESS学习笔记 —— 入门

    今天在网上完成了LESS的基础学习,下面是我的学习笔记.总共有三个文件:index.html.main.less.mian.css,其中 mian.css 是 main.less 经过Koala编译之 ...

  9. Solr学习笔记之5、Component(组件)与Handler(处理器)学习

    Solr学习笔记之5.Component(组件)与Handler(处理器)学习 一.搜索篇 拼写检查(spellCheck) 作用:用来检查用户输入的检索内容是否存在,如果不存在则给它提示出相近或相似 ...

随机推荐

  1. AJAX-基础-1

    概述 AJAX = Asynchronous JavaScript And XML(异步 JavaScript 及 XML) AJAX 是 Asynchronous JavaScript And XM ...

  2. hbase hbck

    Number of Tables: 7Number of live region servers: 3Number of dead region servers: 0Number of empty R ...

  3. $\LaTeX$数学公式大全6

    $6\ Binary\ Operation/Relation\ Symbols$$\ast$ \ast$\star$ \star$\cdot$ \cdot$\circ$ \circ$\bullet$ ...

  4. y7000笔记本 darknet-yolo安装与测试(Ubuntu16.04+Cuda9.0+Cudnn7.1)

    https://zhuanlan.zhihu.com/p/41096599 1.先查看是否安装有以下组件,若有先考虑彻底删除再安装(安装严格按照下面顺序进行) 查看nvidia 版本 nvidia-s ...

  5. Java官方操纵byte数组的方式

    java官方提供了一种操作字节数组的方法——内存流(字节数组流)ByteArrayInputStream.ByteArrayOutputStream ByteArrayOutputStream——by ...

  6. JAVA常见工具配置

    1.MyEclipse中配备struts.xml的自动提示 https://jingyan.baidu.com/article/9158e0004054baa2541228e2.html 2.MySQ ...

  7. Padding Oracle 和 CBC字节翻转攻击学习

    以前一直没时间来好好研究下这两种攻击方式,虽然都是很老的点了= =! 0x01:Padding oracle CBC加密模式为分组加密,初始时有初始向量,密钥,以及明文,明文与初始向量异或以后得到中间 ...

  8. thinkphp session 跨域问题解决方案

    session 跨域,困扰我好几天,今天终于弄明白了! 不管是thinkphp ,还是本身的php 其实都要设置session.cookie_domain 设置好,就OK了 在thinkphp 里,在 ...

  9. Fiddler抓包原理和使用详解

    iddler抓包工具在APP开发过程中使用非常频繁,对开发者理解HTTP网络传输原理以及分析定位网络方面的问题非常有帮助.今天抽点时间出来总结一下Fiddler在实际开发过程中的应用. 我开发过程中使 ...

  10. GsonForamt插件的使用

    第一步:在AS中安装GsonForamt插件 第二步:创建bean类 第三步: 在bean类体中做如下操作即可快速创建bean类 鼠标右击按图选择: 将需要解析的json字符串复制进去 设置界面:可以 ...