|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TeamTNT\Scout; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
|
6
|
|
|
use Laravel\Scout\EngineManager; |
|
7
|
|
|
use TeamTNT\Scout\Console\ImportCommand; |
|
8
|
|
|
use TeamTNT\TNTSearch\TNTSearch; |
|
9
|
|
|
|
|
10
|
|
|
class TNTSearchScoutServiceProvider extends ServiceProvider |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Bootstrap any application services. |
|
14
|
|
|
* |
|
15
|
|
|
* @return void |
|
16
|
|
|
*/ |
|
17
|
|
|
public function boot() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->app[EngineManager::class]->extend('tntsearch', function () { |
|
20
|
|
|
$tnt = new TNTSearch(); |
|
21
|
|
|
$driver = config('database.default'); |
|
22
|
|
|
$config = config('scout.tntsearch') + config("database.connections.$driver"); |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
$tnt->loadConfig($config); |
|
26
|
|
|
$tnt->setDatabaseHandle(app('db')->connection()->getPdo()); |
|
27
|
|
|
$this->setFuzziness($tnt); |
|
28
|
|
|
$this->setAsYouType($tnt); |
|
29
|
|
|
|
|
30
|
|
|
return new Engines\TNTSearchEngine($tnt); |
|
31
|
|
|
}); |
|
32
|
|
|
|
|
33
|
|
|
if ($this->app->runningInConsole()) { |
|
|
|
|
|
|
34
|
|
|
$this->commands([ |
|
35
|
|
|
ImportCommand::class, |
|
36
|
|
|
]); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
private function setFuzziness($tnt) |
|
41
|
|
|
{ |
|
42
|
|
|
$fuzziness = config('scout.tntsearch.fuzziness'); |
|
43
|
|
|
$prefix_length = config('scout.tntsearch.fuzzy.prefix_length'); |
|
44
|
|
|
$max_expansions = config('scout.tntsearch.fuzzy.max_expansions'); |
|
45
|
|
|
$distance = config('scout.tntsearch.fuzzy.distance'); |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
$tnt->fuzziness = isset($fuzziness) ? $fuzziness : $tnt->fuzziness; |
|
49
|
|
|
$tnt->fuzzy_prefix_length = isset($prefix_length) ? $prefix_length : $tnt->fuzzy_prefix_length; |
|
50
|
|
|
$tnt->fuzzy_max_expansions = isset($max_expansions) ? $max_expansions : $tnt->fuzzy_max_expansions; |
|
51
|
|
|
$tnt->fuzzy_distance = isset($distance) ? $distance : $tnt->fuzzy_distance; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
private function setAsYouType($tnt) |
|
55
|
|
|
{ |
|
56
|
|
|
$asYouType = config('scout.tntsearch.asYouType'); |
|
57
|
|
|
|
|
58
|
|
|
$tnt->asYouType = isset($asYouType) ? $asYouType : $tnt->asYouType; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.