Commit 8f93d04d authored by Matt Lee's avatar Matt Lee

don't do a search on an empty term

parent 7bc5670f
Pipeline #41 skipped
......@@ -980,76 +980,81 @@ class Server {
*/
static function search($search_term, $search_type, $limit = 40, $streamable = false) {
global $adodb;
switch ($search_type) {
case 'artist':
$table = 'Artist';
$search_fields[] = 'name';
$data_fields[] = 'name';
$data_fields[] = 'bio_summary';
$data_fields[] = 'streamable';
$data_fields[] = 'image_small';
$data_fields[] = 'image_medium';
$data_fields[] = 'image_large';
break;
case 'user':
$table = 'Users';
$search_fields[] = 'username';
$search_fields[] = 'fullname';
$data_fields[] = 'username';
$data_fields[] = 'fullname';
$data_fields[] = 'bio';
break;
case 'tag':
$table = 'Tags';
$search_fields[] = 'tag';
$data_fields[] = 'tag';
break;
default:
return array();
}
$sql = 'SELECT DISTINCT ';
for ($i = 0; $i < count($data_fields); $i++) {
$sql .= $data_fields[$i];
if ($i < count($data_fields) - 1) {
$sql .= ', ';
}
}
$sql .= ' FROM ' . $table . ' WHERE ';
for ($i = 0; $i < count($search_fields); $i++) {
if ($i > 0) {
$sql .= ' OR ';
}
$sql .= 'LOWER(' . $search_fields[$i] . ') LIKE LOWER(' . $adodb->qstr('%' . $search_term . '%') . ')';
}
if ($streamable) {
$sql .= " AND streamable = 1 ";
}
$sql .= 'LIMIT ' . $limit;
$res = $adodb->CacheGetAll(600, $sql);
$result = array();
foreach ($res as &$i) {
$row = sanitize($i);
switch ($search_type) {
case 'artist':
$row['url'] = Server::getArtistURL($row['name']);
break;
case 'user':
$row['url'] = Server::getUserURL($row['username']);
break;
case 'tag':
$row['url'] = Server::getTagURL($row['tag']);
break;
}
$result[] = $row;
}
if $search_term {
switch ($search_type) {
case 'artist':
$table = 'Artist';
$search_fields[] = 'name';
$data_fields[] = 'name';
$data_fields[] = 'bio_summary';
$data_fields[] = 'streamable';
$data_fields[] = 'image_small';
$data_fields[] = 'image_medium';
$data_fields[] = 'image_large';
break;
case 'user':
$table = 'Users';
$search_fields[] = 'username';
$search_fields[] = 'fullname';
$data_fields[] = 'username';
$data_fields[] = 'fullname';
$data_fields[] = 'bio';
break;
case 'tag':
$table = 'Tags';
$search_fields[] = 'tag';
$data_fields[] = 'tag';
break;
default:
return array();
}
$sql = 'SELECT DISTINCT ';
for ($i = 0; $i < count($data_fields); $i++) {
$sql .= $data_fields[$i];
if ($i < count($data_fields) - 1) {
$sql .= ', ';
}
}
$sql .= ' FROM ' . $table . ' WHERE ';
for ($i = 0; $i < count($search_fields); $i++) {
if ($i > 0) {
$sql .= ' OR ';
}
$sql .= 'LOWER(' . $search_fields[$i] . ') LIKE LOWER(' . $adodb->qstr('%' . $search_term . '%') . ')';
}
if ($streamable) {
$sql .= " AND streamable = 1 ";
}
$sql .= 'LIMIT ' . $limit;
$res = $adodb->CacheGetAll(600, $sql);
$result = array();
foreach ($res as &$i) {
$row = sanitize($i);
switch ($search_type) {
case 'artist':
$row['url'] = Server::getArtistURL($row['name']);
break;
case 'user':
$row['url'] = Server::getUserURL($row['username']);
break;
case 'tag':
$row['url'] = Server::getTagURL($row['tag']);
break;
}
$result[] = $row;
}
}
return $result;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment