FeedModel::searchFeed PHP Method

searchFeed() public method

搜索分享
public searchFeed ( string $key, string $type, integer $loadId, integer $limit, boolean $forApi = false, $feed_type ) : array
$key string 关键字
$type string 搜索类型,following、all、space
$loadId integer 载入分享ID,从此分享ID开始搜索
$limit integer 结果集数目
$forApi boolean 是否返回API数据,默认为false
return array 搜索后的分享数据
    public function searchFeed($key, $type, $loadId, $limit, $forApi = false, $feed_type)
    {
        $page = intval($_REQUEST['p']);
        switch ($type) {
            case 'following':
                $buid = $GLOBALS['ts']['uid'];
                $table = "{$this->tablePrefix}feed AS a LEFT JOIN {$this->tablePrefix}user_follow AS b ON a.uid=b.fid AND b.uid = {$buid} LEFT JOIN {$this->tablePrefix}feed_data AS c ON a.feed_id = c.feed_id";
                $where = !empty($loadId) ? " a.is_del = 0 AND a.is_audit = 1 AND a.feed_id <'{$loadId}'" : 'a.is_del = 0 AND a.is_audit = 1';
                $where .= " AND (a.uid = '{$buid}' OR b.uid = '{$buid}' )";
                $where .= " AND c.feed_data LIKE '%" . t($key) . "%'";
                $feedlist = $this->table($table)->where($where)->field('a.feed_id')->order('a.publish_time DESC')->findPage($limit);
                break;
            case 'union':
                $buid = $GLOBALS['ts']['uid'];
                $table = "{$this->tablePrefix}feed AS a \n\t\t\t\tLEFT JOIN {$this->tablePrefix}feed_data AS c ON a.feed_id = c.feed_id";
                $where = !empty($loadId) ? " a.is_del = 0 AND a.is_audit = 1 AND a.feed_id <'{$loadId}'" : 'a.is_del = 0 AND a.is_audit = 1';
                $where .= " AND c.feed_data LIKE '%" . t($key) . "%'";
                $where .= " and (a.uid in (SELECT fid from ts_user_union WHERE uid={$buid}) \n\t\tor a.uid in (SELECT u.fid from ts_user_union u LEFT JOIN ts_user_follow f ON u.uid=f.fid WHERE f.uid={$buid} )) ";
                $feedlist = $this->table($table)->where($where)->field('a.feed_id')->order('a.publish_time DESC')->findPage($limit);
                break;
            case 'all':
                $map['a.is_del'] = 0;
                $map['a.is_audit'] = 1;
                !empty($loadId) && ($map['a.feed_id'] = array('LT', intval($loadId)));
                $map['b.feed_content'] = array('LIKE', '%' . t($key) . '%');
                if ($feed_type) {
                    $map['a.type'] = $feed_type;
                    if ($map['a.type'] == 'post') {
                        unset($map['a.type']);
                        $map['a.is_repost'] = 0;
                    }
                }
                $table = "{$this->tablePrefix}feed AS a LEFT JOIN {$this->tablePrefix}feed_data AS b ON a.feed_id = b.feed_id";
                $feedlist = $this->table($table)->field('a.feed_id')->where($map)->order('a.publish_time DESC')->findPage($limit);
                $feedcount = $this->table($table)->field('a.feed_id')->where($map)->order('a.publish_time DESC')->count();
                break;
            case 'space':
                $map['a.is_del'] = 0;
                $map['a.is_audit'] = 1;
                !empty($loadId) && ($map['a.feed_id'] = array('LT', intval($loadId)));
                $map['b.feed_content'] = array('LIKE', '%' . t($key) . '%');
                if ($feed_type) {
                    $map['a.type'] = $feed_type;
                    if ($map['a.type'] == 'post') {
                        unset($map['a.type']);
                        $map['a.is_repost'] = 0;
                    }
                }
                $map['a.uid'] = $GLOBALS['ts']['uid'];
                $table = " {$this->tablePrefix}feed AS a LEFT JOIN {$this->tablePrefix}feed_data AS b ON a.feed_id = b.feed_id";
                $feedlist = $this->table($table)->field('a.feed_id')->where($map)->order('a.publish_time DESC')->findPage($limit);
                break;
            case 'topic':
                $map['a.is_del'] = 0;
                $map['a.is_audit'] = 1;
                !empty($loadId) && ($map['a.feed_id'] = array('LT', intval($loadId)));
                $map['b.feed_content'] = array('LIKE', '%#' . t($key) . '#%');
                if ($feed_type) {
                    $map['a.type'] = $feed_type;
                    if ($map['a.type'] == 'post') {
                        unset($map['a.type']);
                        $map['a.is_repost'] = 0;
                    }
                }
                $table = "{$this->tablePrefix}feed AS a LEFT JOIN {$this->tablePrefix}feed_data AS b ON a.feed_id = b.feed_id";
                $feedlist = $this->table($table)->field('a.feed_id')->where($map)->order('a.publish_time DESC')->findPage($limit);
                break;
        }
        $feed_ids = getSubByKey($feedlist['data'], 'feed_id');
        if ($forApi) {
            if ($feedlist['totalPages'] < $page) {
                return array();
            }
            return $this->formatFeed($feed_ids, true);
        }
        $feedlist['data'] = $this->getFeeds($feed_ids);
        return $feedlist;
    }