summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2015-06-28 18:19:43 +0200
committerJohannes Löthberg <johannes@kyriasis.com>2015-06-28 18:25:14 +0200
commita948e4e65ca0505fc6e1e57dff687219e44d34fe (patch)
tree28100a25c793fe976b888a20394a243496830a0b /web
parent40addee4c237cbeff3209e2385d38e234993c724 (diff)
downloadaurweb-a948e4e65ca0505fc6e1e57dff687219e44d34fe.tar.xz
Expose name-only search through the RPC interfacerpc-search-by-name
Fixes FS#37317. Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
Diffstat (limited to 'web')
-rw-r--r--web/lib/aurjson.class.php19
1 files changed, 17 insertions, 2 deletions
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index 6f95406..b926d46 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -16,6 +16,9 @@ class AurJSON {
'search', 'info', 'multiinfo', 'msearch', 'suggest',
'suggest-pkgbase'
);
+ private static $exposed_fields = array(
+ 'name', 'name-desc'
+ );
private static $fields_v1 = array(
'Packages.ID', 'Packages.Name',
'PackageBases.ID AS PackageBaseID',
@@ -80,6 +83,9 @@ class AurJSON {
if (!in_array($http_data['type'], self::$exposed_methods)) {
return $this->json_error('Incorrect request type specified.');
}
+ if (isset($http_data['search_by']) && !in_array($http_data['search_by'], self::$exposed_fields)) {
+ return $this->json_error('Incorrect search_by field specified.');
+ }
$this->dbh = DB::connect();
@@ -322,6 +328,11 @@ class AurJSON {
*/
private function search($http_data) {
$keyword_string = $http_data['arg'];
+ if (isset($http_data['search_by'])) {
+ $search_by = $http_data['search_by'];
+ } else {
+ $search_by = 'name-desc';
+ }
if (strlen($keyword_string) < 2) {
return $this->json_error('Query arg too small');
@@ -329,8 +340,12 @@ class AurJSON {
$keyword_string = $this->dbh->quote("%" . addcslashes($keyword_string, '%_') . "%");
- $where_condition = "(Packages.Name LIKE $keyword_string OR ";
- $where_condition .= "Description LIKE $keyword_string)";
+ if ($search_by === 'name') {
+ $where_condition = "(Packages.Name LIKE $keyword_string)";
+ } else if ($search_by === 'name-desc') {
+ $where_condition = "(Packages.Name LIKE $keyword_string OR ";
+ $where_condition .= "Description LIKE $keyword_string)";
+ }
return $this->process_query('search', $where_condition);
}