myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [2213] trunk: added a boost function to workflows


From: noreply
Subject: [myexperiment-hackers] [2213] trunk: added a boost function to workflows, blobs and packs
Date: Tue, 9 Jun 2009 09:16:58 -0400 (EDT)

Revision
2213
Author
dgc
Date
2009-06-09 09:16:58 -0400 (Tue, 09 Jun 2009)

Log Message

added a boost function to workflows, blobs and packs

Modified Paths

Diff

Modified: trunk/app/models/blob.rb (2212 => 2213)


--- trunk/app/models/blob.rb	2009-06-09 12:50:08 UTC (rev 2212)
+++ trunk/app/models/blob.rb	2009-06-09 13:16:58 UTC (rev 2213)
@@ -25,7 +25,8 @@
   acts_as_attributor
   acts_as_attributable
   
-  acts_as_solr(:fields => [:title, :local_name, :body, :type, :uploader],
+  acts_as_solr(:fields => [:title, :local_name, :body, :kind, :uploader],
+               :boost => "search_boost",
                :include => [ :comments ]) if Conf.solr_enable
 
   belongs_to :content_blob
@@ -46,4 +47,17 @@
   def type
     content_type.title
   end
+
+  alias_method :kind, :type
+
+  def search_boost
+
+    # initial boost depends on viewings count
+    boost = contribution.viewings_count
+
+    # penalty for no description
+    boost = 0 if body.nil? || body.empty?
+    
+    boost
+  end
 end

Modified: trunk/app/models/pack.rb (2212 => 2213)


--- trunk/app/models/pack.rb	2009-06-09 12:50:08 UTC (rev 2212)
+++ trunk/app/models/pack.rb	2009-06-09 13:16:58 UTC (rev 2213)
@@ -27,6 +27,7 @@
   format_attribute :description
   
   acts_as_solr(:fields => [ :title, :description, :contributor_name, :tag_list ],
+               :boost => "search_boost",
                :include => [ :comments ]) if Conf.solr_enable
   
   has_many :contributable_entries,
@@ -892,5 +893,14 @@
     return item_data
   end
   
-  
+  def search_boost
+
+    # initial boost depends on viewings count
+    boost = contribution.viewings_count
+
+    # penalty for no description
+    boost = 0 if description.nil? || description.empty?
+    
+    boost
+  end
 end

Modified: trunk/app/models/workflow.rb (2212 => 2213)


--- trunk/app/models/workflow.rb	2009-06-09 12:50:08 UTC (rev 2212)
+++ trunk/app/models/workflow.rb	2009-06-09 13:16:58 UTC (rev 2213)
@@ -85,6 +85,7 @@
   non_versioned_columns.push("license", "tag_list", "body_html")
   
   acts_as_solr(:fields => [ :title, :body, :tag_list, :contributor_name, :kind, :get_all_search_terms ],
+               :boost => "search_boost",
                :include => [ :comments ]) if Conf.solr_enable
 
   acts_as_runnable
@@ -258,4 +259,15 @@
   end
 
   alias_method :kind, :type
+
+  def search_boost
+
+    # initial boost depends on viewings count
+    boost = contribution.viewings_count
+
+    # penalty for no description
+    boost = 0 if body.nil? || body.empty?
+    
+    boost
+  end
 end

Modified: trunk/vendor/plugins/acts_as_solr/lib/instance_methods.rb (2212 => 2213)


--- trunk/vendor/plugins/acts_as_solr/lib/instance_methods.rb	2009-06-09 12:50:08 UTC (rev 2212)
+++ trunk/vendor/plugins/acts_as_solr/lib/instance_methods.rb	2009-06-09 13:16:58 UTC (rev 2213)
@@ -107,7 +107,9 @@
     end
     
     def validate_boost(boost)
-      if boost.class != Float || boost < 0
+      if boost.class == String
+        return eval(boost)
+      elsif boost.class != Float || boost < 0
         logger.warn "The boost value has to be a float and posisive, but got #{boost}. Using default boost value."
         return solr_configuration[:default_boost]
       end
@@ -136,4 +138,4 @@
     end
     
   end
-end
\ No newline at end of file
+end

reply via email to

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