lucene-3.6.1简单安装与demo运行 for mac

今天刚到新公司入职,第一天没有什么特别具体的任务,于是就在mac上研究了一下lucene的安装和运行。

安装:

去官网下载lucene的最新发行版lucene-3.6.1,放到usr/local目录下,解压。这时,看docs文件夹下的index.html,里面有个getting start,内容如下:

Setting your CLASSPATH

First, you should download the latest Lucene distribution and then extract it to a working directory.

You need two JARs: the Lucene JAR, and the Lucene demo JAR. You should see the Lucene JAR file in the directory you created when you extracted the archive -- it should be named something like lucene-core-{version}.jar. You should also see a file called contrib/demo/lucene-demo-{version}.jar.

Put both of these files in your Java CLASSPATH.

Indexing Files

Once you've gotten this far you're probably itching to go. Let's build an index! Assuming you've set your CLASSPATH correctly, just type:

    java org.apache.lucene.demo.IndexFiles -docs {path-to-lucene}/src
This will produce a subdirectory called  index which will contain an index of all of the Lucene source code.

To search the index type:

    java org.apache.lucene.demo.SearchFiles
You'll be prompted for a query. Type in a swear word and press the enter key. You'll see that the Lucene developers are very well mannered and get no results. Now try entering the word "string". That should return a whole bunch of documents. The results will page at every tenth result and ask you whether you want more results.

demo运行:

首先要设置classpath

mac下设命令如下:

cd ~;

vi .bash_profile;

进行编辑,添加内容如下:

export CLASSPATH=${CLASSPATH}:/usr/local/lucene-3.6.1;/usr/local/lucene-3.6.1/contrib/demo;

编辑完成后,保存并重新启动terminal;

查看CLASSPATH是否设置echo $CLASSPATH,正确后,运行以下命令建议索引:

java org.apache.lucene.demo.IndexFiles -docs /usr/local/lucene-3.6.1
这时,lucene会为/usr/local/lucene-3.6.1下的文件建立索引。会看到一系列的adding xxx

再运行:

    java org.apache.lucene.demo.SearchFiles
要求输入查询关键字,按回车进行查询。

注:如果上面一切正常,则可运行。如果出现ClassNotFoundError的问题,则将 lucene-core-{version}.jar和contrib/demo/lucene-demo-{version}.jar两个jar包以压缩包解压方式进行解压。
PS:直观查看lucene的全文索引功能方法如下。打开changes.txt,随意输入字符串,最好保证唯一性,如你的改名,保存,重新建立索引,再进行查询时,输入你的名字,你就可以看到结果把changes.txt这个文档查出来了!这个方法是不是很直观?嘿嘿


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值