From: actionless <actionless.loveless(a)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