Browse Source

show mime type options that match search results only

main
ghost 2 years ago
parent
commit
4486bdc215
  1. 15
      library/sphinxql.php
  2. 4
      public/search.php

15
library/sphinxql.php

@ -39,11 +39,20 @@ class SphinxQL {
return $query->fetch()->total; 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(); return $query->fetchAll();
} }

4
public/search.php

@ -34,7 +34,7 @@ if (!empty($q)) {
} }
// Mime list // Mime list
$hostPagesMime = $sphinx->getHostPagesMime(); $hostPagesMime = $sphinx->searchHostPagesMime($q);
// Define page basics // Define page basics
$totalPages = $sphinx->getHostPagesTotal(); $totalPages = $sphinx->getHostPagesTotal();
@ -310,7 +310,7 @@ if (filter_var($q, FILTER_VALIDATE_URL) && preg_match(CRAWL_URL_REGEXP, $q)) {
<h1><a href="<?php echo WEBSITE_DOMAIN; ?>"><?php echo _('YGGo!') ?></a></h1> <h1><a href="<?php echo WEBSITE_DOMAIN; ?>"><?php echo _('YGGo!') ?></a></h1>
<input type="text" name="q" placeholder="<?php echo $placeholder ?>" value="<?php echo htmlentities($q) ?>" /> <input type="text" name="q" placeholder="<?php echo $placeholder ?>" value="<?php echo htmlentities($q) ?>" />
<?php foreach ($hostPagesMime as $hostPageMime) { ?> <?php foreach ($hostPagesMime as $hostPageMime) { ?>
<label><input type="radio" name="t" value="<?php echo $hostPageMime->mime ?>" <?php echo ($t == $hostPageMime->mime ? 'checked="checked"' : false) ?>/> <?php echo $hostPageMime->mime ?></label> <label><input type="radio" name="t" value="<?php echo $hostPageMime->mime ?>" <?php echo ($t == $hostPageMime->mime ? 'checked="checked"' : false) ?>/> <?php echo $hostPageMime->mime ?> <!--(<?php // echo $sphinx->searchHostPagesTotalByMime($q, $hostPageMime->mime) ?>)--></label>
<?php } ?> <?php } ?>
<button type="submit"><?php echo _('Search'); ?></button> <button type="submit"><?php echo _('Search'); ?></button>
</form> </form>

Loading…
Cancel
Save