您的位置:首页 > 其它

PyLucene安装与初试

2016-02-03 10:46 453 查看

安装

尝试在Windows上安装,遇到各种各样的bug,遂放弃

在Linux上安装,下载源码,解压缩后根据官网安装指南(http://lucene.apache.org/pylucene/install.html)进行安装

在安装中遇到了如下的问题:

1. 依赖:java jdk, ant

2. 修改MakeFile文件时,环境变量在文件中修改会出问题,需要在terminal中export所有的环境变量

3. 如果需要安装中文分词的工具(Smart Chinese Analyzer), 需要将其对应的jar包解注释,并且找到

–exclude org.apache.lucene.sandbox.queries.regex.JakartaRegexpCapabilities \

在附近加入一句:

–exclude org.apache.lucene.analysis.cn.smart.AnalyzerProfile\

参考文献:http://m.blog.csdn.net/blog/DSbatigol/14448151

初试

现在PyLucene对应的lucene的版本是4.9.0,在使用的过程中发现:

1 直接import Lucene是不能直接工作的,需要像Java的引入方式一样才可以。我觉得PyLucene基本就是在用python的语法写java的程序了。类似于:

import sys, os, lucene, threading, time
from org.apache.lucene.analysis.miscellaneous import LimitTokenCountAnalyzer
from org.apache.lucene.analysis.standard import StandardAnalyzer
from org.apache.lucene.document import Document, Field, FieldType
from org.apache.lucene.index import FieldInfo, IndexWriter, IndexWriterConfig
from org.apache.lucene.store import SimpleFSDirectory
from org.apache.lucene.util import Version


2 lucene的每个版本是不向下兼容的,不同版本的代码用的函数的名称可能不一样,所以需要根据安装的版本号,看相应的文档,不过直接看安装包自带的example还是比较方便快捷的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: