通过homebrew安装solr:
1
brew install solr
安装在
/usr/local/Cellar/solr/
下对应版本号的目录启动solr cloud:
1
solr start -e cloud -noprompt
或者solr单个节点:1
solr start
启动后通过访问:http://localhost:8983/solr/#/~cloud 可以看到系统拓扑图:
导入数据
3.1 导入富文本文件1
post -c gettingstarted /usr/local/Cellar/solr/5.5.0/libexec/docs/
以上命令将导入solr目录下的示例数据文件夹包含的富文本文件.
导入之后,就可以通过访问solr的搜索界面:http://localhost:8983/solr/#/gettingstarted_shard1_replica2/query 进行搜索:
3.2 通过solr xml格式文件导入数据
solr xml文件的定义参见:apache wiki
导入示例文件命令为:1
post -c gettingstarted example/exampledocs/*.xml
通过访问:http://localhost:8983/solr/gettingstarted/browse 可以看到当前已导入的文件列表,同样可以通过搜索界面进行搜索.
3.3 通过json格式文件导入1
post -c gettingstarted example/exampledocs/books.json
3.4 通过csv格式文件导入
1
post -c gettingstarted example/exampledocs/books.csv
3.5 其他导入方式
通过DIH从数据库导入,使用SolrJ插件通过java等基于jvm的代码导入,使用Admin UI …- 通过关键词进行搜索
4.1 单个条件搜索
通过替换搜索界面中q的默认值:*:*
为’foudation’或者访问地址:http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=foundation 可以得到搜索结果.
访问搜索界面需要执行sharding,但是请求搜索结果可以忽略
可以看到返回的结果几乎包含了所有的记录,因为刚才的搜索包含了所有的字段,通过将q设置为name:foudation
可以仅仅搜索name
属性中中包含foudation的记录,同理可以试试q设置为cat:software
搜索cat属性中包含software的记录.
4.2 词组搜索
例如需要搜索CAS latency
,在搜索界面中可以直接录入CAS latency
,但是如果通过url,需要将空格替换为+
.
4.3 组合搜索条件
需要条件出现使用+
,需要条件不出现使用-
例如:http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=%2Bone+%2Bthree 这个链接搜索包含one但是不包含three的记录
4.4 更多
访问apache wiki获取更多有关搜索的细节. - 清理
到现在我们已经大致接触了solr,要将solr恢复到初始状态,执行以下命令:1
bin/solr stop -all ; rm -Rf example/cloud/