pylucene在python2.7下的安装

安装文章,参考这篇文章:http://bendemott.blogspot.com/2013/11/installing-pylucene-4-451.html

Why are we installing pylucene 4?

This may be your first time using lucene with Python, or you may be upgrading.  pylucene 4 adds faceting features, and reworks the module structure to be identical to that of lucene 4 itself.  Check out the samples directory after you download the pylucene package for examples of new and existing functionality.

Install PyLucene

Download pylucene from   http://lucene.apache.org/pylucene/install.html

Extract the Package:
tar -zxvf pylucene-4.5.1-src.tar.gz
Install openjdk:
sudo apt-get install openjdk-7-jdk
Install Apache Ant:
sudo apt-get install ant
Install gnu c++ compiler:
sudo apt-get install g++

Install python dev (python.h) headers:
sudo apt-get install python-dev

Upgrade/install setuptools to 0.7 or higher:
sudo apt-get install pip 
pip install setuptools --upgrade 

Change to the jcc directory:
cd pylucene-4.5.1-1/jcc  (edit to match your extracted directory)
Build and Install JCC:
sudo python setup.py build
sudo python setup.py install 
If all that worked, you're ready to build pylucene!
# cd up to the "pylucene-4.xxx" directory 
cd .. 

Edit the file named "Makefile" located at the root of the pylucene-4.5.1 directory you just extracted
# Locate this line
# Linux     (Ubuntu 11.10 64-bit, Python 2.7.2, OpenJDK 1.7, setuptools 0.6.16)
Uncomment lines in the Makefile as shown (if you are on linux):











Issue make and install command:
make 
sudo make install  
  Test the installation:
# open a python interpreter 
python 
# now at the prompt type... 
import lucene 
lucene.initVM()

 If no exceptions are raised you're done!  You've now installed PyLucene 4 !

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PyLucene 是一个 Python 的 Lucene 库,它提供了 Python 与 Java 编写的 Lucene API 的绑定,可以用于创建和操作 Lucene 索引,执行全文搜索和文本分析等任务。下面是 PyLucene安装和使用方法: 1. 安装 Java PyLucene 是一个 Python 库,但它依赖于 Java 的 Lucene 库。因此,在安装 PyLucene 之前,需要先安装 Java。 2. 安装 JCC JCC 是一个 Java 原生代码编译器,用于为 Python 和 Java 之间的代码绑定生成 JNI 接口。PyLucene 使用 JCC 进行 Python 与 Java 的交互。因此,需要先安装 JCC。 可以使用以下命令安装 JCC: ``` pip install https://github.com/elasticdog/jcc/archive/master.zip ``` 3. 下载 PyLucene 可以从 Apache Lucene 的官方网站下载 PyLucene 的源代码,下载地址为: http://www.apache.org/dyn/closer.lua/lucene/pylucene/ 选择与您使用的 Python 版本和操作系统相应的版本进行下载。 4. 编译 PyLucene 在下载 PyLucene 的源代码后,需要对其进行编译。在编译 PyLucene 之前,需要确保已经安装了 setuptools、numpy 和 Cython。 在命令行中进入 PyLucene 的源代码目录,运行以下命令进行编译: ``` make make install ``` 上述命令将会编译 PyLucene 并将其安装Python 的 site-packages 目录下。 5. 使用 PyLucene 安装完成 PyLucene 后,就可以使用其提供的 API 进行全文搜索和文本分析等任务了。下面是一个简单的示例: ```python from lucene import * # 初始化 Java 虚拟机 vm_env = getVMEnv() # 创建索引 index_dir = SimpleFSDirectory(Paths.get('index')) analyzer = StandardAnalyzer() index_writer = IndexWriter(index_dir, IndexWriterConfig(analyzer)) doc = Document() doc.add(StringField('title', 'Hello World', Field.Store.YES)) index_writer.addDocument(doc) index_writer.commit() index_writer.close() # 执行搜索 index_reader = DirectoryReader.open(index_dir) index_searcher = IndexSearcher(index_reader) query_parser = QueryParser('title', analyzer) query = query_parser.parse('Hello') hits = index_searcher.search(query, 10).scoreDocs for hit in hits: doc = index_searcher.doc(hit.doc) print(doc.get('title')) index_reader.close() ``` 上述示例程序首先初始化了 Java 虚拟机,然后创建了一个包含一个文档的索引,并将其保存到磁盘上。接着,它执行了一个基于查询的搜索操作,并输出了搜索结果。 更多 PyLucene 的用法可以参考其官方文档: https://lucene.apache.org/pylucene/api.html

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值