Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/site/app/controllers/components/search.php
diff options
context:
space:
mode:
Diffstat (limited to 'site/app/controllers/components/search.php')
-rw-r--r--site/app/controllers/components/search.php108
1 files changed, 7 insertions, 101 deletions
diff --git a/site/app/controllers/components/search.php b/site/app/controllers/components/search.php
index 20f25ab..8fae4a5 100644
--- a/site/app/controllers/components/search.php
+++ b/site/app/controllers/components/search.php
@@ -152,7 +152,6 @@ class SearchComponent extends Object {
// fields to search in
$fields = array('name', 'summary', 'description');
- $_termarray = array();
// first prepare text terms
if (is_string($terms) && !empty($terms)) {
@@ -163,6 +162,7 @@ class SearchComponent extends Object {
preg_match_all($this->search_term_regex, $terms, $_termmatches);
// remove quotes around split terms and sanitize them
+ $_termarray = array();
foreach ($_termmatches[0] as $term) {
$term = trim($term, ' "');
$term = $this->controller->Sanitize->sql($term);
@@ -181,12 +181,13 @@ class SearchComponent extends Object {
} else { //in this case enumerate all addons. this allows advanced search to act as a filter
$text_score = "TRUE";
$boolean_score = "TRUE";
+ $_termarray = array();
}
// now initialize compoents of SQL query
$_selects = $_orderby = $_joins = $_where = array();
- $_orderby[] = '(LOWER(a.name) = \''.$this->controller->Sanitize->sql($terms).'\') DESC';
+ $_orderby[] = '(LOWER(a.name) = \''.$terms.'\') DESC';
$_orderby[] = '(a.status='.STATUS_PUBLIC.') DESC'; // show public add-ons first
$_orderby[] = "(a.name LIKE '%".implode(' ', $_termarray)."%') DESC"; // sort exact name hits first
@@ -231,6 +232,10 @@ class SearchComponent extends Object {
$_addon_types = array(ADDON_EXTENSION, ADDON_THEME, ADDON_SEARCH, ADDON_DICT, ADDON_LPAPP, ADDON_LPADDON);
}
}
+
+ // we are sugar
+ $_addon_types = $app_listedtypes[APP_SUGAR];
+
if (!is_array($_addon_types)) $_addon_types = array($_addon_types);
// override the odd-on type if the advanced search parameter $atype sent. Notice am assuming -1 not an add-on type
@@ -355,104 +360,5 @@ class SearchComponent extends Object {
foreach ($_results as $_result) $_result_ids[] = $_result['a']['id'];
return $_result_ids;
}
-
-
- /**
- * The collection search function.
- *
- * @param string terms to search for
- * @param sort is used to specify sort order
- * @param locale controls whether we search within only the current locale and en-US (faster) or all locales
- * @return array of collection ids
- */
- function searchCollections($terms, $sort='', $locale=false) {
- // fields to search in
- $fields = array('name', 'description');
- $_termarray = array();
-
- // first prepare text terms
- if (is_string($terms) && !empty($terms)) {
- // UTF-8 aware case-insensitive search
- $terms = mb_strtolower($terms, 'UTF-8');
-
- // split string into single terms
- preg_match_all($this->search_term_regex, $terms, $_termmatches);
-
- // remove quotes around split terms and sanitize them
- foreach ($_termmatches[0] as $term) {
- $term = trim($term, ' "');
- $term = $this->controller->Sanitize->sql($term);
- if ($term) $_termarray[] = $term;
- }
- // now strip duplicates
- $_termarray = array_unique($_termarray);
- $_search_termarray = array();
- foreach ($_termarray as $term) {
- if (false !== strpos($term, ' ')) $term = '"'.$term.'"'; // enclose "literal phrases" in quotes
- $_search_termarray[] = '+'.$term."*";
- }
-
- $text_score = " MATCH(c.".implode(', c.',$fields).") AGAINST ('".implode(" ", $_termarray)."')";
- $boolean_score = " MATCH(c.".implode(', c.',$fields).") AGAINST ('".implode(" ", $_search_termarray)."' IN BOOLEAN MODE)";
- } else { //in this case enumerate all collections. this allows advanced search to act as a filter
- $text_score = "TRUE";
- $boolean_score = "TRUE";
- }
-
- // now initialize compoents of SQL query
- $_selects = $_orderby = $_where = array();
-
- $_orderby[] = '(LOWER(c.name) = \''.$this->controller->Sanitize->sql($terms).'\') DESC';
- $_orderby[] = "(c.name LIKE '%".implode(' ', $_termarray)."%') DESC"; // sort exact name hits first
-
- if (!$locale) {
- $_matches = "(c.locale = '".LANG."' OR c.locale = 'en-US' ) AND ";
- }
- $_matches .= $boolean_score;
-
- foreach ($fields as $field) {
- // select strings
- $_selects[] = "c.".$field;
- }
- if ($text_score !== "TRUE") {
- $_selects[] = $text_score." AS text_score";
- $_orderby[] = 'text_score DESC';
- }
-
- $_where[] = "`Collection`.`application_id`='".APP_ID."'";
- $_where[] = "`Collection`.`listed`='1'";
-
- // sorting
- switch($sort) {
- case 'all':
- array_unshift($_orderby, "`Collection`.`subscribers` DESC");
- break;
- case 'weekly':
- array_unshift($_orderby, "`Collection`.`weekly_subscribers` DESC");
- break;
- case 'monthly':
- array_unshift($_orderby, "`Collection`.`monthly_subscribers` DESC");
- break;
- case 'newest':
- array_unshift($_orderby, "`Collection`.`created` DESC");
- break;
- }
-
- // build and run query
- $sql = "SELECT DISTINCT `c`.`id`, " . implode(', ', $_selects) . "
- FROM `collections_search_summary` AS `c`
- INNER JOIN `collections` AS `Collection` ON (`Collection`.`id` = `c`.`id`)
- WHERE {$_matches}
- ".(empty($_where) ? '' : 'AND ('.implode(' AND ', $_where).') ')."
- ORDER BY ".implode(', ', $_orderby);
- $_results = $this->controller->Addon->query($sql, true);
-
- // return the ids found
- $_result_ids = array();
- foreach ($_results as $_result) {
- $_result_ids[] = $_result['c']['id'];
- }
- return $_result_ids;
- }
}
?>