Implemented typeahead suggest

Use Twitter Bootstrap JavaScript framework for typeahead support.

Add a new "suggest" JSON method, which returns the first 20
packages that match the beginning characters of a query.

canyonknight: Link format change, commit message
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
Marcel Korpel 2012-12-23 21:23:45 +00:00 committed by Lukas Fleischer
parent b8f07c4c45
commit b004333ead
4 changed files with 354 additions and 2 deletions

View file

@ -15,7 +15,7 @@ include_once("aur.inc.php");
class AurJSON {
private $dbh = false;
private static $exposed_methods = array(
'search', 'info', 'multiinfo', 'msearch'
'search', 'info', 'multiinfo', 'msearch', 'suggest'
);
private static $fields = array(
'Packages.ID', 'Name', 'Version', 'CategoryID', 'Description', 'URL',
@ -276,5 +276,25 @@ class AurJSON {
return $this->process_query('msearch', $where_condition);
}
/**
* Get all package names that start with $search.
* @param string $search Search string.
* @return string The JSON formatted response data.
**/
private function suggest($search) {
$query = 'SELECT Name FROM Packages WHERE Name LIKE ' .
$this->dbh->quote(addcslashes($search, '%_') . '%') .
' ORDER BY Name ASC LIMIT 20';
$result = $this->dbh->query($query);
$result_array = array();
if ($result) {
$result_array = $result->fetchAll(PDO::FETCH_COLUMN, 0);
}
return json_encode($result_array);
}
}