2013年2月1日金曜日

luceneを動かしてみる

まずはここからtar ballをダウンロード で、
 tar zxvf ~/Downloads/lucene-4.1.0-src.tgz   
 cd lucene-4.1.0
ビルドにivyが必要なのでインストールされていなければ
ant ivy-bootstrap
ant
あっさりビルドできた。便利な世の中になったものだ。

とりあえず、demoをビルド

cd demo
ant
これで、lucene_home/build 以下に色々作られる。できたjarをCLASSPATHに登録する。 lucene_homeで
CLASSPATH=. ; for jar in `find . -name '*.jar'` ; do CLASSPATH=$CLASSPATH:$jar ; done 
export CLASSPATH

さて、indexingしてみる。

java org.apache.lucene.demo.IndexFiles -docs . 
これでindexというディレクトリが作られて、そこにいろんなファイルができるようだ。 で、サーチしてみる。
> java org.apache.lucene.demo.SearchFiles                                                                    [~/test/lucene-4.1.0]
Enter query: 
testing
Searching for: testing
162 total matching documents
1. ./analysis/icu/src/test/org/apache/lucene/analysis/icu/segmentation/TestCharArrayIterator.java
2. ./test-framework/src/java/org/apache/lucene/analysis/package.html
3. ./analysis/common/src/test/org/apache/lucene/analysis/util/TestCharArrayIterator.java
4. ./test-framework/src/java/org/apache/lucene/search/package.html
5. ./test-framework/src/java/org/apache/lucene/util/automaton/package.html
6. ./analysis/common/src/test/org/apache/lucene/analysis/compound/compoundDictionary.txt
7. ./analysis/common/src/test/org/apache/lucene/analysis/compound/da_compoundDictionary.txt
おお。うごいた。とりあえず。

0 件のコメント: