Apply fixes from StyleCI

This commit is contained in:
StyleCI Bot 2022-11-24 09:38:21 +00:00
parent 83afe95d61
commit 8b519619e5
No known key found for this signature in database
GPG Key ID: E498B15EE66C8CB3
6 changed files with 50 additions and 15 deletions

View File

@ -27,10 +27,10 @@ return [
(new Flarum\Routes('api'))
->get('/blomstra/search/{type}', 'blomstra.search', Api\Controllers\SearchController::class)
->put('/blomstra/search/index', 'blomstra.search.index', Api\Controllers\IndexController::class),
(new Flarum\Console)
(new Flarum\Console())
->command(Commands\BuildCommand::class),
(new Flarum\Settings)
(new Flarum\Settings())
->default('blomstra-search.search-discussion-subjects', true)
->default('blomstra-search.search-post-bodies', true)
->default('blomstra-search.search-post-bodies', true),
];

View File

@ -64,7 +64,7 @@ class SearchController extends ListDiscussionsController
protected function gatherSearchers(iterable $searchers)
{
return collect($searchers)
->map(fn ($searcher) => new $searcher)
->map(fn ($searcher) => new $searcher())
->filter(fn (Searcher $searcher) => $searcher->enabled());
}
@ -86,11 +86,16 @@ class SearchController extends ListDiscussionsController
$filterQuery = BoolQuery::create();
if (!empty($search)) {
if ($this->matchSentences) $filterQuery->add($this->sentenceMatch($search));
if ($this->matchWords) $filterQuery->add($this->wordMatch($search, 'and'));
if ($this->matchWords) $filterQuery->add($this->wordMatch($search, 'or'));
if ($this->matchSentences) {
$filterQuery->add($this->sentenceMatch($search));
}
if ($this->matchWords) {
$filterQuery->add($this->wordMatch($search, 'and'));
}
if ($this->matchWords) {
$filterQuery->add($this->wordMatch($search, 'or'));
}
}
$builder = (new Builder($this->elastic))
@ -248,11 +253,11 @@ class SearchController extends ListDiscussionsController
protected function boolQuery(Query $parent, float $boost = 1): Query
{
$bool = new BoolQuery;
$bool = new BoolQuery();
/** @var Searcher $searcher */
foreach ($this->searchers as $searcher) {
$searcher = new $searcher;
$searcher = new $searcher();
$bool->add(
BoolQuery::create()

View File

@ -15,8 +15,6 @@ namespace Blomstra\Search;
use Blomstra\Search\Jobs\DeletingJob;
use Blomstra\Search\Jobs\Job;
use Blomstra\Search\Jobs\SavingJob;
use Blomstra\Search\Searchers;
use Blomstra\Search\Seeders;
use Elasticsearch\Client as Elastic;
use Elasticsearch\ClientBuilder;
use Flarum\Api\Client;

View File

@ -1,5 +1,15 @@
<?php
/*
* This file is part of blomstra/search.
*
* Copyright (c) 2022 Blomstra Ltd.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*
*/
namespace Blomstra\Search\Searchers;
use Blomstra\Search\Seeders\CommentSeeder;

View File

@ -1,5 +1,15 @@
<?php
/*
* This file is part of blomstra/search.
*
* Copyright (c) 2022 Blomstra Ltd.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*
*/
namespace Blomstra\Search\Searchers;
use Blomstra\Search\Seeders\DiscussionSeeder;

View File

@ -1,5 +1,15 @@
<?php
/*
* This file is part of blomstra/search.
*
* Copyright (c) 2022 Blomstra Ltd.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*
*/
namespace Blomstra\Search\Searchers;
use Blomstra\Search\Seeders\Seeder;
@ -14,9 +24,11 @@ abstract class Searcher
/** @var Seeder $seeder */
$seeder = $this->seeder;
if (empty($seeder)) throw new \InvalidArgumentException("Implement type or add \$seeder");
if (empty($seeder)) {
throw new \InvalidArgumentException('Implement type or add $seeder');
}
return (new $seeder)->type();
return (new $seeder())->type();
}
public function enabled(): bool