success('清理完毕');
}
public function search(Request $request)
{
$search_content = $request->search_content;
if(_empty_($search_content)){
return JsonResponse::make()->html('
搜索结果为空
')->success('搜索完毕');
}
$res = Http::post('https://mini.minisns.cn/api/v1/three/search_menu', ['search_content'=>$search_content]);
$search_arr = null;
if($res->successful()){
$search_arr = $res->json();
}
$html = '';
$actree = new AcAutomation(SearchUtils::split_keywords($search_content));
$pre_tags = '';
$end_tag = '';
if($search_arr && $search_arr['status']){
if($search_arr['data'] && count($search_arr['data']) > 0){
foreach ($search_arr['data'] as $item){
if($item['menu']){
$uri = admin_url(ltrim($item['menu']['uri'], '/'));
if($item['menu_id'] == $item['parent_id']){
$text = $item['menu']['title'] . ' - ' . $item['keyword'];
}else{
$text = $item['parent']['title'] . ' - ' . $item['menu']['title'] . ' - ' . $item['keyword'];
}
$ac_res = $actree->search($text);
$tmp_text = $text;
$replaced = [];
if($ac_res && is_array($ac_res)){
foreach ($ac_res as $pos) {
$searched_part = mb_substr($tmp_text, $pos[0],$pos[1] - $pos[0],'UTF-8');
if(in_array($searched_part, $replaced)){
continue;
}else{
$replaced[] = $searched_part;
}
$text = str_replace($searched_part, $pre_tags.$searched_part.$end_tag, $text);
// $text = str_replace($searched_part, $pre_tags.$searched_part.$end_tag, $text);
}
}
$html .= ''.$text.'
';
}
}
}else{
return JsonResponse::make()->html('搜索结果为空
')->success('搜索完毕');
}
}
return JsonResponse::make()->html($html)->success('搜索完毕');
}
}