diff --git a/app/Actions/Coconut/SearchMolecule.php b/app/Actions/Coconut/SearchMolecule.php index 428801ca..bef124cb 100644 --- a/app/Actions/Coconut/SearchMolecule.php +++ b/app/Actions/Coconut/SearchMolecule.php @@ -2,6 +2,7 @@ namespace App\Actions\Coconut; +use App\Models\Citation; use App\Models\Collection; use App\Models\Molecule; use App\Models\Organism; @@ -26,6 +27,8 @@ class SearchMolecule public $organisms = null; + public $citations = null; + /** * Search based on given query. */ @@ -140,6 +143,8 @@ private function getFilterMap() 'subclass' => 'chemical_sub_class', 'superclass' => 'chemical_super_class', 'parent' => 'direct_parent_classification', + 'org' => 'organism', + 'cite' => 'ciatation', ]; } @@ -233,6 +238,18 @@ private function buildTagsStatement($offset) return Molecule::whereHas('organisms', function ($query) use ($organismIds) { $query->whereIn('organism_id', $organismIds); })->where('active', true)->where('is_parent', false)->orderBy('annotation_level', 'DESC')->paginate($this->size); + } elseif ($this->tagType == 'citations') { + $this->citations = array_map('strtolower', array_map('trim', explode(',', $this->query))); + $citationIds = Citation::where(function ($query) { + foreach ($this->citations as $name) { + $query->orWhereRaw('LOWER(doi) LIKE ?', ['%'.strtolower($name).'%']) + ->orWhereRaw('LOWER(title) LIKE ?', ['%'.strtolower($name).'%']); + } + })->pluck('id'); + + return Molecule::whereHas('citations', function ($query) use ($citationIds) { + $query->whereIn('citation_id', $citationIds); + })->where('active', true)->where('is_parent', false)->orderBy('annotation_level', 'DESC')->paginate($this->size); } else { return Molecule::withAnyTags([$this->query], $this->tagType)->where('active', true)->where('is_parent', false)->paginate($this->size); } diff --git a/app/Livewire/Search.php b/app/Livewire/Search.php index 745da0d5..998ea89d 100644 --- a/app/Livewire/Search.php +++ b/app/Livewire/Search.php @@ -37,6 +37,9 @@ class Search extends Component public $organisms = null; + #[Url(as: 'activeTab')] + public $activeTab = 'molecules'; + public function placeholder() { return <<<'HTML' diff --git a/resources/views/livewire/search.blade.php b/resources/views/livewire/search.blade.php index 889c3513..ab9152fe 100644 --- a/resources/views/livewire/search.blade.php +++ b/resources/views/livewire/search.blade.php @@ -1,4 +1,4 @@ -
+
@if ($tagType == 'dataSource' && $collection)
@@ -30,51 +30,188 @@ class="italic">{{ ucfirst($organism) }} @endif
-
-
-
-
-
-
-
-
-
-
+
+ + +
+ + + +
+ +
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+ + +
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+ + + + +
- +
+
+
-
- - +
+
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+ + + + +
+
+
+
+ +
+
-
+
- +
+ +
@if ($molecules && count($molecules) > 0)