cloud datastoreを使う前にSolrのおさらいをするためにMySQLとSolrを立てる(今回はSolr)

それでは、同様のことをSolrでしてみます。

Solrですが、たぶん、create table 的なことである、add core とかが あまりなじみがなさそうなので、順番に書きます。

コアの作成

cd solr-4.9.0/example/solr
cp -pR collection1 products
cp -pR collection1 brands
cp -pR collection1 blocks
cp -pR collection1 wblocks

先ほど、Solrを起動させたので起動状態を表すファイルの削除

rm products/core.properties
rm brands/core.properties
rm blocks/core.properties
rm wblocks/core.properties

コアを有効にする

curl "http://localhost:8983/solr/admin/cores?action=CREATE&name=products&instanceDir=products"
curl "http://localhost:8983/solr/admin/cores?action=CREATE&name=brands&instanceDir=brands"
curl "http://localhost:8983/solr/admin/cores?action=CREATE&name=blocks&instanceDir=blocks"
curl "http://localhost:8983/solr/admin/cores?action=CREATE&name=wblocks&instanceDir=wblocks"

ここから、gistを貼付けていこうを思いましたが、コマンド書いたりすると、(このブログが)長くなるのでxmlを落として Solrの管理画面 の Documents から更新してください。

apt-get install git
git clone https://gist.github.com/yuhiwa/d4731586c1cef2716945
git clone https://gist.github.com/yuhiwa/7e1efdbc094cda199a5f
git clone https://gist.github.com/yuhiwa/98ddfa45e1de36e1db57
git clone https://gist.github.com/yuhiwa/4da8e124925008a90eea

(nested_blocks.xml は wblocksコアです、まぎらしくなってしまった)

(あ、brands_data.xml は brands コアです、そのうち直さなきゃ)

join

wget -q 'http://localhost:8983/solr/brands/select?q=*:*&fq={!join from=brand_id_s to=id fromIndex=products}name:iPad' -O - | head

block join

wget -q 'http://localhost:8983/solr/blocks/select?q=*:*&fq={!parent which=type_s:parent}+name:iPhone' -O - | head

wblock join

wget -q 'http://localhost:8983/solr/wblocks/select?q=*:*&fq={!parent which=type_s:parent}+name:iPhone' -O - | head
wget -q 'http://localhost:8983/solr/wblocks/select?q=*:*&fq={!parent which=type_s:grand_parent}+name:iPhone' -O - | head

curlコマンドだと、{}が展開されてしまうので、wget コマンドで書いてます。 Solrの管理画面のfqにfq=の先を入れてしまうのが見やすいです。

解説で次回です。