Apply fixes from StyleCI

This commit is contained in:
StyleCI Bot 2023-10-18 12:26:10 +00:00
parent 54148ab1ad
commit 69003373a9
No known key found for this signature in database
GPG Key ID: E4A5316DFBB23575
14 changed files with 148 additions and 38 deletions

View File

@ -22,7 +22,7 @@ return [
(new Flarum\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),
(new Flarum\Locales(__DIR__.'/resources/locale')),
new Flarum\Locales(__DIR__.'/resources/locale'),
(new Flarum\ServiceProvider())
->register(Provider::class),

View File

@ -12,6 +12,7 @@
namespace Blomstra\Search\Api\Controllers;
use Blomstra\Search\Elasticsearch\Builder;
use Blomstra\Search\Elasticsearch\MatchPhraseQuery;
use Blomstra\Search\Elasticsearch\MatchQuery;
use Blomstra\Search\Elasticsearch\TermsQuery;
@ -32,7 +33,6 @@ use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Psr\Http\Message\ServerRequestInterface;
use Blomstra\Search\Elasticsearch\Builder;
use Spatie\ElasticsearchQueryBuilder\Queries\BoolQuery;
use Spatie\ElasticsearchQueryBuilder\Queries\Query;
use Spatie\ElasticsearchQueryBuilder\Queries\TermQuery;

View File

@ -13,6 +13,7 @@
namespace Blomstra\Search\Commands;
use Blomstra\Search\Discussion\DiscussionIndexer;
use Blomstra\Search\Elasticsearch\Builder;
use Blomstra\Search\Post\CommentPostIndexer;
use Elasticsearch\Client;
use Flarum\Discussion\Discussion;
@ -24,7 +25,6 @@ use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Queue\Queue;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Arr;
use Blomstra\Search\Elasticsearch\Builder;
use Spatie\ElasticsearchQueryBuilder\Queries\BoolQuery;
use Spatie\ElasticsearchQueryBuilder\Queries\RangeQuery;
@ -45,11 +45,11 @@ class BuildCommand extends Command
{
$indexers = [
'discussions' => DiscussionIndexer::class,
'posts' => CommentPostIndexer::class,
'posts' => CommentPostIndexer::class,
];
$models = [
'discussions' => Discussion::class,
'posts' => Post::class,
'posts' => Post::class,
];
$only = $this->option('only');
@ -72,7 +72,7 @@ class BuildCommand extends Command
}
// Create the index.
if (! $this->option('recreate') && $this->option('mapping')) {
if (!$this->option('recreate') && $this->option('mapping')) {
$client->indices()->putMapping([
'index' => $indexer::index(),
'body' => $properties,

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\Discussion;
use Blomstra\Search\Save\Document;
@ -34,12 +44,12 @@ class DiscussionIndexer implements IndexerInterface
$this->elastic->delete(self::index(), $models);
}
function build(): void
public function build(): void
{
$this->elastic->build(self::index(), $this->properties());
}
function flush(): void
public function flush(): void
{
$this->elastic->flush(self::index());
}

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\Discussion;
use Blomstra\Search\Post\CommentPostIndexer;
@ -12,10 +22,10 @@ class DiscussionSearcher extends Searcher
{
public function index(): string
{
return DiscussionIndexer::index() . ',' . CommentPostIndexer::index();
return DiscussionIndexer::index().','.CommentPostIndexer::index();
}
function getQuery(User $actor): Builder
public function getQuery(User $actor): Builder
{
return Discussion::whereVisibleTo($actor)->select('discussions.*');
}

View File

@ -1,7 +1,18 @@
<?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\Discussion;
use Blomstra\Search\Elasticsearch\Builder;
use Blomstra\Search\Elasticsearch\MatchPhraseQuery;
use Blomstra\Search\Elasticsearch\MatchQuery;
use Blomstra\Search\Elasticsearch\TermsQuery;
@ -19,7 +30,6 @@ use Illuminate\Support\Collection;
use Spatie\ElasticsearchQueryBuilder\Aggregations\FilterAggregation;
use Spatie\ElasticsearchQueryBuilder\Aggregations\TermsAggregation;
use Spatie\ElasticsearchQueryBuilder\Aggregations\TopHitsAggregation;
use Blomstra\Search\Elasticsearch\Builder;
use Spatie\ElasticsearchQueryBuilder\Queries\BoolQuery;
use Spatie\ElasticsearchQueryBuilder\Queries\Query;
use Spatie\ElasticsearchQueryBuilder\Sorts\Sort;
@ -81,17 +91,17 @@ class FulltextFilter extends AbstractFulltextFilter
$state->retrieveDatabaseRecordsUsing(function (array $response, SearchCriteria $criteria): Collection {
$buckets = Collection::make(Arr::get($response, 'aggregations.posts.per_discussion.buckets'))
->map(fn (array $hit) => [
'discussion_id' => $hit['key'],
'most_relevant_post_id' => Arr::get($hit, 'most_relevant_post_id.most_relevant_post_id.hits.hits.0._id'),
'discussion_id' => $hit['key'],
'most_relevant_post_id' => Arr::get($hit, 'most_relevant_post_id.most_relevant_post_id.hits.hits.0._id'),
'most_relevant_post_score' => Arr::get($hit, 'most_relevant_post_id.most_relevant_post_id.hits.hits.0._score'),
])->keyBy('discussion_id');
$results = Collection::make(Arr::get($response, 'hits.hits'))
->map(fn (array $hit) => [
'discussion_id' => $hit['_source']['discussion_id'],
'most_relevant_post_id' => Arr::get($buckets->get($hit['_source']['discussion_id']), 'most_relevant_post_id'),
'discussion_id' => $hit['_source']['discussion_id'],
'most_relevant_post_id' => Arr::get($buckets->get($hit['_source']['discussion_id']), 'most_relevant_post_id'),
'most_relevant_post_score' => Arr::get($buckets->get($hit['_source']['discussion_id']), 'most_relevant_post_score'),
'title_score' => $hit['_score'],
'title_score' => $hit['_score'],
])->keyBy('discussion_id');
// We have $hits and $buckets, both are sorted by score.
@ -122,17 +132,17 @@ class FulltextFilter extends AbstractFulltextFilter
->select('discussions.*')
->selectRaw(
$connection->raw('COALESCE(('.$connection->getQueryGrammar()->compileSelect(
$postsQuery = Post::query()
->select('posts.id')
->whereIn('posts.id', $results->pluck('most_relevant_post_id')->filter())
->whereColumn('discussions.id', '=', 'posts.discussion_id')
->limit(1)
->toBase()
).'), first_post_id) as most_relevant_post_id')->getValue($connection->getQueryGrammar())
$postsQuery = Post::query()
->select('posts.id')
->whereIn('posts.id', $results->pluck('most_relevant_post_id')->filter())
->whereColumn('discussions.id', '=', 'posts.discussion_id')
->limit(1)
->toBase()
).'), first_post_id) as most_relevant_post_id')->getValue($connection->getQueryGrammar())
)
->mergeBindings($postsQuery)
->whereIn('discussions.id', $results->pluck('discussion_id'))
->orderByRaw('FIELD(`discussions`.`id`, ' . implode(',', $results->pluck('discussion_id')->all()) . ')')
->orderByRaw('FIELD(`discussions`.`id`, '.implode(',', $results->pluck('discussion_id')->all()).')')
->get();
});
}

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\Discussion;
use Blomstra\Search\Elasticsearch\TermsQuery;
@ -33,7 +43,7 @@ class PrivateFilterMutator implements FilterInterface
{
$actor = $state->getActor();
if (! $this->extensions->isEnabled('fof-byobu') || $actor->isGuest()) {
if (!$this->extensions->isEnabled('fof-byobu') || $actor->isGuest()) {
return;
}

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\Elasticsearch;
class Builder extends \Spatie\ElasticsearchQueryBuilder\Builder

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\Post;
use Blomstra\Search\Save\Document;
@ -25,7 +35,7 @@ class CommentPostIndexer implements IndexerInterface
return 'posts';
}
function save(array $models): void
public function save(array $models): void
{
$this->elastic->save(
self::index(),
@ -34,7 +44,7 @@ class CommentPostIndexer implements IndexerInterface
);
}
function delete(array $models): void
public function delete(array $models): void
{
$this->elastic->delete(
self::index(),

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\Search\Concerns;
use Flarum\Discussion\Discussion;

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\Search;
use Blomstra\Search\Exceptions\IndexingException;
@ -29,8 +39,8 @@ class ElasticIndex
[
'index' => [
'_index' => $index,
'_id' => $document->id
]
'_id' => $document->id,
],
],
$document->toArray(),
];
@ -55,8 +65,8 @@ class ElasticIndex
[
'delete' => [
'_index' => $index(),
'_id' => $model->id
]
'_id' => $model->id,
],
],
];
})->flatten(1);

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\Search;
use Flarum\Search\AbstractDriver;

