chore: tweak
This commit is contained in:
parent
27b4240e89
commit
54148ab1ad
|
|
@ -40,7 +40,7 @@ return [
|
||||||
(new Flarum\SearchDriver(Search\ElasticSearchDriver::class))
|
(new Flarum\SearchDriver(Search\ElasticSearchDriver::class))
|
||||||
->addSearcher(FlarumDiscussion::class, Discussion\DiscussionSearcher::class)
|
->addSearcher(FlarumDiscussion::class, Discussion\DiscussionSearcher::class)
|
||||||
->addFilter(Discussion\DiscussionSearcher::class, Discussion\PrivateFilterMutator::class)
|
->addFilter(Discussion\DiscussionSearcher::class, Discussion\PrivateFilterMutator::class)
|
||||||
// ->addMutator(Discussion\DiscussionSearcher::class, Discussion\PrivateFilterMutator::mutate(...))
|
->addMutator(Discussion\DiscussionSearcher::class, Discussion\PrivateFilterMutator::mutate(...))
|
||||||
->setFulltext(Discussion\DiscussionSearcher::class, Discussion\FulltextFilter::class),
|
->setFulltext(Discussion\DiscussionSearcher::class, Discussion\FulltextFilter::class),
|
||||||
|
|
||||||
(new Flarum\SearchIndex())
|
(new Flarum\SearchIndex())
|
||||||
|
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Blomstra\Search\Elasticsearch;
|
|
||||||
|
|
||||||
use Spatie\ElasticsearchQueryBuilder\Aggregations\Aggregation;
|
|
||||||
|
|
||||||
class BucketSortAggregation extends Aggregation
|
|
||||||
{
|
|
||||||
protected array $fields = [];
|
|
||||||
protected ?int $size = null;
|
|
||||||
|
|
||||||
public static function create(string $name): self
|
|
||||||
{
|
|
||||||
return new static($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
protected string $name
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public function field(string $field, string $order = 'asc'): self
|
|
||||||
{
|
|
||||||
$this->fields[] = [$field => ['order' => $order]];
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function size(int $size): self
|
|
||||||
{
|
|
||||||
$this->size = $size;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function payload(): array
|
|
||||||
{
|
|
||||||
$parameters = [
|
|
||||||
'sort' => $this->fields,
|
|
||||||
];
|
|
||||||
|
|
||||||
if ($this->size) {
|
|
||||||
$parameters['size'] = $this->size;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'bucket_sort' => $parameters,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
<?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;
|
|
||||||
|
|
||||||
use Spatie\ElasticsearchQueryBuilder\Queries\Query;
|
|
||||||
|
|
||||||
class SimpleSearchQuery implements Query
|
|
||||||
{
|
|
||||||
protected float $boost = 1;
|
|
||||||
protected ?string $analyzer = null;
|
|
||||||
|
|
||||||
public static function create(array $field, string $value)
|
|
||||||
{
|
|
||||||
return new self($field, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function boost(float $boost = 1)
|
|
||||||
{
|
|
||||||
$this->boost = $boost;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function analyzer(string $analyzer)
|
|
||||||
{
|
|
||||||
$this->analyzer = $analyzer;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
protected array $fields,
|
|
||||||
protected string $value
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toArray(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'simple_query_string' => [
|
|
||||||
'query' => $this->value,
|
|
||||||
'fields' => $this->fields,
|
|
||||||
'analyzer' => $this->analyzer,
|
|
||||||
'default_operator' => 'AND',
|
|
||||||
'boost' => $this->boost,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Blomstra\Search\Elasticsearch;
|
|
||||||
|
|
||||||
use Spatie\ElasticsearchQueryBuilder\Aggregations\Aggregation;
|
|
||||||
use Spatie\ElasticsearchQueryBuilder\Aggregations\Concerns\WithMissing;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ported from spatie/elasticsearch-query-builder v2.1.0
|
|
||||||
* @link https://github.com/spatie/elasticsearch-query-builder/blob/main/src/Aggregations/SumAggregation.php
|
|
||||||
*/
|
|
||||||
class SumAggregation extends Aggregation
|
|
||||||
{
|
|
||||||
use WithMissing;
|
|
||||||
|
|
||||||
protected string $field;
|
|
||||||
|
|
||||||
public static function create(string $name, string $field): self
|
|
||||||
{
|
|
||||||
return new self($name, $field);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __construct(string $name, string $field)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
$this->field = $field;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function payload(): array
|
|
||||||
{
|
|
||||||
$parameters = [
|
|
||||||
'field' => $this->field,
|
|
||||||
];
|
|
||||||
|
|
||||||
if ($this->missing) {
|
|
||||||
$parameters['missing'] = $this->missing;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'sum' => $parameters,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue