Use laravel scout to search fulltext indexes

This commit is contained in:
DariusIII
2018-02-23 10:39:29 +01:00
parent ab8699efc8
commit e07f3f5584
16 changed files with 261 additions and 14 deletions
+3
View File
@@ -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
+5 -4
View File
@@ -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) {
+3 -2
View File
@@ -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();
}
/**
+1 -4
View File
@@ -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;
+1 -1
View File
@@ -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();
}
/**
+1 -1
View File
@@ -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]) {
+1 -1
View File
@@ -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;
+2
View File
@@ -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
+22
View File
@@ -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,
];
}
}
+19
View File
@@ -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,
];
}
}
+21
View File
@@ -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,
];
}
}
+21
View File
@@ -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,
];
}
}
+21
View File
@@ -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,
];
}
}
+20
View File
@@ -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,
];
}
}
+2
View File
@@ -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"
},
Generated
+118 -1
View File
@@ -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",