myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2403] trunk: added contribution rank and improve


From: noreply
Subject: [myexperiment-hackers] [2403] trunk: added contribution rank and improved contribution rating handling
Date: Wed, 12 May 2010 12:01:11 -0400 (EDT)

Revision
2403
Author
dgc
Date
2010-05-12 12:01:10 -0400 (Wed, 12 May 2010)

Log Message

added contribution rank and improved contribution rating handling

Modified Paths

Diff

Modified: trunk/Rakefile (2402 => 2403)


--- trunk/Rakefile	2010-05-12 15:31:29 UTC (rev 2402)
+++ trunk/Rakefile	2010-05-12 16:01:10 UTC (rev 2403)
@@ -19,3 +19,12 @@
   Pack.rebuild_solr_index
 end
 
+desc 'Refresh contribution caches'
+task "myexp:refresh:contributions" do
+  require File.dirname(__FILE__) + '/config/environment'
+  Contribution.find(:all).each do |c|
+    c.contributable.update_contribution_rank
+    c.contributable.update_contribution_rating
+  end
+end
+

Modified: trunk/app/models/blob.rb (2402 => 2403)


--- trunk/app/models/blob.rb	2010-05-12 15:31:29 UTC (rev 2402)
+++ trunk/app/models/blob.rb	2010-05-12 16:01:10 UTC (rev 2403)
@@ -26,7 +26,7 @@
   acts_as_attributable
   
   acts_as_solr(:fields => [:title, :local_name, :body, :kind, :uploader, :tag_list],
-               :boost => "search_boost",
+               :boost => "rank",
                :include => [ :comments ]) if Conf.solr_enable
 
   belongs_to :content_blob
@@ -51,7 +51,7 @@
 
   alias_method :kind, :type
 
-  def search_boost
+  def rank
 
     # initial boost depends on viewings count
     boost = contribution.viewings_count / 100

Modified: trunk/app/models/rating.rb (2402 => 2403)


--- trunk/app/models/rating.rb	2010-05-12 15:31:29 UTC (rev 2402)
+++ trunk/app/models/rating.rb	2010-05-12 16:01:10 UTC (rev 2403)
@@ -25,7 +25,7 @@
 
   def update_contribution_rating
     if rateable.contribution
-      rateable.contribution.update_attribute(:rating, rateable.rating)
+      rateable.update_contribution_rating
     end
   end
 end

Modified: trunk/app/models/workflow.rb (2402 => 2403)


--- trunk/app/models/workflow.rb	2010-05-12 15:31:29 UTC (rev 2402)
+++ trunk/app/models/workflow.rb	2010-05-12 16:01:10 UTC (rev 2403)
@@ -84,7 +84,7 @@
   non_versioned_columns.push("license_id", "tag_list")
   
   acts_as_solr(:fields => [ :title, :body, :tag_list, :contributor_name, :kind, :get_all_search_terms ],
-               :boost => "search_boost",
+               :boost => "rank",
                :include => [ :comments ]) if Conf.solr_enable
 
   acts_as_runnable
@@ -283,7 +283,7 @@
 
   alias_method :kind, :type
 
-  def search_boost
+  def rank
 
     # initial boost depends on viewings count
     boost = contribution.viewings_count / 100

Modified: trunk/config/base_schema.xml (2402 => 2403)


--- trunk/config/base_schema.xml	2010-05-12 15:31:29 UTC (rev 2402)
+++ trunk/config/base_schema.xml	2010-05-12 16:01:10 UTC (rev 2403)
@@ -13,6 +13,7 @@
     <column type="integer"  name="downloads_count"/>
     <column type="integer"  name="viewings_count"/>
     <column type="float"    name="rating"/>
+    <column type="float"    name="rank"/>
 
   </table>
 

Modified: trunk/lib/acts_as_contributable.rb (2402 => 2403)


--- trunk/lib/acts_as_contributable.rb	2010-05-12 15:31:29 UTC (rev 2402)
+++ trunk/lib/acts_as_contributable.rb	2010-05-12 16:01:10 UTC (rev 2403)
@@ -19,6 +19,8 @@
                   :dependent => :destroy
                   
           after_save :save_contributable_record
+          after_save :update_contribution_rank
+          after_save :update_contribution_rating
 
           class_eval do
             extend Mib::Acts::Contributable::SingletonMethods
@@ -76,6 +78,32 @@
             contribution.save
           end
         end
+
+        def update_contribution_rank
+          if contribution
+
+            if respond_to?(:rank)
+              value = rank
+            else
+              value = 0.0
+            end
+
+            contribution.update_attribute(:rank, value)
+          end
+        end
+
+        def update_contribution_rating
+          if contribution
+
+            if respond_to?(:rating)
+              value = rating
+            else
+              value = 0.0
+            end
+
+            contribution.update_attribute(:rating, value)
+          end
+        end
       end
     end
   end

reply via email to

[Prev in Thread] Current Thread [Next in Thread]