PHP から検索するときは使った方がいい Solr のオプション


PHP から Solr の検索をするときは solrconfig.xml に下のオプションを追加すると検索結果を受け取った後の処理がとても楽になります。

# <queryResponseWriter name="xslt" ... の下あたりに追記する

  <!-- for PHP -->
  <queryResponseWriter name="php" class="org.apache.solr.request.PHPResponseWrit
er"/>
  <queryResponseWriter name="phps" class="org.apache.solr.request.PHPSerializedR
esponseWriter"/>

追記したら Tomcat等のサーブレットコンテナを再起動します。


こんな感じで検索できるようになります。
PHP の場合

$code = file_get_contents('http://localhost:8983/solr/select?q=iPod&wt=php');
eval("\$result = " . $code . ";");
print_r($result);


PHPシリアライズを使う場合

$serializedResult = file_get_contents('http://localhost:8983/solr/select?q=iPod&wt=phps');
$result = unserialize($serializedResult);
print_r($result);


参考ページ
SolPHP