Tuesday, March 20, 2012

Extending Joomla Article Search

The following tutorial will let you know how to extend joomla's default search to add fields of content that are not searched by default, for example 'created_by_alias'. The files mentioned are from Joomla 2.5, previous versions will be quite same.

Following are the things you need to do:
File: plugins\search\content\content.php

You have to add the field in two places, the 'select', and 'where', to add to 'where' look for swtich option at line 73 having cases 'exact' and then below 'all'/'default', add a line for your field like:
$wheres2[] = 'a.created_by_alias LIKE '.$word;


Then moving to 'select' fields like in line 153 and 210:
$query->select('a.title AS title, a.metadesc, a.metakey, a.created AS created');


and add your field like
$query->select('a.title AS title, a.created_by_alias, a.metadesc, a.metakey, a.created AS created');

And finally you need to add your field in the function "searchHelper::checkNoHTML" at the end of the file:
searchHelper::checkNoHTML($article, $searchText, array('text', 'title','metadesc', 'metakey')
to
searchHelper::checkNoHTML($article, $searchText, array('text', 'title','created_by_alias', 'metadesc', 'metakey')



1 comment: