Browse Source

count totals using sphinx index instead of database

main
ghost 2 years ago
parent
commit
8fbd7f3516
  1. 18
      library/mysql.php
  2. 18
      library/sphinxql.php
  3. 8
      public/index.php
  4. 4
      public/search.php

18
library/mysql.php

@ -121,15 +121,6 @@ class MySQL {
} }
// Images // Images
public function getTotalImages() {
$query = $this->_db->prepare('SELECT COUNT(*) AS `total` FROM `hostImage`');
$query->execute();
return $query->fetch()->total;
}
public function getTotalHostImages(int $hostId) { public function getTotalHostImages(int $hostId) {
$query = $this->_db->prepare('SELECT COUNT(*) AS `total` FROM `hostImage` WHERE `hostId` = ?'); $query = $this->_db->prepare('SELECT COUNT(*) AS `total` FROM `hostImage` WHERE `hostId` = ?');
@ -362,15 +353,6 @@ class MySQL {
return $query->fetch()->total; return $query->fetch()->total;
} }
public function getTotalPages() {
$query = $this->_db->prepare('SELECT COUNT(*) AS `total` FROM `hostPage`');
$query->execute();
return $query->fetch()->total;
}
public function getHostPage(int $hostId, int $crc32uri) { public function getHostPage(int $hostId, int $crc32uri) {
$query = $this->_db->prepare('SELECT * FROM `hostPage` WHERE `hostId` = ? AND `crc32uri` = ? LIMIT 1'); $query = $this->_db->prepare('SELECT * FROM `hostPage` WHERE `hostId` = ? AND `crc32uri` = ? LIMIT 1');

18
library/sphinxql.php

@ -49,6 +49,15 @@ class SphinxQL {
return $query->fetchAll(); return $query->fetchAll();
} }
public function getHostPagesTotal() {
$query = $this->_sphinx->prepare('SELECT COUNT(*) AS `total` FROM `hostPage`');
$query->execute();
return $query->fetch()->total;
}
public function searchHostPagesTotal(string $keyword) { public function searchHostPagesTotal(string $keyword) {
$query = $this->_sphinx->prepare('SELECT COUNT(*) AS `total` FROM `hostPage` WHERE MATCH(?)'); $query = $this->_sphinx->prepare('SELECT COUNT(*) AS `total` FROM `hostPage` WHERE MATCH(?)');
@ -66,4 +75,13 @@ class SphinxQL {
return $query->fetch()->total; return $query->fetch()->total;
} }
public function getHostImagesTotal() {
$query = $this->_sphinx->prepare('SELECT COUNT(*) AS `total` FROM `hostImage`');
$query->execute();
return $query->fetch()->total;
}
} }

8
public/index.php

@ -3,12 +3,12 @@
// Load system dependencies // Load system dependencies
require_once('../config/app.php'); require_once('../config/app.php');
require_once('../library/filter.php'); require_once('../library/filter.php');
require_once('../library/mysql.php'); require_once('../library/sphinxql.php');
// Connect database // Connect Sphinx search server
$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); $sphinx = new SphinxQL(SPHINX_HOST, SPHINX_PORT);
$totalPages = $db->getTotalPages(); $totalPages = $sphinx->getHostPagesTotal();
$placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the new one...'), $totalPages), $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the new one...'), $totalPages),
sprintf(_('Over %s pages or enter the new one...'), $totalPages), sprintf(_('Over %s pages or enter the new one...'), $totalPages),

4
public/search.php

@ -26,7 +26,7 @@ switch ($t) {
case 'image': case 'image':
$totalPages = $db->getTotalImages(); $totalPages = $sphinx->getHostImagesTotal();
$placeholder = Filter::plural($totalPages, [sprintf(_('Over %s image or enter the new one...'), $totalPages), $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s image or enter the new one...'), $totalPages),
sprintf(_('Over %s images or enter the new one...'), $totalPages), sprintf(_('Over %s images or enter the new one...'), $totalPages),
@ -36,7 +36,7 @@ switch ($t) {
break; break;
default: default:
$totalPages = $db->getTotalPages(); $totalPages = $sphinx->getHostPagesTotal();
$placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the new one...'), $totalPages), $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the new one...'), $totalPages),
sprintf(_('Over %s pages or enter the new one...'), $totalPages), sprintf(_('Over %s pages or enter the new one...'), $totalPages),

Loading…
Cancel
Save