introduce wildcard, needs further testing
This commit is contained in:
parent
0d51e5d912
commit
877533b43d
|
|
@ -4,6 +4,7 @@ namespace Blomstra\Search\Api\Controllers;
|
|||
|
||||
use Blomstra\Search\Elasticsearch\MatchPhraseQuery;
|
||||
use Blomstra\Search\Elasticsearch\MatchQuery;
|
||||
use Blomstra\Search\Elasticsearch\WildcardQuery;
|
||||
use Blomstra\Search\Save\Document as ElasticDocument;
|
||||
use Blomstra\Search\Elasticsearch\TermsQuery;
|
||||
use Elasticsearch\Client;
|
||||
|
|
@ -204,7 +205,10 @@ class SearchController extends ListDiscussionsController
|
|||
|
||||
protected function partialMatch(string $q)
|
||||
{
|
||||
return (new MatchQuery('content', "*$q*"))->boost(.2);
|
||||
return (new WildcardQuery('content', "*$q*"))
|
||||
->caseSensitivity(false)
|
||||
->rewrite('constant_score_boolean')
|
||||
->boost(.2);
|
||||
}
|
||||
|
||||
protected function getGroups(User $actor): Collection
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Blomstra\Search\Elasticsearch;
|
||||
|
||||
class WildcardQuery extends \Spatie\ElasticsearchQueryBuilder\Queries\WildcardQuery
|
||||
{
|
||||
protected float $boost = 1;
|
||||
protected bool $sensitivity = true;
|
||||
protected ?string $rewrite;
|
||||
|
||||
public function boost(float $boost = 1)
|
||||
{
|
||||
$this->boost = $boost;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function caseSensitivity(bool $sensitivity = true)
|
||||
{
|
||||
$this->sensitivity = $sensitivity;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function rewrite(string $rewrite = null)
|
||||
{
|
||||
$this->rewrite = $rewrite;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$query = parent::toArray();
|
||||
|
||||
$query['wildcard'][$this->field]['boost'] = $this->boost;
|
||||
$query['wildcard'][$this->field]['case_insensitive'] = ! $this->sensitivity;
|
||||
|
||||
if ($this->rewrite) {
|
||||
$query['wildcard'][$this->field]['rewrite'] = $this->rewrite;
|
||||
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue