diff options
author | Lukas Fleischer <lfleischer@archlinux.org> | 2015-05-22 13:19:53 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@archlinux.org> | 2015-05-22 17:09:26 +0200 |
commit | 2db1a559226b64c8c424b9ce8aaa17b4cac219ec (patch) | |
tree | 7a5c28463f0a39890b1e7363a5497ebcb52b4e85 /web/lib | |
parent | 0f48341ed67624f8bf113737eac0ba5b989133b3 (diff) | |
download | aur-2db1a559226b64c8c424b9ce8aaa17b4cac219ec.tar.gz aur-2db1a559226b64c8c424b9ce8aaa17b4cac219ec.tar.xz |
Support boolean operators in search queries
This adds very basic support for boolean search queries such as "video
or movie" or "lin and not linux". However, nested queries such as
"(video or movie) and editing" are not (yet) supported.
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'web/lib')
-rw-r--r-- | web/lib/pkgfuncs.inc.php | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 11ca5915..2b5afaa9 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -602,21 +602,38 @@ function pkg_search_page($SID="") { else { /* Search by name and description (default). */ $count = 0; + $q_where .= "AND ("; + $op = ""; foreach (str_getcsv($_GET['K'], ' ') as $term) { if ($term == "") { continue; } + if ($count > 0 && strtolower($term) == "and") { + $op = "AND "; + continue; + } + if ($count > 0 && strtolower($term) == "or") { + $op = "OR "; + continue; + } + if ($count > 0 && strtolower($term) == "not") { + $op .= "NOT "; + continue; + } $term = "%" . addcslashes($term, '%_') . "%"; - $q_where .= "AND (Packages.Name LIKE " . $dbh->quote($term) . " OR "; + $q_where .= $op . " (Packages.Name LIKE " . $dbh->quote($term) . " OR "; $q_where .= "Description LIKE " . $dbh->quote($term) . ") "; $count++; if ($count >= 20) { break; } + $op = "AND "; } + + $q_where .= ") "; } } |