Apache solr tutorial入门(转载) Apache solr tutorial入门

Apache solr tutorial入门

找得的一篇比较简单的solr入门教程。

博客分类:
 

Apache solr tutorial

 

本节我们来学习apache solr,并且学习启动solr和检索,这个只能算是hello world教程,能让你在学习solr时,有个最为感性的认识。学习完本教程,你会感觉到信心大增,对于solr的最基础的配置和应用,应该算是入门了。

 

 

准备:

1:java:Oracle/openJDK/IBM ,版本好大于1.6

2:solr:Solr Release:http://lucene.apache.org/solr/downloads.html,官网上已经有最新版本的了,我们直接下载最新版本即可。现在网上的教程都是基于nightly版本,本文直接使用solr4.0版本作为示范

 

最后提示一点。我这个示范是在linux下面,其实并不仅限于linux,如果你在window平台上,只要有java环境,一样可以顺利启动。

 

 

installation:

 

Shell代码   收藏代码
  1. ls  
  2. unzip apache-solr-4.0.0.zip  
  3. cd apache-solr-4.0.0/example/  

 

 

执行

 

Java代码   收藏代码
  1. java -jar start.jar  

 

 

控制台会打印出一大堆的日志,不过当你看到:

 

Shell代码   收藏代码
  1. INFO:oejs.AbstractConnector:Started SocketConnector@0.0.0.0:8983  

 

 

就说明solr已经顺利启动,在监听8983端口。

现在你打开浏览器,输入

 

Shell代码   收藏代码
  1. http://localhost:8983/solr/  
 

 

能看到solr的熟悉的管理界面,如果没有看到,或者报异常,请看下日志,看看是什么原因。

在管理界面上自己点一下,熟悉下solr的最基础的功能。

 

 

现在solr已经正常启动并且顺利运行,你可以通过post请求为solr添加、删除文档等 各种操作。

现在进入exampledocs目录,向solr提交post请求,请求solr对请求数据进行索引。

 

Shell代码   收藏代码
  1. java -jar post.jar solr.xml monitor.xml  

 

 

看solr的日志,能看到solr对这两个文件的索引日志。

 

 

 

现在点开solr的管理界面,在Query模块中q输入框中输入solr,点击execute,看下搜索结果。

 

或者直接在浏览器执行

 

Shell代码   收藏代码
  1. http://localhost:8983/solr/collection1/select?q=solr&wt=xml  

 

 

如果想看下json格式的返回:

 

Shell代码   收藏代码
  1. http://localhost:8983/solr/collection1/select?q=solr&wt=json  

 

 

在exampledocs下执行

 

Shell代码   收藏代码
  1. java -jar post.jar *.xml  

其中*为匹配符,会将该目录下的所有xml文档提交

 

 

看到solr索引成功后,可以在管理见面点击、查询结果

如video、hard、Samsung等,看下搜素结果。

 

如果想了解的更为细致,可以看下mem.xml、money.xml,熟悉下solr添加索引的数据结构。

如果想通过solr添加索引,就得遵从solr的处理方式。

后面我们会更加细致的学习solr的细节。

 

在上面的url中出现了collection1的东西,这个是什么东东?这个collection1其实是solr管理index的一个core:

solr Core的解释可以参考这里:

 

Java代码   收藏代码
  1. Multiple cores let you have a single Solr instance with separate configurations and indexes, with their own config and schema for very different applications, but still have the convenience of unified administration. Individual indexes are still fairly isolated, but you can manage them as a single application, create new indexes on the fly by spinning up new SolrCores, and even make one SolrCore replace another SolrCore without ever restarting your Servlet Container.  

 

一句话解释,方便管理、配置,关于solrCore的配置可以参考solr/solr.xml配置文件,这个是个比较高级的概念,是为分布式索引的关键,先了解下,当然在管理界面中也可以直接添加core,自己找下并且点几下自己添加个core,感受下这个功能。

 

猜你喜欢

转载自hongtoushizi.iteye.com/blog/1920701