Apply fixes from StyleCI
This commit is contained in:
parent
83afe95d61
commit
8b519619e5
|
|
@ -27,10 +27,10 @@ return [
|
||||||
(new Flarum\Routes('api'))
|
(new Flarum\Routes('api'))
|
||||||
->get('/blomstra/search/{type}', 'blomstra.search', Api\Controllers\SearchController::class)
|
->get('/blomstra/search/{type}', 'blomstra.search', Api\Controllers\SearchController::class)
|
||||||
->put('/blomstra/search/index', 'blomstra.search.index', Api\Controllers\IndexController::class),
|
->put('/blomstra/search/index', 'blomstra.search.index', Api\Controllers\IndexController::class),
|
||||||
(new Flarum\Console)
|
(new Flarum\Console())
|
||||||
->command(Commands\BuildCommand::class),
|
->command(Commands\BuildCommand::class),
|
||||||
|
|
||||||
(new Flarum\Settings)
|
(new Flarum\Settings())
|
||||||
->default('blomstra-search.search-discussion-subjects', true)
|
->default('blomstra-search.search-discussion-subjects', true)
|
||||||
->default('blomstra-search.search-post-bodies', true)
|
->default('blomstra-search.search-post-bodies', true),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ class SearchController extends ListDiscussionsController
|
||||||
protected function gatherSearchers(iterable $searchers)
|
protected function gatherSearchers(iterable $searchers)
|
||||||
{
|
{
|
||||||
return collect($searchers)
|
return collect($searchers)
|
||||||
->map(fn ($searcher) => new $searcher)
|
->map(fn ($searcher) => new $searcher())
|
||||||
->filter(fn (Searcher $searcher) => $searcher->enabled());
|
->filter(fn (Searcher $searcher) => $searcher->enabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,11 +86,16 @@ class SearchController extends ListDiscussionsController
|
||||||
|
|
||||||
$filterQuery = BoolQuery::create();
|
$filterQuery = BoolQuery::create();
|
||||||
|
|
||||||
|
if (!empty($search)) {
|
||||||
if (! empty($search)) {
|
if ($this->matchSentences) {
|
||||||
if ($this->matchSentences) $filterQuery->add($this->sentenceMatch($search));
|
$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->matchWords) {
|
||||||
|
$filterQuery->add($this->wordMatch($search, 'and'));
|
||||||
|
}
|
||||||
|
if ($this->matchWords) {
|
||||||
|
$filterQuery->add($this->wordMatch($search, 'or'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$builder = (new Builder($this->elastic))
|
$builder = (new Builder($this->elastic))
|
||||||
|
|
@ -248,11 +253,11 @@ class SearchController extends ListDiscussionsController
|
||||||
|
|
||||||
protected function boolQuery(Query $parent, float $boost = 1): Query
|
protected function boolQuery(Query $parent, float $boost = 1): Query
|
||||||
{
|
{
|
||||||
$bool = new BoolQuery;
|
$bool = new BoolQuery();
|
||||||
|
|
||||||
/** @var Searcher $searcher */
|
/** @var Searcher $searcher */
|
||||||
foreach ($this->searchers as $searcher) {
|
foreach ($this->searchers as $searcher) {
|
||||||
$searcher = new $searcher;
|
$searcher = new $searcher();
|
||||||
|
|
||||||
$bool->add(
|
$bool->add(
|
||||||
BoolQuery::create()
|
BoolQuery::create()
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ namespace Blomstra\Search;
|
||||||
use Blomstra\Search\Jobs\DeletingJob;
|
use Blomstra\Search\Jobs\DeletingJob;
|
||||||
use Blomstra\Search\Jobs\Job;
|
use Blomstra\Search\Jobs\Job;
|
||||||
use Blomstra\Search\Jobs\SavingJob;
|
use Blomstra\Search\Jobs\SavingJob;
|
||||||
use Blomstra\Search\Searchers;
|
|
||||||
use Blomstra\Search\Seeders;
|
|
||||||
use Elasticsearch\Client as Elastic;
|
use Elasticsearch\Client as Elastic;
|
||||||
use Elasticsearch\ClientBuilder;
|
use Elasticsearch\ClientBuilder;
|
||||||
use Flarum\Api\Client;
|
use Flarum\Api\Client;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,15 @@
|
||||||
<?php
|
<?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;
|
namespace Blomstra\Search\Searchers;
|
||||||
|
|
||||||
use Blomstra\Search\Seeders\CommentSeeder;
|
use Blomstra\Search\Seeders\CommentSeeder;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,15 @@
|
||||||
<?php
|
<?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;
|
namespace Blomstra\Search\Searchers;
|
||||||
|
|
||||||
use Blomstra\Search\Seeders\DiscussionSeeder;
|
use Blomstra\Search\Seeders\DiscussionSeeder;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,15 @@
|
||||||
<?php
|
<?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;
|
namespace Blomstra\Search\Searchers;
|
||||||
|
|
||||||
use Blomstra\Search\Seeders\Seeder;
|
use Blomstra\Search\Seeders\Seeder;
|
||||||
|
|
@ -14,9 +24,11 @@ abstract class Searcher
|
||||||
/** @var Seeder $seeder */
|
/** @var Seeder $seeder */
|
||||||
$seeder = $this->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
|
public function enabled(): bool
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue