Popular Searches solve xunsearch, not in accordance with the number of scheduling problems

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');

incorrect

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

correct

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

Guess you like

Origin www.cnblogs.com/jiqing9006/p/12024070.html