Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugin][search][content] give priority on result when title is matched #20197

Merged
merged 7 commits into from
Apr 29, 2018
21 changes: 18 additions & 3 deletions plugins/search/content/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,18 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu
$case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':');
$case_when1 .= ' ELSE ';
$case_when1 .= $c_id . ' END as catslug';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove tabs.

// Title priority
$case_whenp = ' CASE WHEN ';
$case_whenp .= $wheres2[0];
$case_whenp .= ' THEN 1 ';
$case_whenp .= ' ELSE 0 ';
$case_whenp .= ' END as priority';

$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')
->select($case_whenp)
->from('#__content AS a')
->join('INNER', '#__categories AS c ON c.id=a.catid')
->where(
Expand All @@ -286,7 +294,7 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu
. 'AND (a.publish_down = ' . $db->quote($nullDate) . ' OR a.publish_down >= ' . $db->quote($now) . ')'
)
->group('a.id, a.title, a.metadesc, a.metakey, a.created, a.language, a.catid, a.introtext, a.fulltext, c.title, a.alias, c.alias, c.id')
->order($order);
->order('priority DESC, ' . $order);

// Filter by language.
if ($app->isClient('site') && JLanguageMultilang::isEnabled())
Expand Down Expand Up @@ -342,11 +350,18 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu
$case_when1 .= ' ELSE ';
$case_when1 .= $c_id . ' END as catslug';

// Title priority
$case_whenp = ' CASE WHEN ';
$case_whenp .= $wheres2[0];
$case_whenp .= ' THEN 1 ';
$case_whenp .= ' ELSE 0 ';
$case_whenp .= ' END as priority';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove tab

$query->select(
'a.title AS title, a.metadesc, a.metakey, a.created AS created, '
. $query->concatenate(array('a.introtext', 'a.fulltext')) . ' AS text,'
. $case_when . ',' . $case_when1 . ', '
. 'c.title AS section, \'2\' AS browsernav'
. 'c.title AS section, \'2\' AS browsernav, ' . $case_whenp
);

// .'CONCAT_WS("/", c.title) AS section, \'2\' AS browsernav' );
Expand All @@ -358,7 +373,7 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu
. 'AND (a.publish_up = ' . $db->quote($nullDate) . ' OR a.publish_up <= ' . $db->quote($now) . ') '
. 'AND (a.publish_down = ' . $db->quote($nullDate) . ' OR a.publish_down >= ' . $db->quote($now) . ')'
)
->order($order);
->order('priority DESC, ' . $order);

// Join over Fields is no longer neded

Expand Down