apache solr安装和使用笔记

来源:互联网 发布:启用网络发现保存不了 编辑:程序博客网 时间:2024/06/05 02:26

 一、安装

A、 利用自带的Jetty服务器

首先在dos命令中进入到下载好的solr解压的目录apache-solr-3.4.0的example目录

cd E:\JAR\solr\apache-solr-3.4.0\example

然后利用java命令,启动jetty服务器。Java –jar start.jar

clip_image004

启动Jetty成功后,如果没有看到错误消息,你可以看到端口信息。

clip_image006

如果你的端口冲突了,你可以到解压的solr示例包的example/etc的jetty.xml中,修改端口port信息。

<Set name="port">

<SystemProperty name="jetty.port" default="8983"/>

</Set>

B、 利用tomcat发布solr示例

将下载的solr解压后,进入apache-solr-3.4.0\dist目录,将里面的solr.war放到D:\tomcat-6.0.28\webapps目录下,启动tomcat会自动解压。(当然,你也可以手动解压放到wabapps目录下)

当然你也可以设置context指向你的solr工程,在D:\tomcat-6.0.28\conf\Catalina\localhost目录加入solr.xml配置,配置如下:

<Context docBase="D:\solr.war" debug="0" crossContext="true" >
    <Environment name="solr/home" type="java.lang.String" value="D:\solr" override="true" />
</Context>

上面的2步都是一样的,这样还没有完。启动后你可能会看到如下错误:

clip_image008

我们需要将一些配置和index库文件也放到解压好的solr工程下。我们到解压的apache-solr-3.4.0\example\solr目录下,将里面的conf和data目录copy到刚才我们部署的D:\tomcat-6.0.28\webapps\solr工程目录下。或是copy到你的solr.xml中的context指定的路径下工程目录中。

重启tomcat就ok了。

4、 这个时候你就可以访问http://localhost:8983/solr/admin/你就可以看到如下界面:

clip_image010

在Query String中输入solr,点击Search就可以查询到相应的结果,结果以xml形式返回。当然你也可以设置返回数据类型为json。

<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
  <int name="status">0</int>
  <int name="QTime">0</int>
  <lst name="params">
    <str name="indent">on</str>
    <str name="start">0</str>
    <str name="q">solr</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>software</str><str>search</str></arr>
    <arr name="features"><str>Advanced Full-Text Search Capabilities using Lucene</str><str>Optimized for High Volume Web Traffic</str><str>Standards Based Open Interfaces - XML and HTTP</str>
      <str>Comprehensive HTML Administration Interfaces</str><str>Scalability - Efficient Replication to other Solr Search Servers</str><str>Flexible and Adaptable with XML configuration and Schema</str><str>Good unicode support: h¨¦llo (hello with an accent over the e)</str></arr>
    <str name="id">SOLR1000</str>
    <bool name="inStock">true</bool>
    <date name="incubationdate_dt">2006-01-17T00:00:00Z</date>
    <str name="manu">Apache Software Foundation</str>
    <str name="name">Solr, the Enterprise Search Server</str>
    <int name="popularity">10</int>
    <float name="price">0.0</float>
  </doc>
</result>
</response>
 
http://www.cnblogs.com/hoojo/archive/2011/10/21/2220431.html
0 0
原创粉丝点击