diff --git a/plugins/search/content/content.php b/plugins/search/content/content.php index 6734c6ae129cb..7369712412aaf 100644 --- a/plugins/search/content/content.php +++ b/plugins/search/content/content.php @@ -91,6 +91,8 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu $wheres2[] = 'a.metakey LIKE ' . $text; $wheres2[] = 'a.metadesc LIKE ' . $text; + $relevance[] = ' CASE WHEN ' . $wheres2[0] . ' THEN 5 ELSE 0 END '; + // Join over Fields. $subQuery = $db->getQuery(true); $subQuery->select("cfv.item_id") @@ -146,6 +148,8 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu $wheres2[] = 'LOWER(a.metakey) LIKE LOWER(' . $word . ')'; $wheres2[] = 'LOWER(a.metadesc) LIKE LOWER(' . $word . ')'; + $relevance[] = ' CASE WHEN ' . $wheres2[0] . ' THEN 5 ELSE 0 END '; + if ($phrase === 'all') { // Join over Fields. @@ -274,6 +278,12 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu $case_when1 .= ' ELSE '; $case_when1 .= $c_id . ' END as catslug'; + if (!empty($relevance)) + { + $query->select(implode(' + ', $relevance) . ' AS relevance'); + $order = ' relevance DESC, ' . $order; + } + $query->select('a.title AS title, a.metadesc, a.metakey, a.created AS created, a.language, a.catid') ->select($query->concatenate(array('a.introtext', 'a.fulltext')) . ' AS text') ->select('c.title AS section, ' . $case_when . ',' . $case_when1 . ', ' . '\'2\' AS browsernav') @@ -342,6 +352,12 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu $case_when1 .= ' ELSE '; $case_when1 .= $c_id . ' END as catslug'; + if (!empty($relevance)) + { + $query->select(implode(' + ', $relevance) . ' AS relevance'); + $order = ' relevance DESC, ' . $order; + } + $query->select( 'a.title AS title, a.metadesc, a.metakey, a.created AS created, ' . $query->concatenate(array('a.introtext', 'a.fulltext')) . ' AS text,'