_select) { $this->_select = $this->_db->select(); $this->_select->union([ $this->_getCategoryList4Select(), $this->_getPostList4Select(), ]); $this->_applySelectOptions($this->_select, $this->_selectOptions); $this->_select->order(['type', 'title']); } return $this->_select; } /** * @param \Zend_Db_Select $select * @param string $tableAlias * @param array $filterFields * @return Obj */ protected function _unionFilter(\Zend_Db_Select $select, $tableAlias, array $filterFields) { if (!$this->hasFilter()) { return $this; } if (!empty($filterFields) && array_key_exists('query', $this->_filter)) { \Qs_Db_Filter::where($select, [$tableAlias => $filterFields], $this->_filter['query']); } $filter = $this->_getCleanedFilter($this->_filter); \Qs_Db::filter($select, $filter, $this->_tableShortAlias ?: $this->_tableAlias); return $this; } /** * @return \Zend_Db_Select */ protected function _getCategoryList4Select() { $select = $this->_db->select(); $columns = [ 'type' => new \Zend_Db_Expr('"' . static::TYPE_CATEGORY . '"'), 'categoryId' => 'id', 'id', 'alias', 'title', 'excerpt' => new \Zend_Db_Expr('""'), 'rawContent' => new \Zend_Db_Expr('""'), ]; $select->from($this->_getPair($this->_tableAliasCategory), $columns); $select->where('`' . $this->_tableAliasCategory . '`.`enabled` = "y"'); $select->where('EXISTS (' . $this->_getHasPostSelect() . ')'); $this->_unionFilter($select, $this->_tableAliasCategory, $this->_categoryFilterFields); return $select; } /** * @return \Zend_Db_Select; */ protected function _getHasPostSelect() { $select = $this->_db->select(); $select->from($this->_getPair($this->_tableAlias), new \Zend_Db_Expr('1')); $select->where('`' . $this->_tableAlias . '`.`categoryId` = `' . $this->_tableAliasCategory . '`.`id`'); $select->where('`' . $this->_tableAlias . '`.`enabled` = "y"'); $select->limit(1); return $select; } /** * @return \Zend_Db_Select */ protected function _getPostList4Select() { $select = $this->_db->select(); $columns = [ 'type' => new \Zend_Db_Expr('"' . static::TYPE_POST . '"'), 'categoryId', 'id', 'alias', 'title', 'excerpt', 'rawContent', ]; $select->from($this->_getPair($this->_tableAlias), $columns); $select->join( $this->_getPair($this->_tableAliasCategory), '`' . $this->_tableAlias . '`.`categoryId` = `' . $this->_tableAliasCategory . '`.`id`', [] ); $select->where('`' . $this->_tableAlias . '`.`enabled` = "y"'); $select->where('`' . $this->_tableAliasCategory . '`.`enabled` = "y"'); $this->_unionFilter($select, $this->_tableAlias, $this->_filterFields); return $select; } /** * @return string * @throws \Qs_Exception */ protected function _getSitemapUlr() { if (null === $this->_sitemapUrl) { $this->_sitemapUrl = \Qs_SiteMap::findFirst(null, ['type' => 'Blog\\'], null, 'url'); if (!$this->_sitemapUrl) { throw new \Qs_Exception('Can not determine Blog URL'); } } return $this->_sitemapUrl; } /** * @param array $list items list * @param array $providerOptions provider options from site/App/Search/config.php * @return Obj */ protected function _prepareSearchList(array &$list, array $providerOptions) { $this->_prepareList($list); if (!empty($list)) { foreach ($list as &$row) { $row['title'] = \Qs_Text_Mark::markSearchWords($row['title'], $this->getFilter('query')); if (static::TYPE_POST == $row['type']) { $content = $row['excerpt'] . ' ' . $row['rawContent']; $content = trim($content); $row['content'] = \Qs_Text_Mark::markSearchWords($content, $this->getFilter('query')); $row['searchUrl'] = $this->_getSitemapUlr() . '/' . $row['alias']; } else { /* TYPE_CATEGORY */ $row['searchUrl'] = $this->_getSitemapUlr() . '/category/' . $row['alias']; } } } return $this; } }