/** * Custom load model: Get data by user query phrase * * @param \Magento\Search\Model\SynonymReader $object * @param string $phrase * @return $this */ public function loadByPhrase(\Magento\Search\Model\SynonymReader $object, $phrase) { $rows = $this->queryByPhrase(strtolower($phrase)); $synsPerScope = $this->getSynRowsPerScope($rows); if (!empty($synsPerScope[\Magento\Store\Model\ScopeInterface::SCOPE_STORES])) { $object->setData($synsPerScope[\Magento\Store\Model\ScopeInterface::SCOPE_STORES]); } elseif (!empty($synsPerScope[\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES])) { $object->setData($synsPerScope[\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES]); } else { $object->setData($synsPerScope[\Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT]); } $this->_afterLoad($object); return $this; }
/** * Custom load model: Get data by user query phrase and store view id * * @param SynReaderModel $object * @param string $value * @return $this */ public function loadByPhrase(SynReaderModel $object, $value) { $phrase = strtolower($value); $matchQuery = $this->fullTextSelect->getMatchQuery(['synonyms' => 'synonyms'], $phrase, Fulltext::FULLTEXT_MODE_BOOLEAN); $query = $this->getConnection()->select()->from($this->getMainTable())->where('store_id = ?', $object->getStoreViewId())->where($matchQuery); $rows = $this->getConnection()->fetchAll($query); $object->setData($rows); $this->_afterLoad($object); return $this; }