fix issues with discussion search
This commit is contained in:
parent
d0c4eb615a
commit
33ae86a539
|
|
@ -17,8 +17,6 @@ use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Spatie\ElasticsearchQueryBuilder\Aggregations\TermsAggregation;
|
|
||||||
use Spatie\ElasticsearchQueryBuilder\Aggregations\TopHitsAggregation;
|
|
||||||
use Spatie\ElasticsearchQueryBuilder\Builder;
|
use Spatie\ElasticsearchQueryBuilder\Builder;
|
||||||
use Spatie\ElasticsearchQueryBuilder\Queries\BoolQuery;
|
use Spatie\ElasticsearchQueryBuilder\Queries\BoolQuery;
|
||||||
use Spatie\ElasticsearchQueryBuilder\Queries\MatchQuery;
|
use Spatie\ElasticsearchQueryBuilder\Queries\MatchQuery;
|
||||||
|
|
@ -59,12 +57,7 @@ class SearchController extends ListDiscussionsController
|
||||||
->from($this->extractOffset($request))
|
->from($this->extractOffset($request))
|
||||||
->addQuery(
|
->addQuery(
|
||||||
$this->addFilters($filterQuery, $actor)
|
$this->addFilters($filterQuery, $actor)
|
||||||
)
|
);
|
||||||
// ->addAggregation(
|
|
||||||
// TermsAggregation::create('discussions', 'discussion_id')
|
|
||||||
// ->aggregation(TopHitsAggregation::create('hits', 1))
|
|
||||||
// )
|
|
||||||
;
|
|
||||||
|
|
||||||
foreach ($this->extractSort($request) as $field => $direction) {
|
foreach ($this->extractSort($request) as $field => $direction) {
|
||||||
$field = $this->translateSort[$field] ?? $field;
|
$field = $this->translateSort[$field] ?? $field;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
namespace Blomstra\Search\Jobs;
|
namespace Blomstra\Search\Jobs;
|
||||||
|
|
||||||
|
use Blomstra\Search\Exceptions\SeedingException;
|
||||||
use Elasticsearch\Client;
|
use Elasticsearch\Client;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class SavingJob extends Job
|
class SavingJob extends Job
|
||||||
{
|
{
|
||||||
|
|
@ -27,5 +29,16 @@ class SavingJob extends Job
|
||||||
'body' => $body->toArray(),
|
'body' => $body->toArray(),
|
||||||
'refresh' => true
|
'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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class DiscussionSeeder extends Seeder
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->extensionEnabled('flarum-sticky')) {
|
if ($this->extensionEnabled('flarum-sticky')) {
|
||||||
$document['is_sticky'] = $model->is_sticky;
|
$document['is_sticky'] = (bool) $model->is_sticky;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $document;
|
return $document;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue