Exemplo n.º 1
0
 public function testGetTops()
 {
     $text = '迅搜(xunsearch)是优秀的开源全文检索解决方案';
     $tops = $this->object->getTops($text, 4);
     $this->assertEquals(4, count($tops));
     $this->assertEquals('全文检索', $tops[0]['word']);
     $this->assertEquals('开源', $tops[1]['word']);
 }
Exemplo n.º 2
0
 /**
  * 取文本的关键词
  * limit 默认取10个
  * xattr   条件:在返回结果的词性过滤, 多个词性之间用逗号分隔, 以~开头取反 
  * 			如: 设为 n,v 表示只返回名词和动词; 设为 ~n,v 则表示返回名词和动词以外的其它词
  * return 返回词汇数组, 每个词汇是包含 [times:次数,attr:词性,word:词]
  * */
 public function xs_get_keyword()
 {
     $text = $this->input['text'];
     $limit = $this->input['limit'] ? $this->input['limit'] : 10;
     $xattr = $this->input['xattr'];
     $conf = realpath(CUR_CONF_PATH . 'data/' . 'textsearch_textsearch' . '.ini');
     if (!$conf) {
         $this->errorOutput('NO_DEFAULT.INI');
     }
     try {
         include_once CUR_CONF_PATH . 'lib/xunsearch/XS.php';
         $xs = new XS($conf);
         $xsts = new XSTokenizerScws();
         $result = $xsts->getTops($text, $limit, $xattr);
         //,100,'~n,v'
     } catch (XSException $e) {
         $this->errorOutput('error');
     }
     $this->addItem($result);
     $this->output();
 }