Skip to content

Commit

Permalink
fix: display organisms list
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed Aug 11, 2024
1 parent b1246e6 commit e6763bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/Actions/Coconut/SearchMolecule.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function query($query, $size, $type, $sort, $tagType, $page)
}
}

return [$results, $this->collection];
return [$results, $this->collection, $this->organisms];

} catch (QueryException $exception) {

Expand Down Expand Up @@ -228,12 +228,14 @@ private function buildTagsStatement($offset)
return [];
}
} elseif ($this->tagType == 'organisms') {
$this->organisms = array_map('strtolower', array_map('trim', explode(',', $this->query)));
$organismIds = Organism::where(function ($query) {
$query_organisms = array_map('strtolower', array_map('trim', explode(',', $this->query)));
$this->organisms = Organism::where(function ($query) {
foreach ($this->organisms as $name) {
$query->orWhereRaw('LOWER(name) LIKE ?', ['%'.strtolower($name).'%']);
}
})->pluck('id');
});

$organismIds = $this->organisms->pluck('id');

return Molecule::whereHas('organisms', function ($query) use ($organismIds) {
$query->whereIn('organism_id', $organismIds);
Expand Down
1 change: 1 addition & 0 deletions app/Livewire/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function render(SearchMolecule $search)
try {
$results = $search->query($this->query, $this->size, $this->type, $this->sort, $this->tagType, $this->page);
$this->collection = $results[1];
$this->organisms = $results[2];

return view('livewire.search', [
'molecules' => $results[0],
Expand Down

0 comments on commit e6763bc

Please sign in to comment.