* Finish task #41751.

This commit is contained in:
tianshujie98
2021-08-23 15:54:03 +08:00
parent a075fd552e
commit a6ce38ef9c
2 changed files with 9 additions and 11 deletions
+6 -4
View File
@@ -202,9 +202,11 @@ class search extends control
$type = (empty($type) or $type[0] == 'all') ? 'all' : $type;
$this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $this->config->search->recPerPage, $pageID);
$begin = time();
$result = $this->search->getList($words, $pager, $type);
$begin = time();
$results = $this->search->getList($words, $type);
$recTotal = count($results);
$pager = new pager($recTotal, $this->config->search->recPerPage, $pageID);
$results = array_chunk($results, $pager->recPerPage);
/* Set session. */
$uri = inlink('index', "recTotal=$pager->recTotal&pageID=$pager->pageID");
@@ -237,7 +239,7 @@ class search extends control
if(strpos($this->server->http_referer, 'search') === false) $this->session->set('referer', $this->server->http_referer);
$this->view->results = $result;
$this->view->results = empty($results) ? $results : $results[$pageID - 1];
$this->view->consumed = time() - $begin;
$this->view->title = $this->lang->search->index;
$this->view->type = $type;
+3 -7
View File
@@ -499,12 +499,11 @@ class searchModel extends model
* get search results of keywords.
*
* @param string $keywords
* @param object $pager
* @param string $type
* @access public
* @return array
*/
public function getList($keywords, $pager, $type)
public function getList($keywords, $type)
{
$spliter = $this->app->loadClass('spliter');
$words = explode(' ', self::unify($keywords, ' '));
@@ -557,7 +556,6 @@ class searchModel extends model
->andWhere('objectType')->in($allowedObject)
->andWhere('addedDate')->le(helper::now())
->orderBy('score_desc, editedDate_desc')
->page($pager)
->fetchAll('id');
foreach($results as $record)
@@ -643,7 +641,7 @@ class searchModel extends model
}
}
return $this->checkPriv($results, $pager);
return $this->checkPriv($results);
}
/**
@@ -775,11 +773,10 @@ class searchModel extends model
* Check product and project priv.
*
* @param array $results
* @param object $pager
* @access public
* @return array
*/
public function checkPriv($results, $pager = null)
public function checkPriv($results)
{
if($this->app->user->admin) return $results;
@@ -931,7 +928,6 @@ class searchModel extends model
}
}
}
if($total != count($results)) $pager->recTotal = $pager->recTotal - ($total - count($results));
return $results;
}