Browse Source

fix max_matches error

main
ghost 2 years ago
parent
commit
fcee7f62ef
  1. 10
      library/sphinxql.php
  2. 2
      public/api.php
  3. 4
      public/search.php

10
library/sphinxql.php

@ -11,9 +11,15 @@ class SphinxQL {
$this->_sphinx->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); $this->_sphinx->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
} }
public function searchHostPages(string $keyword, int $start, int $limit) { public function searchHostPages(string $keyword, int $start, int $limit, int $maxMatches) {
$query = $this->_sphinx->prepare('SELECT * FROM `hostPage` WHERE MATCH(?) LIMIT ' . (int) $start . ',' . (int) $limit); $query = $this->_sphinx->prepare('SELECT * FROM `hostPage`
WHERE MATCH(?)
LIMIT ' . (int) ($start > $maxMatches ? ($maxMatches > 0 ? $maxMatches - 1 : 0) : $start) . ',' . (int) $limit . '
OPTION `max_matches`=' . (int) ($maxMatches > 1 ? $maxMatches : 1));
$query->execute([$keyword]); $query->execute([$keyword]);

2
public/api.php

@ -29,8 +29,8 @@ if (API_ENABLED) {
$page = !empty($_GET['page']) ? Filter::url($_GET['page']) : 1; $page = !empty($_GET['page']) ? Filter::url($_GET['page']) : 1;
// Make search request // Make search request
$sphinxResults = $sphinx->searchHostPages('"' . $query . '"', $page * API_SEARCH_PAGINATION_RESULTS_LIMIT - API_SEARCH_PAGINATION_RESULTS_LIMIT, API_SEARCH_PAGINATION_RESULTS_LIMIT);
$sphinxResultsTotal = $sphinx->searchHostPagesTotal('"' . $query . '"'); $sphinxResultsTotal = $sphinx->searchHostPagesTotal('"' . $query . '"');
$sphinxResults = $sphinx->searchHostPages('"' . $query . '"', $page * API_SEARCH_PAGINATION_RESULTS_LIMIT - API_SEARCH_PAGINATION_RESULTS_LIMIT, API_SEARCH_PAGINATION_RESULTS_LIMIT, $sphinxResultsTotal);
// Generate results // Generate results
$dbResults = []; $dbResults = [];

4
public/search.php

@ -106,13 +106,13 @@ if (filter_var($q, FILTER_VALIDATE_URL) && preg_match(CRAWL_URL_REGEXP, $q)) {
// Search request // Search request
if (!empty($q)) { if (!empty($q)) {
$results = $sphinx->searchHostPages('"' . $q . '"', $p * WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT - WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT, WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT);
$resultsTotal = $sphinx->searchHostPagesTotal('"' . $q . '"'); $resultsTotal = $sphinx->searchHostPagesTotal('"' . $q . '"');
$results = $sphinx->searchHostPages('"' . $q . '"', $p * WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT - WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT, WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT, $resultsTotal);
} else { } else {
$results = [];
$resultsTotal = 0; $resultsTotal = 0;
$results = [];
} }
?> ?>

Loading…
Cancel
Save