参考文档:https://cwiki.apache.org/confluence/display/solr/Getting+Started
环境:
CentOS 6.5, JDK 1.7, Solr5.0.0
一、standalone模型的安装、索引、搜索
1. 下载 Solr 5.0.0
资源地址:http://lucene.apache.org/solr/
#注意: Solr 5.0.0 必需JRE 1.7或者以上版本
2. 解压缩 Solr 5.0.0
tar zxf solr-5.0.0.tgz
3. 启动服务
bin/solr start
#注意:默认以后台进程启动服务,并监听在8983端口
4. 检查服务状态
bin/solr status
或
http://localhost:8983/solr/ #访问Solr管理界面
5. 创建core
bin/solr create -c gettingstarted
#创建一个gettingstarted的core, 并且scheme为data-driven(自动猜测数据类型)
6. 增加文档到索引
bin/post -c gettingstarted example/exampledocs/*.json
#提交example/exampledocs目录下所有的JSON文档到gettingstarted core
7. 搜索文档
直接构造带有搜索参数的URL即可
eg.
http://localhost:8983/solr/gettingstarted/select?q=video
#搜索gettingstarted core中所有文档字段中包含'video'的文档
http://localhost:8983/solr/gettingstarted/select?q=video&fl=id,name,price
#搜索gettingstarted core中所有文档字段中包含'video'的文档,并且每篇文档只返回id,name,price三个字段
http://localhost:8983/solr/gettingstarted/select?q=name:black
#搜索gettingstarted core中name字段包含'black'的文档
http://localhost:8983/solr/gettingstarted/select?q=price:[0%20TO%20400]&fl=id,name,price
#搜索gettingstarted core中price字段在0到400区间的文档,并且每篇文档只返回id,name,price三个字段
http://localhost:8983/solr/gettingstarted/select?q=price:[0%20TO%20400]&fl=id,name,price&facet=true&facet.field=cat
#搜索gettingstarted core中price字段在0到400区间的文档,每篇文档只返回id,name,price三个字段,并按照cat字段进行facet搜索
http://localhost:8983/solr/gettingstarted/select?q=price:0%20TO%20400&fl=id,name,price&facet=true&facet.field=cat&fq=cat:software
#搜索gettingstarted core中price字段在0到400区间的文档,每篇文档只返回id,name,price三个字段,按照cat字段进行facet搜索,并过滤返回cat字段为'software'的文档
二、bin/solr脚本常用操作
bin/solr start #开启solr服务,默认后台运行
bin/solr start -f #前台启动solr服务
bin/solr -help #查看bin/solr使用帮助
bin/solr start -help #查看bin/solr start使用帮助
bin/solr stop -p 8983 #停止8983端口上的solr服务,需要指定端口
bin/solr stop -all #停止所有端口上的solr服务
bin/solr status #查看solr服务运行状态
bin/solr create -c <name> #创建<name>的core
bin/solr create -help #查看bin/solr create的使用帮助