Confusing Attributes in getSearchResults Method For Select From Field

I came across this code in filament v3
public function getSearchResults(string $search): array
{
if (! $this->getSearchResultsUsing) {
return [];
}

$results = $this->evaluate($this->getSearchResultsUsing, [
'query' => $search,
'search' => $search,
'searchQuery' => $search,
]);

if ($results instanceof Arrayable) {
$results = $results->toArray();
}

return $results;
}
public function getSearchResults(string $search): array
{
if (! $this->getSearchResultsUsing) {
return [];
}

$results = $this->evaluate($this->getSearchResultsUsing, [
'query' => $search,
'search' => $search,
'searchQuery' => $search,
]);

if ($results instanceof Arrayable) {
$results = $results->toArray();
}

return $results;
}
My question is why the query and search and searchQuery keys in the evaluate method have value of $search? this is confusing especially when I use query I expected a query builder not a search value. its need some refactoring on the values side or on the keys side of the array. Any suggestion or explanation for this part? I would suggest to make it look like this
public function getSearchResults(string $search): array
{
if (! $this->getSearchResultsUsing) {
return [];
}

$relationship = Relation::noConstraints(fn() => $this->getRelationship());

$relationshipQuery = app(RelationshipJoiner::class)->prepareQueryForNoConstraints($relationship);

$results = $this->evaluate($this->getSearchResultsUsing, [
'query' => $relationshipQuery,
'search' => $search,
]);

if ($results instanceof Arrayable) {
$results = $results->toArray();
}

return $results;
}
public function getSearchResults(string $search): array
{
if (! $this->getSearchResultsUsing) {
return [];
}

$relationship = Relation::noConstraints(fn() => $this->getRelationship());

$relationshipQuery = app(RelationshipJoiner::class)->prepareQueryForNoConstraints($relationship);

$results = $this->evaluate($this->getSearchResultsUsing, [
'query' => $relationshipQuery,
'search' => $search,
]);

if ($results instanceof Arrayable) {
$results = $results->toArray();
}

return $results;
}
Solution:
I would suggest to make it look like this
You can implement this in your code, right? I don't think the change will happen because it's a breaking change....
Jump to solution
3 Replies
Dennis Koch
Dennis Koch4d ago
My question is why the query and search and searchQuery keys in the evaluate method have value of $search?
I guess it's some kind of legacy. Maybe started with query but found search better and endedwith all 3 of them.
Solution
Dennis Koch
Dennis Koch4d ago
I would suggest to make it look like this
You can implement this in your code, right? I don't think the change will happen because it's a breaking change.
Hasan Tahseen
Hasan TahseenOP4d ago
Ok, Sounds good. thanks for the clarifications

Did you find this page helpful?