12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace addons\cms\controller\api;
- use addons\cms\library\FulltextSearch;
- use addons\cms\library\Service;
- use addons\cms\model\Archives;
- use addons\cms\model\SearchLog;
- use think\Config;
- use think\Session;
- /**
- * 搜索控制器
- * Class Search
- * @package addons\cms\controller
- */
- class Search extends Base
- {
- protected $noNeedLogin = ['index'];
- public function index()
- {
- $config = get_addon_config('cms');
- $search = $this->request->request("search", $this->request->request("q", ""));
- $search = mb_substr($search, 0, 100);
-
- $filterList = [];
- $orderList = [];
- $orderby = $this->request->get('orderby', '');
- $orderway = $this->request->get('orderway', '', 'strtolower');
- $params = ['q' => $search];
- if ($orderby) {
- $params['orderby'] = $orderby;
- }
- if ($orderway) {
- $params['orderway'] = $orderway;
- }
- //默认排序字段
- $orders = [
- ['name' => 'default', 'field' => 'weigh', 'title' => __('Default')],
- ['name' => 'views', 'field' => 'views', 'title' => __('Views')],
- ['name' => 'id', 'field' => 'id', 'title' => __('Post date')],
- ];
- //获取排序列表
- list($orderList, $orderby, $orderway) = Service::getOrderList($orderby, $orderway, $orders, $params);
- $pageList = Archives
- ::where('status', 'normal')
- ->whereNull('deletetime')
- ->where('title', 'like', "%{$search}%")
- ->order($orderby, $orderway)
- ->paginate(10, $config['pagemode'] == 'simple', ['type' => '\\addons\\cms\\library\\Bootstrap']);
- foreach($pageList as $item){
- $item->append(['images_list']);
- }
- $pageList->appends(array_filter($params));
-
- Config::set('cms.title', __("Search for %s", $search));
- $this->success('',[
- 'filterList'=>$filterList,
- 'orderList'=>$orderList,
- 'pageList'=>$pageList
- ]);
- }
- }
|