1
|
|
|
<?php namespace TeamTNT\Scout; |
2
|
|
|
|
3
|
|
|
use Engines\TNTSearchEngine; |
4
|
|
|
use TeamTNT\TNTSearch\TNTSearch; |
5
|
|
|
use Laravel\Scout\EngineManager; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use TeamTNT\Scout\Console\ImportCommand; |
8
|
|
|
|
9
|
|
|
class TNTSearchScoutServiceProvider extends ServiceProvider |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Bootstrap any application services. |
13
|
|
|
* |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
|
|
public function boot() |
17
|
|
|
{ |
18
|
|
|
$this->app[EngineManager::class]->extend('tntsearch', function ($app) { |
|
|
|
|
19
|
|
|
$tnt = new TNTSearch(); |
20
|
|
|
|
21
|
|
|
$driver = config('database.default'); |
22
|
|
|
$config = config('scout.tntsearch') + config("database.connections.{$driver}"); |
23
|
|
|
|
24
|
|
|
$tnt->loadConfig($config); |
25
|
|
|
$tnt->setDatabaseHandle(app('db')->connection()->getPdo()); |
26
|
|
|
|
27
|
|
|
$this->setFuzziness($tnt); |
28
|
|
|
$this->setAsYouType($tnt); |
29
|
|
|
|
30
|
|
|
return new TNTSearchEngine($tnt); |
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
if ($this->app->runningInConsole()) { |
34
|
|
|
$this->commands([ |
35
|
|
|
ImportCommand::class, |
36
|
|
|
]); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function setFuzziness($tnt) |
41
|
|
|
{ |
42
|
|
|
$tnt->fuzziness = config('scout.tntsearch.fuzziness', $tnt->fuzziness); |
43
|
|
|
$tnt->fuzzy_distance = config('scout.tntsearch.fuzzy.distance', $tnt->fuzzy_distance); |
44
|
|
|
$tnt->fuzzy_prefix_length = config('scout.tntsearch.fuzzy.prefix_length', $tnt->fuzzy_prefix_length); |
45
|
|
|
$tnt->fuzzy_max_expansions = config('scout.tntsearch.fuzzy.max_expansions', $tnt->fuzzy_max_expansions); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function setAsYouType($tnt) |
49
|
|
|
{ |
50
|
|
|
$tnt->asYouType = config('scout.tntsearch.asYouType', $tnt->asYouType); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.