[PATCH] feat(rpc): return "providers" packages when querying by `name` or `name-desc`

Morgan Adamiec morganamilo at gmail.com
Tue Mar 20 04:59:42 UTC 2018


On 20 March 2018 at 04:49, morganamilo <morganamilo at gmail.com> wrote:
> From: actionless <actionless.loveless at gmail.com>
>
> ---
>  doc/rpc.txt               |  4 ++--
>  web/lib/aurjson.class.php | 16 +++++++++++++++-
>  2 files changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/doc/rpc.txt b/doc/rpc.txt
> index f353ff0..83cdae3 100644
> --- a/doc/rpc.txt
> +++ b/doc/rpc.txt
> @@ -8,8 +8,8 @@ Package searches can be performed by issuing HTTP GET requests of the form
>  +/rpc/?v=5&type=search&by=_field_&arg=_keywords_+ where _keywords_ is the
>  search argument and _field_ is one of the following values:
>
> -* `name` (search by package name only)
> -* `name-desc` (search by package name and description)
> +* `name` (search by package name or packages which provide that name)
> +* `name-desc` (the same as `name` and search by description)
>  * `maintainer` (search by package maintainer)
>
>  The _by_ parameter can be skipped and defaults to `name-desc`.
> diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
> index 9eeaafd..6e580a9 100644
> --- a/web/lib/aurjson.class.php
> +++ b/web/lib/aurjson.class.php
> @@ -392,12 +392,26 @@ class AurJSON {
>                         if (strlen($keyword_string) < 2) {
>                                 return $this->json_error('Query arg too small.');
>                         }
> +
> +                       //packages which provide the package we are looking for:
> +                       $providers = pkg_providers(addcslashes($keyword_string, '%_'));
> +                       $provided_names = array();
> +                       foreach ($providers as $provider) {
> +                               if ($provider[0] != 0) {        // if package is not from repo
> +                                       $name = $this->dbh->quote($provider[1]);
> +                                       array_push($provided_names, $name);
> +                               }
> +                       }
> +                       $provided_query = "(" . join(", ", $provided_names) . ")";
> +
>                         $keyword_string = $this->dbh->quote("%" . addcslashes($keyword_string, '%_') . "%");
>
>                         if ($search_by === 'name') {
> -                               $where_condition = "(Packages.Name LIKE $keyword_string)";
> +                               $where_condition = "(Packages.Name LIKE $keyword_string OR ";
> +                               $where_condition .= "Packages.Name IN $provided_query )";
>                         } else if ($search_by === 'name-desc') {
>                                 $where_condition = "(Packages.Name LIKE $keyword_string OR ";
> +                               $where_condition .= "Packages.Name IN $provided_query OR ";
>                                 $where_condition .= "Description LIKE $keyword_string)";
>                         }
>                 } else if ($search_by === 'maintainer') {
> --
> 2.16.2
>

Sent on behalf of actionless <actionless.loveless at gmail.com>. I have
an intrest in this myself so if he decides he does not want to further
this I wouldn't mind taking it over.


More information about the aur-dev mailing list