remove string binding

This commit is contained in:
Daniel Klabbers 2021-11-02 13:58:59 +01:00
parent 47fc5c2f1b
commit c04a9f9861
5 changed files with 8 additions and 19 deletions

View File

@ -35,15 +35,11 @@ class SearchController extends ListDiscussionsController
'createdAt' => 'created_at' 'createdAt' => 'created_at'
]; ];
public function __construct() public function __construct(protected Client $elastic)
{ {}
}
protected function data(ServerRequestInterface $request, Document $document) protected function data(ServerRequestInterface $request, Document $document)
{ {
/** @var Client $client */
$client = resolve('blomstra.search.elastic');
$type = Arr::get($request->getQueryParams(), 'type'); $type = Arr::get($request->getQueryParams(), 'type');
$actor = RequestUtil::getActor($request); $actor = RequestUtil::getActor($request);
@ -57,7 +53,7 @@ class SearchController extends ListDiscussionsController
BoolQuery::create() BoolQuery::create()
->add(MatchQuery::create('content', $filters['q'])) ->add(MatchQuery::create('content', $filters['q']))
); );
$builder = (new Builder($client)) $builder = (new Builder($this->client))
->index(resolve('blomstra.search.elastic_index')) ->index(resolve('blomstra.search.elastic_index'))
->size($this->extractLimit($request)) ->size($this->extractLimit($request))
->from($this->extractOffset($request)) ->from($this->extractOffset($request))

View File

@ -30,7 +30,7 @@ class RebuildDocumentsCommand extends Command
$queue = $container->make(Queue::class); $queue = $container->make(Queue::class);
/** @var Client $client */ /** @var Client $client */
$client = $container->make('blomstra.search.elastic'); $client = $container->make(Client::class);
/** @var SettingsRepositoryInterface $settings */ /** @var SettingsRepositoryInterface $settings */
$settings = $container->make(SettingsRepositoryInterface::class); $settings = $container->make(SettingsRepositoryInterface::class);

View File

@ -3,18 +3,14 @@
namespace Blomstra\Search\Jobs; namespace Blomstra\Search\Jobs;
use Elasticsearch\Client; use Elasticsearch\Client;
use Illuminate\Contracts\Container\Container;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class DeletingJob extends Job class DeletingJob extends Job
{ {
public function handle(Container $container) public function handle(Client $client)
{ {
if ($this->models->isEmpty()) return; if ($this->models->isEmpty()) return;
/** @var Client $client */
$client = $container->make('blomstra.search.elastic');
// Preparing body for storing. // Preparing body for storing.
$body = $this->models->map(function (Model $model) { $body = $this->models->map(function (Model $model) {
$document = $this->seeder->toDocument($model); $document = $this->seeder->toDocument($model);

View File

@ -3,18 +3,14 @@
namespace Blomstra\Search\Jobs; namespace Blomstra\Search\Jobs;
use Elasticsearch\Client; use Elasticsearch\Client;
use Illuminate\Contracts\Container\Container;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class SavingJob extends Job class SavingJob extends Job
{ {
public function handle(Container $container) public function handle(Client $client)
{ {
if ($this->models->isEmpty()) return; if ($this->models->isEmpty()) return;
/** @var Client $client */
$client = $container->make('blomstra.search.elastic');
// Preparing body for storing. // Preparing body for storing.
$body = $this->models->map(function (Model $model) { $body = $this->models->map(function (Model $model) {
$document = $this->seeder->toDocument($model); $document = $this->seeder->toDocument($model);

View File

@ -5,6 +5,7 @@ namespace Blomstra\Search;
use Blomstra\Search\Jobs\DeletingJob; use Blomstra\Search\Jobs\DeletingJob;
use Blomstra\Search\Jobs\SavingJob; use Blomstra\Search\Jobs\SavingJob;
use Blomstra\Search\Seeders; use Blomstra\Search\Seeders;
use Elasticsearch\Client;
use Elasticsearch\ClientBuilder; use Elasticsearch\ClientBuilder;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Settings\SettingsRepositoryInterface;
@ -26,7 +27,7 @@ class Provider extends AbstractServiceProvider
/** @var SettingsRepositoryInterface $settings */ /** @var SettingsRepositoryInterface $settings */
$settings = $this->container->make(SettingsRepositoryInterface::class); $settings = $this->container->make(SettingsRepositoryInterface::class);
$this->container->singleton('blomstra.search.elastic', function (Container $container) use ($settings) { $this->container->singleton(Client::class, function (Container $container) use ($settings) {
$builder = ClientBuilder::create() $builder = ClientBuilder::create()
->setHosts([$settings->get('blomstra-search.elastic-endpoint')]) ->setHosts([$settings->get('blomstra-search.elastic-endpoint')])
->setLogger($container->make(LoggerInterface::class)); ->setLogger($container->make(LoggerInterface::class));