mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
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>
This commit is contained in:
parent
0f48341ed6
commit
2db1a55922
1 changed files with 18 additions and 1 deletions
|
@ -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 .= ") ";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue