Solr5 快速开始

来源:互联网 发布:安全生产网络知识竞赛 编辑:程序博客网 时间:2024/06/08 19:32

http://lucene.apache.org/solr/quickstart.html

下载解压,略过。

一、按照例子启动后,solr会在“7574”和“8983”这两个节点启动起来。http://localhost:8983/solr/#/   可以通过这个url打开solr的管理页面Solr Admin(相当于控制台)在core selector下拉框处可以选择节点进行查看。

二、索引数据

    solr已经启动了,但还没有数据。solr的bin目录下包含了post的命令,能够很轻易的把不同类型的文件进行索引(目前window下还没有post工具,但可以通过java程序进行调用——后面详解-------https://cwiki.apache.org/confluence/display/solr/Post+Tool#PostTool-Windows)。

1.索引富文本

solr的目录下docs目录中包含了很多类型的文件用于索引示例。  在bin目录中,执行命令:

bin/post -c getting started  docs/

  1. -c gettingstarted: name of the collection to index into (索引存放的集合的名称)
  2. docs/: a relative path of the Solr install docs/ directory(目录的相对路径)

到solr的控制台,选择某个节点,点击Query查询tab页,在common下方的“q”输入框一栏中输入“solr”替换“*”(匹配全部),并点击execute query进行查询,右侧会显示出结果。

如果要索引自己的目录,修改目录地址即可。cleanup命令(http://lucene.apache.org/solr/quickstart.html#cleanup)用于清除示例生成的内容。

2.索引xml

bin/solr start -e techproducts(启动solr索引xml的例子)此处不谈这个。

bin/post -c gettingstarted example/exampledocs/*.xml  执行该命令进行索引xml。
http://localhost:8983/solr/gettingstarted/browse 查看索引的文件

3.索引JSON

bin/post -c getting started  docs/books.json

其他的像csv文件等  操作类似。

其他的索引技术(data import handler)DIH———后续介绍

三、更新数据

你会发现即使你执行了多次创建索引的操作,但查询到的数据却不会重复,这是因为例子example中的schema.xml定义了一个唯一的字段“id”。当你重复执行索引操作的时候,id一样的索引会被覆盖更新。在solr Admin UI的overview,可以看到max doc和 num docs。

四、删除数据

bin/post -c gettingstarted -d "<delete><id>SP2514N</id></delete>

五、检索

solr可以被rest、curl、wget等等调用。Solr AdminUI包含了检索的一个构建器。

1.简单查询

curl "http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=foundation"

返回

/solr-5.1.0$curl "http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=foundation"
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"indent":"true",
"q":"foundation",
"wt":"json"}},
"response":{"numFound":2812,"start":0,"docs":[
{
"id":"0553293354",
"cat":["book"],
"name":"Foundation”,

numFound说明找到了2812个结果,默认是返回从0开始的10条数据。如果要定制返回的内容,可以通过“f1”条件。如curl "http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=foundation&f1=id” 这样就只会返回id了。

语法: "q=field:value”  复杂检索、联合检索后续介绍。


Faceting   :能够将检索的结果按照某种类型分成子集。如域属性,数值或者日期范围。

先写到这。后续详细介绍。



0 0
原创粉丝点击