`

Solr, Hello World.

    博客分类:
  • Solr
阅读更多

现在Solr的版本是3.1,与Lucene Java开始同版本号发布。

 

Hello, World!

 

Solr的官网下载Solr的包,我们就挑一个国内的镜像吧,http://labs.renren.com/apache-mirror//lucene/solr/3.1.0/,可以看到,这里有一个是源码包,一个是可执行包。我们就先下载可执行包apache-solr-3.1.0.zip

 

把包解开。可以看到里面有几个文件夹:

client:用来存放Solr客户端的文件夹,目前里面值存放了一个Ruby的客户端。

contrib:Solr的强劲插件所用到得依赖Jar包

dist:Solr的发布文件,包括Solr的插件

docs:文档和Javadoc

example:示例

 

好,先不多说,直奔主题:命令行进入example文件夹,

 

E:\tony\libDoc\Java\Lucene\apache-solr-3.1.0\example>java -jar start.jar

 如无意外,可以看到Jetty的启动过程以及Solr的初始化过程:

在命令行最后一行显示的内容应该是:

 

2011-5-10 10:12:19 org.apache.solr.core.SolrCore registerSearcher
信息: [] Registered new searcher Searcher@50903025 main

 

值得注意的是,Jetty帮我们打开的端口是8983, 这时候,我们应该可以从浏览器里面浏览 http://localhost:8983/solr/

我们从http://localhost:8983/solr/admin/stats.jsp#core可以看到

numDocs : 0

 

 表示说我们的Solr是干净的,什么也没有。

好,现在网Solr里面塞点数据,命令行进入 solr解压文件夹/example/exampledocs

 

E:\tony\libDoc\Java\Lucene\apache-solr-3.1.0\example\exampledocs>java -jar post.
jar *.xml
SimplePostTool: version 1.3
SimplePostTool: POSTing files to http://localhost:8983/solr/update..
SimplePostTool: POSTing file gb18030-example.xml
SimplePostTool: POSTing file hd.xml
SimplePostTool: POSTing file ipod_other.xml
SimplePostTool: POSTing file ipod_video.xml
SimplePostTool: POSTing file mem.xml
SimplePostTool: POSTing file monitor.xml
SimplePostTool: POSTing file monitor2.xml
SimplePostTool: POSTing file mp500.xml
SimplePostTool: POSTing file sd500.xml
SimplePostTool: POSTing file solr.xml
SimplePostTool: POSTing file utf8-example.xml
SimplePostTool: POSTing file vidcard.xml
SimplePostTool: COMMITting Solr index changes..
 

这时,我们再看看Solr里面的文档数:

 

numDocs : 17

 到这里,我们已经建立了Solr的demo,我们现在来试试搜索:

回到http://localhost:8983/solr/admin/,在的Query String:文本框里面填入

name:apple

  点击search button,会从定向到 http://localhost:8983/solr/select/?q=name%3Aapple&version=2.2&start=0&rows=10&indent=on

结果是一个XML文档

 

<?xml version="1.0" encoding="UTF-8"?>
<response>

<lst name="responseHeader">
  <int name="status">0</int>
  <int name="QTime">6</int>
  <lst name="params">
    <str name="indent">on</str>
    <str name="start">0</str>
    <str name="q">name:apple</str>
    <str name="version">2.2</str>
    <str name="rows">10</str>
  </lst>
</lst>
<result name="response" numFound="1" start="0">
  <doc>
    <arr name="cat"><str>electronics</str><str>music</str></arr>
    <arr name="features"><str>iTunes, Podcasts, Audiobooks</str><str>Stores up to 15,000 songs, 25,000 photos, or 150 hours of video</str><str>2.5-inch, 320x240 color TFT LCD display with LED backlight</str>
      <str>Up to 20 hours of battery life</str><str>Plays AAC, MP3, WAV, AIFF, Audible, Apple Lossless, H.264 video</str><str>Notes, Calendar, Phone book, Hold button, Date display, Photo wallet, Built-in games, JPEG photo playback, Upgradeable firmware, USB 2.0 compatibility, Playback speed control, Rechargeable capability, Battery level indication</str></arr>
    <str name="id">MA147LL/A</str>
    <bool name="inStock">true</bool>
    <str name="includes">earbud headphones, USB cable</str>
    <str name="manu">Apple Computer Inc.</str>
    <date name="manufacturedate_dt">2005-10-12T08:00:00Z</date>
    <str name="name">Apple 60 GB iPod with Video Playback Black</str>
    <int name="popularity">10</int>
    <float name="price">399.0</float>
    <str name="store">37.7752,-100.0232</str>
    <float name="weight">5.5</float>
  </doc>
</result>
</response>

这样,Solr经过全文检索,返回给我们一条结果,耗时6ms。 

 

0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics