Modified: branches/dashboard/app/models/pack.rb (2521 => 2522)
--- branches/dashboard/app/models/pack.rb 2010-09-27 16:31:12 UTC (rev 2521)
+++ branches/dashboard/app/models/pack.rb 2010-09-28 14:12:47 UTC (rev 2522)
@@ -12,21 +12,21 @@
class Pack < ActiveRecord::Base
-
+
acts_as_site_entity :owner_text => 'Creator'
-
+
acts_as_contributable
acts_as_bookmarkable
acts_as_commentable
acts_as_rateable
acts_as_taggable
-
+
validates_presence_of :title
format_attribute :description
- acts_as_solr(:fields => [ :title, :description, :contributor_name, :tag_list ],
+ acts_as_solr(:fields => [ :title, :description, :contributor_name, :tag_list, :get_remote_search_terms, :get_contributable_search_terms ],
:boost => "rank",
:include => [ :comments ]) if Conf.solr_enable
@@ -46,6 +46,49 @@
return contributable_entries_count + remote_entries_count
end
+ #Solr Indexing
+
+ def get_remote_search_terms
+ words = StringIO.new
+ remote_entries.each do |remote_entry|
+ words << remote_entry.title
+ words << remote_entry.comment
+ end
+ words.rewind
+ words.read
+ end
+
+ def get_contributable_search_terms
+ words = StringIO.new
+ contributable_entries.each do |contributable_entry|
+ words << get_contributable_entry(contributable_entry)
+ end
+ words.rewind
+ words.read
+ end
+
+ def get_contributable_entry(contributable_entry)
+ #return nil unless (pack_entry = Pack.find(:first, :condition => ["id = ?", contributable_entry.id]))
+ if contributable_entry.contributable_type == 'Workflow'
+ p "workflow"
+ workflow_entry = Workflow.find(:first, :conditions => ["id = ?", contributable_entry.contributable_id])
+ #p workflow_entry.title + " " + workflow_entry.body
+ return workflow_entry.title + " " + workflow_entry.body
+ elsif contributable_entry.contributable_type == 'Blob'
+ blob_entry = Blob.find(:first, :conditions => ["id = ?", contributable_entry.contributable_id])
+ #p blob_entry.title + " " + blob_entry.body
+ return blob_entry.title + " " + blob_entry.body
+ elsif
+ contributable_entry.contributable_type == 'Pack'
+ pack_entry = Pack.find(:first, :conditions => ["id = ?", contributable_entry.contributable_id])
+ #p "pack", pack_entry.title + " " + pack_entry.description
+ return pack_entry.title + " " + pack_entry.description
+ else
+ return nil
+ end
+ end
+
+
# returns packs that have largest total number of items
# the maximum number of results is set by #limit#
def self.most_items(limit=10)
@@ -61,7 +104,7 @@
SELECT pack_id
FROM pack_contributable_entries
WHERE contributable_id = ? AND contributable_type = ? )"
-
+
return Pack.find_by_sql([ sql, contributable.id, contributable.class.to_s ])
end