码迷,mamicode.com
首页 > 编程语言 > 详细

解决xunsearch热门搜索,不按照数量排序问题

时间:2019-12-11 19:21:05      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:成功   exce   rest   操作   desc   throw   sort   array   getc   

public function getHotQuery($limit = 6, $type = 'total')
{
    $ret = array();
    $limit = max(1, min(50, intval($limit)));
    $this->xs->setScheme(XSFieldScheme::logger());
    try {
        $this->setDb(self::LOG_DB)->setLimit($limit);
        if ($type !== 'lastnum' && $type !== 'currnum') {
            $type = 'total';
        }
        // 加上下面这一句就OK了
        $this->setSort('total');
        $result = $this->search($type . ':1');
        foreach ($result as $doc) /* @var $doc XSDocument */ {
            $body = $doc->body;
            $ret[$body] = $doc->f($type);
        }
        $this->restoreDb();
    } catch (XSException $e) {
        if ($e->getCode() != XS_CMD_ERR_XAPIAN) {
            throw $e;
        }
    }
    $this->xs->restoreScheme();
    return $ret;
}
$this->setSort('total');

不正确的

{
    "errno": 0,
    "errdesc": "操作成功",
    "timestamp": 1576057980,
    "data": {
        "项目测试": "2",
        "俗话说": "1",
        "测试": "12",
        "项目": "1"
    }
}

正确的

{
    "errno": 0,
    "errdesc": "操作成功",
    "timestamp": 1576057928,
    "data": {
        "测试": "12",
        "项目测试": "2",
        "俗话说": "1",
        "项目": "1"
    }
}

解决xunsearch热门搜索,不按照数量排序问题

标签:成功   exce   rest   操作   desc   throw   sort   array   getc   

原文地址:https://www.cnblogs.com/jiqing9006/p/12024070.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!