aurjson: Rename the search_by parameter to "by"

This parameter is only supported by the search command. We do not need
to repeat ourselves.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Lukas Fleischer 2015-10-09 17:35:29 +02:00
parent 9d8345d4e0
commit 1f6237ffa7
2 changed files with 17 additions and 10 deletions

View file

@ -5,11 +5,14 @@ Package Search
-------------- --------------
Package searches can be performed by issuing HTTP GET requests of the form Package searches can be performed by issuing HTTP GET requests of the form
+/rpc/?v=5&type=search&search_by=_by_&arg=_keywords_+ where _by_ is either +/rpc/?v=5&type=search&by=_field_&arg=_keywords_+ where _keywords_ is the
`name` (search by package name only), `name-desc` (search by package name and search argument and _field_ is one of the following values:
description) or `maintainer` (search by package maintainer) and _keywords_ is
the search argument. The _search_by_ parameter can be skipped and defaults to * `name` (search by package name only)
`name-desc`. * `name-desc` (search by package name and description)
* `maintainer` (search by package maintainer)
The _by_ parameter can be skipped and defaults to `name-desc`.
If a maintainer search is performed and the search argument is left empty, a If a maintainer search is performed and the search argument is left empty, a
list of orphan packages is returned. list of orphan packages is returned.

View file

@ -86,8 +86,12 @@ class AurJSON {
if (!in_array($http_data['type'], self::$exposed_methods)) { if (!in_array($http_data['type'], self::$exposed_methods)) {
return $this->json_error('Incorrect request type specified.'); 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.'); if (isset($http_data['search_by']) && !isset($http_data['by'])) {
$http_data['by'] = $http_data['search_by'];
}
if (isset($http_data['by']) && !in_array($http_data['by'], self::$exposed_fields)) {
return $this->json_error('Incorrect by field specified.');
} }
$this->dbh = DB::connect(); $this->dbh = DB::connect();
@ -362,8 +366,8 @@ class AurJSON {
private function search($http_data) { private function search($http_data) {
$keyword_string = $http_data['arg']; $keyword_string = $http_data['arg'];
if (isset($http_data['search_by'])) { if (isset($http_data['by'])) {
$search_by = $http_data['search_by']; $search_by = $http_data['by'];
} else { } else {
$search_by = 'name-desc'; $search_by = 'name-desc';
} }
@ -455,7 +459,7 @@ class AurJSON {
* @return mixed Returns an array of value data containing the package data * @return mixed Returns an array of value data containing the package data
*/ */
private function msearch($http_data) { private function msearch($http_data) {
$http_data['search_by'] = 'maintainer'; $http_data['by'] = 'maintainer';
return $this->search($http_data); return $this->search($http_data);
} }