diff --git a/extend.php b/extend.php index 0efc381..ace56c8 100644 --- a/extend.php +++ b/extend.php @@ -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), ]; diff --git a/src/Api/Controllers/SearchController.php b/src/Api/Controllers/SearchController.php index e563ec0..a0c91e3 100644 --- a/src/Api/Controllers/SearchController.php +++ b/src/Api/Controllers/SearchController.php @@ -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 (!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')); + } } $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() diff --git a/src/Provider.php b/src/Provider.php index 687011d..f8f45b2 100644 --- a/src/Provider.php +++ b/src/Provider.php @@ -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; diff --git a/src/Searchers/CommentPostSearcher.php b/src/Searchers/CommentPostSearcher.php index a2f575b..73bbe78 100644 --- a/src/Searchers/CommentPostSearcher.php +++ b/src/Searchers/CommentPostSearcher.php @@ -1,5 +1,15 @@ 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