diff --git a/library/sphinxql.php b/library/sphinxql.php index 8062761..c259d67 100644 --- a/library/sphinxql.php +++ b/library/sphinxql.php @@ -39,11 +39,20 @@ class SphinxQL { return $query->fetch()->total; } - public function getHostPagesMime() { + public function searchHostPagesTotalByMime(string $keyword, string $mime) { - $query = $this->_sphinx->prepare('SELECT `mime` FROM `hostPage` GROUP BY `mime` ORDER BY `mime` ASC'); + $query = $this->_sphinx->prepare('SELECT COUNT(*) AS `total` FROM `hostPage` WHERE MATCH(?) AND `mime` = ?'); - $query->execute(); + $query->execute([$keyword, $mime]); + + return $query->fetch()->total; + } + + public function searchHostPagesMime(string $keyword) { + + $query = $this->_sphinx->prepare('SELECT `mime` FROM `hostPage` WHERE MATCH(?) GROUP BY `mime` ORDER BY `mime` ASC'); + + $query->execute([$keyword]); return $query->fetchAll(); } diff --git a/public/search.php b/public/search.php index f448ac8..9ec954c 100644 --- a/public/search.php +++ b/public/search.php @@ -34,7 +34,7 @@ if (!empty($q)) { } // Mime list -$hostPagesMime = $sphinx->getHostPagesMime(); +$hostPagesMime = $sphinx->searchHostPagesMime($q); // Define page basics $totalPages = $sphinx->getHostPagesTotal(); @@ -310,7 +310,7 @@ if (filter_var($q, FILTER_VALIDATE_URL) && preg_match(CRAWL_URL_REGEXP, $q)) {

- +