From 26bb14e290855c9d4fd78e2060d254bbc59f684b Mon Sep 17 00:00:00 2001 From: DariusIII Date: Mon, 21 Jan 2019 11:27:47 +0100 Subject: [PATCH] Update search, update matching --- Blacklight/IRCScraper.php | 2 +- Blacklight/NameFixer.php | 6 ++--- Blacklight/Releases.php | 24 ++++++++++--------- Blacklight/SphinxSearch.php | 18 ++++++++++---- Changelog | 2 ++ .../Controllers/Admin/PredbController.php | 2 +- app/Models/Predb.php | 9 +++---- 7 files changed, 39 insertions(+), 24 deletions(-) diff --git a/Blacklight/IRCScraper.php b/Blacklight/IRCScraper.php index a6b8d392f..41bbb3a3c 100755 --- a/Blacklight/IRCScraper.php +++ b/Blacklight/IRCScraper.php @@ -289,7 +289,7 @@ class IRCScraper extends IRCClient */ protected function _insertNewPre() { - $sphinxData = $this->sphinxsearch->searchIndexes($this->_curPre['title'], ['title'], 'predb_rt'); + $sphinxData = $this->sphinxsearch->searchIndexes('predb_rt', $this->_curPre['title'], ['title']); if (! empty($sphinxData) || empty($this->_curPre['title'])) { return; } diff --git a/Blacklight/NameFixer.php b/Blacklight/NameFixer.php index 2f548aa0c..d924407c7 100755 --- a/Blacklight/NameFixer.php +++ b/Blacklight/NameFixer.php @@ -1268,7 +1268,7 @@ class NameFixer $this->_cleanMatchFiles(); $preMatch = $this->preMatch($this->_fileName); if ($preMatch[0] === true) { - $results = $this->sphinx->searchIndexes($preMatch[1], ['filename', 'title'], 'predb_rt'); + $results = $this->sphinx->searchIndexes('predb_rt', $preMatch[1], ['filename', 'title']); if (! empty($results)) { foreach ($results as $result) { if (! empty($result)) { @@ -2443,7 +2443,7 @@ class NameFixer $this->_cleanMatchFiles(); if (! empty($this->_fileName)) { - foreach ($this->sphinx->searchIndexes($this->_fileName, ['filename', 'title'], 'predb_rt') as $match) { + foreach ($this->sphinx->searchIndexes('predb_rt', $this->_fileName, ['filename', 'title']) as $match) { if (! empty($match)) { $this->updateRelease($release, $match['title'], 'PreDb: Filename match', $echo, $type, $nameStatus, $show, $match['id']); @@ -2470,7 +2470,7 @@ class NameFixer $this->_cleanMatchFiles(); $this->cleanFileNames(); if (! empty($this->_fileName)) { - foreach ($this->sphinx->searchIndexes($this->_fileName, 'title', 'predb_rt') as $match) { + foreach ($this->sphinx->searchIndexes('predb_rt', $this->_fileName, 'title') as $match) { if (! empty($match)) { $this->updateRelease($release, $match['title'], 'PreDb: Title match', $echo, $type, $nameStatus, $show, $match['id']); diff --git a/Blacklight/Releases.php b/Blacklight/Releases.php index 08aceee8e..6dd76c5be 100755 --- a/Blacklight/Releases.php +++ b/Blacklight/Releases.php @@ -619,21 +619,23 @@ class Releases $orderBy = $this->getBrowseOrder($orderBy); } - $query = $this->sphinxSearch->sphinxQL->select()->from('releases_rt')->option('max_matches', 10000); + $searchFields = []; if ($searchName !== -1) { - $query->match('searchname', $searchName); + $searchFields['searchname'] = $searchName; } if ($usenetName !== -1) { - $query->match('name', $usenetName); + $searchFields['name'] = $usenetName; } if ($posterName !== -1) { - $query->match('fromname', $posterName); + $searchFields['fromname'] = $posterName; } if ($fileName !== -1) { - $query->match('filename', $fileName); + $searchFields['filename'] = $fileName; } - $results = $query->execute()->fetchAllAssoc() ?? []; + + + $results = $this->sphinxSearch->searchIndexes('releases_rt', '', '', $searchFields); $searchResult = array_pluck($results, 'id'); @@ -731,7 +733,7 @@ class Releases public function apiSearch($searchName, $groupName, $offset = 0, $limit = 1000, $maxAge = -1, array $excludedCats = [], array $cat = [-1], $minSize = 0, array $tags = []) { if ($searchName !== -1) { - $searchResult = array_pluck($this->sphinxSearch->searchIndexes($searchName, ['searchname'], 'releases_rt'), 'id'); + $searchResult = array_pluck($this->sphinxSearch->searchIndexes('releases_rt', $searchName, ['searchname']), 'id'); } $catQuery = Category::getCategorySearch($cat); @@ -871,7 +873,7 @@ class Releases } if (! empty($name)) { - $searchResult = array_pluck($this->sphinxSearch->searchIndexes($name, ['searchname'], 'releases_rt'), 'id'); + $searchResult = array_pluck($this->sphinxSearch->searchIndexes('releases_rt', $name, ['searchname']), 'id'); } $whereSql = sprintf( @@ -1016,7 +1018,7 @@ class Releases } if (! empty($name)) { - $searchResult = array_pluck($this->sphinxSearch->searchIndexes($name, ['searchname'], 'releases_rt'), 'id'); + $searchResult = array_pluck($this->sphinxSearch->searchIndexes('releases_rt', $name, ['searchname']), 'id'); } $whereSql = sprintf( @@ -1093,7 +1095,7 @@ class Releases public function animeSearch($aniDbID, $offset = 0, $limit = 100, $name = '', array $cat = [-1], $maxAge = -1, array $excludedCategories = []) { if (! empty($name)) { - $searchResult = array_pluck($this->sphinxSearch->searchIndexes($name, ['searchname'], 'releases_rt'), 'id'); + $searchResult = array_pluck($this->sphinxSearch->searchIndexes('releases_rt', $name, ['searchname']), 'id'); } $whereSql = sprintf( @@ -1167,7 +1169,7 @@ class Releases public function moviesSearch($imDbId = -1, $tmDbId = -1, $traktId = -1, $offset = 0, $limit = 100, $name = '', array $cat = [-1], $maxAge = -1, $minSize = 0, array $excludedCategories = [], array $tags = []) { if (! empty($name)) { - $searchResult = array_pluck($this->sphinxSearch->searchIndexes($name, ['searchname'], 'releases_rt'), 'id'); + $searchResult = array_pluck($this->sphinxSearch->searchIndexes('releases_rt', $name, ['searchname']), 'id'); } $whereSql = sprintf( diff --git a/Blacklight/SphinxSearch.php b/Blacklight/SphinxSearch.php index 8407dbf06..04a4709c9 100755 --- a/Blacklight/SphinxSearch.php +++ b/Blacklight/SphinxSearch.php @@ -187,12 +187,22 @@ class SphinxSearch /** * @param string $searchString (what are we looking for?) - * @param string|array $column (one or multiple columns from the columns that exist in indexes) - * @param string $rt_index (releases_rt or predb_rt) + * @param array $column (one or multiple columns from the columns that exist in indexes) + * @param string $rt_index (releases_rt or predb_rt) + * @param array $searchArray + * * @return array */ - public function searchIndexes(string $searchString, $column, string $rt_index): array + public function searchIndexes(string $rt_index, $searchString = '', $column = [], array $searchArray = []): array { - return $this->sphinxQL->select()->from($rt_index)->match($column, $searchString)->option('max_matches', 10000)->execute()->fetchAllAssoc() ?? []; + $query = $this->sphinxQL->select()->from($rt_index)->option('max_matches', 10000)->option('ranker', 'matchany')->limit(0, 10000)->orderBy('weight()', 'desc'); + if (! empty($searchArray)) { + foreach ($searchArray as $key => $value) { + $query->match($key, $value); + } + return $query->execute()->fetchAllAssoc() ?? []; + } + + return $query->match($column, $searchString)->execute()->fetchAllAssoc() ?? []; } } diff --git a/Changelog b/Changelog index 117b8dd31..db7328eca 100755 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +2019-01-21 DariusIII + * Chg: Update search, update matching 2019-01-20 DariusIII * Chg: Update rest of the cover checking files * Fix: Fix misc/tesing/PostProc/updateXXXImages.php script error (fixes issue #852) diff --git a/app/Http/Controllers/Admin/PredbController.php b/app/Http/Controllers/Admin/PredbController.php index 805fb7d1a..39be86ee3 100644 --- a/app/Http/Controllers/Admin/PredbController.php +++ b/app/Http/Controllers/Admin/PredbController.php @@ -19,7 +19,7 @@ class PredbController extends BasePageController if ($request->has('presearch')) { $lastSearch = $request->input('presearch'); - $parr = Predb::getAll($request->input('presearch')); + $parr = Predb::getAll(array_wrap($request->input('presearch'))); } else { $lastSearch = ''; $parr = Predb::getAll(); diff --git a/app/Models/Predb.php b/app/Models/Predb.php index 9510f9740..af979c728 100644 --- a/app/Models/Predb.php +++ b/app/Models/Predb.php @@ -173,16 +173,17 @@ class Predb extends Model } /** - * @param string $search + * @param array $search + * * @return mixed * @throws \Exception */ - public static function getAll($search = '') + public static function getAll($search = []) { $sql = self::query()->remember(config('nntmux.cache_expiry_medium'))->leftJoin('releases', 'releases.predb_id', '=', 'predb.id')->orderByDesc('predb.predate'); - if ($search !== '') { + if (! empty($search)) { $sphinx = new SphinxSearch(); - $ids = array_pluck($sphinx->searchIndexes($search, 'title', 'predb_rt'), 'id'); + $ids = array_pluck($sphinx->searchIndexes('predb_rt', $search, 'title'), 'id'); $sql->whereIn('predb.id', $ids); }