`
hongtoushizi
  • 浏览: 359251 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

ubuntu 安装solr中文分词(转载)

阅读更多

这个简短的教程描述了如何在 Ubuntu Server 上安装 Solr 4,我使用的版本是:Ubuntu Server 12.04 和 Apache Solr 4.0-BETA. 我同时将展示如何测试安装以及执行一个简单的索引和查询任务。

在 Ubuntu 12.04 LTS 上安装 Tomcat

1. 安装包

1 apt-get install tomcat6 curl

 

2. 从 http://lucene.apache.org/solr 上下载 Solr 4 (写文章是的最新版本是 apache-solr-4.0.0-BETA.tgz)

3. 为 solr 选择一个目录,并使用 SOLR_HOME 环境变量指向这个目录,我这里选择的是 /opt/solr ,因此我的 SOLR_HOME=/opt/solr. 如果你想选择不同的目录请替换 /opt/solr

4. 解压缩文件并复制到 $SOLR_HOME:

  • 复制 example/solr/* 到 /opt/solr
  • 复制 example/webapps/solr.war 到 /opt/solr

5. 编辑 /opt/solr/collection1/conf/solrconfig.xml 中的 dataDir 配置项

1 <dataDir>${solr.data.dir:/opt/solr/data}</dataDir>

 

6. 为 Solr 创建数据目录,并给 tomcat 设置可读写权限

1 mkdir /opt/solr/data
2 sudo chown tomcat6 /opt/solr/data

 

下面是我的 /opt/solr 目录的结构:

$ tree -d ├── bin
├── collection1
│   └── conf
│       ├── lang
│       ├── velocity
│       └── xslt
└── data

7. 在 Tomcat 中设置新的 context (web应用程序)并指向我们的 solr 文件,只需要在创建文件/etc/tomcat6/Catalina/localhost/solr.xml ,内容如下:

1 <?xml version="1.0" encoding="utf-8"?>
2 <Context docBase="/opt/solr/solr.war" debug="0" crossContext="true">
3   <Environment name="solr/home" type="java.lang.String"value="/opt/solr" override="true"/>
4 </Context>

 

8. 重启 tomcat

1 /etc/init.d/tomcat6 restart

 

9. 你可以在浏览器上打开 http://localhost:8080/solr 来验证是否安装成功

solr dashboard

solr 面板

索引测试以及 UTF-8 测试

solr 安装文件包含一个简单的 schema.xml (我们已经复制到了 $SOLR_HOME 目录) 和一些包含示例数据的 xml 文件,我们将使用这些数据来测试 UTF-8 编码是否正常。

1. 进入 solr 解压目录然后使用 curl 导入 utf8-example.xml 文件

1 URL=http://localhost:8080/solr/update
2 curl $URL --data-binary @example/exampledocs/utf8-example.xml -H'Content-type:application/xml'

 

来自服务器的响应类似如下XML信息:

1 <?xml version="1.0" encoding="UTF-8"?>
2 <response>
3 <lst name="responseHeader"><int name="status">0</int><intname="QTime">22</int></lst>
4 </response>
5 </xml>

 

2. 提交文档

1 curl "$URL?softCommit=true"

 

3. 通过测试搜索字符串 êâîôû ,使用 Solr 管理界面或者使用 GET 请求访问

http://localhost:8080/solr/collection1/select?q=êâîôû

你将看到返回一个搜索结果。

 

转载自: http://www.oschina.net/question/12_71342

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics