Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2010-02-26 08:17:26 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2010-02-26 08:17:26 (GMT)
commit3d912c085949e8d250da311973bf42db6cd2777f (patch)
tree6dcc181a145eeedbe8a9a7b2d59c458566101711
parent82740196d586ecc1113eeb0b74b6e405a0f8f8e7 (diff)
Include all versions to search results
-rw-r--r--bin/update-search-views.php4
-rw-r--r--site/app/controllers/components/search.php44
-rw-r--r--site/app/controllers/search_controller.php2
-rw-r--r--site/app/models/addon.php8
-rw-r--r--site/app/models/version.php38
-rw-r--r--site/app/views/elements/amo2009/results_addon.thtml12
-rw-r--r--site/app/views/search/index.thtml1
7 files changed, 50 insertions, 59 deletions
diff --git a/bin/update-search-views.php b/bin/update-search-views.php
index e1e05c4..24731b8 100644
--- a/bin/update-search-views.php
+++ b/bin/update-search-views.php
@@ -105,10 +105,10 @@ $sql_commands[] = "DELETE FROM `versions_summary`";
$sql_commands[] = "INSERT INTO `versions_summary`
SELECT DISTINCT v.addon_id, v.id, av.application_id, v.created, v.modified, av.min, av.max
- FROM (SELECT DISTINCT v.addon_id AS addon_id, MAX(v.created) AS created
+ FROM (SELECT DISTINCT v.addon_id AS addon_id, v.created AS created
FROM versions AS v
INNER JOIN files AS f ON (f.version_id = v.id AND f.status IN (".implode(',',$valid_status)."))
- GROUP BY v.addon_id) AS mrv
+ ) AS mrv
NATURAL JOIN versions AS v
LEFT JOIN applications_versions AS av
ON (av.version_id = v.id )";
diff --git a/site/app/controllers/components/search.php b/site/app/controllers/components/search.php
index 76c0cd6..2bca931 100644
--- a/site/app/controllers/components/search.php
+++ b/site/app/controllers/components/search.php
@@ -132,7 +132,7 @@ class SearchComponent extends Object {
* @return array of information about results (modified cake results)
*/
function search($terms, $tagFilter=null, $searchTagsOnly = false, $searchtype=NULL, $category=0, $status=NULL,
- $lver = -1, $hver = -1, $vfuz =false, $atype = ADDON_ANY,
+ $ver = -1, $hver = -1, $vfuz =false, $atype = ADDON_ANY,
$platform= PLATFORM_ANY, $lup = "", $sort = "", $locale=false ) {
global $valid_status, $hybrid_categories, $app_listedtypes;
@@ -293,40 +293,9 @@ class SearchComponent extends Object {
one of v.min or v.max is in $range_wanted. Each of the three array is used in SQL in clauses which are probably implemented
by mysql with in-memory hash tables so should be fast checks.
*/
- if ($lver != -1 && $hver != -1 ) {
- $range_wanted = array();
- $below_wanted = array();
- $above_wanted = array();
- $all_appversions = $this->controller->Amo->getVersionIdsByApp(APP_ID);
-
- $lver = $this->controller->Sanitize->sql($lver);
- $hver = $this->controller->Sanitize->sql($hver);
-
- $fuz = "";
- if (isset($this->params['url']['vfuz']) && $this->params['url']['vfuz'] == true)
- $fuz = "*";
-
- $vcompare = $this->controller->Versioncompare;
-
- foreach($all_appversions as $appversion => $appvid) {
- // because of version fuzziness may be used, the three cases below are not necessarily disjoint
- if ($vcompare->compareVersions($appversion, $lver) < 0) {
- $below_wanted[] = $appvid;
- }
- if (($vcompare->compareVersions($lver, $appversion) <= 0 || $vcompare->compareVersions($lver.$fuz, $appversion) <= 0 || $lver == 'any') &&
- ($vcompare->compareVersions($appversion, $hver) <= 0 || $vcompare->compareVersions($appversion, $hver.$fuz) <= 0 || $hver == 'any')) {
- $range_wanted[] = $appvid; //note we want the version id's not the version numbers
- }
- if ($vcompare->compareVersions($appversion, $lver) > 0) {
- $above_wanted[] = $appvid;
- }
- }
-
- $_ver_string = "('".implode("', '", $range_wanted) ."') ";
- $vcheck = " v.min IN ".$_ver_string." OR v.max IN ".$_ver_string;
- $_ver_string = "('".implode("', '", $below_wanted) ."') ";
- $_ver_string2 = "('".implode("', '", $above_wanted) ."') ";
- $vcheck .= " OR (v.min IN ".$_ver_string." AND v.max IN ".$_ver_string2.")";
+ if ($ver != -1 && $ver != 'any') {
+ $ver = $this->controller->Sanitize->sql($ver);
+ $vcheck = " CAST(appmin.version AS DECIMAL(3,3)) <= CAST('".$ver."' AS DECIMAL(3,3)) AND CAST(appmax.version AS DECIMAL(3,3)) >= CAST('".$ver."' AS DECIMAL(3,3))";
if (in_array(ADDON_SEARCH, $_addon_types) ) {
$vcheck = "(a.addontype = ".ADDON_SEARCH." OR ".$vcheck.")";
@@ -360,12 +329,15 @@ class SearchComponent extends Object {
$_where[] = '(a.addontype = '.ADDON_SEARCH." OR {$_app_compat})";
// else: only search engines => do not restrict by application
- $sql = "SELECT DISTINCT a.id, " . implode(', ', $_selects)
+ $sql = "SELECT DISTINCT a.id, " . implode(', ', $_selects). ", MAX(v.created)"
." FROM text_search_summary AS a " . implode(' ', $_joins)
+ ." INNER JOIN appversions appmin ON appmin.id = v.min "
+ ." INNER JOIN appversions appmax ON appmax.id = v.max "
." WHERE $_matches "
."AND a.addontype IN (" . implode(',', $_addon_types) . ") "
."AND a.status IN(".$sql_status.") AND a.inactive = 0 "
.(empty($_where) ? '' : 'AND ('.implode(' AND ', $_where).') ')
+ ."GROUP BY v.addon_id "
."ORDER BY ".implode(', ', $_orderby);
// query the db and return the ids found
diff --git a/site/app/controllers/search_controller.php b/site/app/controllers/search_controller.php
index fce640e..3c17b17 100644
--- a/site/app/controllers/search_controller.php
+++ b/site/app/controllers/search_controller.php
@@ -219,7 +219,7 @@ class SearchController extends AppController
}
if (!empty($_result_ids)) {
- $results = $this->Addon->getAddonList($_result_ids, $associations);
+ $results = $this->Addon->getAddonList($_result_ids, $associations, $lver);
// Show top 10 tags
$topTags = $this->Tag->getTopForAddons(10, $_result_ids);
} else {
diff --git a/site/app/models/addon.php b/site/app/models/addon.php
index 9413ec4..cf533d2 100644
--- a/site/app/models/addon.php
+++ b/site/app/models/addon.php
@@ -177,7 +177,7 @@ class Addon extends AppModel
* By convention, the associations array should be all lower case and sorted
* alphabetically, to promote cache hits across pages.
*/
- function getAddon($id, $associations = array()) {
+ function getAddon($id, $associations = array(), $app_ver = null) {
global $valid_status;
// if this object is cached, grab it from memcache
@@ -313,7 +313,7 @@ class Addon extends AppModel
$this->Version->useDbConfig = 'shadow';
$buf = $this->Version->findAll(array(
'Version.id' => $this->Version->getVersionByAddonId($id,
- ($addon['Addon']['status']==STATUS_PUBLIC ? STATUS_PUBLIC : $valid_status))),
+ ($addon['Addon']['status']==STATUS_PUBLIC ? STATUS_PUBLIC : $valid_status), $app_ver)),
array('Version.id', 'Version.version', 'Version.created'));
if (!empty($buf[0]['Version'])) {
@@ -396,10 +396,10 @@ class Addon extends AppModel
* Get a list of add-ons by id, each with the given associations
* uses the object invalidation framework
*/
- function getAddonList($ids, $associations = array()) {
+ function getAddonList($ids, $associations = array(), $app_ver = null) {
$result = array();
foreach ($ids as $id) {
- $result[] = $this->getAddon($id, $associations);
+ $result[] = $this->getAddon($id, $associations, $app_ver);
}
return $result;
}
diff --git a/site/app/models/version.php b/site/app/models/version.php
index f19c0b9..8d8054d 100644
--- a/site/app/models/version.php
+++ b/site/app/models/version.php
@@ -133,20 +133,26 @@ class Version extends AppModel
* @param array $status non-empty array
* @return int $id of the latest version or 0
*/
- function getVersionByAddonId($id, $status = array(STATUS_PUBLIC)) {
+ function getVersionByAddonId($id, $status = array(STATUS_PUBLIC), $app_ver = null) {
if (!is_array($status)) $status = array($status);
$status_sql = implode(',',$status);
- if (preg_match('/OLPC\/0\.([^-]*)-/', env('HTTP_USER_AGENT'), $matches)) {
- if (floatval($matches[1]) <= 4.6)
- $sp = '0.82';
- else
- $sp = '0.84';
- } else {
- if (preg_match('/Sugar Labs\/([0-9]+)\.([0-9]+)/', env('HTTP_USER_AGENT'), $matches))
- $sp = $matches[1].'.'.$matches[2];
- else
- $sp = SITE_SUGAR_STABLE;
+ $sp = null;
+ if (isset($app_ver))
+ if ($app_ver != 'any')
+ $sp = $app_ver;
+ else {
+ if (preg_match('/OLPC\/0\.([^-]*)-/', env('HTTP_USER_AGENT'), $matches)) {
+ if (floatval($matches[1]) <= 4.6)
+ $sp = '0.82';
+ else
+ $sp = '0.84';
+ } else {
+ if (preg_match('/Sugar Labs\/([0-9]+)\.([0-9]+)/', env('HTTP_USER_AGENT'), $matches))
+ $sp = $matches[1].'.'.$matches[2];
+ else
+ $sp = SITE_SUGAR_STABLE;
+ }
}
$sql = "
@@ -164,8 +170,14 @@ class Version extends AppModel
appversions as C ON C.id = A.max
WHERE
Version.addon_id = {$id}
- ORDER BY
- IF({$sp} AND ({$sp} < CAST(B.version AS DECIMAL(3,3)) OR {$sp} > CAST(C.version AS DECIMAL(3,3))), 1, 1000000) + CAST(Version.version AS DECIMAL) DESC
+ ORDER BY";
+ if (isset($sp))
+ $sql .= "
+ IF({$sp} AND ({$sp} < CAST(B.version AS DECIMAL(3,3)) OR {$sp} > CAST(C.version AS DECIMAL(3,3))), 1, 1000000) + CAST(Version.version AS DECIMAL) DESC";
+ else
+ $sql .= "
+ Version.created DESC";
+ $sql .= "
LIMIT 1
";
diff --git a/site/app/views/elements/amo2009/results_addon.thtml b/site/app/views/elements/amo2009/results_addon.thtml
index d9c5922..b696980 100644
--- a/site/app/views/elements/amo2009/results_addon.thtml
+++ b/site/app/views/elements/amo2009/results_addon.thtml
@@ -102,11 +102,17 @@ if (isset($addonStatus) && in_array($addonStatus, $experimental_status)) {
echo sprintf($_update_string, strftime(___('%B %e, %Y'), strtotime($_version_date)));
?>
</p>
- <?=$installButton->button(array(
+ <?php
+
+ $install_options =array(
'flags' => $flags,
'addon' => $addon,
- 'src' => 'search'
- ))?>
+ 'src' => 'search');
+ if (isset($addon['is_latest']))
+ $install_options['is_latest'] = $addon['is_latest'];
+ ?>
+ <?=$installButton->button($install_options)
+ ?>
</div>
<blockquote cite="#"><p><?=$addonSummary?></p></blockquote>
diff --git a/site/app/views/search/index.thtml b/site/app/views/search/index.thtml
index 43b4d62..872fd23 100644
--- a/site/app/views/search/index.thtml
+++ b/site/app/views/search/index.thtml
@@ -132,6 +132,7 @@ $params = array(
<?php endif; ?>
</div> <!-- listing-header -->
<?php foreach ($search_results as $var => $val): ?>
+ <?php $val['is_latest'] = false;?>
<?=$this->renderElement('amo2009/results_addon', array('addon' => $val));?>
<?php endforeach; ?>
</div> <!-- featured-inner -->