can anyone tell me if im going in the right direction??
<?php
//Add Username search function to the search engine
function cust_search_keyword_wildcard_with_user_username($params) {
if ($params['sPattern']) {
$mSearch = Search::newInstance();
$query_elements = (array) json_decode($mSearch->toJson());
$pattern = $query_elements['sPattern'];
$query_elements['sPattern'] = str_replace(' ', '* ', $pattern) . '*';
$mSearch->setJsonAlert($query_elements);
// Search by user.Username too
$mSearch->addJoinTable(count($query_elements['tables_join']), DB_TABLE_PREFIX."t_user u", "fk_i_user_id = u.pk_i_id", 'INNER');
$aPattern = explode(' ', $pattern);
$userNameCond = '';
$userItemCond = '';
foreach ($aPattern as $word) {
if ($word) $userNameCond .= sprintf(" || u.s_username = '%s'", $word);
}
foreach ($aPattern as $item) {
if ($item) $userItemCond .= sprintf(" || t_item_description.fk_i_item_id = '%s'", $item);
}
$mSearch->addConditions("1 = 1 " . $userNameCond);
$mSearch->addConditions("1 = 1 " . $userItemCond);
$mSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
}
}
osc_add_hook('search_conditions', 'cust_search_keyword_wildcard_with_user_username', 1);
?>
thanks