diff --git a/.env.example b/.env.example index 94c78b7ab..452d55335 100644 --- a/.env.example +++ b/.env.example @@ -78,3 +78,6 @@ FLOOD_MAX_REQUESTS_PER_SECOND=5 ECHOCLI=true RENAME_PAR2=true RENAME_MUSIC_MEDIAINFO=true + +SCOUT_DRIVER=mysql +SCOUT_QUEUE=false diff --git a/Blacklight/Books.php b/Blacklight/Books.php index 680b1cf01..f57cb3d5d 100755 --- a/Blacklight/Books.php +++ b/Blacklight/Books.php @@ -114,7 +114,8 @@ class Books /** * @param $title - * @return \Illuminate\Database\Eloquent\Model|null|static + * + * @return \Illuminate\Database\Eloquent\Model */ public function getBookInfoByName($title) { @@ -136,7 +137,7 @@ class Books } $searchWords = trim($searchWords); - return BookInfo::query()->whereRaw('MATCH(author, title) AGAINST(? IN BOOLEAN MODE)', [$searchWords])->first(); + return BookInfo::search($searchWords)->first(); } /** @@ -445,13 +446,13 @@ class Books // Do a local lookup first $bookCheck = $this->getBookInfoByName($bookInfo); - if ($bookCheck === false && \in_array($bookInfo, $this->failCache, false)) { + if ($bookCheck === null && \in_array($bookInfo, $this->failCache, false)) { // Lookup recently failed, no point trying again if ($this->echooutput) { ColorCLI::doEcho(ColorCLI::headerOver('Cached previous failure. Skipping.'), true); } $bookId = -2; - } elseif ($bookCheck === false) { + } elseif ($bookCheck !== null) { $bookId = $this->updateBookInfo($bookInfo); $usedAmazon = true; if ($bookId === -2) { diff --git a/Blacklight/Console.php b/Blacklight/Console.php index 5265f2587..afc14d221 100755 --- a/Blacklight/Console.php +++ b/Blacklight/Console.php @@ -118,7 +118,8 @@ class Console /** * @param $title * @param $platform - * @return \Illuminate\Database\Eloquent\Model|null|static + * + * @return \Illuminate\Database\Eloquent\Model */ public function getConsoleInfoByName($title, $platform) { @@ -140,7 +141,7 @@ class Console } $searchWords = trim($searchWords); - return ConsoleInfo::query()->whereRaw('MATCH(title, platform) AGAINST(? IN BOOLEAN MODE) AND platform = ?', [$searchWords, $platform])->first(); + return ConsoleInfo::search($searchWords, $platform)->first(); } /** diff --git a/Blacklight/Games.php b/Blacklight/Games.php index 125fe8cc8..a3027e953 100755 --- a/Blacklight/Games.php +++ b/Blacklight/Games.php @@ -163,10 +163,7 @@ class Games return $bestMatch; } - $results = GamesInfo::query() - ->whereRaw('MATCH(title) AGAINST(?)', $title) - ->limit(20) - ->get(); + $results = GamesInfo::search($title)->get(); if ($results instanceof \Traversable) { $bestMatchPct = 0; diff --git a/Blacklight/Music.php b/Blacklight/Music.php index bf7e1bc98..0c11fd71e 100755 --- a/Blacklight/Music.php +++ b/Blacklight/Music.php @@ -133,7 +133,7 @@ class Music } $searchwords = trim($searchwords); - return MusicInfo::query()->whereRaw('MATCH(artist, title) AGAINST(? IN BOOLEAN MODE)', $searchwords)->first(); + return MusicInfo::search($searchwords)->first(); } /** diff --git a/Blacklight/NameFixer.php b/Blacklight/NameFixer.php index 84d3f8fd0..4d8248f50 100755 --- a/Blacklight/NameFixer.php +++ b/Blacklight/NameFixer.php @@ -1208,7 +1208,7 @@ class NameFixer $this->_cleanMatchFiles(); $preMatch = preg_match('/(\d{2}\.\d{2}\.\d{2})+[\w-.]+[\w]$/i', $this->_fileName, $match); if ($preMatch) { - $result = $this->pdo->queryOneRow(sprintf("SELECT filename AS filename FROM predb WHERE MATCH(filename) AGAINST ('$match[0]' IN BOOLEAN MODE)")); + $result = Predb::search($match[0])->first(); $preFTmatch = preg_match('/(\d{2}\.\d{2}\.\d{2})+[\w-.]+[\w]$/i', $result['filename'], $match1); if ($preFTmatch) { if ($match[0] === $match1[0]) { diff --git a/Blacklight/Steam.php b/Blacklight/Steam.php index 9dea0930e..9cb7878d5 100755 --- a/Blacklight/Steam.php +++ b/Blacklight/Steam.php @@ -112,7 +112,7 @@ class Steam $this->populateSteamAppsTable(); - $results = SteamApp::query()->whereRaw('MATCH(name) AGAINST(?)', [$searchTerm])->limit(20)->get(['name', 'appid']); + $results = SteamApp::search($searchTerm)->get(); if ($results instanceof \Traversable) { $bestMatchPct = 0; diff --git a/Changelog b/Changelog index 99d3322a9..d4bc41402 100755 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +2018-02-23 DariusIII + * Chg: Use laravel scout to search fulltext indexes 2018-02-22 DariusIII * Chg: Update laravel/framework to version 5.6.5 * Chg: Add try catch block to imdb information fetching diff --git a/app/Models/BookInfo.php b/app/Models/BookInfo.php index 30732285d..480645754 100644 --- a/app/Models/BookInfo.php +++ b/app/Models/BookInfo.php @@ -3,9 +3,11 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Laravel\Scout\Searchable; class BookInfo extends Model { + use Searchable; /** * @var string */ @@ -20,4 +22,24 @@ class BookInfo extends Model * @var array */ protected $guarded = []; + + /** + * @return string + */ + public function searchableAs() + { + return 'ix_bookinfo_author_title_ft'; + } + + /** + * @return array + */ + public function toSearchableArray() + { + + return [ + 'author'=> $this->author, + 'title' => $this->title, + ]; + } } diff --git a/app/Models/ConsoleInfo.php b/app/Models/ConsoleInfo.php index ece3adefe..a8bb7dbb3 100644 --- a/app/Models/ConsoleInfo.php +++ b/app/Models/ConsoleInfo.php @@ -3,9 +3,11 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Laravel\Scout\Searchable; class ConsoleInfo extends Model { + use Searchable; /** * @var string */ @@ -20,4 +22,21 @@ class ConsoleInfo extends Model * @var array */ protected $guarded = []; + + public function searchableAs() + { + return 'ix_consoleinfo_title_platform_ft'; + } + + /** + * @return array + */ + public function toSearchableArray() + { + + return [ + 'title'=> $this->title, + 'platform' => $this->platform, + ]; + } } diff --git a/app/Models/GamesInfo.php b/app/Models/GamesInfo.php index b7f3222c2..b79aa24cc 100644 --- a/app/Models/GamesInfo.php +++ b/app/Models/GamesInfo.php @@ -3,9 +3,12 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Laravel\Scout\Searchable; class GamesInfo extends Model { + use Searchable; + /** * @var string */ @@ -20,4 +23,22 @@ class GamesInfo extends Model * @var array */ protected $guarded = []; + + /** + * @return string + */ + public function searchableAs() + { + return 'ix_title_ft'; + } + + /** + * @return array + */ + public function toSearchableArray() + { + return [ + 'title' => $this->title, + ]; + } } diff --git a/app/Models/MusicInfo.php b/app/Models/MusicInfo.php index 8236a5ca7..6bfeba051 100644 --- a/app/Models/MusicInfo.php +++ b/app/Models/MusicInfo.php @@ -3,9 +3,11 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Laravel\Scout\Searchable; class MusicInfo extends Model { + use Searchable; /** * @var string */ @@ -29,4 +31,23 @@ class MusicInfo extends Model { return $this->belongsTo(Genre::class, 'genres_id'); } + + /** + * @return string + */ + public function searchableAs() + { + return 'ix_musicinfo_artist_title_ft'; + } + + /** + * @return array + */ + public function toSearchableArray() + { + return [ + 'artist'=> $this->artist, + 'title' => $this->title, + ]; + } } diff --git a/app/Models/Predb.php b/app/Models/Predb.php index 59abc71fd..cf6d2648d 100644 --- a/app/Models/Predb.php +++ b/app/Models/Predb.php @@ -7,6 +7,7 @@ use Blacklight\ConsoleTools; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Cache; use Illuminate\Database\Eloquent\Model; +use Laravel\Scout\Searchable; /** * @property mixed $release @@ -14,6 +15,8 @@ use Illuminate\Database\Eloquent\Model; */ class Predb extends Model { + use Searchable; + // Nuke status. public const PRE_NONUKE = 0; // Pre is not nuked. public const PRE_UNNUKED = 1; // Pre was un nuked. @@ -221,4 +224,22 @@ class Predb extends Model { return self::query()->where('id', $preID)->first(); } + + /** + * @return string + */ + public function searchableAs() + { + return 'ft_predb_filename'; + } + + /** + * @return array + */ + public function toSearchableArray() + { + return [ + 'filename' => $this->filename, + ]; + } } diff --git a/app/Models/SteamApp.php b/app/Models/SteamApp.php index a7d7ed28b..e709403cc 100644 --- a/app/Models/SteamApp.php +++ b/app/Models/SteamApp.php @@ -3,9 +3,11 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Laravel\Scout\Searchable; class SteamApp extends Model { + use Searchable; /** * @var bool */ @@ -25,4 +27,22 @@ class SteamApp extends Model * @var array */ protected $guarded = []; + + /** + * @return string + */ + public function searchableAs() + { + return 'ix_name_ft'; + } + + /** + * @return array + */ + public function toSearchableArray() + { + return [ + 'name' => $this->name, + ]; + } } diff --git a/composer.json b/composer.json index dff940626..2fdf815a6 100755 --- a/composer.json +++ b/composer.json @@ -137,6 +137,7 @@ "joshpinkney/tv-maze-php-api": "dev-master", "kevinlebrun/colors.php": "^1.0", "laravel/framework": "5.6.*", + "laravel/scout": "^4.0", "laravel/tinker": "~1.0", "mayconbordin/l5-fixtures": "dev-master", "monolog/monolog": "^1.22", @@ -151,6 +152,7 @@ "spatie/laravel-fractal": "^5.3", "vlucas/phpdotenv": "^2.4", "watson/rememberable": "^2.0", + "yab/laravel-scout-mysql-driver": "^2.0", "yadakhov/insert-on-duplicate-key": "^1.2" }, diff --git a/composer.lock b/composer.lock index f45f4ea79..1538983e8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "7187fa86d885704763fb2400be914368", + "content-hash": "785bb1a6b6af3e1cc5a701c691802bb7", "packages": [ { "name": "adrenth/thetvdb2", @@ -3299,6 +3299,71 @@ ], "time": "2018-02-22T19:21:38+00:00" }, + { + "name": "laravel/scout", + "version": "v4.0.1", + "source": { + "type": "git", + "url": "https://github.com/laravel/scout.git", + "reference": "28a88fa764cd2bf0225e427b067a024f7cbb5d4f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/scout/zipball/28a88fa764cd2bf0225e427b067a024f7cbb5d4f", + "reference": "28a88fa764cd2bf0225e427b067a024f7cbb5d4f", + "shasum": "" + }, + "require": { + "illuminate/bus": "~5.4", + "illuminate/contracts": "~5.4", + "illuminate/database": "~5.4", + "illuminate/pagination": "~5.4", + "illuminate/queue": "~5.4", + "illuminate/support": "~5.4", + "php": ">=7.0" + }, + "require-dev": { + "algolia/algoliasearch-client-php": "^1.10", + "mockery/mockery": "~1.0", + "phpunit/phpunit": "~6.0" + }, + "suggest": { + "algolia/algoliasearch-client-php": "Required to use the Algolia engine (^1.10)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Scout\\ScoutServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Scout\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel Scout provides a driver based solution to searching your Eloquent models.", + "keywords": [ + "algolia", + "laravel", + "search" + ], + "time": "2018-02-12T14:35:52+00:00" + }, { "name": "laravel/tinker", "version": "v1.0.3", @@ -6321,6 +6386,58 @@ ], "time": "2017-12-21T01:09:18+00:00" }, + { + "name": "yab/laravel-scout-mysql-driver", + "version": "v2.0.3", + "source": { + "type": "git", + "url": "https://github.com/YABhq/laravel-scout-mysql-driver.git", + "reference": "3f9cf88098265d36e158c595b25e3aa4a99e106d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/YABhq/laravel-scout-mysql-driver/zipball/3f9cf88098265d36e158c595b25e3aa4a99e106d", + "reference": "3f9cf88098265d36e158c595b25e3aa4a99e106d", + "shasum": "" + }, + "require": { + "laravel/framework": "5.3.*|5.4.*|5.5.*|5.6.*", + "laravel/scout": "^2.0|^3.0|^4.0", + "php": ">=5.6.4" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Yab\\MySQLScout\\Providers\\MySQLScoutServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Yab\\MySQLScout\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matt Lantz", + "email": "matt@yabhq.com" + }, + { + "name": "Damian Crisafulli", + "email": "damian.crisafulli@troyweb.com" + } + ], + "description": "MySQL driver for Laravel Scout.", + "time": "2018-02-17T11:47:40+00:00" + }, { "name": "yadakhov/insert-on-duplicate-key", "version": "v1.2.0",