Skip to content

Commit

Permalink
Added full text search options as the second argument to the SearchUs…
Browse files Browse the repository at this point in the history
…ingFullText attribute.

Removed the SearchUsingOptions attribute.
  • Loading branch information
den1n committed Mar 21, 2022
1 parent 9cd187e commit dc50d37
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
8 changes: 7 additions & 1 deletion src/Attributes/SearchUsingFullText.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ class SearchUsingFullText
*/
public $columns = [];

/**
* The full-text options.
*/
public $options = [];

/**
* Create a new attribute instance.
*
* @param array|string $columns
* @return void
*/
public function __construct($columns)
public function __construct($columns, $options = [])
{
$this->columns = Arr::wrap($columns);
$this->options = Arr::wrap($options);
}
}
23 changes: 0 additions & 23 deletions src/Attributes/SearchUsingOptions.php

This file was deleted.

15 changes: 12 additions & 3 deletions src/Engines/DatabaseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,23 @@ protected function getAttributeColumns(Builder $builder, $attributeClass)

/**
* Get the full-text search options for the query.
*
* @param \Laravel\Scout\Builder $builder
* @return array
*/
protected function getFullTextOptions(Builder $builder)
{
$reflection = new ReflectionMethod($builder->model, 'toSearchableArray');
$options = [];

if ($attribute = collect($reflection->getAttributes(SearchUsingOptions::class))->first()) {
return collect($attribute->getArguments())->first();
if (PHP_MAJOR_VERSION < 8) {
return [];
}

foreach ((new ReflectionMethod($builder->model, 'toSearchableArray'))->getAttributes(SearchUsingFullText::class) as $attribute) {
$columns = array_merge($options, Arr::wrap($attribute->getArguments()[1]));
}

return $columns;
}

/**
Expand Down

0 comments on commit dc50d37

Please sign in to comment.