<?php//Add Username search function to the search enginefunction 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']; $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 = ''; foreach ($aPattern as $word) { if ($word) $userNameCond .= sprintf(" || u.s_username = '%s'", $word); } $mSearch->addConditions("1 = 1 " . $userNameCond); $mSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id'); }}osc_add_hook('search_conditions', 'cust_search_keyword_wildcard_with_user_username', 1);?>
$query_elements['sPattern'] = str_replace(' ', '* ', $pattern) . '*';