mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Add search for keywords only
Implements FS#45619. Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
parent
d5d08b8f92
commit
4516f07d9c
2 changed files with 65 additions and 39 deletions
|
@ -575,7 +575,10 @@ function pkg_display_details($id=0, $row, $SID="") {
|
||||||
* SeB- property that search string (K) represents
|
* SeB- property that search string (K) represents
|
||||||
* values: n - package name
|
* values: n - package name
|
||||||
* nd - package name & description
|
* nd - package name & description
|
||||||
* x - package name (exact match)
|
* b - package base name
|
||||||
|
* N - package name (exact match)
|
||||||
|
* B - package base name (exact match)
|
||||||
|
* k - package keyword(s)
|
||||||
* m - package maintainer's username
|
* m - package maintainer's username
|
||||||
* s - package submitter's username
|
* s - package submitter's username
|
||||||
* do_Orphans - boolean. whether to search packages
|
* do_Orphans - boolean. whether to search packages
|
||||||
|
@ -667,6 +670,10 @@ function pkg_search_page($SID="") {
|
||||||
$K = "%" . addcslashes($_GET['K'], '%_') . "%";
|
$K = "%" . addcslashes($_GET['K'], '%_') . "%";
|
||||||
$q_where .= "AND (PackageBases.Name LIKE " . $dbh->quote($K) . ") ";
|
$q_where .= "AND (PackageBases.Name LIKE " . $dbh->quote($K) . ") ";
|
||||||
}
|
}
|
||||||
|
elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "k") {
|
||||||
|
/* Search by keywords. */
|
||||||
|
$q_where .= construct_keyword_search($dbh, false);
|
||||||
|
}
|
||||||
elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "N") {
|
elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "N") {
|
||||||
/* Search by name (exact match). */
|
/* Search by name (exact match). */
|
||||||
$q_where .= "AND (Packages.Name = " . $dbh->quote($_GET['K']) . ") ";
|
$q_where .= "AND (Packages.Name = " . $dbh->quote($_GET['K']) . ") ";
|
||||||
|
@ -677,44 +684,7 @@ function pkg_search_page($SID="") {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Keyword search (default). */
|
/* Keyword search (default). */
|
||||||
$count = 0;
|
$q_where .= construct_keyword_search($dbh, true);
|
||||||
$q_keywords = "";
|
|
||||||
$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_keywords .= $op . " (Packages.Name LIKE " . $dbh->quote($term) . " OR ";
|
|
||||||
$q_keywords .= "Description LIKE " . $dbh->quote($term) . " OR ";
|
|
||||||
$q_keywords .= "EXISTS (SELECT * FROM PackageKeywords WHERE ";
|
|
||||||
$q_keywords .= "PackageKeywords.PackageBaseID = Packages.PackageBaseID AND ";
|
|
||||||
$q_keywords .= "PackageKeywords.Keyword LIKE " . $dbh->quote($term) . ")) ";
|
|
||||||
|
|
||||||
$count++;
|
|
||||||
if ($count >= 20) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$op = "AND ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($q_keywords)) {
|
|
||||||
$q_where .= "AND (" . $q_keywords . ") ";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -833,6 +803,61 @@ function pkg_search_page($SID="") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the WHERE part of the sophisticated keyword search
|
||||||
|
*
|
||||||
|
* @param handle $dbh Database handle
|
||||||
|
* @param boolean $namedesc Search name and description fields
|
||||||
|
*
|
||||||
|
* @return string WHERE part of the SQL clause
|
||||||
|
*/
|
||||||
|
function construct_keyword_search($dbh, $namedesc) {
|
||||||
|
$count = 0;
|
||||||
|
$where_part = "";
|
||||||
|
$q_keywords = "";
|
||||||
|
$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_keywords .= $op . " (";
|
||||||
|
if ($namedesc) {
|
||||||
|
$q_keywords .= "Packages.Name LIKE " . $dbh->quote($term) . " OR ";
|
||||||
|
$q_keywords .= "Description LIKE " . $dbh->quote($term) . " OR ";
|
||||||
|
}
|
||||||
|
$q_keywords .= "EXISTS (SELECT * FROM PackageKeywords WHERE ";
|
||||||
|
$q_keywords .= "PackageKeywords.PackageBaseID = Packages.PackageBaseID AND ";
|
||||||
|
$q_keywords .= "PackageKeywords.Keyword LIKE " . $dbh->quote($term) . ")) ";
|
||||||
|
|
||||||
|
$count++;
|
||||||
|
if ($count >= 20) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$op = "AND ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($q_keywords)) {
|
||||||
|
$where_part = "AND (" . $q_keywords . ") ";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $where_part;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a POST string has been sent by a visitor
|
* Determine if a POST string has been sent by a visitor
|
||||||
*
|
*
|
||||||
|
|
|
@ -7,6 +7,7 @@ $searchby = array(
|
||||||
'b' => __('Package Base'),
|
'b' => __('Package Base'),
|
||||||
'N' => __('Exact Name'),
|
'N' => __('Exact Name'),
|
||||||
'B' => __('Exact Package Base'),
|
'B' => __('Exact Package Base'),
|
||||||
|
'k' => __('Keywords'),
|
||||||
'm' => __('Maintainer'),
|
'm' => __('Maintainer'),
|
||||||
's' => __('Submitter')
|
's' => __('Submitter')
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue