Пример #1
0
 /**
  * @param \Mirasvit\Search\Model\Index $index
  * @param string                       $indexName
  * @param array                        $documents
  * @return void
  */
 public function saveDocuments($index, $indexName, array $documents)
 {
     foreach ($documents as $id => $document) {
         $this->getQuery()->delete()->from($indexName)->where('id', '=', $id)->execute();
         $query = $this->getQuery()->insert()->into($indexName)->value('id', $id);
         $doc = [];
         foreach ($document as $attr => $value) {
             if (is_int($attr)) {
                 $attr = $index->getIndexInstance()->getAttributeCode($attr);
             }
             if (isset($this->availableAttributes[$indexName]) && !in_array($attr, $this->availableAttributes[$indexName])) {
                 $attr = 'options';
             }
             if (isset($doc[$attr])) {
                 $doc[$attr] .= ' ' . $value;
             } else {
                 $doc[$attr] = $value;
             }
         }
         foreach ($doc as $attr => $value) {
             $query->value($attr, $value);
         }
         try {
             $query->execute();
         } catch (\Exception $e) {
         }
     }
 }