LoginSignup
3
4

More than 3 years have passed since last update.

Apache Solr インストール〜起動まで(MAC)

Last updated at Posted at 2020-01-24

solr.png

Solrとは

Apacheが提供しているオープンソースの全文検索エンジン

クックパッドなど大規模なサービスに利用されていて、とにかく速いことが特徴

目次

1.Javaのインストール
2.Solrの起動
3.データの投入
4.検索
5.リセット
6.Javaのインストール

Solrの起動にはJavaが必要。入っていない場合はHomebrewを使ってインストールしましょう。

インストールの前にHomebrewを更新

$ brew update

javaのインストール

$ brew cask install java

バージョンを確認してインストール場所のパスを確認

$ /usr/libexec/java_home -V

インストール場所を.bash_profileにコピペして追記し、パスを通す
※パスは$ /usr/libexec/java_home -Vで確認したものに書き換えを

.bash_profile
export PATH=$PATH:/Library/Java/JavaVirtualMachines/openjdk-12.0.2.jdk/Contents/Home`
`export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-12.0.2.jdk/Contents/Home

※.bash_profileがなければルートディレクトリに作成

追記した内容が反映されるようbash_profileを更新

$ source ~/.bash_profile

下記コマンドで記述したパスが表示されればOK

$ echo $PATH`
$ echo $JAVA_HOME`

ミラーサイトからsolr-7.7.2.zip をダウンロード

解凍したsolr-7.7.2ディレクトリに$ cdで移動
場所はどこでも大丈夫

Solrの起動

起動コマンドを入力

$ ./bin/solr start -e cloud

起動オプションを入力

起動するノード数

This interactive session will help you launch a SolrCloud cluster on your local workstation.

To begin, how many Solr nodes would you like to run in your local cluster? (specify 1-4 nodes) [2]:

デフォルトの2つでOKなのでEnter

1つ目のノードのポート番号

Ok, let's start up 2 Solr nodes for your example SolrCloud cluster.

Please enter the port for node1 [8983]:

こちらもデフォルトでOKなのでEnter

2つ目のノードのポート番号

Please enter the port for node2 [7574]:

こちらもEnter

コレクション名

Please provide a name for your new collection: [gettingstarted]

コレクション名は下記で

echproducts

インデックスの分割数

How many shards would you like to split techproducts into? [2]

デフォルトでOKなのでEnter

レプリカの数

*How many replicas per shard would you like to create? [2] *

こちらもEnter

configset

Please choose a configuration for the techproducts collection, available options are:

_default or sample_techproducts_configs [_default]

促されているように下記でセット

sample_techproducts_configs

すると

Created collection 'techproducts' with 2 shard(s), 2 replica(s) with config-set 'techproducts'
Enabling auto soft-commits with maxTime 3 secs using the Config API
POSTing request to Config API: http://localhost:8983/solr/techproducts/config
{"set-property":{"updateHandler.autoSoftCommit.maxTime":"3000"}}
Successfully set-property updateHandler.autoSoftCommit.maxTime to 3000
SolrCloud example running, please visit: http://localhost:8983/solr

↑で言われたとおりhttp://localhost:8983/solr にアクセスします

Apache Solrの画面が表示されていれば起動できています

データの投入

解凍したsolr-7.7.2の中のexampleディレクトリの中にあらかじめsolrが用意したサンプルファイルがあるので、今回はとりあえずそれを投入

$ bin/post -c techproducts example/exampledocs/*

検索

$ curl "http://localhost:8983/solr/techproducts/select?q=book&wt=xml&indent=true"


q=検索したいワード
wt=出力するファイル形式
indent=インデントをつけるかどうか
をそれぞれ入れると・・

···

検索結果がxml形式で出力される!

···

停止

$ bin/solr stop -all

リセット

ノードを削除し最初の状態に戻します

$ bin/solr stop -all ; rm -Rf example/cloud/
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4