PyLucene安装与初试

来源:互联网 发布:java都能做什么 编辑:程序博客网 时间:2024/04/30 03:07

安装

  1. 尝试在Windows上安装,遇到各种各样的bug,遂放弃
  2. 在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还是比较方便快捷的。

0 0
原创粉丝点击