View File

@ -1,10 +1,20 @@
<?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\Search;
use Blomstra\Search\Elasticsearch\Builder;
use Closure;
use Flarum\Search\SearchState;
use Blomstra\Search\Elasticsearch\Builder;
class ElasticSearchState extends SearchState
{

View File

@ -1,7 +1,18 @@
<?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\Search;
use Blomstra\Search\Elasticsearch\Builder;
use Elasticsearch\Client;
use Flarum\Search\Filter\FilterManager;
use Flarum\Search\SearchCriteria;
@ -10,7 +21,6 @@ use Flarum\Search\SearchResults;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Blomstra\Search\Elasticsearch\Builder;
use Spatie\ElasticsearchQueryBuilder\Sorts\Sort;
abstract class Searcher implements SearcherInterface
@ -43,8 +53,8 @@ abstract class Searcher implements SearcherInterface
$id = Str::after($hit['_source']['id'], "$type:");
return [
'id' => $id,
'score' => Arr::get($hit, '_score'),
'id' => $id,
'score' => Arr::get($hit, '_score'),
'weight' => Arr::get($hit, 'sort.0'),
];
})->sortByDesc('weight');
@ -56,7 +66,7 @@ abstract class Searcher implements SearcherInterface
return $this->getQuery($criteria->actor)
->whereIn('id', $ids)
->orderByRaw('FIELD(id, ' . implode(',', $ids) . ')')
->orderByRaw('FIELD(id, '.implode(',', $ids).')')
->get();
});
@ -81,7 +91,7 @@ abstract class Searcher implements SearcherInterface
$callback = $state->getRetrieveDatabaseRecordsUsing();
if (! $callback) {
if (!$callback) {
throw new \RuntimeException('No callback set to retrieve database records');
}
@ -94,7 +104,7 @@ abstract class Searcher implements SearcherInterface
{
$sort = $criteria->sort;
if ($criteria->sortIsDefault && ! empty($state->getDefaultSort())) {
if ($criteria->sortIsDefault && !empty($state->getDefaultSort())) {
$sort = $state->getDefaultSort();
}