LoginSignup
0
0

More than 5 years have passed since last update.

SolrのmultiValuedなFieldにPHPから値をいれる

Last updated at Posted at 2015-09-07

PHPからsolrのmultiValuedなFieldに値を追加する方法です。

solr schema.xmlの設定の一部はこんな感じ。

schema.xml
...
<field name="multi_no" type="int" indexed="true" multiValued="true"/>
...

当初は↓のように、

$multiNos = array();
$multiModels = $this->getMultiModel($id);
foreach ($multiModels as $multiModel) {
    $multiNos[] = $multiModel->multi_no;
}

$doc = new SolrInputDocument();
$doc->addField('multi_no', $multiNos);

単にarrayを突っ込めばいけるのかと思ってました。
しかしそれではダメで、

$multiNos = array();
$multiModels = $this->getMultiModel($id);
foreach ($multiModels as $multiModel) {
    $multiNos[] = $multiModel->multi_no;
}

$doc = new SolrInputDocument();
foreach ($multiNos as $multiNo) {
    $doc->addField('multi_no', $multiNo);
}

↑のようにforeachで回すんですね。
知らんかった。

0
0
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
0
0