public function testLogger()
 {
     $log = XSFieldScheme::logger();
     $this->assertInstanceOf('XSFieldScheme', $log);
     $this->assertEquals('id', strval($log->getFieldId()));
     $this->assertFalse($log->getFieldTitle());
     $this->assertNotEquals(false, $log->getField('pinyin', false));
     $this->assertNotEquals(false, $log->getField('partial', false));
     $this->assertTrue($log->getField('total')->isNumeric());
     $this->assertTrue($log->getField('lastnum')->isNumeric());
     $this->assertTrue($log->getField('currnum')->isNumeric());
     $this->assertFalse($log->getField('currtag')->isNumeric());
     $this->assertTrue($log->getField('body')->isSpeical());
     $this->assertEquals(XSFieldScheme::MIXED_VNO, $log->getFieldBody()->vno);
 }
Exemple #2
0
    -h|--help           显示帮助信息

EOF;
    exit(0);
}
// create xs project
$ini = XSUtil::toProjectIni($project);
if (!file_exists($ini)) {
    echo "错误:无效的项目名称 ({$project}),不存在相应的配置文件。\n";
    exit(-1);
}
try {
    $db = XSSearch::LOG_DB;
    $log_ready = false;
    $xs = new XS($ini);
    $xs->setScheme(XSFieldScheme::logger());
    $search = $xs->search;
    try {
        // NOTE: use setQuery to call preQueryString for preparing fieldset
        $search->setDb($db)->setQuery('dummy');
        $search->setTimeout(0);
        // sometimes user may import lots of terms
        $log_ready = true;
    } catch (Exception $e) {
    }
    // hot, query ==> read-only
    if ($hot !== null) {
        $limit = $limit === null ? 10 : intval($limit);
        $type = $hot === 'cur' ? 'currnum' : ($hot === 'last' ? 'lastnum' : 'total');
        $result = $search->getHotQuery($limit, $type);
        if (count($result) === 0) {
Exemple #3
0
 /**
  * 获取相关搜索词列表
  * @param string $query 搜索语句, 若传入 null 使用默认语句
  * @param int $limit 需要返回的相关搜索数量上限, 默认为 6, 最大值为 20
  * @return array 返回搜索词组成的数组
  */
 public function getRelatedQuery($query = null, $limit = 6)
 {
     $ret = array();
     $limit = max(1, min(20, intval($limit)));
     // Simple to disable query with field filter
     if ($query === null) {
         $query = $this->cleanFieldQuery($this->_query);
     }
     if (empty($query) || strpos($query, ':') !== false) {
         return $ret;
     }
     // Search the log database
     $op = $this->_defaultOp;
     $this->xs->setScheme(XSFieldScheme::logger());
     try {
         $result = $this->setDb(self::LOG_DB)->setFuzzy()->setLimit($limit + 1)->search($query);
         foreach ($result as $doc) {
             $doc->setCharset($this->_charset);
             $body = $doc->body;
             if (!strcasecmp($body, $query)) {
                 continue;
             }
             $ret[] = $body;
             if (count($ret) == $limit) {
                 break;
             }
         }
     } catch (XSException $e) {
         if ($e->getCode() != CMD_ERR_XAPIAN) {
             throw $e;
         }
     }
     $this->restoreDb();
     $this->xs->restoreScheme();
     $this->_defaultOp = $op;
     return $ret;
 }
Exemple #4
0
 public function testAddSearchLog()
 {
     $search = self::$xs->search;
     $search->addSearchLog('php 教程');
     $search->addSearchLog('php 教学');
     $search->addSearchLog('php 教导', 999);
     $search->addSearchLog('php 教程');
     self::$xs->index->reopen(true)->flushLogging();
     sleep(2);
     self::$xs->setScheme(XSFieldScheme::logger());
     $search->reopen(true);
     $docs = $search->setDb(XSSearch::LOG_DB)->search('php');
     $search->setDb(null);
     self::$xs->restoreScheme();
     $this->assertEquals($docs[0]->total, 999);
     $this->assertEquals($docs[1]->total, 2);
     $this->assertEquals($docs[2]->total, 1);
 }