diff --git a/app/Actions/Coconut/SearchMolecule.php b/app/Actions/Coconut/SearchMolecule.php index 02706143..8cd60f30 100644 --- a/app/Actions/Coconut/SearchMolecule.php +++ b/app/Actions/Coconut/SearchMolecule.php @@ -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) { @@ -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); diff --git a/app/Livewire/Search.php b/app/Livewire/Search.php index 998ea89d..04647bf8 100644 --- a/app/Livewire/Search.php +++ b/app/Livewire/Search.php @@ -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],