fix issues with discussion search

This commit is contained in:
Daniel Klabbers 2021-11-04 10:01:54 +01:00
parent d0c4eb615a
commit 33ae86a539
4 changed files with 29 additions and 9 deletions

View File

@ -17,8 +17,6 @@ use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Psr\Http\Message\ServerRequestInterface;
use Spatie\ElasticsearchQueryBuilder\Aggregations\TermsAggregation;
use Spatie\ElasticsearchQueryBuilder\Aggregations\TopHitsAggregation;
use Spatie\ElasticsearchQueryBuilder\Builder;
use Spatie\ElasticsearchQueryBuilder\Queries\BoolQuery;
use Spatie\ElasticsearchQueryBuilder\Queries\MatchQuery;
@ -59,12 +57,7 @@ class SearchController extends ListDiscussionsController
->from($this->extractOffset($request))
->addQuery(
$this->addFilters($filterQuery, $actor)
)
// ->addAggregation(
// TermsAggregation::create('discussions', 'discussion_id')
// ->aggregation(TopHitsAggregation::create('hits', 1))
// )
;
);
foreach ($this->extractSort($request) as $field => $direction) {
$field = $this->translateSort[$field] ?? $field;

View File

@ -0,0 +1,14 @@
<?php
namespace Blomstra\Search\Exceptions;
use Throwable;
class SeedingException extends \Exception
{
public function __construct($message = "", public array $items, $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

View File

@ -2,8 +2,10 @@
namespace Blomstra\Search\Jobs;
use Blomstra\Search\Exceptions\SeedingException;
use Elasticsearch\Client;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
class SavingJob extends Job
{
@ -27,5 +29,16 @@ class SavingJob extends Job
'body' => $body->toArray(),
'refresh' => true
]);
if (Arr::get($response, 'errors') !== true) return true;
$items = Arr::get($response, 'items');
$error = Arr::get(Arr::first($items), 'index.error.reason');
throw new SeedingException(
"Failed to seed: $error",
$items
);
}
}

View File

@ -62,7 +62,7 @@ class DiscussionSeeder extends Seeder
}
if ($this->extensionEnabled('flarum-sticky')) {
$document['is_sticky'] = $model->is_sticky;
$document['is_sticky'] = (bool) $model->is_sticky;
}
return $document;