diff -ur lms/modules/quicksearch.php lms.new//modules/quicksearch.php --- lms/modules/quicksearch.php 2011-03-18 09:59:24.000000000 +0100 +++ lms.new//modules/quicksearch.php 2011-03-29 20:41:29.772258200 +0200 @@ -1,7 +1,7 @@ GetAll('SELECT id, email, address, post_address, deleted, + $candidates = $DB->GetAll('SELECT id, email, address, post_name, post_address, deleted, '.$DB->Concat('UPPER(lastname)',"' '",'name').' AS username FROM customersview WHERE '.(preg_match('/^[0-9]+$/', $search) ? 'id = '.intval($search).' OR ' : '').' LOWER('.$DB->Concat('lastname',"' '",'name').') ?LIKE? LOWER(\'%'.$search.'%\') OR LOWER(address) ?LIKE? LOWER(\'%'.$search.'%\') + OR LOWER(post_name) ?LIKE? LOWER(\'%'.$search.'%\') OR LOWER(post_address) ?LIKE? LOWER(\'%'.$search.'%\') OR LOWER(email) ?LIKE? LOWER(\'%'.$search.'%\') ORDER by deleted, username, email, address @@ -105,6 +106,10 @@ $descriptions[$row['id']] = escape_js(trans('Address:').' '.$row['address']); continue; } + else if (preg_match("~$search~i",$row['post_name'])) { + $descriptions[$row['id']] = escape_js(trans('Name:').' '.$row['post_name']); + continue; + } else if (preg_match("~$search~i",$row['post_address'])) { $descriptions[$row['id']] = escape_js(trans('Address:').' '.$row['post_address']); continue; @@ -156,20 +161,37 @@ case 'node': if(isset($_GET['ajax'])) // support for AutoSuggest { - $candidates = $DB->GetAll('SELECT n.id, n.name, INET_NTOA(ipaddr) as ip, - INET_NTOA(ipaddr_pub) AS ip_pub, mac - FROM vnodes n - WHERE ('.(preg_match('/^[0-9]+$/',$search) ? 'n.id = '.intval($search).' OR ' : '').' - LOWER(n.name) ?LIKE? LOWER(\'%'.$search.'%\') - OR INET_NTOA(ipaddr) ?LIKE? \'%'.$search.'%\' - OR INET_NTOA(ipaddr_pub) ?LIKE? \'%'.$search.'%\' - OR LOWER(mac) ?LIKE? LOWER(\'%'.macformat($search).'%\') - ) - AND NOT EXISTS ( - SELECT 1 FROM customerassignments a - JOIN excludedgroups e ON (a.customergroupid = e.customergroupid) - WHERE e.userid = lms_current_user() AND a.customerid = n.ownerid) - ORDER BY n.name LIMIT 15'); + // Build different query for each database engine, + // MySQL is slow here when vnodes view is used + if ($CONFIG['database']['type'] == 'postgres') + $sql_query = 'SELECT n.id, n.name, INET_NTOA(ipaddr) as ip, + INET_NTOA(ipaddr_pub) AS ip_pub, mac + FROM vnodes n + WHERE %where + ORDER BY n.name LIMIT 15'; + else + $sql_query = 'SELECT n.id, n.name, INET_NTOA(ipaddr) as ip, + INET_NTOA(ipaddr_pub) AS ip_pub, mac + FROM nodes n + JOIN ( + SELECT nodeid, GROUP_CONCAT(mac SEPARATOR \',\') AS mac + FROM macs + GROUP BY nodeid + ) m ON (n.id = m.nodeid) + WHERE %where + ORDER BY n.name LIMIT 15'; + + $sql_where = '('.(preg_match('/^[0-9]+$/',$search) ? 'n.id = '.intval($search).' OR ' : '').' + LOWER(n.name) ?LIKE? LOWER(\'%'.$search.'%\') + OR INET_NTOA(ipaddr) ?LIKE? \'%'.$search.'%\' + OR INET_NTOA(ipaddr_pub) ?LIKE? \'%'.$search.'%\' + OR LOWER(mac) ?LIKE? LOWER(\'%'.macformat($search).'%\')) + AND NOT EXISTS ( + SELECT 1 FROM customerassignments a + JOIN excludedgroups e ON (a.customergroupid = e.customergroupid) + WHERE e.userid = lms_current_user() AND a.customerid = n.ownerid)'; + + $candidates = $DB->GetAll(str_replace('%where', $sql_where, $sql_query)); $eglible=array(); $actions=array(); $descriptions=array(); if ($candidates)