lucene-gosenを試してみる その1では単発でlucene-gosenを使ってみましたが、 今度はSolrに組み込んで、動かしてみようと思います。 ■ Solrのインストール ↓のダウンロードページから apache-solr-3.5.0.zip をダウンロードしてきます。 http://www.apache.org/dyn/closer.cgi/lucene/solr/ 今回はWindowsを使うのC直下に解凍しました。
C:apache-solr-3.5.0>dir C:apache-solr-3.5.0 のディレクトリ 2012/02/13 14:24 <DIR> . 2012/02/13 14:24 <DIR> .. 2011/11/22 14:55 159,619 CHANGES.txt 2012/02/13 14:23 <DIR> client 2012/02/13 14:24 <DIR> contrib 2012/02/13 14:24 <DIR> dist 2012/02/13 14:24 <DIR> docs 2012/02/13 14:25 <DIR> example 2011/11/22 14:55 81,191 LICENSE.txt 2011/11/22 14:55 17,469 NOTICE.txt 2011/11/22 14:55 5,034 README.txt
distディレクトリのwarファイルを抜き出してローカルのTomcatに~ とかやるのもメンドイなぁと思ってたら、 exampleディレクトリの中にREADME.txtがあって、中身みてみると、、
Solr example configuration -------------------------- To run this example configuration, use java -jar start.jar in this directory, and when Solr is started connect to http://localhost:8983/solr/admin/
だそうで。どうも内部的にJettyを使ってる感じみたいです、と。 さっそく立ち上げてみると、、
C:apache-solr-3.5.0example>java -jar start.jar 2012-02-13 14:30:13.948:INFO::Logging to STDERR via org.mortbay.log.StdErrLog 2012-02-13 14:30:14.026:INFO::jetty-6.1-SNAPSHOT 2012-02-13 14:30:14.085:INFO::Extract file:/C:/apache-solr-3.5.0/example/webapps/solr.war to C:apache-solr-3.5.0exampleworkJetty_0_0_0_0_8983_solr.war__s f17webapp 2 13, 2012 2:30:15 午後 org.apache.solr.core.SolrResourceLoader locateSolrHome ~略~ 情報: SolrUpdateServlet.init() done 2012-02-13 14:30:17.184:INFO::Started SocketConnector@0.0.0.0:8983
なんか上がったみたいです。 8983ポートの/solrにブラウザからアクセスしてみると↓見おぼえのある… ■ lucene-gosenをSolrに突っ込む ってことでさっそくlucene-gosenをSolrに突っ込んでみますよ、と。 今後辞書を自分で追加してホゲホゲみたいな感じにしたいので、 Solr/Lucene本で有名(ってかlucene-gosenの開発者)な関口さんの↓のブログを参考に。 lucene-gosen + Solr 3.1 | 関口宏司のLuceneブログ 今回はWindowsなのでTortoiseSVNを使ってチェックアウトしてきます。 Apache Antのzipファイルをhttp://ant.apache.org/bindownload.cgiからダウンロードしてきて、 先ほどのチェックアウトしてきたディレクトリに解凍します。 で、さっそくビルドしてみます。
C:lucene-gosen>apache-ant-1.8.2binant Buildfile: C:lucene-gosenbuild.xml prepare-directories: ~略~ BUILD FAILED C:lucene-gosenbuild.xml:170: The following error occurred while executing this line: C:lucene-gosendictionarybuild.xml:56: More than 25 times redirected, giving up
失敗してますがな。。 例のごとくプロキシサーバーが邪魔してるみたいです。
C:lucene-gosen>set http_proxy=http://hogehoge.~
コレやっても失敗します。AntはJavaのツールなので、Javaにプロキシを教えてあげなきゃいけません。 AntっていうかJavaは-Dオプションでプロキシサーバとプロキシポートを指定する感じなので、 ↓のようにして叩いてやります。
C:lucene-gosen>apache-ant-1.8.2binant -Dproxy.host=proxy.hogehoge.co.jp -Dproxy.port=9999
それでも落ちますがな、と。
download: [get] Getting: http://chasen.aist-nara.ac.jp/stable/ipadic/ipadic-2.6.0.tar.gz [get] To: C:lucene-gosendictionaryipadicipadic-2.6.0.tar.gz [get] Error opening connection java.io.FileNotFoundException: http://chasen.aist-nara.ac.jp/stable/ipadic/ipadic-2.6.0.tar.gz [get] Error opening connection java.io.FileNotFoundException: http://chasen.aist-nara.ac.jp/stable/ipadic/ipadic-2.6.0.tar.gz [get] Error opening connection java.io.FileNotFoundException: http://chasen.aist-nara.ac.jp/stable/ipadic/ipadic-2.6.0.tar.gz [get] Can't get http://chasen.aist-nara.ac.jp/stable/ipadic/ipadic-2.6.0.tar.gz to C:lucene-gosendictionaryipadicipadic-2.6.0.tar.gz BUILD FAILED
普通にブラウザからアクセスしても
Not Found The requested URL /stable/ipadic/ipadic-2.6.0.tar.gz was not found on this server. Apache Server at chasen.aist-nara.ac.jp Port 80
って言われるよねぇと。。 build.xmlを追っていくと、こいつを取ってくるところは dictionaryってディレクトリのipadic.propertiesの中の↓は
dic.home=http://chasen.aist-nara.ac.jp/stable/ipadic
chasen.naist.jpが正しいURLみたいなので↓に書き換えてやります。
dic.home=http://chasen.naist.jp/stable/ipadic
↓のように、ようやくビルド出来ましたがなっていう。
~略~ compile: [mkdir] Created dir: C:lucene-gosensrccompiled-dictionariesipadicnetjavasen [copy] Copying 6 files to C:lucene-gosensrccompiled-dictionariesipadicnetjavasen jar: [jar] Building jar: C:lucene-gosendistlucene-gosen-1.3-dev-ipadic.jar BUILD SUCCESSFUL
↓distの中にこんな感じで出来てます。
C:lucene-gosendist>dir 2012/02/14 11:30 <DIR> . 2012/02/14 11:30 <DIR> .. 2012/02/14 11:30 8,298,744 lucene-gosen-1.3-dev-ipadic.jar
出来たjarファイルを↓のようにSolrをインストールしたディレクトリの exampleのsolrのlibに突っ込んでやります。 でもって↓のようにschema.xmlを書き換えると、、、 ↓こんな風に狙った感じで解析できました。 が、例えば、"コボちゃん"だと↓こんな風になってしまいます。
Index Analyzer org.apache.solr.analysis.JapaneseTokenizerFactory {luceneMatchVersion=LUCENE_35} position 1 2 term text コボ ちゃん startOffset 0 2 endOffset 2 5 basicForm * * conjugationalForm * conjugationalForm (en) * conjugationalType * conjugationalType (en) * partOfSpeech 未知語 名詞-接尾-人名 partOfSpeech (en) unknown noun-suffix-person pronunciations [] [チャン] pronunciations (en) [] [chan] readings [] [チャン] readings (en) [] [chan] sentenceStart true false cost 31059 4111
"コボ"と"ちゃん"じゃなくて、"コボちゃん"です。 ってことで単語を追加してやる感じです。 lucene-gosenの辞書編集方法 | エメラルドアオキロック を参考にさせていただいてやってみます。 checkoutしてきたlucene-gosenのdictionaryディレクトリに oreore.csvってのを作って↓のようなのを入れてやります。 #エンコーディングはUTF-8で改行コードはLFにしてやります。
"コボちゃん",3000,名詞,固有名詞,人名,名,*,*,"コボちゃん","コボチャン","コボチャン"
辞書を一回消して、追加の辞書を指定して作り直してから、
C:lucene-gosendictionary>C:lucene-gosenapache-ant-1.8.2binant clean-sen C:lucene-gosendictionary>ant -Dcustom.dics=oreore.csv
もっかいjarを作って、Solrのexampleのlibの中に置いてSolrサーバを再起動します。 ↓のように狙ったキーワードでやりくりできました。 次はSinatraでWeb画面作って、上記の単語を追加して、再ビルド的なのをボタン押下で 出来るようにしてみようかなー。 って、アナライザ動かしただけで、インデクシングも検索もしてないじゃんね。汗 ってことで、次回に続く。。