Solrインストール
アプリケーションに検索機能をつけるため、Solrを開発環境にインストールする。
ちなみに、開発環境はVagrant上で構築する。
vagrant@vagrant-debian-squeeze:~$ java -bash: java: command not found
javaないと言われるので、javaをaptitudeでインストールする。
vagrant@vagrant-debian-squeeze:~$ sudo aptitude install java-sdk "java-sdk" is a virtual package provided by: openjdk-6-jdk default-jdk gcj-4.4-jdk gcj-jdk You must choose one to install. No packages will be installed, upgraded, or removed. 0 packages upgraded, 0 newly installed, 0 to remove and 27 not upgraded. Need to get 0 B of archives. After unpacking 0 B will be used.
javaといっても、いろいろあると出てくるので、今回はdefault-jdkをインストールする。
vagrant@vagrant-debian-squeeze:~$ sudo aptitude install default-jdk The following NEW packages will be installed: # (省略) Setting up default-jdk (1:1.6-40) ... Processing triggers for menu ... vagrant@vagrant-debian-squeeze:~$ java -version java version "1.6.0_18" OpenJDK Runtime Environment (IcedTea6 1.8.13) (6b18-1.8.13-0+squeeze2) OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)
javaが入れられたことを確認できた。
2. Solrをダウンロード & インストール
Solrをインストールするために、
http://www.apache.org/dyn/closer.cgi/lucene/solr/4.2.0
の適当なミラーサイトからダウンロードする。
今回は、バージョン4.2.0。
そのあと、unzipで解凍する。
vagrant@vagrant-debian-squeeze:~$ wget http://ftp.tsukuba.wide.ad.jp/software/apache/lucene/solr/4.2.0/solr-4.2.0.zip --2013-04-04 16:30:54-- http://ftp.tsukuba.wide.ad.jp/software/apache/lucene/solr/4.2.0/solr-4.2.0.zip Resolving ftp.tsukuba.wide.ad.jp... 203.178.132.80 Connecting to ftp.tsukuba.wide.ad.jp|203.178.132.80|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 121058888 (115M) [application/zip] Saving to: “solr-4.2.0.zip” 100%[==================================================================================================================================================================>] 121,058,888 2.43M/s in 79s 2013-04-04 16:32:18 (1.46 MB/s) - “solr-4.2.0.zip” saved [121058888/121058888] vagrant@vagrant-debian-squeeze:~$ unzip solr-4.2.0.zip Archive: solr-4.2.0.zip creating: solr-4.2.0/ creating: solr-4.2.0/contrib/ # (省略)
4. Solr 管理画面起動
Solrの管理画面をstart.jarで起動する。
vagrant@vagrant-debian-squeeze:~$ cd solr-4.2.0/example/ vagrant@vagrant-debian-squeeze:~/solr-4.2.0/example$ java -jar start.jar
http://xxxxxxxx:xxxx/solr/adminを叩いて確認する。
(xxxxxxxx:xxxxはホスト名:ポート番号。)
5. データ更新
標準で付いてくるサンプルxmlをPOSTして、データ更新する。
vagrant@vagrant-debian-squeeze:~/solr-4.2.0/example$ cd exampledocs/ vagrant@vagrant-debian-squeeze:~/solr-4.2.0/example/exampledocs$ java -jar post.jar ipod_other.xml
データが入っていることを確認する。
今回は、2ドキュメント入った。
6. データ検索
ちゃんと検索できるか確認する。
ipod_other.xmlのデータを入れたから、ipodで検索する。
http://xxxxxxxx:xxxx/solr/collection1/select?q=ipod&wt=xml&indent=true
で検索する(xxxxxxxx:xxxxはホスト名:ポート番号。)