/**
  *
  * @access public
  * @return void
  * @author majiechao
  *         @修改日期 2015-09-15 16:18:11
  */
 public function wordAction()
 {
     $text = $this->request->get('text', 'string', '');
     if (empty($text)) {
         exit('[]');
     }
     $mss = mss_create("confilter_main", -1);
     $timestamp = mss_timestamp($mss);
     $is_ready = mss_is_ready($mss);
     if ($is_ready) {
         // 如果redis dict最后更新时间大于mss实例创建时间,就重载
         $updateTime = $this->di['confilter']->get($this->dictUpdateKey);
         if ($updateTime > $timestamp) {
             mss_destroy($mss);
             $mss = mss_create("confilter_main", -1);
             $timestamp = mss_timestamp($mss);
             $is_ready = mss_is_ready($mss);
         }
     } else {
         $this->loadDict($mss, $this->dictKey);
     }
     $matches = mss_search($mss, $text);
     $word_arr = array();
     foreach ($matches as $key => $value) {
         $word_arr[] = $value[0];
     }
     $json = json_encode($word_arr);
     echo $json;
     exit;
 }
Beispiel #2
0
 public function reload()
 {
     $mss = mss_create("default", -1);
     $is_ready = mss_is_ready($mss);
     if ($is_ready) {
         $this->loadDict($mss, $this->dictKey);
         return 'mss has reloaded';
     } else {
         return 'mss is not ready';
     }
 }
Beispiel #3
0
            mss_add($mss, trim($line[0]), trim($line[1]));
        } else {
            mss_add($mss, trim($line[0]));
        }
    }
}
$mss = mss_create("example");
$timestamp = mss_timestamp($mss);
$is_ready = mss_is_ready($mss);
if ($is_ready) {
    $stat = stat("example.dic");
    if ($stat['mtime'] > $timestamp) {
        mss_destroy($mss);
        $mss = mss_create("example");
        $timestamp = mss_timestamp($mss);
        $is_ready = mss_is_ready($mss);
    }
}
if (!$is_ready) {
    echo "Load dict\n";
    load_dict($mss, "example.dic");
}
$text = file_get_contents("example.txt");
//
//
echo "mss_creation: " . date("Y-m-d H:i:s", $timestamp) . "\n";
//
//
echo "mms_match(): original text\n";
$ret = mss_match($mss, $text);
echo "    ", $ret ? "matched" : "not matched", "\n";