/** * Index url * * @param \Mirasvit\Search\Model\Index $index * * @return string */ public function getIndexUrl($index) { $query = ['index' => $index->getId(), 'p' => null]; if ($index->hasData('store_id') && $index->getData('store_id') != $this->getCurrentStore()->getId()) { return $this->getUrl('stores/store/switch', ['_query' => ['___store' => $index->getData('store_code')]]); } $params = ['_current' => true, '_query' => $query]; if ($index->hasData('store_id')) { $params['_scope'] = $index->getData('store_id'); } return $this->getUrl('*/*/*', $params); }
/** * Search collection for index * * @param \Mirasvit\Search\Model\Index $index * @return array */ public function getCollection($index) { $index->getSearchCollection()->setPageSize((int) $this->config->getIndexOptionValue($index->getData('code'), 'limit')); return $index->getSearchCollection(); }
/** * @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) { } } }