写了一个定时任务,准备定时访问该地址,完成匹配品牌的功能。
用了结巴分词,分离商品标题
本地运行没问题。在线上运行时,只查出一条商品的情况下,没问题。多条就会自动跳转到配置文件中的的“ERROR_PAGE”.Log日志文件中没有记录。现在不知道怎么查看该问题的原因,找不到解决办法。
应该是循环引起的问题,但是不知道问题出在哪?
附相关代码:
$quan_lists = M("Quan")->field('id,title')->where(array("fromtype" => array("gt", 0),"addtime" => array("gt", $limit_time)))->limit(20)->order("id desc")->select();
$productLogic = tkD("Product", "Logic");
$searchLogic = tkD('Search', 'Logic');
if(!empty($quan_lists)) {
foreach($quan_lists as $quan) {
//分词结果
$aTags = $productLogic->jieba($quan['title']);
if (empty($aTags)) {
continue;
}
$like_zh_map = $like_en_map = $condition = $map = array();
foreach($aTags as $tag) {
if(preg_match("/^[0-9a-zA-Z\s]+$/", $tag)) {
$like_en_map[] = "{$tag}%";
} else {
$like_zh_map[] = "{$tag}%";
}
}
if(count($like_zh_map) > 0) {
$condition['zh_name'] = array('like', $like_zh_map, 'OR');
}
if(count($like_en_map) > 0) {
$condition['en_name'] = array('like', $like_en_map, 'OR');
}
if(count($like_zh_map) > 0 && count($like_en_map) > 0) {
$condition['_logic'] = 'or';
}
$map['_complex'] = $condition;
$map['status'] = 1;
$aDatas = M('Brand')->field('id,zh_name,en_name')->where($map)->find();
if(empty($aDatas)) {
continue;
} else {
M("Quan")->where(array("id" => $quan['id']))->save(array("brand_id" => intval($aDatas["id"])));
$searchLogic->searchupdate(2, $quan['id']); //更新搜索引擎
}
}
}
public function jieba($title)
{
if (empty($title)) {
return false;
}
ini_set('memory_limit', '200M');//吃内存
import('Vendor/jieba/src/vendor/multi-array/MultiArray', '', '.php');
import('Vendor/jieba/src/vendor/multi-array/Factory/MultiArrayFactory', '', '.php');
import('Vendor/jieba/src/class/Jieba', '', '.php');
import('Vendor/jieba/src/class/Finalseg', '', '.php');
\Fukuball\Jieba\Jieba::init(array('dict' => 'small'));
\Fukuball\Jieba\Finalseg::init();
$aSeglist = \Fukuball\Jieba\Jieba::cut($title, false);
if ($aSeglist) {
$aTags = array();
foreach ($aSeglist as $str) {
if (is_numeric($str)) {
continue;
} elseif (mb_strlen($str, 'utf8') < 2) {
continue;
} else {
$aTags[] = $str;
}
}
return $aTags;
} else {
return false;
}
}
分词的时候:
ini_set('memory_limit', '200M')
这段代码看起来有点问题