Skip to content

Commit

Permalink
fix: text search ordering added
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed Jun 3, 2024
1 parent beba591 commit 0ebb9b9
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions app/Livewire/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,22 @@ public function render()
} else {
if ($this->query) {
$this->query = str_replace("'", "''", $this->query);
$statement =
"select id, COUNT(*) OVER () from molecules WHERE (\"name\"::TEXT ILIKE '%".
$this->query.
"%') OR (\"synonyms\"::TEXT ILIKE '%".
$this->query.
"%') OR (\"identifier\"::TEXT ILIKE '%".
$this->query.
"%') limit ".
$this->size.
' offset '.
$offset;
$statement = "
SELECT id, COUNT(*) OVER ()
FROM molecules
WHERE
(\"name\"::TEXT ILIKE '%".$this->query."%')
OR (\"synonyms\"::TEXT ILIKE '%".$this->query."%')
OR (\"identifier\"::TEXT ILIKE '%".$this->query."%')
ORDER BY
CASE
WHEN \"name\"::TEXT ILIKE '%".$this->query."%' THEN 1
WHEN \"synonyms\"::TEXT ILIKE '%".$this->query."%' THEN 2
WHEN \"identifier\"::TEXT ILIKE '%".$this->query."%' THEN 3
ELSE 4
END
LIMIT ".$this->size.' OFFSET '.$offset;

} else {
$statement =
'select id, COUNT(*) OVER () from molecules ORDER BY annotation_level DESC limit '.
Expand Down

0 comments on commit 0ebb9b9

Please sign in to comment.