diff --git a/config/sphinx.conf.txt b/config/sphinx.conf.txt index 5b8e481..62edaf8 100644 --- a/config/sphinx.conf.txt +++ b/config/sphinx.conf.txt @@ -14,10 +14,7 @@ source hostPage : common sql_query = \ SELECT `hostPage`.`hostPageId`, \ `hostPage`.`uri`, \ - REPLACE(`hostPage`.`uri`, '.', ' '), \ - REPLACE(`hostPage`.`uri`, '-', ' '), \ - REPLACE(`hostPage`.`uri`, '_', ' '), \ - REPLACE(`hostPage`.`uri`, '/', ' '), \ + REPLACE(REPLACE(REPLACE(REPLACE(`hostPage`.`uri`, '/', ' '), '_', ' '), '-', ' '), '.', ' ') AS `hostPageURIKeywords`, \ `hostPage`.`rank`, \ `host`.`name`, \ IF (`host`.`port` IS NOT NULL, \ diff --git a/library/sphinxql.php b/library/sphinxql.php index 3e12b0a..e1059d1 100644 --- a/library/sphinxql.php +++ b/library/sphinxql.php @@ -11,9 +11,18 @@ class SphinxQL { $this->_sphinx->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); } + public function searchHostPagesTotal(string $keyword, string $mime) { + + $query = $this->_sphinx->prepare('SELECT COUNT(*) AS `total` FROM `hostPage` WHERE MATCH(?) AND `mime` = ?'); + + $query->execute([$keyword, $mime]); + + return $query->fetch()->total; + } + public function searchHostPages(string $keyword, string $mime, int $start, int $limit, int $maxMatches) { - $query = $this->_sphinx->prepare('SELECT *, WEIGHT() + `rank` * IF (`rank` > 0, 1000, 1) AS `priority` + $query = $this->_sphinx->prepare("SELECT *, WEIGHT() + `rank` * IF (`rank` > 0, 1000, 1) AS `priority` FROM `hostPage` @@ -21,9 +30,9 @@ class SphinxQL { ORDER BY `priority` DESC, WEIGHT() DESC - LIMIT ' . (int) ($start >= $maxMatches ? ($maxMatches > 0 ? $maxMatches - 1 : 0) : $start) . ',' . (int) $limit . ' + LIMIT " . (int) ($start >= $maxMatches ? ($maxMatches > 0 ? $maxMatches - 1 : 0) : $start) . "," . (int) $limit . " - OPTION `max_matches`=' . (int) ($maxMatches >= 1 ? $maxMatches : 1)); + OPTION `max_matches`=" . (int) ($maxMatches >= 1 ? $maxMatches : 1)); $query->execute([$keyword, $mime]); @@ -65,13 +74,4 @@ class SphinxQL { return $query->fetchAll(); } - - public function searchHostPagesTotal(string $keyword, string $mime) { - - $query = $this->_sphinx->prepare('SELECT COUNT(*) AS `total` FROM `hostPage` WHERE MATCH(?) AND `mime` = ?'); - - $query->execute([$keyword, $mime]); - - return $query->fetch()->total; - } }