前提
Solrのホームディレクトリは以下とする。
solr-7.6.0
coreの名前とディレクトリは以下とする。
solr-7.6.0/server/solr/core_nlp/conf
JARの設定
JARは標準のインストールで用意されているのでコピーして使う。
コピー元(contrib/analysis-extras)
solr-7.6.0/contrib/analysis-extras/lib/opennlp-tools-1.9.0.jar
solr-7.6.0/contrib/analysis-extras/lucene-libs/lucene-analyzers-opennlp-7.6.0.jar
コピー先(dist)
*後でわかりやすいように「opennlp」というフォルダにする。
solr-7.6.0/dist/opennlp/lucene-analyzers-opennlp-7.6.0.jar
solr-7.6.0/dist/opennlp/opennlp-tools-1.9.0.jar
*注意
JARのクラスパスを通すのに「solr-7.6.0/server/lib」や「solr-7.6.0/server/lib/ext」でもよさそうに見えるが、これはアウト。
Coreのクラスパス設定
solrconfig.xml を編集することで core 単位でクラスパスを通す
solr-7.6.0/server/solr/core_nlp/conf/solrconfig.xml
<lib dir="${solr.install.dir:../../../..}/dist/opennlp" regex=".*\.jar" />
Modelのダウンロード
JARは同梱されているが、Modelはダウンロードが必要。
http://opennlp.sourceforge.net/models-1.5/
Modelダウンロード元
en-chunker.bin
en-pos-maxent.bin
en-sent.bin
en-token.bin
Modelダウンロード先
core のフォルダにダウンロードする。後でわかりやすいように「opennlp」のディレクトリを作成する
solr-7.6.0/server/solr/core_nlp/conf/opennlp/en-chunker.bin
solr-7.6.0/server/solr/core_nlp/conf/opennlp/en-pos-maxent.bin
solr-7.6.0/server/solr/core_nlp/conf/opennlp/en-sent.bin
solr-7.6.0/server/solr/core_nlp/conf/opennlp/en-token.bin
CoreのSchema設定
やり方は本家サイトにも書いてある。
https://lucene.apache.org/solr/guide/7_4/language-analysis.html#opennlp-integration
(が、ちゃんと読まない人がこの記事を読むのでしょうね。私も含め。)
以下の設定ファイル(managed-schema)(中身はXML)を編集する。
Modelファイル名の指定は絶対パスでも相対パスでも可能とのこと。
ここでは「solr-7.6.0/server/solr/core_nlp/conf」からの相対パスになる。
solr-7.6.0/server/solr/core_nlp/conf/managed-schema
<fieldType name="text_opennlp" class="solr.TextField" positionIncrementGap="100" multiValued="true" >
<analyzer>
<tokenizer class="solr.OpenNLPTokenizerFactory"
sentenceModel="opennlp/en-sent.bin"
tokenizerModel="opennlp/en-token.bin"/>
<filter class="solr.OpenNLPPOSFilterFactory" posTaggerModel="opennlp/en-pos-maxent.bin"/>
<filter class="solr.OpenNLPChunkerFilterFactory" chunkerModel="opennlp/en-chunker.bin"/>
<filter class="solr.TypeAsPayloadFilterFactory"/>
</analyzer>
</fieldType>
Solr の再起動
solr-7.6.0>bin\solr stop -all
Stopping Solr process 11004 running on port 8983
4 秒待っています。続行するには何かキーを押してください ...
solr-7.6.0>bin\solr start
INFO - 2018-12-26 12:03:15.477; org.apache.solr.util.configuration.SSLCredentialProviderFactory; Processing SSL Credential Provider chain: env;sysprop
Waiting up to 30 to see Solr running on port 8983
Started Solr server on port 8983. Happy searching!
以上。