diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 3857380..4bf5766 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -92,6 +92,8 @@ class Index extends QfShop $data['page_size'] = 10; $data['title'] = $name; $data['category_id'] = $cate; + $data['search_type'] = 1; + $data['is_time'] = 1; $list = $this->SourceModel->getList($data); diff --git a/app/model/Source.php b/app/model/Source.php index c607c7c..f2f8b7e 100644 --- a/app/model/Source.php +++ b/app/model/Source.php @@ -109,7 +109,8 @@ class Source extends QfShop $ip = $_SERVER['REMOTE_ADDR']; $ips = Log::where(['ip'=>$ip])->find(); if(empty($ips)){ - Log::save(['name' => '访问记录','ip'=>$ip]); + $log = new Log(); + $log->save(['name' => '访问记录','ip'=>$ip]); }else{ Log::where('id', $ips['id'])->update(['update_time' => time()]); } @@ -133,7 +134,8 @@ class Source extends QfShop // 如果存在 title,则进行分词 if (!empty($data['title'])) { - $search_type = config('qfshop.search_type')??1; + $search_type = isset($data['search_type']) ? (config('qfshop.search_type') ?? 1) : 1; //默认除网页端其它均为模糊搜索,想开启机器人分词搜索注释该行,取消注释下一行 + // $search_type = config('qfshop.search_type') ?? 1; if($search_type == 0){ $map[] = ['title|description', 'like', '%' . trim($data['title']) . '%']; @@ -142,9 +144,13 @@ class Source extends QfShop $fc = new VicWord(); $keywords = $fc->getAutoWord($data['title']); $keywords = filterAndExtractWords($keywords); + $keywords = array_filter($keywords, function($keyword) { + return mb_strlen($keyword, 'UTF-8') > 1; + }); + $keywords = array_values($keywords); // 如果分词后有关键词 - if (count($keywords) > 1) { + if (count($keywords) >= 1) { if($search_type == 1){ //分词同时满足才搜索的到! foreach ($keywords as $keyword) {