From 10711c4c59943c24b2125684808bbb40e83475b8 Mon Sep 17 00:00:00 2001 From: Sagar Date: Mon, 14 Oct 2024 16:45:01 +0200 Subject: [PATCH] feat: now the search allows for partial inchikey search --- app/Actions/Coconut/SearchMolecule.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Actions/Coconut/SearchMolecule.php b/app/Actions/Coconut/SearchMolecule.php index c360495b..7fd7c0de 100644 --- a/app/Actions/Coconut/SearchMolecule.php +++ b/app/Actions/Coconut/SearchMolecule.php @@ -73,11 +73,9 @@ public function query($query, $size, $type, $sort, $tagType, $page) } return [$results, $this->collection, $this->organisms]; - } catch (QueryException $exception) { return $this->handleException($exception); - } } @@ -89,6 +87,7 @@ private function determineQueryType($query) $patterns = [ 'inchi' => '/^((InChI=)?[^J][0-9BCOHNSOPrIFla+\-\(\)\\\\\/,pqbtmsih]{6,})$/i', 'inchikey' => '/^([0-9A-Z\-]{27})$/i', // Modified to ensure exact length + 'parttialinchikey' => '/^([A-Z]{14})$/i', 'smiles' => '/^([^J][0-9BCOHNSOPrIFla@+\-\[\]\(\)\\\\\/%=#$]{6,})$/i', ]; @@ -102,6 +101,8 @@ private function determineQueryType($query) return 'inchi'; } elseif ($type == 'inchikey' && substr($query, 14, 1) == '-' && strlen($query) == 27) { return 'inchikey'; + } elseif ($type == 'parttialinchikey' && strlen($query) == 14) { + return 'parttialinchikey'; } elseif ($type == 'smiles') { return 'smiles'; } @@ -179,6 +180,7 @@ private function buildStatement($queryType, $offset, $filterMap) break; case 'inchikey': + case 'parttialinchikey': $statement = "SELECT id, COUNT(*) OVER () FROM molecules WHERE standard_inchi_key LIKE '%{$this->query}%' @@ -330,7 +332,7 @@ private function buildDefaultStatement($offset) WHEN \"name\"::TEXT ILIKE '%{$this->query}%' THEN 4 WHEN \"synonyms\"::TEXT ILIKE '%{$this->query}%' THEN 5 WHEN \"identifier\"::TEXT ILIKE '%{$this->query}%' THEN 6 - ELSE 7 + ELSE 7 END LIMIT {$this->size} OFFSET {$offset}"; } else {