Commit c7ef702919b0b76418e19b4b938cda3e4b933afe
1 parent
2b84844f
Exists in
master
and in
29 other branches
Rails 3 porting: bootstrap development environment
./script/quick-start runs back to back now You will notice that solr was removed.
Showing
188 changed files
with
134 additions
and
105843 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 188 files displayed.
MIGRATION_ISSUES
@@ -27,3 +27,5 @@ | @@ -27,3 +27,5 @@ | ||
27 | * rewrite conditional routing. See FIXME in lib/route_if.rb and re-implement using the Rails 3 mechanism - http://guides.rubyonrails.org/routing.html#advanced-constraints | 27 | * rewrite conditional routing. See FIXME in lib/route_if.rb and re-implement using the Rails 3 mechanism - http://guides.rubyonrails.org/routing.html#advanced-constraints |
28 | 28 | ||
29 | * check FIXME's in config/environment.rb | 29 | * check FIXME's in config/environment.rb |
30 | + | ||
31 | +* xss_terminate sucks. We should replace it with the builtin mechanism in Rails 3 |
app/models/article.rb
@@ -2,6 +2,8 @@ require 'hpricot' | @@ -2,6 +2,8 @@ require 'hpricot' | ||
2 | 2 | ||
3 | class Article < ActiveRecord::Base | 3 | class Article < ActiveRecord::Base |
4 | 4 | ||
5 | + attr_accessible :name, :body, :abstract, :profile | ||
6 | + | ||
5 | # use for internationalizable human type names in search facets | 7 | # use for internationalizable human type names in search facets |
6 | # reimplement on subclasses | 8 | # reimplement on subclasses |
7 | def self.type_name | 9 | def self.type_name |
@@ -142,7 +144,6 @@ class Article < ActiveRecord::Base | @@ -142,7 +144,6 @@ class Article < ActiveRecord::Base | ||
142 | else | 144 | else |
143 | ArticleCategorization.add_category_to_article(c, self) | 145 | ArticleCategorization.add_category_to_article(c, self) |
144 | self.categories(reload) | 146 | self.categories(reload) |
145 | - self.solr_save | ||
146 | end | 147 | end |
147 | end | 148 | end |
148 | 149 | ||
@@ -160,7 +161,6 @@ class Article < ActiveRecord::Base | @@ -160,7 +161,6 @@ class Article < ActiveRecord::Base | ||
160 | ArticleCategorization.add_category_to_article(item, self) | 161 | ArticleCategorization.add_category_to_article(item, self) |
161 | end | 162 | end |
162 | self.categories(true) | 163 | self.categories(true) |
163 | - self.solr_save | ||
164 | pending_categorizations.clear | 164 | pending_categorizations.clear |
165 | end | 165 | end |
166 | 166 | ||
@@ -238,7 +238,6 @@ class Article < ActiveRecord::Base | @@ -238,7 +238,6 @@ class Article < ActiveRecord::Base | ||
238 | body || '' | 238 | body || '' |
239 | end | 239 | end |
240 | 240 | ||
241 | - include ApplicationHelper | ||
242 | def reported_version(options = {}) | 241 | def reported_version(options = {}) |
243 | article = self | 242 | article = self |
244 | search_path = File.join(Rails.root, 'app', 'views', 'shared', 'reported_versions') | 243 | search_path = File.join(Rails.root, 'app', 'views', 'shared', 'reported_versions') |
@@ -469,10 +468,6 @@ class Article < ActiveRecord::Base | @@ -469,10 +468,6 @@ class Article < ActiveRecord::Base | ||
469 | allow_post_content?(user) || user && allow_members_to_edit && user.is_member_of?(profile) | 468 | allow_post_content?(user) || user && allow_members_to_edit && user.is_member_of?(profile) |
470 | end | 469 | end |
471 | 470 | ||
472 | - def comments_updated | ||
473 | - solr_save | ||
474 | - end | ||
475 | - | ||
476 | def accept_category?(cat) | 471 | def accept_category?(cat) |
477 | !cat.is_a?(ProductCategory) | 472 | !cat.is_a?(ProductCategory) |
478 | end | 473 | end |
@@ -636,21 +631,6 @@ class Article < ActiveRecord::Base | @@ -636,21 +631,6 @@ class Article < ActiveRecord::Base | ||
636 | 631 | ||
637 | private | 632 | private |
638 | 633 | ||
639 | - # FIXME: workaround for development env. | ||
640 | - # Subclasses aren't (re)loaded, and acts_as_solr | ||
641 | - # depends on subclasses method to search | ||
642 | - # see http://stackoverflow.com/questions/4138957/activerecordsubclassnotfound-error-when-using-sti-in-rails/4139245 | ||
643 | - UploadedFile | ||
644 | - TextArticle | ||
645 | - TinyMceArticle | ||
646 | - TextileArticle | ||
647 | - Folder | ||
648 | - EnterpriseHomepage | ||
649 | - Gallery | ||
650 | - Blog | ||
651 | - Forum | ||
652 | - Event | ||
653 | - | ||
654 | def self.f_type_proc(klass) | 634 | def self.f_type_proc(klass) |
655 | klass.constantize.type_name | 635 | klass.constantize.type_name |
656 | end | 636 | end |
@@ -682,9 +662,6 @@ class Article < ActiveRecord::Base | @@ -682,9 +662,6 @@ class Article < ActiveRecord::Base | ||
682 | end | 662 | end |
683 | 663 | ||
684 | delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true | 664 | delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true |
685 | - def name_sortable # give a different name for solr | ||
686 | - name | ||
687 | - end | ||
688 | 665 | ||
689 | def public | 666 | def public |
690 | self.public? | 667 | self.public? |
@@ -694,39 +671,6 @@ class Article < ActiveRecord::Base | @@ -694,39 +671,6 @@ class Article < ActiveRecord::Base | ||
694 | categories_including_virtual_ids | 671 | categories_including_virtual_ids |
695 | end | 672 | end |
696 | 673 | ||
697 | - public | ||
698 | - | ||
699 | - acts_as_faceted :fields => { | ||
700 | - :f_type => {:label => _('Type'), :proc => proc{|klass| f_type_proc(klass)}}, | ||
701 | - :f_published_at => {:type => :date, :label => _('Published date'), :queries => {'[* TO NOW-1YEARS/DAY]' => _("Older than one year"), | ||
702 | - '[NOW-1YEARS TO NOW/DAY]' => _("In the last year"), '[NOW-1MONTHS TO NOW/DAY]' => _("In the last month"), '[NOW-7DAYS TO NOW/DAY]' => _("In the last week"), '[NOW-1DAYS TO NOW/DAY]' => _("In the last day")}, | ||
703 | - :queries_order => ['[NOW-1DAYS TO NOW/DAY]', '[NOW-7DAYS TO NOW/DAY]', '[NOW-1MONTHS TO NOW/DAY]', '[NOW-1YEARS TO NOW/DAY]', '[* TO NOW-1YEARS/DAY]']}, | ||
704 | - :f_profile_type => {:label => _('Profile'), :proc => proc{|klass| f_profile_type_proc(klass)}}, | ||
705 | - :f_category => {:label => _('Categories')}, | ||
706 | - }, :category_query => proc { |c| "category_filter:\"#{c.id}\"" }, | ||
707 | - :order => [:f_type, :f_published_at, :f_profile_type, :f_category] | ||
708 | - | ||
709 | - acts_as_searchable :fields => facets_fields_for_solr + [ | ||
710 | - # searched fields | ||
711 | - {:name => {:type => :text, :boost => 2.0}}, | ||
712 | - {:slug => :text}, {:body => :text}, | ||
713 | - {:abstract => :text}, {:filename => :text}, | ||
714 | - # filtered fields | ||
715 | - {:public => :boolean}, {:environment_id => :integer}, | ||
716 | - {:profile_id => :integer}, :language, | ||
717 | - {:category_filter => :integer}, | ||
718 | - # ordered/query-boosted fields | ||
719 | - {:name_sortable => :string}, :last_changed_by_id, :published_at, :is_image, | ||
720 | - :updated_at, :created_at, | ||
721 | - ], :include => [ | ||
722 | - {:profile => {:fields => [:name, :identifier, :address, :nickname, :region_id, :lat, :lng]}}, | ||
723 | - {:comments => {:fields => [:title, :body, :author_name, :author_email]}}, | ||
724 | - {:categories => {:fields => [:name, :path, :slug, :lat, :lng, :acronym, :abbreviation]}}, | ||
725 | - ], :facets => facets_option_for_solr, | ||
726 | - :boost => proc { |a| 10 if a.profile && a.profile.enabled }, | ||
727 | - :if => proc{ |a| ! ['RssFeed'].include?(a.class.name) } | ||
728 | - handle_asynchronously :solr_save | ||
729 | - | ||
730 | private | 674 | private |
731 | 675 | ||
732 | def sanitize_tag_list | 676 | def sanitize_tag_list |
app/models/blog_archives_block.rb
@@ -2,7 +2,7 @@ class BlogArchivesBlock < Block | @@ -2,7 +2,7 @@ class BlogArchivesBlock < Block | ||
2 | 2 | ||
3 | include ActionView::Helpers::TagHelper | 3 | include ActionView::Helpers::TagHelper |
4 | include ActionView::Helpers::UrlHelper | 4 | include ActionView::Helpers::UrlHelper |
5 | - include ActionController::UrlWriter | 5 | + include Rails.application.routes.url_helpers |
6 | include ActionView::Helpers::AssetTagHelper | 6 | include ActionView::Helpers::AssetTagHelper |
7 | include DatesHelper | 7 | include DatesHelper |
8 | 8 |
app/models/category.rb
@@ -90,23 +90,4 @@ class Category < ActiveRecord::Base | @@ -90,23 +90,4 @@ class Category < ActiveRecord::Base | ||
90 | self.children.find(:all, :conditions => {:display_in_menu => true}).empty? | 90 | self.children.find(:all, :conditions => {:display_in_menu => true}).empty? |
91 | end | 91 | end |
92 | 92 | ||
93 | - private | ||
94 | - def name_sortable # give a different name for solr | ||
95 | - name | ||
96 | - end | ||
97 | - public | ||
98 | - | ||
99 | - acts_as_searchable :fields => [ | ||
100 | - # searched fields | ||
101 | - {:name => {:type => :text, :boost => 2.0}}, | ||
102 | - {:path => :text}, {:slug => :text}, | ||
103 | - {:abbreviation => :text}, {:acronym => :text}, | ||
104 | - # filtered fields | ||
105 | - :parent_id, | ||
106 | - # ordered/query-boosted fields | ||
107 | - {:name_sortable => :string}, | ||
108 | - ] | ||
109 | - after_save_reindex [:articles, :profiles], :with => :delayed_job | ||
110 | - handle_asynchronously :solr_save | ||
111 | - | ||
112 | end | 93 | end |
app/models/certifier.rb
@@ -24,6 +24,4 @@ class Certifier < ActiveRecord::Base | @@ -24,6 +24,4 @@ class Certifier < ActiveRecord::Base | ||
24 | self.name.downcase.transliterate <=> b.name.downcase.transliterate | 24 | self.name.downcase.transliterate <=> b.name.downcase.transliterate |
25 | end | 25 | end |
26 | 26 | ||
27 | - after_save_reindex [:products], :with => :delayed_job | ||
28 | - | ||
29 | end | 27 | end |
app/models/change_password.rb
@@ -80,7 +80,7 @@ class ChangePassword < Task | @@ -80,7 +80,7 @@ class ChangePassword < Task | ||
80 | _('Your password was changed successfully.') | 80 | _('Your password was changed successfully.') |
81 | end | 81 | end |
82 | 82 | ||
83 | - include ActionController::UrlWriter | 83 | + include Rails.application.routes.url_helpers |
84 | def task_created_message | 84 | def task_created_message |
85 | hostname = self.requestor.environment.default_hostname | 85 | hostname = self.requestor.environment.default_hostname |
86 | code = self.code | 86 | code = self.code |
app/models/enterprise.rb
@@ -14,7 +14,6 @@ class Enterprise < Organization | @@ -14,7 +14,6 @@ class Enterprise < Organization | ||
14 | 14 | ||
15 | has_and_belongs_to_many :fans, :class_name => 'Person', :join_table => 'favorite_enteprises_people' | 15 | has_and_belongs_to_many :fans, :class_name => 'Person', :join_table => 'favorite_enteprises_people' |
16 | 16 | ||
17 | - after_save_reindex [:products], :with => :delayed_job | ||
18 | extra_data_for_index :product_categories | 17 | extra_data_for_index :product_categories |
19 | def product_categories | 18 | def product_categories |
20 | products.includes(:product_category).map{|p| p.category_full_name}.compact | 19 | products.includes(:product_category).map{|p| p.category_full_name}.compact |
app/models/environment.rb
@@ -764,18 +764,49 @@ class Environment < ActiveRecord::Base | @@ -764,18 +764,49 @@ class Environment < ActiveRecord::Base | ||
764 | after_create :create_templates | 764 | after_create :create_templates |
765 | 765 | ||
766 | def create_templates | 766 | def create_templates |
767 | - pre = self.name.to_slug + '_' | ||
768 | - ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :visible => false, :is_template => true).id | ||
769 | - inactive_enterprise_tmpl = Enterprise.create!(:name => 'Inactive Enterprise template', :identifier => pre + 'inactive_enterprise_template', :environment => self, :visible => false, :is_template => true) | ||
770 | - com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :visible => false, :is_template => true).id | 767 | + prefix = self.name.to_slug + '_' |
768 | + | ||
769 | + enterprise_template = Enterprise.new( | ||
770 | + :name => 'Enterprise template', | ||
771 | + :identifier => prefix + 'enterprise_template' | ||
772 | + ) | ||
773 | + | ||
774 | + inactive_enterprise_template = Enterprise.new( | ||
775 | + :name => 'Inactive Enterprise template', | ||
776 | + :identifier => prefix + 'inactive_enterprise_template' | ||
777 | + ) | ||
778 | + | ||
779 | + community_template = Community.new( | ||
780 | + :name => 'Community template', | ||
781 | + :identifier => prefix + 'community_template' | ||
782 | + ) | ||
783 | + | ||
784 | + [ | ||
785 | + enterprise_template, | ||
786 | + inactive_enterprise_template, | ||
787 | + community_template | ||
788 | + ].each do |profile| | ||
789 | + profile.is_template = true | ||
790 | + profile.visible = false | ||
791 | + profile.environment = self | ||
792 | + profile.save! | ||
793 | + end | ||
794 | + | ||
771 | pass = Digest::MD5.hexdigest rand.to_s | 795 | pass = Digest::MD5.hexdigest rand.to_s |
772 | - user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person | ||
773 | - user.update_attributes(:visible => false, :name => "Person template", :is_template => true) | ||
774 | - usr_id = user.id | ||
775 | - self.settings[:enterprise_template_id] = ent_id | ||
776 | - self.inactive_enterprise_template = inactive_enterprise_tmpl | ||
777 | - self.settings[:community_template_id] = com_id | ||
778 | - self.settings[:person_template_id] = usr_id | 796 | + user = User.new(:login => (prefix + 'person_template'), :email => (prefix + 'template@template.noo'), :password => pass, :password_confirmation => pass) |
797 | + user.environment = self | ||
798 | + user.save! | ||
799 | + | ||
800 | + person_template = user.person | ||
801 | + person_template.name = "Person template" | ||
802 | + person_template.is_template = true | ||
803 | + person_template.visible = false | ||
804 | + person_template.save! | ||
805 | + | ||
806 | + self.enterprise_template = enterprise_template | ||
807 | + self.inactive_enterprise_template = inactive_enterprise_template | ||
808 | + self.community_template = community_template | ||
809 | + self.person_template = person_template | ||
779 | self.save! | 810 | self.save! |
780 | end | 811 | end |
781 | 812 | ||
@@ -788,14 +819,20 @@ class Environment < ActiveRecord::Base | @@ -788,14 +819,20 @@ class Environment < ActiveRecord::Base | ||
788 | 819 | ||
789 | after_create :create_default_licenses | 820 | after_create :create_default_licenses |
790 | def create_default_licenses | 821 | def create_default_licenses |
791 | - License.create!(:name => 'CC (by)', :url => 'http://creativecommons.org/licenses/by/3.0/legalcode', :environment => self) | ||
792 | - License.create!(:name => 'CC (by-nd)', :url => 'http://creativecommons.org/licenses/by-nd/3.0/legalcode', :environment => self) | ||
793 | - License.create!(:name => 'CC (by-sa)', :url => 'http://creativecommons.org/licenses/by-sa/3.0/legalcode', :environment => self) | ||
794 | - License.create!(:name => 'CC (by-nc)', :url => 'http://creativecommons.org/licenses/by-nc/3.0/legalcode', :environment => self) | ||
795 | - License.create!(:name => 'CC (by-nc-nd)', :url => 'http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode', :environment => self) | ||
796 | - License.create!(:name => 'CC (by-nc-sa)', :url => 'http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode', :environment => self) | ||
797 | - License.create!(:name => 'Free Art', :url => 'http://artlibre.org/licence/lal/en', :environment => self) | ||
798 | - License.create!(:name => 'GNU FDL', :url => 'http://www.gnu.org/licenses/fdl-1.3.txt', :environment => self) | 822 | + [ |
823 | + { :name => 'CC (by)', :url => 'http://creativecommons.org/licenses/by/3.0/legalcode'}, | ||
824 | + { :name => 'CC (by-nd)', :url => 'http://creativecommons.org/licenses/by-nd/3.0/legalcode'}, | ||
825 | + { :name => 'CC (by-sa)', :url => 'http://creativecommons.org/licenses/by-sa/3.0/legalcode'}, | ||
826 | + { :name => 'CC (by-nc)', :url => 'http://creativecommons.org/licenses/by-nc/3.0/legalcode'}, | ||
827 | + { :name => 'CC (by-nc-nd)', :url => 'http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode'}, | ||
828 | + { :name => 'CC (by-nc-sa)', :url => 'http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode'}, | ||
829 | + { :name => 'Free Art', :url => 'http://artlibre.org/licence/lal/en'}, | ||
830 | + { :name => 'GNU FDL', :url => 'http://www.gnu.org/licenses/fdl-1.3.txt'}, | ||
831 | + ].each do |data| | ||
832 | + license = License.new(data) | ||
833 | + license.environment = self | ||
834 | + license.save! | ||
835 | + end | ||
799 | end | 836 | end |
800 | 837 | ||
801 | def highlighted_products_with_image(options = {}) | 838 | def highlighted_products_with_image(options = {}) |
app/models/license.rb
1 | class License < ActiveRecord::Base | 1 | class License < ActiveRecord::Base |
2 | + | ||
3 | + attr_accessible :name, :url | ||
4 | + | ||
2 | belongs_to :environment | 5 | belongs_to :environment |
3 | has_many :content, :class_name => 'Article', :foreign_key => 'license_id' | 6 | has_many :content, :class_name => 'Article', :foreign_key => 'license_id' |
4 | 7 |
app/models/link_list_block.rb
app/models/my_network_block.rb
app/models/organization_mailing.rb
@@ -23,7 +23,7 @@ class OrganizationMailing < Mailing | @@ -23,7 +23,7 @@ class OrganizationMailing < Mailing | ||
23 | _('Sent by community %s.') % source.name | 23 | _('Sent by community %s.') % source.name |
24 | end | 24 | end |
25 | 25 | ||
26 | - include ActionController::UrlWriter | 26 | + include Rails.application.routes.url_helpers |
27 | def url | 27 | def url |
28 | url_for(source.url) | 28 | url_for(source.url) |
29 | end | 29 | end |
app/models/person.rb
@@ -8,20 +8,6 @@ class Person < Profile | @@ -8,20 +8,6 @@ class Person < Profile | ||
8 | acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)} | 8 | acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)} |
9 | acts_as_accessor | 9 | acts_as_accessor |
10 | 10 | ||
11 | - @@human_names = {} | ||
12 | - | ||
13 | - def self.human_names | ||
14 | - @@human_names | ||
15 | - end | ||
16 | - | ||
17 | - # FIXME ugly workaround | ||
18 | - def self.human_attribute_name(attrib) | ||
19 | - human_names.each do |key, human_text| | ||
20 | - return human_text if attrib.to_sym == key.to_sym | ||
21 | - end | ||
22 | - super | ||
23 | - end | ||
24 | - | ||
25 | scope :members_of, lambda { |resources| | 11 | scope :members_of, lambda { |resources| |
26 | resources = [resources] if !resources.kind_of?(Array) | 12 | resources = [resources] if !resources.kind_of?(Array) |
27 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') | 13 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') |
app/models/product.rb
@@ -192,7 +192,7 @@ class Product < ActiveRecord::Base | @@ -192,7 +192,7 @@ class Product < ActiveRecord::Base | ||
192 | self.enterprise.environment.production_costs + self.enterprise.production_costs | 192 | self.enterprise.environment.production_costs + self.enterprise.production_costs |
193 | end | 193 | end |
194 | 194 | ||
195 | - include ActionController::UrlWriter | 195 | + include Rails.application.routes.url_helpers |
196 | def price_composition_bar_display_url | 196 | def price_composition_bar_display_url |
197 | url_for({:host => enterprise.default_hostname, :controller => 'manage_products', :action => 'display_price_composition_bar', :profile => enterprise.identifier, :id => self.id }.merge(Noosfero.url_options)) | 197 | url_for({:host => enterprise.default_hostname, :controller => 'manage_products', :action => 'display_price_composition_bar', :profile => enterprise.identifier, :id => self.id }.merge(Noosfero.url_options)) |
198 | end | 198 | end |
@@ -245,9 +245,7 @@ class Product < ActiveRecord::Base | @@ -245,9 +245,7 @@ class Product < ActiveRecord::Base | ||
245 | 245 | ||
246 | alias_method :name_sortable, :name | 246 | alias_method :name_sortable, :name |
247 | delegate :enabled, :region, :region_id, :environment, :environment_id, :to => :enterprise | 247 | delegate :enabled, :region, :region_id, :environment, :environment_id, :to => :enterprise |
248 | - def name_sortable # give a different name for solr | ||
249 | - name | ||
250 | - end | 248 | + |
251 | def public | 249 | def public |
252 | self.public? | 250 | self.public? |
253 | end | 251 | end |
@@ -257,47 +255,5 @@ class Product < ActiveRecord::Base | @@ -257,47 +255,5 @@ class Product < ActiveRecord::Base | ||
257 | def category_filter | 255 | def category_filter |
258 | enterprise.categories_including_virtual_ids << product_category_id | 256 | enterprise.categories_including_virtual_ids << product_category_id |
259 | end | 257 | end |
260 | - public | ||
261 | - | ||
262 | - acts_as_faceted :fields => { | ||
263 | - :f_category => {:label => _('Related products')}, | ||
264 | - :f_region => {:label => _('City'), :proc => proc { |id| f_region_proc(id) }}, | ||
265 | - :f_qualifier => {:label => _('Qualifiers'), :proc => proc { |id| f_qualifier_proc(id) }}, | ||
266 | - }, :category_query => proc { |c| "category_filter:#{c.id}" }, | ||
267 | - :order => [:f_category, :f_region, :f_qualifier] | ||
268 | - | ||
269 | - Boosts = [ | ||
270 | - [:image, 0.55, proc{ |p| p.image ? 1 : 0}], | ||
271 | - [:qualifiers, 0.45, proc{ |p| p.product_qualifiers.count > 0 ? 1 : 0}], | ||
272 | - [:open_price, 0.45, proc{ |p| p.price_described? ? 1 : 0}], | ||
273 | - [:solidarity, 0.45, proc{ |p| p.percentage_from_solidarity_economy[0].to_f/100 }], | ||
274 | - [:available, 0.35, proc{ |p| p.available ? 1 : 0}], | ||
275 | - [:price, 0.35, proc{ |p| (!p.price.nil? and p.price > 0) ? 1 : 0}], | ||
276 | - [:new_product, 0.35, proc{ |p| (p.updated_at.to_i - p.created_at.to_i) < 24*3600 ? 1 : 0}], | ||
277 | - [:description, 0.3, proc{ |p| !p.description.blank? ? 1 : 0}], | ||
278 | - [:enabled, 0.2, proc{ |p| p.enterprise.enabled ? 1 : 0}], | ||
279 | - ] | ||
280 | - | ||
281 | - acts_as_searchable :fields => facets_fields_for_solr + [ | ||
282 | - # searched fields | ||
283 | - {:name => {:type => :text, :boost => 2.0}}, | ||
284 | - {:description => :text}, {:category_full_name => :text}, | ||
285 | - # filtered fields | ||
286 | - {:public => :boolean}, {:environment_id => :integer}, | ||
287 | - {:enabled => :boolean}, {:category_filter => :integer}, | ||
288 | - # ordered/query-boosted fields | ||
289 | - {:price_sortable => :decimal}, {:name_sortable => :string}, | ||
290 | - {:lat => :float}, {:lng => :float}, | ||
291 | - :updated_at, :created_at, | ||
292 | - ], :include => [ | ||
293 | - {:product_category => {:fields => [:name, :path, :slug, :lat, :lng, :acronym, :abbreviation]}}, | ||
294 | - {:region => {:fields => [:name, :path, :slug, :lat, :lng]}}, | ||
295 | - {:enterprise => {:fields => [:name, :identifier, :address, :nickname, :lat, :lng]}}, | ||
296 | - {:qualifiers => {:fields => [:name]}}, | ||
297 | - {:certifiers => {:fields => [:name]}}, | ||
298 | - ], :facets => facets_option_for_solr, | ||
299 | - :boost => proc{ |p| boost = 1; Boosts.each{ |b| boost = boost * (1 - ((1 - b[2].call(p)) * b[1])) }; boost} | ||
300 | - handle_asynchronously :solr_save | ||
301 | - after_save_reindex [:enterprise], :with => :delayed_job | ||
302 | 258 | ||
303 | end | 259 | end |
app/models/product_category.rb
@@ -11,6 +11,4 @@ class ProductCategory < Category | @@ -11,6 +11,4 @@ class ProductCategory < Category | ||
11 | top_category ? top_category.children : top_level_for(env).select{|c|c.kind_of?(ProductCategory)} | 11 | top_category ? top_category.children : top_level_for(env).select{|c|c.kind_of?(ProductCategory)} |
12 | end | 12 | end |
13 | 13 | ||
14 | - after_save_reindex [:products], :with => :delayed_job | ||
15 | - | ||
16 | end | 14 | end |
app/models/products_block.rb
@@ -2,7 +2,7 @@ class ProductsBlock < Block | @@ -2,7 +2,7 @@ class ProductsBlock < Block | ||
2 | 2 | ||
3 | include ActionView::Helpers::TagHelper | 3 | include ActionView::Helpers::TagHelper |
4 | include ActionView::Helpers::UrlHelper | 4 | include ActionView::Helpers::UrlHelper |
5 | - include ActionController::UrlWriter | 5 | + include Rails.application.routes.url_helpers |
6 | 6 | ||
7 | def self.description | 7 | def self.description |
8 | _('Products') | 8 | _('Products') |
app/models/profile.rb
@@ -3,6 +3,8 @@ | @@ -3,6 +3,8 @@ | ||
3 | # which by default is the one returned by Environment:default. | 3 | # which by default is the one returned by Environment:default. |
4 | class Profile < ActiveRecord::Base | 4 | class Profile < ActiveRecord::Base |
5 | 5 | ||
6 | + attr_accessible :name, :identifier | ||
7 | + | ||
6 | # use for internationalizable human type names in search facets | 8 | # use for internationalizable human type names in search facets |
7 | # reimplement on subclasses | 9 | # reimplement on subclasses |
8 | def self.type_name | 10 | def self.type_name |
@@ -117,11 +119,6 @@ class Profile < ActiveRecord::Base | @@ -117,11 +119,6 @@ class Profile < ActiveRecord::Base | ||
117 | 119 | ||
118 | has_many :comments_received, :class_name => 'Comment', :through => :articles, :source => :comments | 120 | has_many :comments_received, :class_name => 'Comment', :through => :articles, :source => :comments |
119 | 121 | ||
120 | - # FIXME ugly workaround | ||
121 | - def self.human_attribute_name(attrib) | ||
122 | - _(self.superclass.human_attribute_name(attrib)) | ||
123 | - end | ||
124 | - | ||
125 | def scraps(scrap=nil) | 122 | def scraps(scrap=nil) |
126 | scrap = scrap.is_a?(Scrap) ? scrap.id : scrap | 123 | scrap = scrap.is_a?(Scrap) ? scrap.id : scrap |
127 | scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap) | 124 | scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap) |
@@ -258,7 +255,6 @@ class Profile < ActiveRecord::Base | @@ -258,7 +255,6 @@ class Profile < ActiveRecord::Base | ||
258 | else | 255 | else |
259 | ProfileCategorization.add_category_to_profile(c, self) | 256 | ProfileCategorization.add_category_to_profile(c, self) |
260 | self.categories(true) | 257 | self.categories(true) |
261 | - self.solr_save | ||
262 | end | 258 | end |
263 | self.categories(reload) | 259 | self.categories(reload) |
264 | end | 260 | end |
@@ -927,46 +923,14 @@ private :generate_url, :url_options | @@ -927,46 +923,14 @@ private :generate_url, :url_options | ||
927 | self.enabled | 923 | self.enabled |
928 | end | 924 | end |
929 | 925 | ||
930 | - def name_sortable # give a different name for solr | ||
931 | - name | ||
932 | - end | ||
933 | def public | 926 | def public |
934 | self.public? | 927 | self.public? |
935 | end | 928 | end |
936 | def category_filter | 929 | def category_filter |
937 | categories_including_virtual_ids | 930 | categories_including_virtual_ids |
938 | end | 931 | end |
939 | - public | ||
940 | 932 | ||
941 | - acts_as_faceted :fields => { | ||
942 | - :f_enabled => {:label => _('Situation'), :type_if => proc { |klass| klass.kind_of?(Enterprise) }, | ||
943 | - :proc => proc { |id| f_enabled_proc(id) }}, | ||
944 | - :f_region => {:label => _('City'), :proc => proc { |id| f_region_proc(id) }}, | ||
945 | - :f_categories => {:multi => true, :proc => proc {|facet, id| f_categories_proc(facet, id)}, | ||
946 | - :label => proc { |env| f_categories_label_proc(env) }, :label_abbrev => proc{ |env| f_categories_label_abbrev_proc(env) }}, | ||
947 | - }, :category_query => proc { |c| "category_filter:#{c.id}" }, | ||
948 | - :order => [:f_region, :f_categories, :f_enabled] | ||
949 | - | ||
950 | - acts_as_searchable :fields => facets_fields_for_solr + [:extra_data_for_index, | ||
951 | - # searched fields | ||
952 | - {:name => {:type => :text, :boost => 2.0}}, | ||
953 | - {:identifier => :text}, {:nickname => :text}, | ||
954 | - # filtered fields | ||
955 | - {:public => :boolean}, {:environment_id => :integer}, | ||
956 | - {:category_filter => :integer}, | ||
957 | - # ordered/query-boosted fields | ||
958 | - {:name_sortable => :string}, {:user_id => :integer}, | ||
959 | - :enabled, :active, :validated, :public_profile, | ||
960 | - {:lat => :float}, {:lng => :float}, | ||
961 | - :updated_at, :created_at, | ||
962 | - ], | ||
963 | - :include => [ | ||
964 | - {:region => {:fields => [:name, :path, :slug, :lat, :lng]}}, | ||
965 | - {:categories => {:fields => [:name, :path, :slug, :lat, :lng, :acronym, :abbreviation]}}, | ||
966 | - ], :facets => facets_option_for_solr, | ||
967 | - :boost => proc{ |p| 10 if p.enabled } | ||
968 | - after_save_reindex [:articles], :with => :delayed_job | ||
969 | - handle_asynchronously :solr_save | 933 | + public |
970 | 934 | ||
971 | def control_panel_settings_button | 935 | def control_panel_settings_button |
972 | {:title => _('Profile Info and settings'), :icon => 'edit-profile'} | 936 | {:title => _('Profile Info and settings'), :icon => 'edit-profile'} |
app/models/profile_image_block.rb
app/models/profile_list_block.rb
1 | class ProfileListBlock < Block | 1 | class ProfileListBlock < Block |
2 | 2 | ||
3 | + attr_accessible :limit, :prioritize_profiles_with_image | ||
4 | + | ||
3 | settings_items :limit, :type => :integer, :default => 6 | 5 | settings_items :limit, :type => :integer, :default => 6 |
4 | settings_items :prioritize_profiles_with_image, :type => :boolean, :default => true | 6 | settings_items :prioritize_profiles_with_image, :type => :boolean, :default => true |
5 | 7 |
app/models/qualifier.rb
@@ -15,6 +15,4 @@ class Qualifier < ActiveRecord::Base | @@ -15,6 +15,4 @@ class Qualifier < ActiveRecord::Base | ||
15 | self.name.downcase.transliterate <=> b.name.downcase.transliterate | 15 | self.name.downcase.transliterate <=> b.name.downcase.transliterate |
16 | end | 16 | end |
17 | 17 | ||
18 | - after_save_reindex [:products], :with => :delayed_job | ||
19 | - | ||
20 | end | 18 | end |
app/models/recent_documents_block.rb
@@ -14,7 +14,7 @@ class RecentDocumentsBlock < Block | @@ -14,7 +14,7 @@ class RecentDocumentsBlock < Block | ||
14 | 14 | ||
15 | settings_items :limit, :type => :integer, :default => 5 | 15 | settings_items :limit, :type => :integer, :default => 5 |
16 | 16 | ||
17 | - include ActionController::UrlWriter | 17 | + include Rails.application.routes.url_helpers |
18 | def content(args={}) | 18 | def content(args={}) |
19 | docs = self.limit.nil? ? owner.recent_documents(nil, {}, false) : owner.recent_documents(self.limit, {}, false) | 19 | docs = self.limit.nil? ? owner.recent_documents(nil, {}, false) : owner.recent_documents(self.limit, {}, false) |
20 | block_title(title) + | 20 | block_title(title) + |
app/models/rss_feed.rb
@@ -63,7 +63,7 @@ class RssFeed < Article | @@ -63,7 +63,7 @@ class RssFeed < Article | ||
63 | 'text/xml' | 63 | 'text/xml' |
64 | end | 64 | end |
65 | 65 | ||
66 | - include ActionController::UrlWriter | 66 | + include Rails.application.routes.url_helpers |
67 | def fetch_articles | 67 | def fetch_articles |
68 | if parent && parent.has_posts? | 68 | if parent && parent.has_posts? |
69 | language = self.language.blank? ? {} : { :language => self.language } | 69 | language = self.language.blank? ? {} : { :language => self.language } |
app/models/tags_block.rb
@@ -2,7 +2,7 @@ class TagsBlock < Block | @@ -2,7 +2,7 @@ class TagsBlock < Block | ||
2 | 2 | ||
3 | include TagsHelper | 3 | include TagsHelper |
4 | include BlockHelper | 4 | include BlockHelper |
5 | - include ActionController::UrlWriter | 5 | + include Rails.application.routes.url_helpers |
6 | 6 | ||
7 | settings_items :limit, :type => :integer, :default => 12 | 7 | settings_items :limit, :type => :integer, :default => 12 |
8 | 8 |
app/models/user.rb
1 | require 'digest/sha1' | 1 | require 'digest/sha1' |
2 | +require 'user_activation_job' | ||
2 | 3 | ||
3 | # User models the system users, and is generated by the acts_as_authenticated | 4 | # User models the system users, and is generated by the acts_as_authenticated |
4 | # Rails generator. | 5 | # Rails generator. |
5 | class User < ActiveRecord::Base | 6 | class User < ActiveRecord::Base |
6 | 7 | ||
8 | + attr_accessible :login, :email, :password, :password_confirmation | ||
9 | + | ||
7 | N_('Password') | 10 | N_('Password') |
8 | N_('Password confirmation') | 11 | N_('Password confirmation') |
9 | N_('Terms accepted') | 12 | N_('Terms accepted') |
@@ -15,9 +18,12 @@ class User < ActiveRecord::Base | @@ -15,9 +18,12 @@ class User < ActiveRecord::Base | ||
15 | # FIXME ugly workaround | 18 | # FIXME ugly workaround |
16 | def self.human_attribute_name(attrib) | 19 | def self.human_attribute_name(attrib) |
17 | case attrib.to_sym | 20 | case attrib.to_sym |
18 | - when :login: return _('Username') | ||
19 | - when :email: return _('e-Mail') | ||
20 | - else _(self.superclass.human_attribute_name(attrib)) | 21 | + when :login |
22 | + return _('Username') | ||
23 | + when :email | ||
24 | + return _('e-Mail') | ||
25 | + else | ||
26 | + _(self.superclass.human_attribute_name(attrib)) | ||
21 | end | 27 | end |
22 | end | 28 | end |
23 | 29 | ||
@@ -29,11 +35,18 @@ class User < ActiveRecord::Base | @@ -29,11 +35,18 @@ class User < ActiveRecord::Base | ||
29 | end | 35 | end |
30 | 36 | ||
31 | after_create do |user| | 37 | after_create do |user| |
32 | - user.person ||= Person.new | ||
33 | - user.person.attributes = user.person_data.merge(:identifier => user.login, :user => user, :environment_id => user.environment_id) | ||
34 | - user.person.name ||= user.login | ||
35 | - user.person.visible = false unless user.activated? | ||
36 | - user.person.save! | 38 | + unless user.person |
39 | + p = Person.new | ||
40 | + | ||
41 | + p.attributes = user.person_data | ||
42 | + p.identifier = user.login | ||
43 | + p.user = user | ||
44 | + p.environment = user.environment | ||
45 | + p.name ||= user.login | ||
46 | + p.visible = false unless user.activated? | ||
47 | + | ||
48 | + user.person = p | ||
49 | + end | ||
37 | if user.environment.enabled?('skip_new_user_email_confirmation') | 50 | if user.environment.enabled?('skip_new_user_email_confirmation') |
38 | user.activate | 51 | user.activate |
39 | end | 52 | end |
@@ -51,6 +64,8 @@ class User < ActiveRecord::Base | @@ -51,6 +64,8 @@ class User < ActiveRecord::Base | ||
51 | end | 64 | end |
52 | 65 | ||
53 | class Mailer < ActionMailer::Base | 66 | class Mailer < ActionMailer::Base |
67 | + | ||
68 | + # FIXME use new ActionMailer API here | ||
54 | def activation_email_notify(user) | 69 | def activation_email_notify(user) |
55 | user_email = "#{user.login}@#{user.email_domain}" | 70 | user_email = "#{user.login}@#{user.email_domain}" |
56 | recipients user_email | 71 | recipients user_email |
@@ -64,16 +79,19 @@ class User < ActiveRecord::Base | @@ -64,16 +79,19 @@ class User < ActiveRecord::Base | ||
64 | end | 79 | end |
65 | 80 | ||
66 | def activation_code(user) | 81 | def activation_code(user) |
67 | - recipients user.email | ||
68 | - | ||
69 | - from "#{user.environment.name} <#{user.environment.contact_email}>" | ||
70 | - subject _("[%s] Activate your account") % [user.environment.name] | ||
71 | - body :recipient => user.name, | ||
72 | - :activation_code => user.activation_code, | ||
73 | - :environment => user.environment.name, | ||
74 | - :url => user.environment.top_url | 82 | + @recipient = user.name, |
83 | + @activation_code = user.activation_code | ||
84 | + @environment = user.environment.name | ||
85 | + @url = user.environment.top_url | ||
86 | + | ||
87 | + mail( | ||
88 | + :from => "#{user.environment.name} <#{user.environment.contact_email}>", | ||
89 | + :to => user.email, | ||
90 | + :subject => _("[%s] Activate your account") % [user.environment.name], | ||
91 | + ) | ||
75 | end | 92 | end |
76 | 93 | ||
94 | + # FIXME use new ActionMailer API here | ||
77 | def signup_welcome_email(user) | 95 | def signup_welcome_email(user) |
78 | email_body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name) | 96 | email_body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name) |
79 | email_subject = user.environment.signup_welcome_text_subject | 97 | email_subject = user.environment.signup_welcome_text_subject |
@@ -93,7 +111,7 @@ class User < ActiveRecord::Base | @@ -93,7 +111,7 @@ class User < ActiveRecord::Base | ||
93 | self.person.save! | 111 | self.person.save! |
94 | end | 112 | end |
95 | end | 113 | end |
96 | - | 114 | + |
97 | has_one :person, :dependent => :destroy | 115 | has_one :person, :dependent => :destroy |
98 | belongs_to :environment | 116 | belongs_to :environment |
99 | 117 | ||
@@ -136,6 +154,7 @@ class User < ActiveRecord::Base | @@ -136,6 +154,7 @@ class User < ActiveRecord::Base | ||
136 | false | 154 | false |
137 | else | 155 | else |
138 | if environment.enabled?('send_welcome_email_to_new_users') && environment.has_signup_welcome_text? | 156 | if environment.enabled?('send_welcome_email_to_new_users') && environment.has_signup_welcome_text? |
157 | + # FIXME use new ActionMailer API here | ||
139 | User::Mailer.delay.deliver_signup_welcome_email(self) | 158 | User::Mailer.delay.deliver_signup_welcome_email(self) |
140 | end | 159 | end |
141 | true | 160 | true |
@@ -329,7 +348,7 @@ class User < ActiveRecord::Base | @@ -329,7 +348,7 @@ class User < ActiveRecord::Base | ||
329 | 348 | ||
330 | def deliver_activation_code | 349 | def deliver_activation_code |
331 | return if person.is_template? | 350 | return if person.is_template? |
332 | - User::Mailer.deliver_activation_code(self) unless self.activation_code.blank? | 351 | + User::Mailer.activation_code(self).deliver unless self.activation_code.blank? |
333 | end | 352 | end |
334 | 353 | ||
335 | def delay_activation_check | 354 | def delay_activation_check |
config/initializers/dependencies.rb
1 | # locally-developed modules | 1 | # locally-developed modules |
2 | -require 'acts_as_faceted' | ||
3 | require 'acts_as_filesystem' | 2 | require 'acts_as_filesystem' |
4 | require 'acts_as_having_settings' | 3 | require 'acts_as_having_settings' |
5 | -require 'acts_as_searchable' | ||
6 | require 'acts_as_having_boxes' | 4 | require 'acts_as_having_boxes' |
7 | require 'acts_as_having_image' | 5 | require 'acts_as_having_image' |
8 | require 'acts_as_having_posts' | 6 | require 'acts_as_having_posts' |
@@ -11,6 +9,7 @@ require 'maybe_add_http' | @@ -11,6 +9,7 @@ require 'maybe_add_http' | ||
11 | require 'set_profile_region_from_city_state' | 9 | require 'set_profile_region_from_city_state' |
12 | require 'authenticated_system' | 10 | require 'authenticated_system' |
13 | require 'needs_profile' | 11 | require 'needs_profile' |
12 | +require 'white_list_filter' | ||
14 | 13 | ||
15 | # third-party libraries | 14 | # third-party libraries |
16 | require 'will_paginate' | 15 | require 'will_paginate' |
config/initializers/html_safe.rb
@@ -2,8 +2,9 @@ | @@ -2,8 +2,9 @@ | ||
2 | 2 | ||
3 | # Disable Rails html autoescaping. This is due to noosfero using too much helpers/models to output html. | 3 | # Disable Rails html autoescaping. This is due to noosfero using too much helpers/models to output html. |
4 | # It it would change too much code and make it hard to maintain. | 4 | # It it would change too much code and make it hard to maintain. |
5 | +# FIXME THIS IS SO WRONG | ||
5 | class Object | 6 | class Object |
6 | def html_safe? | 7 | def html_safe? |
7 | true | 8 | true |
8 | end | 9 | end |
9 | -end | ||
10 | \ No newline at end of file | 10 | \ No newline at end of file |
11 | +end |
lib/acts_as_faceted.rb
@@ -1,222 +0,0 @@ | @@ -1,222 +0,0 @@ | ||
1 | -module ActsAsFaceted | ||
2 | - | ||
3 | - module ClassMethods | ||
4 | - end | ||
5 | - | ||
6 | - module ActsMethods | ||
7 | - # Example: | ||
8 | - # | ||
9 | - #acts_as_faceted :fields => { | ||
10 | - # :f_type => {:label => _('Type'), :proc => proc{|klass| f_type_proc(klass)}}, | ||
11 | - # :f_published_at => {:type => :date, :label => _('Published date'), :queries => {'[* TO NOW-1YEARS/DAY]' => _("Older than one year"), | ||
12 | - # '[NOW-1YEARS TO NOW/DAY]' => _("Last year"), '[NOW-1MONTHS TO NOW/DAY]' => _("Last month"), '[NOW-7DAYS TO NOW/DAY]' => _("Last week"), '[NOW-1DAYS TO NOW/DAY]' => _("Last day")}}, | ||
13 | - # :f_profile_type => {:label => _('Author'), :proc => proc{|klass| f_profile_type_proc(klass)}}, | ||
14 | - # :f_category => {:label => _('Categories')}}, | ||
15 | - # :order => [:f_type, :f_published_at, :f_profile_type, :f_category] | ||
16 | - # | ||
17 | - #acts_as_searchable :additional_fields => [ {:name => {:type => :string, :as => :name_sort, :boost => 5.0}} ] + facets_fields_for_solr, | ||
18 | - # :exclude_fields => [:setting], | ||
19 | - # :include => [:profile], | ||
20 | - # :facets => facets_option_for_solr, | ||
21 | - # :if => proc{|a| ! ['RssFeed'].include?(a.class.name)} | ||
22 | - def acts_as_faceted(options) | ||
23 | - extend ClassMethods | ||
24 | - extend ActsAsSolr::CommonMethods | ||
25 | - | ||
26 | - cattr_accessor :facets | ||
27 | - cattr_accessor :facets_order | ||
28 | - cattr_accessor :to_solr_fields_names | ||
29 | - cattr_accessor :facets_results_containers | ||
30 | - cattr_accessor :solr_fields_names | ||
31 | - cattr_accessor :facets_option_for_solr | ||
32 | - cattr_accessor :facets_fields_for_solr | ||
33 | - cattr_accessor :facet_category_query | ||
34 | - | ||
35 | - self.facets = options[:fields] | ||
36 | - self.facets_order = options[:order] || self.facets.keys | ||
37 | - self.facets_results_containers = {:fields => 'facet_fields', :queries => 'facet_queries', :ranges => 'facet_ranges'} | ||
38 | - self.facets_option_for_solr = Hash[facets.select{ |id,data| ! data.has_key?(:queries) }].keys | ||
39 | - self.facets_fields_for_solr = facets.map{ |id,data| {id => data[:type] || :facet} } | ||
40 | - self.solr_fields_names = facets.map{ |id,data| id.to_s + '_' + get_solr_field_type(data[:type] || :facet) } | ||
41 | - self.facet_category_query = options[:category_query] | ||
42 | - | ||
43 | - # A hash to retrieve the field key for the solr facet string returned | ||
44 | - # :field_name => "field_name_facet" | ||
45 | - self.to_solr_fields_names = Hash[facets.keys.zip(solr_fields_names)] | ||
46 | - | ||
47 | - def facet_by_id(id) | ||
48 | - {:id => id}.merge(facets[id]) if facets[id] | ||
49 | - end | ||
50 | - | ||
51 | - def map_facets_for(environment) | ||
52 | - facets_order.map do |id| | ||
53 | - facet = facet_by_id(id) | ||
54 | - next if facet[:type_if] and !facet[:type_if].call(self.new) | ||
55 | - | ||
56 | - if facet[:multi] | ||
57 | - facet[:label].call(environment).map do |label_id, label| | ||
58 | - facet.merge({:id => facet[:id].to_s+'_'+label_id.to_s, :solr_field => facet[:id], :label_id => label_id, :label => label}) | ||
59 | - end | ||
60 | - else | ||
61 | - facet.merge(:id => facet[:id].to_s, :solr_field => facet[:id]) | ||
62 | - end | ||
63 | - end.compact.flatten | ||
64 | - end | ||
65 | - | ||
66 | - def map_facet_results(facet, facet_params, facets_data, unfiltered_facets_data = {}, options = {}) | ||
67 | - raise 'Use map_facets_for before this method' if facet[:solr_field].nil? | ||
68 | - facets_data = {} if facets_data.blank? # could be empty array | ||
69 | - solr_facet = to_solr_fields_names[facet[:solr_field]] | ||
70 | - unfiltered_facets_data ||= {} | ||
71 | - | ||
72 | - if facet[:queries] | ||
73 | - container = facets_data[facets_results_containers[:queries]] | ||
74 | - facet_data = (container.nil? or container.empty?) ? [] : container.select{ |k,v| k.starts_with? solr_facet } | ||
75 | - container = unfiltered_facets_data[facets_results_containers[:queries]] | ||
76 | - unfiltered_facet_data = (container.nil? or container.empty?) ? [] : container.select{ |k,v| k.starts_with? solr_facet } | ||
77 | - else | ||
78 | - container = facets_data[facets_results_containers[:fields]] | ||
79 | - facet_data = (container.nil? or container.empty?) ? [] : container[solr_facet] || [] | ||
80 | - container = unfiltered_facets_data[facets_results_containers[:fields]] | ||
81 | - unfiltered_facet_data = (container.nil? or container.empty?) ? [] : container[solr_facet] || [] | ||
82 | - end | ||
83 | - | ||
84 | - if !unfiltered_facets_data.blank? and !facet_params.blank? | ||
85 | - f = Hash[Array(facet_data)] | ||
86 | - zeros = [] | ||
87 | - facet_data = unfiltered_facet_data.map do |id, count| | ||
88 | - count = f[id] | ||
89 | - if count.nil? | ||
90 | - zeros.push [id, 0] | ||
91 | - nil | ||
92 | - else | ||
93 | - [id, count] | ||
94 | - end | ||
95 | - end.compact + zeros | ||
96 | - end | ||
97 | - | ||
98 | - facet_count = facet_data.length | ||
99 | - | ||
100 | - if facet[:queries] | ||
101 | - result = facet_data.map do |id, count| | ||
102 | - q = id[id.index(':')+1,id.length] | ||
103 | - label = facet_result_name(facet, q) | ||
104 | - [q, label, count] if count > 0 | ||
105 | - end.compact | ||
106 | - result = facet[:queries_order].map{ |id| result.detect{ |rid, label, count| rid == id } }.compact if facet[:queries_order] | ||
107 | - elsif facet[:proc] | ||
108 | - if facet[:label_id] | ||
109 | - result = facet_data.map do |id, count| | ||
110 | - name = facet_result_name(facet, id) | ||
111 | - [id, name, count] if name | ||
112 | - end.compact | ||
113 | - # FIXME limit is NOT improving performance in this case :( | ||
114 | - facet_count = result.length | ||
115 | - result = result.first(options[:limit]) if options[:limit] | ||
116 | - else | ||
117 | - facet_data = facet_data.first(options[:limit]) if options[:limit] | ||
118 | - result = facet_data.map { |id, count| [id, facet_result_name(facet, id), count] } | ||
119 | - end | ||
120 | - else | ||
121 | - facet_data = facet_data.first(options[:limit]) if options[:limit] | ||
122 | - result = facet_data.map { |id, count| [id, facet_result_name(facet, id), count] } | ||
123 | - end | ||
124 | - | ||
125 | - sorted = facet_result_sort(facet, result, options[:sort]) | ||
126 | - | ||
127 | - # length can't be used if limit option is given; | ||
128 | - # total_entries comes to help | ||
129 | - sorted.class.send(:define_method, :total_entries, proc { facet_count }) | ||
130 | - | ||
131 | - sorted | ||
132 | - end | ||
133 | - | ||
134 | - def facet_result_sort(facet, facets_data, sort_by = nil) | ||
135 | - if facet[:queries_order] | ||
136 | - facets_data | ||
137 | - elsif sort_by == :alphabetically | ||
138 | - facets_data.sort{ |a,b| Array(a[1])[0] <=> Array(b[1])[0] } | ||
139 | - elsif sort_by == :count | ||
140 | - facets_data.sort{ |a,b| -1*(a[2] <=> b[2]) } | ||
141 | - else | ||
142 | - facets_data | ||
143 | - end | ||
144 | - end | ||
145 | - | ||
146 | - def facet_result_name(facet, data) | ||
147 | - if facet[:queries] | ||
148 | - gettext(facet[:queries][data]) | ||
149 | - elsif facet[:proc] | ||
150 | - if facet[:multi] | ||
151 | - facet[:label_id] ||= 0 | ||
152 | - facet[:proc].call(facet, data) | ||
153 | - else | ||
154 | - gettext(facet[:proc].call(data)) | ||
155 | - end | ||
156 | - else | ||
157 | - data | ||
158 | - end | ||
159 | - end | ||
160 | - | ||
161 | - def facet_label(facet) | ||
162 | - return nil unless facet | ||
163 | - _(facet[:label]) | ||
164 | - end | ||
165 | - | ||
166 | - def facets_find_options(facets_selected = {}, options = {}) | ||
167 | - browses = [] | ||
168 | - facets_selected ||= {} | ||
169 | - facets_selected.map do |id, value| | ||
170 | - next unless facets[id.to_sym] | ||
171 | - if value.kind_of?(Hash) | ||
172 | - value.map do |label_id, value| | ||
173 | - value.to_a.each do |value| | ||
174 | - browses << id.to_s + ':' + (facets[id.to_sym][:queries] ? value : '"'+value.to_s+'"') | ||
175 | - end | ||
176 | - end | ||
177 | - else | ||
178 | - browses << id.to_s + ':' + (facets[id.to_sym][:queries] ? value : '"'+value.to_s+'"') | ||
179 | - end | ||
180 | - end.flatten | ||
181 | - | ||
182 | - {:facets => {:zeros => false, :sort => :count, | ||
183 | - :fields => facets_option_for_solr, | ||
184 | - :browse => browses, | ||
185 | - :query => facets.map { |f, options| options[:queries].keys.map { |q| f.to_s + ':' + q } if options[:queries] }.compact.flatten, | ||
186 | - } | ||
187 | - } | ||
188 | - end | ||
189 | - end | ||
190 | - end | ||
191 | - | ||
192 | -end | ||
193 | - | ||
194 | -ActiveRecord::Base.extend ActsAsFaceted::ActsMethods | ||
195 | - | ||
196 | -# from https://github.com/rubyworks/facets/blob/master/lib/core/facets/enumerable/graph.rb | ||
197 | -module Enumerable | ||
198 | - def graph(&yld) | ||
199 | - if yld | ||
200 | - h = {} | ||
201 | - each do |*kv| | ||
202 | - r = yld[*kv] | ||
203 | - case r | ||
204 | - when Hash | ||
205 | - nk, nv = *r.to_a[0] | ||
206 | - when Range | ||
207 | - nk, nv = r.first, r.last | ||
208 | - else | ||
209 | - nk, nv = *r | ||
210 | - end | ||
211 | - h[nk] = nv | ||
212 | - end | ||
213 | - h | ||
214 | - else | ||
215 | - Enumerator.new(self,:graph) | ||
216 | - end | ||
217 | - end | ||
218 | - | ||
219 | - # Alias for #graph, which stands for "map hash". | ||
220 | - alias_method :mash, :graph | ||
221 | -end | ||
222 | - |
lib/acts_as_searchable.rb
@@ -1,87 +0,0 @@ | @@ -1,87 +0,0 @@ | ||
1 | -module ActsAsSearchable | ||
2 | - | ||
3 | - module ClassMethods | ||
4 | - ACTS_AS_SEARCHABLE_ENABLED = true unless defined? ACTS_AS_SEARCHABLE_ENABLED | ||
5 | - | ||
6 | - def acts_as_searchable(options = {}) | ||
7 | - return if !ACTS_AS_SEARCHABLE_ENABLED | ||
8 | - | ||
9 | - if options[:fields] | ||
10 | - options[:fields] << {:schema_name => :string} | ||
11 | - else | ||
12 | - options[:additional_fields] ||= [] | ||
13 | - options[:additional_fields] << {:schema_name => :string} | ||
14 | - end | ||
15 | - | ||
16 | - acts_as_solr options | ||
17 | - extend FindByContents | ||
18 | - send :include, InstanceMethods | ||
19 | - end | ||
20 | - | ||
21 | - module InstanceMethods | ||
22 | - def schema_name | ||
23 | - self.class.schema_name | ||
24 | - end | ||
25 | - | ||
26 | - # replace solr_id from vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/instance_methods.rb | ||
27 | - # to include schema_name | ||
28 | - def solr_id | ||
29 | - id = "#{self.class.name}:#{record_id(self)}" | ||
30 | - id.insert(0, "#{schema_name}:") unless schema_name.blank? | ||
31 | - id | ||
32 | - end | ||
33 | - end | ||
34 | - | ||
35 | - module FindByContents | ||
36 | - | ||
37 | - def schema_name | ||
38 | - (Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql?) ? ActiveRecord::Base.connection.schema_search_path : '' | ||
39 | - end | ||
40 | - | ||
41 | - def find_by_contents(query, pg_options = {}, options = {}, db_options = {}) | ||
42 | - pg_options[:page] ||= 1 | ||
43 | - pg_options[:per_page] ||= 20 | ||
44 | - options[:page] = pg_options[:page].to_i | ||
45 | - options[:per_page] = pg_options[:per_page].to_i | ||
46 | - options[:scores] ||= true | ||
47 | - options[:filter_queries] ||= [] | ||
48 | - options[:filter_queries] << "schema_name:\"#{schema_name}\"" unless schema_name.blank? | ||
49 | - all_facets_enabled = options.delete(:all_facets) | ||
50 | - options[:per_page] = options.delete(:extra_limit) if options[:extra_limit] | ||
51 | - results = [] | ||
52 | - facets = all_facets = {} | ||
53 | - | ||
54 | - solr_result = find_by_solr(query, options) | ||
55 | - if all_facets_enabled | ||
56 | - options[:facets][:browse] = nil | ||
57 | - all_facets = find_by_solr(query, options.merge(:per_page => 0)).facets | ||
58 | - end | ||
59 | - | ||
60 | - if !solr_result.nil? | ||
61 | - facets = options.include?(:facets) ? solr_result.facets : [] | ||
62 | - | ||
63 | - if db_options.empty? | ||
64 | - results = solr_result | ||
65 | - else | ||
66 | - ids = solr_result.results.map{ |r| r[:id].to_i } | ||
67 | - if ids.empty? | ||
68 | - ids << -1 | ||
69 | - end | ||
70 | - | ||
71 | - if db_options[:conditions] | ||
72 | - db_options[:conditions] = sanitize_sql_for_conditions(db_options[:conditions]) + " and #{table_name}.id in (#{ids.join(', ')})" | ||
73 | - else | ||
74 | - db_options[:conditions] = "#{table_name}.id in (#{ids.join(', ')})" | ||
75 | - end | ||
76 | - | ||
77 | - results = find(:all, db_options) | ||
78 | - end | ||
79 | - end | ||
80 | - | ||
81 | - {:results => results, :facets => facets, :all_facets => all_facets} | ||
82 | - end | ||
83 | - end | ||
84 | - end | ||
85 | -end | ||
86 | - | ||
87 | -ActiveRecord::Base.send(:extend, ActsAsSearchable::ClassMethods) |
lib/tasks/data.rake
1 | namespace :db do | 1 | namespace :db do |
2 | namespace :data do | 2 | namespace :data do |
3 | task :minimal do | 3 | task :minimal do |
4 | - sh './script/runner', "Environment.create!(:name => 'Noosfero', :is_default => true)" | 4 | + sh 'rails', 'runner', "Environment.create!(:name => 'Noosfero', :is_default => true)" |
5 | unless ENV['NOOSFERO_DOMAIN'].blank? | 5 | unless ENV['NOOSFERO_DOMAIN'].blank? |
6 | - sh './script/runner', "Environment.default.domains << Domain.new(:name => ENV['NOOSFERO_DOMAIN'])" | 6 | + sh 'rails', 'runner', "Environment.default.domains << Domain.new(:name => ENV['NOOSFERO_DOMAIN'])" |
7 | end | 7 | end |
8 | end | 8 | end |
9 | end | 9 | end |
script/quick-start
@@ -66,15 +66,6 @@ else | @@ -66,15 +66,6 @@ else | ||
66 | fi | 66 | fi |
67 | fi | 67 | fi |
68 | 68 | ||
69 | -# setup solr | ||
70 | -run 'rake solr:download || true' | ||
71 | -if ! test -f vendor/plugins/acts_as_solr_reloaded/solr/start.jar; then | ||
72 | - complain "Failed to download solr!" | ||
73 | - exit 1 | ||
74 | -fi | ||
75 | - | ||
76 | -run cp config/solr.yml.dist config/solr.yml | ||
77 | - | ||
78 | # create the database with sample data | 69 | # create the database with sample data |
79 | run cp config/database.yml.sqlite3 config/database.yml | 70 | run cp config/database.yml.sqlite3 config/database.yml |
80 | run rake db:schema:load | 71 | run rake db:schema:load |
vendor/plugins/access_control/lib/role.rb
1 | class Role < ActiveRecord::Base | 1 | class Role < ActiveRecord::Base |
2 | 2 | ||
3 | + attr_accessible :key, :name, :environment, :permissions | ||
4 | + | ||
3 | has_many :role_assignments, :dependent => :destroy | 5 | has_many :role_assignments, :dependent => :destroy |
4 | belongs_to :environment | 6 | belongs_to :environment |
5 | serialize :permissions, Array | 7 | serialize :permissions, Array |
vendor/plugins/acts_as_solr_reloaded/.gitignore
@@ -1,33 +0,0 @@ | @@ -1,33 +0,0 @@ | ||
1 | -# inside solr | ||
2 | -solr/LICENSE.txt | ||
3 | -solr/NOTICE.txt | ||
4 | -solr/README.txt | ||
5 | -solr/etc/ | ||
6 | -solr/work/ | ||
7 | -solr/lib/ | ||
8 | -solr/solr/README.txt | ||
9 | -solr/solr/solr.xml | ||
10 | -solr/start.jar | ||
11 | -solr/webapps/ | ||
12 | -solr/solr/data/* | ||
13 | - | ||
14 | -Gemfile.lock | ||
15 | -test/solr | ||
16 | -test/tmp | ||
17 | - | ||
18 | -acts_as_solr_reloaded-*.gem | ||
19 | -*.log | ||
20 | -*.log | ||
21 | -*_pid | ||
22 | - | ||
23 | -coverage | ||
24 | -coverage/* | ||
25 | -coverage.data | ||
26 | -test/db/*.db | ||
27 | -test/log/*.log | ||
28 | -pkg/* | ||
29 | -*.sw? | ||
30 | -rdoc | ||
31 | -pkg | ||
32 | -tags | ||
33 | -.svn |
vendor/plugins/acts_as_solr_reloaded/.travis.yml
@@ -1,13 +0,0 @@ | @@ -1,13 +0,0 @@ | ||
1 | -before_script: | ||
2 | - - mongo mydb_test --eval 'db.addUser("travis", "test");' | ||
3 | - - gem update --system 1.4.1 > /dev/null 2>&1 | ||
4 | - - rake solr:download | ||
5 | - - RAILS_ENV=test rake solr:start | ||
6 | - | ||
7 | -script: "bundle exec rake $TASK --trace" | ||
8 | - | ||
9 | -rvm: | ||
10 | - - 1.8.7 | ||
11 | -env: | ||
12 | - - TASK=test | ||
13 | - - TASK=test:functional |
vendor/plugins/acts_as_solr_reloaded/Gemfile
vendor/plugins/acts_as_solr_reloaded/LICENSE
@@ -1,22 +0,0 @@ | @@ -1,22 +0,0 @@ | ||
1 | -(The MIT License) | ||
2 | - | ||
3 | -Copyright © 2010 | ||
4 | - | ||
5 | -Permission is hereby granted, free of charge, to any person obtaining | ||
6 | -a copy of this software and associated documentation files (the | ||
7 | -‘Software’), to deal in the Software without restriction, including | ||
8 | -without limitation the rights to use, copy, modify, merge, publish, | ||
9 | -distribute, sublicense, and/or sell copies of the Software, and to | ||
10 | -permit persons to whom the Software is furnished to do so, subject to | ||
11 | -the following conditions: | ||
12 | - | ||
13 | -The above copyright notice and this permission notice shall be | ||
14 | -included in all copies or substantial portions of the Software. | ||
15 | - | ||
16 | -THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, | ||
17 | -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
18 | -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
19 | -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
20 | -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
21 | -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
22 | -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
vendor/plugins/acts_as_solr_reloaded/README.markdown
@@ -1,128 +0,0 @@ | @@ -1,128 +0,0 @@ | ||
1 | -[](http://travis-ci.org/coletivoEITA/acts_as_solr_reloaded) | ||
2 | - | ||
3 | -Description | ||
4 | -====== | ||
5 | -This plugin adds full text search capabilities and many other nifty features from Apache's [Solr](http://lucene.apache.org/solr/) to any Rails model. | ||
6 | -It was based on the first draft by Erik Hatcher. | ||
7 | - | ||
8 | -This plugin is intended for use in old versions of Rails. For newer versions, I strongly advice using Sunspot! | ||
9 | -Nevertheless, this plugin is used for Noosfero project in production. Any problem please open an issue. | ||
10 | - | ||
11 | -It should support Rails 2.1 (and greater 2.x) and is developed latest Solr versions, so don't expect it to run on older Solr. | ||
12 | - | ||
13 | -Installation | ||
14 | -====== | ||
15 | - | ||
16 | -Install as a plugin | ||
17 | - | ||
18 | - script/plugin install git://github.com/brauliobo/acts_as_solr_reloaded.git | ||
19 | - | ||
20 | -Download Solr | ||
21 | - | ||
22 | - rake solr:download | ||
23 | - | ||
24 | -Requirements | ||
25 | ------- | ||
26 | -* Java Runtime Environment(JRE) 6.0 (or newer) from Oracle or OpenJDK | ||
27 | - | ||
28 | -Configuration | ||
29 | -====== | ||
30 | -See config/solr.yml file. | ||
31 | - | ||
32 | -For solr configuration the important files are solrconfig.xml and schema.xml. | ||
33 | - | ||
34 | -Basic Usage | ||
35 | -====== | ||
36 | -Just include the line below to any of your ActiveRecord models: | ||
37 | - | ||
38 | - acts_as_solr | ||
39 | - | ||
40 | -Or if you want, you can specify only the fields that should be indexed: | ||
41 | - | ||
42 | - acts_as_solr :fields => [:name, :author] | ||
43 | - | ||
44 | -Then to find instances of your model, just do: | ||
45 | - | ||
46 | - Model.search(query) #query is a string representing your query | ||
47 | - | ||
48 | -Please see ActsAsSolr::ActsMethods for a complete info | ||
49 | - | ||
50 | -Pagination | ||
51 | -====== | ||
52 | -ActsAsSolr implements in SearchResults class an interface compatible with will_paginate and maybe others. | ||
53 | - | ||
54 | -In your tests | ||
55 | -====== | ||
56 | -To test code that uses `acts_as_solr` you must start a Solr server for the test environment. | ||
57 | -You can add to the beggining of your test/test_helper.rb the code: | ||
58 | - | ||
59 | - ENV["RAILS_ENV"] = "test" | ||
60 | - abort unless system 'rake solr:start' | ||
61 | - at_exit { system 'rake solr:stop' } | ||
62 | - | ||
63 | -However, if you would like to mock out Solr calls so that a Solr server is not needed (and your tests will run much faster), just add this to your `test_helper.rb` or similar: | ||
64 | - | ||
65 | - class ActsAsSolr::Post | ||
66 | - def self.execute(request) | ||
67 | - true | ||
68 | - end | ||
69 | - end | ||
70 | - | ||
71 | -Or to be more realistic and preserve performance, enable Solr when needed, | ||
72 | -by calling `TestSolr.enable` and disable solr otherwise by calling | ||
73 | -`TestSolr.disable` on `Test::Unit::TestCase`'s `setup`: | ||
74 | - | ||
75 | - class ActsAsSolr::Post | ||
76 | - class << self | ||
77 | - alias_method :execute_orig, :execute | ||
78 | - end | ||
79 | - end | ||
80 | - module ActsAsSolr::ParserMethods | ||
81 | - alias_method :parse_results_orig, :parse_results | ||
82 | - end | ||
83 | - | ||
84 | - class TestSolr | ||
85 | - | ||
86 | - def self.enable | ||
87 | - ActsAsSolr::Post.class_eval do | ||
88 | - def self.execute(*args) | ||
89 | - execute_orig *args | ||
90 | - end | ||
91 | - end | ||
92 | - ActsAsSolr::ParserMethods.module_eval do | ||
93 | - def parse_results(*args) | ||
94 | - parse_results_orig *args | ||
95 | - end | ||
96 | - end | ||
97 | - | ||
98 | - # clear index | ||
99 | - ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => '*:*')) | ||
100 | - | ||
101 | - @solr_disabled = false | ||
102 | - end | ||
103 | - | ||
104 | - def self.disable | ||
105 | - return if @solr_disabled | ||
106 | - | ||
107 | - ActsAsSolr::Post.class_eval do | ||
108 | - def self.execute(*args) | ||
109 | - true | ||
110 | - end | ||
111 | - end | ||
112 | - ActsAsSolr::ParserMethods.module_eval do | ||
113 | - def parse_results(*args) | ||
114 | - parse_results_orig nil, args[1] | ||
115 | - end | ||
116 | - end | ||
117 | - | ||
118 | - @solr_disabled = true | ||
119 | - end | ||
120 | - | ||
121 | - end | ||
122 | - | ||
123 | - # disable solr actions by default | ||
124 | - TestSolr.disable | ||
125 | - | ||
126 | -Release Information | ||
127 | -====== | ||
128 | -Released under the MIT license. |
vendor/plugins/acts_as_solr_reloaded/Rakefile
@@ -1,71 +0,0 @@ | @@ -1,71 +0,0 @@ | ||
1 | -require 'rubygems' | ||
2 | -require 'rake' | ||
3 | -require 'rake/testtask' | ||
4 | -require 'rake/rdoctask' | ||
5 | - | ||
6 | -ENV['RAILS_ENV'] = "test" | ||
7 | -require File.expand_path("#{File.dirname(__FILE__)}/config/solr_environment") | ||
8 | - | ||
9 | -Dir["#{File.dirname(__FILE__)}/lib/tasks/*.rake"].sort.each { |ext| load ext } | ||
10 | - | ||
11 | -desc "Default Task" | ||
12 | -task :default => [:test] | ||
13 | - | ||
14 | -desc "Runs the unit tests" | ||
15 | -task :test => "test:unit" | ||
16 | - | ||
17 | -namespace :test do | ||
18 | - task :setup do | ||
19 | - DB ||= 'sqlite' | ||
20 | - puts "Using " + DB | ||
21 | - %x(mysql -u#{MYSQL_USER} < #{File.dirname(__FILE__) + "/test/fixtures/db_definitions/mysql.sql"}) if DB == 'mysql' | ||
22 | - | ||
23 | - Rake::Task["test:migrate"].invoke | ||
24 | - end | ||
25 | - | ||
26 | - desc 'Measures test coverage using rcov' | ||
27 | - task :rcov => :setup do | ||
28 | - rm_f "coverage" | ||
29 | - rm_f "coverage.data" | ||
30 | - rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib" | ||
31 | - | ||
32 | - system("#{rcov} --html #{Dir.glob('test/**/*_shoulda.rb').join(' ')}") | ||
33 | - system("open coverage/index.html") if PLATFORM['darwin'] | ||
34 | - end | ||
35 | - | ||
36 | - desc 'Runs the functional tests, testing integration with Solr' | ||
37 | - Rake::TestTask.new(:functional => :setup) do |t| | ||
38 | - t.pattern = "test/functional/*_test.rb" | ||
39 | - t.verbose = true | ||
40 | - end | ||
41 | - | ||
42 | - desc "Unit tests" | ||
43 | - Rake::TestTask.new(:unit => :setup) do |t| | ||
44 | - t.libs << 'test/unit' | ||
45 | - t.pattern = "test/unit/*_shoulda.rb" | ||
46 | - t.verbose = true | ||
47 | - end | ||
48 | -end | ||
49 | - | ||
50 | -Rake::RDocTask.new do |rd| | ||
51 | - rd.main = "README.rdoc" | ||
52 | - rd.rdoc_dir = "rdoc" | ||
53 | - rd.rdoc_files.exclude("lib/solr/**/*.rb", "lib/solr.rb") | ||
54 | - rd.rdoc_files.include("README.rdoc", "lib/**/*.rb") | ||
55 | -end | ||
56 | - | ||
57 | -begin | ||
58 | - require 'jeweler' | ||
59 | - Jeweler::Tasks.new do |s| | ||
60 | - s.name = "acts_as_solr_reloaded" | ||
61 | - s.summary = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model." | ||
62 | - s.email = "dc.rec1@gmail.com" | ||
63 | - s.homepage = "http://github.com/dcrec1/acts_as_solr_reloaded" | ||
64 | - s.description = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model." | ||
65 | - s.authors = ["Diego Carrion"] | ||
66 | - s.files = FileList["[A-Z]*", "{bin,generators,config,lib,solr}/**/*"] + | ||
67 | - FileList["test/**/*"].reject {|f| f.include?("test/log")}.reject {|f| f.include?("test/tmp")} | ||
68 | - end | ||
69 | -rescue LoadError | ||
70 | - puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler" | ||
71 | -end |
vendor/plugins/acts_as_solr_reloaded/TESTING_THE_PLUGIN
@@ -1,21 +0,0 @@ | @@ -1,21 +0,0 @@ | ||
1 | -acts_as_solr comes with a quick and fast unit test suite, and with a longer-running | ||
2 | -functional test suite, the latter testing the actual integration with Solr. | ||
3 | - | ||
4 | -== Install dependencies | ||
5 | -sudo apt-get install mongodb-server | ||
6 | -bundle install | ||
7 | -gem update --system 1.4.1 | ||
8 | - | ||
9 | -== Running test | ||
10 | -To run the acts_as_solr's plugin tests run the following steps: | ||
11 | - | ||
12 | -- RAILS_ENV=test rake solr:start | ||
13 | - | ||
14 | -- rake test:unit | ||
15 | -(or just rake test) | ||
16 | - | ||
17 | -- rake test:functional (Accepts the following arguments: DB=sqlite|mysql and MYSQL_USER=user) | ||
18 | - | ||
19 | -== Troubleshooting: | ||
20 | -If for some reason the tests don't run and you get MySQL errors, make sure you edit the MYSQL_USER entry under | ||
21 | -config/environment.rb. It's recommended to create or use a MySQL user with no password. |
vendor/plugins/acts_as_solr_reloaded/VERSION
vendor/plugins/acts_as_solr_reloaded/acts_as_solr_reloaded.gemspec
@@ -1,205 +0,0 @@ | @@ -1,205 +0,0 @@ | ||
1 | -# Generated by jeweler | ||
2 | -# DO NOT EDIT THIS FILE DIRECTLY | ||
3 | -# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' | ||
4 | -# -*- encoding: utf-8 -*- | ||
5 | - | ||
6 | -Gem::Specification.new do |s| | ||
7 | - s.name = %q{acts_as_solr_reloaded} | ||
8 | - s.version = "1.6.0" | ||
9 | - | ||
10 | - s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= | ||
11 | - s.authors = ["Diego Carrion"] | ||
12 | - s.date = %q{2011-03-20} | ||
13 | - s.description = %q{This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model.} | ||
14 | - s.email = %q{dc.rec1@gmail.com} | ||
15 | - s.extra_rdoc_files = [ | ||
16 | - "LICENSE", | ||
17 | - "README.markdown", | ||
18 | - "README.rdoc" | ||
19 | - ] | ||
20 | - s.files = [ | ||
21 | - "LICENSE", | ||
22 | - "README.markdown", | ||
23 | - "README.rdoc", | ||
24 | - "Rakefile", | ||
25 | - "TESTING_THE_PLUGIN", | ||
26 | - "VERSION", | ||
27 | - "config/solr.yml", | ||
28 | - "config/solr_environment.rb", | ||
29 | - "generators/dynamic_attributes_migration/dynamic_attributes_migration_generator.rb", | ||
30 | - "generators/dynamic_attributes_migration/templates/migration.rb", | ||
31 | - "generators/local_migration/local_migration_generator.rb", | ||
32 | - "generators/local_migration/templates/migration.rb", | ||
33 | - "lib/acts_as_solr.rb", | ||
34 | - "lib/acts_as_solr/acts_methods.rb", | ||
35 | - "lib/acts_as_solr/class_methods.rb", | ||
36 | - "lib/acts_as_solr/common_methods.rb", | ||
37 | - "lib/acts_as_solr/deprecation.rb", | ||
38 | - "lib/acts_as_solr/dynamic_attribute.rb", | ||
39 | - "lib/acts_as_solr/instance_methods.rb", | ||
40 | - "lib/acts_as_solr/lazy_document.rb", | ||
41 | - "lib/acts_as_solr/local.rb", | ||
42 | - "lib/acts_as_solr/mongo_mapper.rb", | ||
43 | - "lib/acts_as_solr/parser_methods.rb", | ||
44 | - "lib/acts_as_solr/search_results.rb", | ||
45 | - "lib/acts_as_solr/solr_fixtures.rb", | ||
46 | - "lib/acts_as_solr/tasks.rb", | ||
47 | - "lib/acts_as_solr_reloaded.rb", | ||
48 | - "lib/solr.rb", | ||
49 | - "lib/solr/connection.rb", | ||
50 | - "lib/solr/document.rb", | ||
51 | - "lib/solr/exception.rb", | ||
52 | - "lib/solr/field.rb", | ||
53 | - "lib/solr/importer.rb", | ||
54 | - "lib/solr/importer/array_mapper.rb", | ||
55 | - "lib/solr/importer/delimited_file_source.rb", | ||
56 | - "lib/solr/importer/hpricot_mapper.rb", | ||
57 | - "lib/solr/importer/mapper.rb", | ||
58 | - "lib/solr/importer/solr_source.rb", | ||
59 | - "lib/solr/importer/xpath_mapper.rb", | ||
60 | - "lib/solr/indexer.rb", | ||
61 | - "lib/solr/request.rb", | ||
62 | - "lib/solr/request/add_document.rb", | ||
63 | - "lib/solr/request/base.rb", | ||
64 | - "lib/solr/request/commit.rb", | ||
65 | - "lib/solr/request/delete.rb", | ||
66 | - "lib/solr/request/dismax.rb", | ||
67 | - "lib/solr/request/index_info.rb", | ||
68 | - "lib/solr/request/modify_document.rb", | ||
69 | - "lib/solr/request/optimize.rb", | ||
70 | - "lib/solr/request/ping.rb", | ||
71 | - "lib/solr/request/select.rb", | ||
72 | - "lib/solr/request/spellcheck.rb", | ||
73 | - "lib/solr/request/standard.rb", | ||
74 | - "lib/solr/request/update.rb", | ||
75 | - "lib/solr/response.rb", | ||
76 | - "lib/solr/response/add_document.rb", | ||
77 | - "lib/solr/response/base.rb", | ||
78 | - "lib/solr/response/commit.rb", | ||
79 | - "lib/solr/response/delete.rb", | ||
80 | - "lib/solr/response/dismax.rb", | ||
81 | - "lib/solr/response/index_info.rb", | ||
82 | - "lib/solr/response/modify_document.rb", | ||
83 | - "lib/solr/response/optimize.rb", | ||
84 | - "lib/solr/response/ping.rb", | ||
85 | - "lib/solr/response/ruby.rb", | ||
86 | - "lib/solr/response/select.rb", | ||
87 | - "lib/solr/response/spellcheck.rb", | ||
88 | - "lib/solr/response/standard.rb", | ||
89 | - "lib/solr/response/xml.rb", | ||
90 | - "lib/solr/solrtasks.rb", | ||
91 | - "lib/solr/util.rb", | ||
92 | - "lib/solr/xml.rb", | ||
93 | - "lib/tasks/database.rake", | ||
94 | - "lib/tasks/solr.rake", | ||
95 | - "lib/tasks/test.rake", | ||
96 | - "test/config/solr.yml", | ||
97 | - "test/db/connections/mysql/connection.rb", | ||
98 | - "test/db/connections/sqlite/connection.rb", | ||
99 | - "test/db/migrate/001_create_books.rb", | ||
100 | - "test/db/migrate/002_create_movies.rb", | ||
101 | - "test/db/migrate/003_create_categories.rb", | ||
102 | - "test/db/migrate/004_create_electronics.rb", | ||
103 | - "test/db/migrate/005_create_authors.rb", | ||
104 | - "test/db/migrate/006_create_postings.rb", | ||
105 | - "test/db/migrate/007_create_posts.rb", | ||
106 | - "test/db/migrate/008_create_gadgets.rb", | ||
107 | - "test/db/migrate/009_create_dynamic_attributes.rb", | ||
108 | - "test/db/migrate/010_create_advertises.rb", | ||
109 | - "test/db/migrate/011_create_locals.rb", | ||
110 | - "test/db/test.db", | ||
111 | - "test/fixtures/advertises.yml", | ||
112 | - "test/fixtures/authors.yml", | ||
113 | - "test/fixtures/books.yml", | ||
114 | - "test/fixtures/categories.yml", | ||
115 | - "test/fixtures/db_definitions/mysql.sql", | ||
116 | - "test/fixtures/dynamic_attributes.yml", | ||
117 | - "test/fixtures/electronics.yml", | ||
118 | - "test/fixtures/locals.yml", | ||
119 | - "test/fixtures/movies.yml", | ||
120 | - "test/fixtures/postings.yml", | ||
121 | - "test/functional/acts_as_solr_test.rb", | ||
122 | - "test/functional/association_indexing_test.rb", | ||
123 | - "test/functional/faceted_search_test.rb", | ||
124 | - "test/functional/multi_solr_search_test.rb", | ||
125 | - "test/models/advertise.rb", | ||
126 | - "test/models/author.rb", | ||
127 | - "test/models/book.rb", | ||
128 | - "test/models/category.rb", | ||
129 | - "test/models/document.rb", | ||
130 | - "test/models/dynamic_attribute.rb", | ||
131 | - "test/models/electronic.rb", | ||
132 | - "test/models/gadget.rb", | ||
133 | - "test/models/local.rb", | ||
134 | - "test/models/movie.rb", | ||
135 | - "test/models/novel.rb", | ||
136 | - "test/models/post.rb", | ||
137 | - "test/models/posting.rb", | ||
138 | - "test/test_helper.rb", | ||
139 | - "test/unit/acts_methods_shoulda.rb", | ||
140 | - "test/unit/class_methods_shoulda.rb", | ||
141 | - "test/unit/common_methods_shoulda.rb", | ||
142 | - "test/unit/instance_methods_shoulda.rb", | ||
143 | - "test/unit/lazy_document_shoulda.rb", | ||
144 | - "test/unit/parser_instance.rb", | ||
145 | - "test/unit/parser_methods_shoulda.rb", | ||
146 | - "test/unit/solr_instance.rb", | ||
147 | - "test/unit/test_helper.rb" | ||
148 | - ] | ||
149 | - s.homepage = %q{http://github.com/dcrec1/acts_as_solr_reloaded} | ||
150 | - s.require_paths = ["lib"] | ||
151 | - s.rubygems_version = %q{1.5.0} | ||
152 | - s.summary = %q{This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model.} | ||
153 | - s.test_files = [ | ||
154 | - "test/db/connections/mysql/connection.rb", | ||
155 | - "test/db/connections/sqlite/connection.rb", | ||
156 | - "test/db/migrate/001_create_books.rb", | ||
157 | - "test/db/migrate/002_create_movies.rb", | ||
158 | - "test/db/migrate/003_create_categories.rb", | ||
159 | - "test/db/migrate/004_create_electronics.rb", | ||
160 | - "test/db/migrate/005_create_authors.rb", | ||
161 | - "test/db/migrate/006_create_postings.rb", | ||
162 | - "test/db/migrate/007_create_posts.rb", | ||
163 | - "test/db/migrate/008_create_gadgets.rb", | ||
164 | - "test/db/migrate/009_create_dynamic_attributes.rb", | ||
165 | - "test/db/migrate/010_create_advertises.rb", | ||
166 | - "test/db/migrate/011_create_locals.rb", | ||
167 | - "test/functional/acts_as_solr_test.rb", | ||
168 | - "test/functional/association_indexing_test.rb", | ||
169 | - "test/functional/faceted_search_test.rb", | ||
170 | - "test/functional/multi_solr_search_test.rb", | ||
171 | - "test/models/advertise.rb", | ||
172 | - "test/models/author.rb", | ||
173 | - "test/models/book.rb", | ||
174 | - "test/models/category.rb", | ||
175 | - "test/models/document.rb", | ||
176 | - "test/models/dynamic_attribute.rb", | ||
177 | - "test/models/electronic.rb", | ||
178 | - "test/models/gadget.rb", | ||
179 | - "test/models/local.rb", | ||
180 | - "test/models/movie.rb", | ||
181 | - "test/models/novel.rb", | ||
182 | - "test/models/post.rb", | ||
183 | - "test/models/posting.rb", | ||
184 | - "test/test_helper.rb", | ||
185 | - "test/unit/acts_methods_shoulda.rb", | ||
186 | - "test/unit/class_methods_shoulda.rb", | ||
187 | - "test/unit/common_methods_shoulda.rb", | ||
188 | - "test/unit/instance_methods_shoulda.rb", | ||
189 | - "test/unit/lazy_document_shoulda.rb", | ||
190 | - "test/unit/parser_instance.rb", | ||
191 | - "test/unit/parser_methods_shoulda.rb", | ||
192 | - "test/unit/solr_instance.rb", | ||
193 | - "test/unit/test_helper.rb" | ||
194 | - ] | ||
195 | - | ||
196 | - if s.respond_to? :specification_version then | ||
197 | - s.specification_version = 3 | ||
198 | - | ||
199 | - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then | ||
200 | - else | ||
201 | - end | ||
202 | - else | ||
203 | - end | ||
204 | -end | ||
205 | - |
vendor/plugins/acts_as_solr_reloaded/config/solr.yml
@@ -1,22 +0,0 @@ | @@ -1,22 +0,0 @@ | ||
1 | -# Config file for the acts_as_solr plugin. | ||
2 | -# | ||
3 | -# If you change the host or port number here, make sure you update | ||
4 | -# them in your Solr config file | ||
5 | - | ||
6 | -development: | ||
7 | - url: http://0.0.0.0:8982/solr | ||
8 | - jvm_options: -server -Xmx128M -Xms16M | ||
9 | - timeout: 0 | ||
10 | - | ||
11 | -production: | ||
12 | - url: http://127.0.0.1:8983/solr | ||
13 | - jvm_options: -server -Xmx192M -Xms64M | ||
14 | - timeout: 0 | ||
15 | - | ||
16 | -test: &TEST | ||
17 | - url: http://0.0.0.0:8981/solr | ||
18 | - jvm_options: -server -Xmx128M -Xms16M | ||
19 | - timeout: 0 | ||
20 | - | ||
21 | -cucumber: | ||
22 | - <<: *TEST |
vendor/plugins/acts_as_solr_reloaded/config/solr_environment.rb
@@ -1,49 +0,0 @@ | @@ -1,49 +0,0 @@ | ||
1 | -ENV['RAILS_ENV'] = (ENV['RAILS_ENV'] || 'development').dup | ||
2 | -require "uri" | ||
3 | -require "fileutils" | ||
4 | -require "yaml" | ||
5 | -require 'net/http' | ||
6 | - | ||
7 | -dir = File.dirname(__FILE__) | ||
8 | -SOLR_PATH = File.expand_path("#{dir}/../solr") unless defined? SOLR_PATH | ||
9 | - | ||
10 | -unless defined? Rails.root | ||
11 | - # define Rails.root for test environment | ||
12 | - Rails.root = defined?(Rails) ? Rails.root : File.expand_path("#{File.dirname(__FILE__)}/../test") | ||
13 | -end | ||
14 | -unless defined? RAILS_ENV | ||
15 | - RAILS_ENV = ENV['RAILS_ENV'] | ||
16 | -end | ||
17 | -unless defined? SOLR_LOGS_PATH | ||
18 | - SOLR_LOGS_PATH = ENV["SOLR_LOGS_PATH"] || "#{Rails.root}/log" | ||
19 | -end | ||
20 | -unless defined? SOLR_PIDS_PATH | ||
21 | - SOLR_PIDS_PATH = ENV["SOLR_PIDS_PATH"] || "#{Rails.root}/tmp/pids" | ||
22 | -end | ||
23 | -unless defined? SOLR_DATA_PATH | ||
24 | - SOLR_DATA_PATH = ENV["SOLR_DATA_PATH"] || "#{Rails.root}/solr/#{ENV['RAILS_ENV']}" | ||
25 | -end | ||
26 | -unless defined? SOLR_CONFIG_PATH | ||
27 | - SOLR_CONFIG_PATH = ENV["SOLR_CONFIG_PATH"] || "#{SOLR_PATH}/solr" | ||
28 | -end | ||
29 | -unless defined? SOLR_PID_FILE | ||
30 | - SOLR_PID_FILE="#{SOLR_PIDS_PATH}/solr.#{ENV['RAILS_ENV']}.pid" | ||
31 | -end | ||
32 | - | ||
33 | -unless defined? SOLR_PORT | ||
34 | - config = YAML::load_file(Rails.root+'/config/solr.yml') | ||
35 | - raise("No solr environment defined for RAILS_ENV = #{ENV['RAILS_ENV'].inspect}") unless config[ENV['RAILS_ENV']] | ||
36 | - | ||
37 | - SOLR_HOST = ENV['HOST'] || URI.parse(config[ENV['RAILS_ENV']]['url']).host | ||
38 | - SOLR_PORT = ENV['PORT'] || URI.parse(config[ENV['RAILS_ENV']]['url']).port | ||
39 | -end | ||
40 | - | ||
41 | -SOLR_JVM_OPTIONS = config[ENV['RAILS_ENV']]['jvm_options'] unless defined? SOLR_JVM_OPTIONS | ||
42 | - | ||
43 | -if ENV["RAILS_ENV"] == 'test' | ||
44 | - require "active_record" | ||
45 | - DB = (ENV['DB'] ? ENV['DB'] : 'sqlite') unless defined?(DB) | ||
46 | - MYSQL_USER = (ENV['MYSQL_USER'].nil? ? 'root' : ENV['MYSQL_USER']) unless defined? MYSQL_USER | ||
47 | - require File.join(File.dirname(File.expand_path(__FILE__)), '..', 'test', 'db', 'connections', DB, 'connection.rb') | ||
48 | -end | ||
49 | - |
vendor/plugins/acts_as_solr_reloaded/generators/dynamic_attributes_migration/dynamic_attributes_migration_generator.rb
@@ -1,7 +0,0 @@ | @@ -1,7 +0,0 @@ | ||
1 | -class DynamicAttributesMigrationGenerator < Rails::Generator::Base | ||
2 | - def manifest | ||
3 | - record do |m| | ||
4 | - m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "dynamic_attributes_migration" | ||
5 | - end | ||
6 | - end | ||
7 | -end | ||
8 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/plugins/acts_as_solr_reloaded/generators/dynamic_attributes_migration/templates/migration.rb
@@ -1,17 +0,0 @@ | @@ -1,17 +0,0 @@ | ||
1 | -class DynamicAttributesMigration < ActiveRecord::Migration | ||
2 | - def self.up | ||
3 | - create_table :dynamic_attributes do |t| | ||
4 | - t.integer :dynamicable_id | ||
5 | - t.string :dynamicable_type | ||
6 | - t.string :name | ||
7 | - t.text :value | ||
8 | - t.timestamps | ||
9 | - end | ||
10 | - add_index :dynamic_attributes, [:dynamicable_id, :dynamicable_type, :name], :unique => true, :name => 'da_pk' | ||
11 | - end | ||
12 | - | ||
13 | - def self.down | ||
14 | - remove_index 'da_pk' | ||
15 | - drop_table :dynamic_attributes | ||
16 | - end | ||
17 | -end |
vendor/plugins/acts_as_solr_reloaded/generators/local_migration/local_migration_generator.rb
@@ -1,7 +0,0 @@ | @@ -1,7 +0,0 @@ | ||
1 | -class LocalMigrationGenerator < Rails::Generator::Base | ||
2 | - def manifest | ||
3 | - record do |m| | ||
4 | - m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "local_migration" | ||
5 | - end | ||
6 | - end | ||
7 | -end | ||
8 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/plugins/acts_as_solr_reloaded/generators/local_migration/templates/migration.rb
@@ -1,16 +0,0 @@ | @@ -1,16 +0,0 @@ | ||
1 | -class LocalMigration < ActiveRecord::Migration | ||
2 | - def self.up | ||
3 | - create_table :locals do |t| | ||
4 | - t.integer :localizable_id | ||
5 | - t.string :localizable_type | ||
6 | - t.string :latitude | ||
7 | - t.string :longitude | ||
8 | - | ||
9 | - t.timestamps | ||
10 | - end | ||
11 | - end | ||
12 | - | ||
13 | - def self.down | ||
14 | - drop_table :locals | ||
15 | - end | ||
16 | -end | ||
17 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/plugins/acts_as_solr_reloaded/init.rb
vendor/plugins/acts_as_solr_reloaded/install.rb
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr.rb
@@ -1,25 +0,0 @@ | @@ -1,25 +0,0 @@ | ||
1 | -require 'active_record' | ||
2 | -require 'rexml/document' | ||
3 | -require 'net/http' | ||
4 | -require 'yaml' | ||
5 | -require 'time' | ||
6 | -require 'erb' | ||
7 | -require 'rexml/xpath' | ||
8 | - | ||
9 | -require File.dirname(__FILE__) + '/solr' | ||
10 | -require File.dirname(__FILE__) + '/acts_as_solr/acts_methods' | ||
11 | -require File.dirname(__FILE__) + '/acts_as_solr/common_methods' | ||
12 | -require File.dirname(__FILE__) + '/acts_as_solr/parser_methods' | ||
13 | -require File.dirname(__FILE__) + '/acts_as_solr/class_methods' | ||
14 | -require File.dirname(__FILE__) + '/acts_as_solr/dynamic_attribute' | ||
15 | -require File.dirname(__FILE__) + '/acts_as_solr/local' | ||
16 | -require File.dirname(__FILE__) + '/acts_as_solr/instance_methods' | ||
17 | -require File.dirname(__FILE__) + '/acts_as_solr/common_methods' | ||
18 | -require File.dirname(__FILE__) + '/acts_as_solr/deprecation' | ||
19 | -require File.dirname(__FILE__) + '/acts_as_solr/search_results' | ||
20 | -require File.dirname(__FILE__) + '/acts_as_solr/lazy_document' | ||
21 | -require File.dirname(__FILE__) + '/acts_as_solr/mongo_mapper' | ||
22 | -require File.dirname(__FILE__) + '/acts_as_solr/post' | ||
23 | - | ||
24 | -# reopen ActiveRecord and include the acts_as_solr method | ||
25 | -ActiveRecord::Base.extend ActsAsSolr::ActsMethods |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb
@@ -1,390 +0,0 @@ | @@ -1,390 +0,0 @@ | ||
1 | -# a list of models which called acts_as_solr | ||
2 | -$solr_indexed_models = [] | ||
3 | - | ||
4 | -module ActsAsSolr #:nodoc: | ||
5 | - | ||
6 | - module ActsMethods | ||
7 | - | ||
8 | - # declares a class as solr-searchable | ||
9 | - # | ||
10 | - # ==== options: | ||
11 | - # fields:: This option can be used to specify only the fields you'd | ||
12 | - # like to index. If not given, all the attributes from the | ||
13 | - # class will be indexed. You can also use this option to | ||
14 | - # include methods that should be indexed as fields | ||
15 | - # | ||
16 | - # class Movie < ActiveRecord::Base | ||
17 | - # acts_as_solr :fields => [:name, :description, :current_time] | ||
18 | - # def current_time | ||
19 | - # Time.now.to_s | ||
20 | - # end | ||
21 | - # end | ||
22 | - # | ||
23 | - # Each field passed can also be a hash with the value being a field type | ||
24 | - # | ||
25 | - # class Electronic < ActiveRecord::Base | ||
26 | - # acts_as_solr :fields => [{:price => :range_float}] | ||
27 | - # def current_time | ||
28 | - # Time.now | ||
29 | - # end | ||
30 | - # end | ||
31 | - # | ||
32 | - # The field types accepted are: | ||
33 | - # | ||
34 | - # :float:: Index the field value as a float (ie.: 12.87) | ||
35 | - # :integer:: Index the field value as an integer (ie.: 31) | ||
36 | - # :boolean:: Index the field value as a boolean (ie.: true/false) | ||
37 | - # :date:: Index the field value as a date (ie.: Wed Nov 15 23:13:03 PST 2006) | ||
38 | - # :string:: Index the field value as a text string, not applying the same indexing | ||
39 | - # filters as a regular text field | ||
40 | - # :range_integer:: Index the field value for integer range queries (ie.:[5 TO 20]) | ||
41 | - # :range_float:: Index the field value for float range queries (ie.:[14.56 TO 19.99]) | ||
42 | - # | ||
43 | - # Setting the field type preserves its original type when indexed | ||
44 | - # | ||
45 | - # The field may also be passed with a hash value containing options | ||
46 | - # | ||
47 | - # class Author < ActiveRecord::Base | ||
48 | - # acts_as_solr :fields => [{:full_name => {:type => :text, :as => :name}}] | ||
49 | - # def full_name | ||
50 | - # self.first_name + ' ' + self.last_name | ||
51 | - # end | ||
52 | - # end | ||
53 | - # | ||
54 | - # The options accepted are: | ||
55 | - # | ||
56 | - # :type:: Index the field using the specified type | ||
57 | - # :as:: Index the field using the specified field name | ||
58 | - # | ||
59 | - # additional_fields:: This option takes fields to be include in the index | ||
60 | - # in addition to those derived from the database. You | ||
61 | - # can also use this option to include custom fields | ||
62 | - # derived from methods you define. This option will be | ||
63 | - # ignored if the :fields option is given. It also accepts | ||
64 | - # the same field types as the option above | ||
65 | - # | ||
66 | - # class Movie < ActiveRecord::Base | ||
67 | - # acts_as_solr :additional_fields => [:current_time] | ||
68 | - # def current_time | ||
69 | - # Time.now.to_s | ||
70 | - # end | ||
71 | - # end | ||
72 | - # | ||
73 | - # exclude_fields:: This option taks an array of fields that should be ignored from indexing: | ||
74 | - # | ||
75 | - # class User < ActiveRecord::Base | ||
76 | - # acts_as_solr :exclude_fields => [:password, :login, :credit_card_number] | ||
77 | - # end | ||
78 | - # | ||
79 | - # include:: This option can be used for association indexing, which | ||
80 | - # means you can include any :has_one, :has_many, :belongs_to | ||
81 | - # and :has_and_belongs_to_many association to be indexed: | ||
82 | - # | ||
83 | - # class Category < ActiveRecord::Base | ||
84 | - # has_many :books | ||
85 | - # acts_as_solr :include => [:books] | ||
86 | - # end | ||
87 | - # | ||
88 | - # Each association may also be specified as a hash with an option hash as a value | ||
89 | - # | ||
90 | - # class Book < ActiveRecord::Base | ||
91 | - # belongs_to :author | ||
92 | - # has_many :distribution_companies | ||
93 | - # has_many :copyright_dates | ||
94 | - # has_many :media_types | ||
95 | - # acts_as_solr( | ||
96 | - # :fields => [:name, :description], | ||
97 | - # :include => [ | ||
98 | - # {:author => {:using => :fullname, :as => :name}}, | ||
99 | - # {:media_types => {:using => lambda{|media| type_lookup(media.id)}}} | ||
100 | - # {:distribution_companies => {:as => :distributor, :multivalued => true}}, | ||
101 | - # {:copyright_dates => {:as => :copyright, :type => :date}} | ||
102 | - # ] | ||
103 | - # ] | ||
104 | - # | ||
105 | - # The options accepted are: | ||
106 | - # | ||
107 | - # :type:: Index the associated objects using the specified type | ||
108 | - # :as:: Index the associated objects using the specified field name | ||
109 | - # :using:: Index the associated objects using the value returned by the specified method or proc. If a method | ||
110 | - # symbol is supplied, it will be sent to each object to look up the value to index; if a proc is | ||
111 | - # supplied, it will be called once for each object with the object as the only argument | ||
112 | - # :multivalued:: Index the associated objects using one field for each object rather than joining them | ||
113 | - # all into a single field | ||
114 | - # | ||
115 | - # facets:: This option can be used to specify the fields you'd like to | ||
116 | - # index as facet fields | ||
117 | - # | ||
118 | - # class Electronic < ActiveRecord::Base | ||
119 | - # acts_as_solr :facets => [:category, :manufacturer] | ||
120 | - # end | ||
121 | - # | ||
122 | - # boost:: You can pass a boost (float) value that will be used to boost the document and/or a field. To specify a more | ||
123 | - # boost for the document, you can either pass a block or a symbol. The block will be called with the record | ||
124 | - # as an argument, a symbol will result in the according method being called: | ||
125 | - # | ||
126 | - # class Electronic < ActiveRecord::Base | ||
127 | - # acts_as_solr :fields => [{:price => {:boost => 5.0}}], :boost => 10.0 | ||
128 | - # end | ||
129 | - # | ||
130 | - # class Electronic < ActiveRecord::Base | ||
131 | - # acts_as_solr :fields => [{:price => {:boost => 5.0}}], :boost => proc {|record| record.id + 120*37} | ||
132 | - # end | ||
133 | - # | ||
134 | - # class Electronic < ActiveRecord::Base | ||
135 | - # acts_as_solr :fields => [{:price => {:boost => :price_rating}}], :boost => 10.0 | ||
136 | - # end | ||
137 | - # | ||
138 | - # if:: Only indexes the record if the condition evaluated is true. The argument has to be | ||
139 | - # either a symbol, string (to be eval'ed), proc/method, or class implementing a static | ||
140 | - # validation method. It behaves the same way as ActiveRecord's :if option. | ||
141 | - # | ||
142 | - # class Electronic < ActiveRecord::Base | ||
143 | - # acts_as_solr :if => proc{|record| record.is_active?} | ||
144 | - # end | ||
145 | - # | ||
146 | - # offline:: Assumes that your using an outside mechanism to explicitly trigger indexing records, e.g. you only | ||
147 | - # want to update your index through some asynchronous mechanism. Will accept either a boolean or a block | ||
148 | - # that will be evaluated before actually contacting the index for saving or destroying a document. Defaults | ||
149 | - # to false. It doesn't refer to the mechanism of an offline index in general, but just to get a centralized point | ||
150 | - # where you can control indexing. Note: This is only enabled for saving records. acts_as_solr doesn't always like | ||
151 | - # it, if you have a different number of results coming from the database and the index. This might be rectified in | ||
152 | - # another patch to support lazy loading. | ||
153 | - # | ||
154 | - # class Electronic < ActiveRecord::Base | ||
155 | - # acts_as_solr :offline => proc {|record| record.automatic_indexing_disabled?} | ||
156 | - # end | ||
157 | - # | ||
158 | - # auto_commit:: The commit command will be sent to Solr only if its value is set to true: | ||
159 | - # | ||
160 | - # class Author < ActiveRecord::Base | ||
161 | - # acts_as_solr :auto_commit => false | ||
162 | - # end | ||
163 | - # | ||
164 | - # dynamic_attributes: Default false. When true, requires a has_many relationship to a DynamicAttribute | ||
165 | - # (:name, :value) model. Then, all dynamic attributes will be mapped as normal attributes | ||
166 | - # in Solr, so you can filter like this: Model.find_by_solr "#{dynamic_attribute.name}:Lorem" | ||
167 | - # | ||
168 | - # taggable: Default false. When true, indexes tags with field name tag. Tags are taken from taggings.tag | ||
169 | - # | ||
170 | - # spatial: Default false. When true, indexes model.local.latitude and model.local.longitude as coordinates. | ||
171 | - # | ||
172 | - def acts_as_solr(options={}, solr_options={}, &deferred_solr_configuration) | ||
173 | - | ||
174 | - $solr_indexed_models << self | ||
175 | - | ||
176 | - extend ClassMethods | ||
177 | - include InstanceMethods | ||
178 | - include CommonMethods | ||
179 | - include ParserMethods | ||
180 | - | ||
181 | - define_solr_configuration_methods | ||
182 | - | ||
183 | - acts_as_taggable_on :tags if options[:taggable] | ||
184 | - has_many :dynamic_attributes, :as => "dynamicable" if options[:dynamic_attributes] | ||
185 | - has_one :local, :as => "localizable" if options[:spatial] | ||
186 | - | ||
187 | - after_save :solr_save | ||
188 | - after_destroy :solr_destroy | ||
189 | - | ||
190 | - if deferred_solr_configuration | ||
191 | - self.deferred_solr_configuration = deferred_solr_configuration | ||
192 | - else | ||
193 | - process_acts_as_solr(options, solr_options) | ||
194 | - end | ||
195 | - end | ||
196 | - | ||
197 | - def process_acts_as_solr(options, solr_options) | ||
198 | - process_solr_options(options, solr_options) | ||
199 | - end | ||
200 | - | ||
201 | - def define_solr_configuration_methods | ||
202 | - # I'd like to use cattr_accessor, but it does not support lazy loaders and delegation to the class in the instance methods. | ||
203 | - # TODO: Reconcile with cattr_accessor, or a more appropriate method. | ||
204 | - class_eval(<<-EOS, __FILE__, __LINE__) | ||
205 | - @@configuration = nil unless defined?(@@configuration) | ||
206 | - @@solr_configuration = nil unless defined?(@@solr_configuration) | ||
207 | - @@deferred_solr_configuration = nil unless defined?(@@deferred_solr_configuration) | ||
208 | - | ||
209 | - def self.configuration | ||
210 | - return @@configuration if @@configuration | ||
211 | - process_deferred_solr_configuration | ||
212 | - @@configuration | ||
213 | - end | ||
214 | - def configuration | ||
215 | - self.class.configuration | ||
216 | - end | ||
217 | - def self.configuration=(value) | ||
218 | - @@configuration = value | ||
219 | - end | ||
220 | - def configuration=(value) | ||
221 | - self.class.configuration = value | ||
222 | - end | ||
223 | - | ||
224 | - def self.solr_configuration | ||
225 | - return @@solr_configuration if @@solr_configuration | ||
226 | - process_deferred_solr_configuration | ||
227 | - @@solr_configuration | ||
228 | - end | ||
229 | - def solr_configuration | ||
230 | - self.class.solr_configuration | ||
231 | - end | ||
232 | - def self.solr_configuration=(value) | ||
233 | - @@solr_configuration = value | ||
234 | - end | ||
235 | - def solr_configuration=(value) | ||
236 | - self.class.solr_configuration = value | ||
237 | - end | ||
238 | - | ||
239 | - def self.deferred_solr_configuration | ||
240 | - return @@deferred_solr_configuration if @@deferred_solr_configuration | ||
241 | - @@deferred_solr_configuration | ||
242 | - end | ||
243 | - def deferred_solr_configuration | ||
244 | - self.class.deferred_solr_configuration | ||
245 | - end | ||
246 | - def self.deferred_solr_configuration=(value) | ||
247 | - @@deferred_solr_configuration = value | ||
248 | - end | ||
249 | - def deferred_solr_configuration=(value) | ||
250 | - self.class.deferred_solr_configuration = value | ||
251 | - end | ||
252 | - EOS | ||
253 | - end | ||
254 | - | ||
255 | - def process_deferred_solr_configuration | ||
256 | - return unless deferred_solr_configuration | ||
257 | - options, solr_options = deferred_solr_configuration.call | ||
258 | - self.deferred_solr_configuration = nil | ||
259 | - self.process_solr_options(options, solr_options) | ||
260 | - end | ||
261 | - | ||
262 | - def process_solr_options(options={}, solr_options={}) | ||
263 | - self.configuration = { | ||
264 | - :fields => nil, | ||
265 | - :format => :objects, | ||
266 | - :additional_fields => nil, | ||
267 | - :dynamic_attributes => false, | ||
268 | - :exclude_fields => [], | ||
269 | - :auto_commit => ['production'].include?(Rails.env) ? false : true, | ||
270 | - :include => nil, | ||
271 | - :facets => nil, | ||
272 | - :boost => nil, | ||
273 | - :if => "true", | ||
274 | - :offline => false, | ||
275 | - :spatial => false, | ||
276 | - } | ||
277 | - self.solr_configuration = { | ||
278 | - :type_field => "type_s", | ||
279 | - :primary_key_field => "pk_s", | ||
280 | - :default_boost => 1.0, | ||
281 | - } | ||
282 | - | ||
283 | - solr_options ||= {} | ||
284 | - raise "Invalid options: #{(options.keys-configuration.keys).join(',')}" unless (options.keys-configuration.keys).empty? | ||
285 | - raise "Invalid solr options: #{(solr_options.keys-solr_configuration.keys).join(',')}" unless (solr_options.keys-solr_configuration.keys).empty? | ||
286 | - | ||
287 | - configuration.update(options) if options.is_a?(Hash) | ||
288 | - solr_configuration.update(solr_options) if solr_options.is_a?(Hash) | ||
289 | - Deprecation.validate_index(configuration) | ||
290 | - | ||
291 | - configuration[:solr_fields] = {} | ||
292 | - configuration[:solr_includes] = {} | ||
293 | - | ||
294 | - if configuration[:fields].respond_to?(:each) | ||
295 | - process_fields(configuration[:fields]) | ||
296 | - else | ||
297 | - process_fields(self.new.attributes.keys.map { |k| k.to_sym }) | ||
298 | - process_fields(configuration[:additional_fields]) | ||
299 | - end | ||
300 | - | ||
301 | - process_includes(configuration[:include]) if configuration[:include] | ||
302 | - end | ||
303 | - | ||
304 | - def after_save_reindex(associations, options = {}) | ||
305 | - extend ActsAsSolr::CommonMethods | ||
306 | - Array(associations).each do |association| | ||
307 | - after_save do |ar| | ||
308 | - if options[:with] == :delayed_job | ||
309 | - delay(:run_at => (Date.today+1.day).to_time+4.hours).solr_batch_add_association ar, association | ||
310 | - else | ||
311 | - solr_batch_add_association ar, association | ||
312 | - end | ||
313 | - end | ||
314 | - end | ||
315 | - end | ||
316 | - | ||
317 | - private | ||
318 | - | ||
319 | - def get_field_value(field) | ||
320 | - field_name, options = determine_field_name_and_options(field) | ||
321 | - configuration[:solr_fields][field_name] = options | ||
322 | - | ||
323 | - define_method "#{field_name}_for_solr" do | ||
324 | - value = self.send field_name | ||
325 | - case options[:type] | ||
326 | - when :date # format dates properly; return nil for nil dates | ||
327 | - value ? (value.respond_to?(:utc) ? value.utc : value).strftime("%Y-%m-%dT%H:%M:%SZ") : nil | ||
328 | - else | ||
329 | - value | ||
330 | - end | ||
331 | - end | ||
332 | - end | ||
333 | - | ||
334 | - def process_fields(raw_field) | ||
335 | - if raw_field.respond_to?(:each) | ||
336 | - raw_field.each do |field| | ||
337 | - next if configuration[:exclude_fields].include?(field) | ||
338 | - get_field_value(field) | ||
339 | - end | ||
340 | - end | ||
341 | - end | ||
342 | - | ||
343 | - def process_includes(includes) | ||
344 | - Array(includes).each do |assoc| | ||
345 | - field_name, options = determine_field_name_and_options(assoc) | ||
346 | - configuration[:solr_includes][field_name] = options | ||
347 | - end | ||
348 | - end | ||
349 | - | ||
350 | - def determine_field_name_and_options(field) | ||
351 | - if field.is_a?(Hash) | ||
352 | - name = field.keys.first | ||
353 | - options = field.values.first | ||
354 | - if options.is_a?(Hash) | ||
355 | - [name, {:type => type_for_field(field)}.merge(options)] | ||
356 | - else | ||
357 | - [name, {:type => options}] | ||
358 | - end | ||
359 | - else | ||
360 | - [field, {:type => type_for_field(field)}] | ||
361 | - end | ||
362 | - end | ||
363 | - | ||
364 | - def type_for_field(field) | ||
365 | - if configuration[:facets] && configuration[:facets].include?(field) | ||
366 | - :facet | ||
367 | - elsif column = columns_hash[field.to_s] | ||
368 | - column_type = format_column_type(column.type) | ||
369 | - | ||
370 | - case column_type | ||
371 | - when :string then :string | ||
372 | - when :datetime then :date | ||
373 | - when :time then :date | ||
374 | - else column_type | ||
375 | - end | ||
376 | - else | ||
377 | - :text | ||
378 | - end | ||
379 | - end | ||
380 | - | ||
381 | - def format_column_type(type) | ||
382 | - if type.class.eql? Symbol | ||
383 | - type | ||
384 | - else | ||
385 | - type.to_s.eql?("ObjectId") ? :string : type.to_s.downcase.to_sym | ||
386 | - end | ||
387 | - end | ||
388 | - end | ||
389 | -end | ||
390 | - |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/class_methods.rb
@@ -1,278 +0,0 @@ | @@ -1,278 +0,0 @@ | ||
1 | -module ActsAsSolr #:nodoc: | ||
2 | - | ||
3 | - module ClassMethods | ||
4 | - include CommonMethods | ||
5 | - include ParserMethods | ||
6 | - | ||
7 | - # Finds instances of a model. Terms are ANDed by default, can be overwritten | ||
8 | - # by using OR between terms | ||
9 | - # | ||
10 | - # Here's a sample (untested) code for your controller: | ||
11 | - # | ||
12 | - # def search | ||
13 | - # results = Book.find_by_solr params[:query] | ||
14 | - # end | ||
15 | - # | ||
16 | - # For specific fields searching use :filter_queries options | ||
17 | - # | ||
18 | - # ====options: | ||
19 | - # offset:: - The first document to be retrieved (offset) | ||
20 | - # page:: - The page to be retrieved | ||
21 | - # limit:: - The number of rows per page | ||
22 | - # per_page:: - Alias for limit | ||
23 | - # filter_queries:: - Use solr filter queries to sort by fields | ||
24 | - # | ||
25 | - # Book.find_by_solr 'ruby', :filter_queries => ['price:5'] | ||
26 | - # | ||
27 | - # sort:: - Orders (sort by) the result set using a given criteria: | ||
28 | - # | ||
29 | - # Book.find_by_solr 'ruby', :sort => 'description asc' | ||
30 | - # | ||
31 | - # field_types:: This option is deprecated and will be obsolete by version 1.0. | ||
32 | - # There's no need to specify the :field_types anymore when doing a | ||
33 | - # search in a model that specifies a field type for a field. The field | ||
34 | - # types are automatically traced back when they're included. | ||
35 | - # | ||
36 | - # class Electronic < ActiveRecord::Base | ||
37 | - # acts_as_solr :fields => [{:price => :range_float}] | ||
38 | - # end | ||
39 | - # | ||
40 | - # facets:: This option argument accepts the following arguments: | ||
41 | - # fields:: The fields to be included in the faceted search (Solr's facet.field) | ||
42 | - # query:: The queries to be included in the faceted search (Solr's facet.query) | ||
43 | - # zeros:: Display facets with count of zero. (true|false) | ||
44 | - # sort:: Sorts the faceted resuls by highest to lowest count. (true|false) | ||
45 | - # browse:: This is where the 'drill-down' of the facets work. Accepts an array of | ||
46 | - # fields in the format "facet_field:term" | ||
47 | - # mincount:: Replacement for zeros (it has been deprecated in Solr). Specifies the | ||
48 | - # minimum count necessary for a facet field to be returned. (Solr's | ||
49 | - # facet.mincount) Overrides :zeros if it is specified. Default is 0. | ||
50 | - # | ||
51 | - # dates:: Run date faceted queries using the following arguments: | ||
52 | - # fields:: The fields to be included in the faceted date search (Solr's facet.date). | ||
53 | - # It may be either a String/Symbol or Hash. If it's a hash the options are the | ||
54 | - # same as date_facets minus the fields option (i.e., :start:, :end, :gap, :other, | ||
55 | - # :between). These options if provided will override the base options. | ||
56 | - # (Solr's f.<field_name>.date.<key>=<value>). | ||
57 | - # start:: The lower bound for the first date range for all Date Faceting. Required if | ||
58 | - # :fields is present | ||
59 | - # end:: The upper bound for the last date range for all Date Faceting. Required if | ||
60 | - # :fields is prsent | ||
61 | - # gap:: The size of each date range expressed as an interval to be added to the lower | ||
62 | - # bound using the DateMathParser syntax. Required if :fields is prsent | ||
63 | - # hardend:: A Boolean parameter instructing Solr what do do in the event that | ||
64 | - # facet.date.gap does not divide evenly between facet.date.start and facet.date.end. | ||
65 | - # other:: This param indicates that in addition to the counts for each date range | ||
66 | - # constraint between facet.date.start and facet.date.end, other counds should be | ||
67 | - # calculated. May specify more then one in an Array. The possible options are: | ||
68 | - # before:: - all records with lower bound less than start | ||
69 | - # after:: - all records with upper bound greater than end | ||
70 | - # between:: - all records with field values between start and end | ||
71 | - # none:: - compute no other bounds (useful in per field assignment) | ||
72 | - # all:: - shortcut for before, after, and between | ||
73 | - # filter:: Similar to :query option provided by :facets, in that accepts an array of | ||
74 | - # of date queries to limit results. Can not be used as a part of a :field hash. | ||
75 | - # This is the only option that can be used if :fields is not present. | ||
76 | - # | ||
77 | - # Example: | ||
78 | - # | ||
79 | - # Electronic.find_by_solr "memory", :facets => {:zeros => false, :sort => true, | ||
80 | - # :query => ["price:[* TO 200]", | ||
81 | - # "price:[200 TO 500]", | ||
82 | - # "price:[500 TO *]"], | ||
83 | - # :fields => [:category, :manufacturer], | ||
84 | - # :browse => ["category:Memory","manufacturer:Someone"]} | ||
85 | - # | ||
86 | - # | ||
87 | - # Examples of date faceting: | ||
88 | - # | ||
89 | - # basic: | ||
90 | - # Electronic.find_by_solr "memory", :facets => {:dates => {:fields => [:updated_at, :created_at], | ||
91 | - # :start => 'NOW-10YEARS/DAY', :end => 'NOW/DAY', :gap => '+2YEARS', :other => :before}} | ||
92 | - # | ||
93 | - # advanced: | ||
94 | - # Electronic.find_by_solr "memory", :facets => {:dates => {:fields => [:updated_at, | ||
95 | - # {:created_at => {:start => 'NOW-20YEARS/DAY', :end => 'NOW-10YEARS/DAY', :other => [:before, :after]} | ||
96 | - # }], :start => 'NOW-10YEARS/DAY', :end => 'NOW/DAY', :other => :before, :filter => | ||
97 | - # ["created_at:[NOW-10YEARS/DAY TO NOW/DAY]", "updated_at:[NOW-1YEAR/DAY TO NOW/DAY]"]}} | ||
98 | - # | ||
99 | - # filter only: | ||
100 | - # Electronic.find_by_solr "memory", :facets => {:dates => {:filter => "updated_at:[NOW-1YEAR/DAY TO NOW/DAY]"}} | ||
101 | - # | ||
102 | - # | ||
103 | - # | ||
104 | - # scores:: If set to true this will return the score as a 'solr_score' attribute | ||
105 | - # for each one of the instances found. Does not currently work with find_id_by_solr | ||
106 | - # | ||
107 | - # books = Book.find_by_solr 'ruby OR splinter', :scores => true | ||
108 | - # books.records.first.solr_score | ||
109 | - # => 1.21321397 | ||
110 | - # books.records.last.solr_score | ||
111 | - # => 0.12321548 | ||
112 | - # | ||
113 | - # lazy:: If set to true the search will return objects that will touch the database when you ask for one | ||
114 | - # of their attributes for the first time. Useful when you're using fragment caching based solely on | ||
115 | - # types and ids. | ||
116 | - # | ||
117 | - # relevance:: Sets fields relevance | ||
118 | - # | ||
119 | - # Book.find_by_solr "zidane", :relevance => {:title => 5, :author => 2} | ||
120 | - # | ||
121 | - def find_by_solr(query, options={}) | ||
122 | - data = parse_query(query, options) | ||
123 | - return parse_results(data, options) | ||
124 | - end | ||
125 | - alias :search :find_by_solr | ||
126 | - | ||
127 | - # Finds instances of a model and returns an array with the ids: | ||
128 | - # Book.find_id_by_solr "rails" => [1,4,7] | ||
129 | - # The options accepted are the same as find_by_solr | ||
130 | - # | ||
131 | - def find_id_by_solr(query, options={}) | ||
132 | - data = parse_query(query, options) | ||
133 | - return parse_results(data, {:format => :ids}) | ||
134 | - end | ||
135 | - | ||
136 | - # This method can be used to execute a search across multiple models: | ||
137 | - # Book.multi_solr_search "Napoleon OR Tom", :models => [Movie] | ||
138 | - # | ||
139 | - # ====options: | ||
140 | - # Accepts the same options as find_by_solr plus: | ||
141 | - # models:: The additional models you'd like to include in the search | ||
142 | - # results_format:: Specify the format of the results found | ||
143 | - # :objects :: Will return an array with the results being objects (default). Example: | ||
144 | - # Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :objects | ||
145 | - # :ids :: Will return an array with the ids of each entry found. Example: | ||
146 | - # Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :ids | ||
147 | - # => [{"id" => "Movie:1"},{"id" => Book:1}] | ||
148 | - # Where the value of each array is as Model:instance_id | ||
149 | - # scores:: If set to true this will return the score as a 'solr_score' attribute | ||
150 | - # for each one of the instances found. Does not currently work with find_id_by_solr | ||
151 | - # | ||
152 | - # books = Book.multi_solr_search 'ruby OR splinter', :scores => true | ||
153 | - # books.records.first.solr_score | ||
154 | - # => 1.21321397 | ||
155 | - # books.records.last.solr_score | ||
156 | - # => 0.12321548 | ||
157 | - # | ||
158 | - def multi_solr_search(query, options = {}) | ||
159 | - options.update(:results_format => :objects) unless options[:results_format] | ||
160 | - data = parse_query(query, options) | ||
161 | - | ||
162 | - if data.nil? or data.total_hits == 0 | ||
163 | - return SearchResults.new(:docs => [], :total => 0) | ||
164 | - end | ||
165 | - | ||
166 | - result = find_multi_search_objects(data, options) | ||
167 | - if options[:scores] and options[:results_format] == :objects | ||
168 | - add_scores(result, data) | ||
169 | - end | ||
170 | - SearchResults.new :docs => result, :total => data.total_hits | ||
171 | - end | ||
172 | - | ||
173 | - def find_multi_search_objects(data, options) | ||
174 | - result = [] | ||
175 | - if options[:results_format] == :objects | ||
176 | - data.hits.each do |doc| | ||
177 | - k = doc.fetch('id').first.to_s.split(':') | ||
178 | - result << k[0].constantize.find_by_id(k[1]) | ||
179 | - end | ||
180 | - elsif options[:results_format] == :ids | ||
181 | - data.hits.each{|doc| result << {"id" => doc["id"].to_s}} | ||
182 | - end | ||
183 | - result | ||
184 | - end | ||
185 | - | ||
186 | - # returns the total number of documents found in the query specified: | ||
187 | - # Book.count_by_solr 'rails' => 3 | ||
188 | - # | ||
189 | - def count_by_solr(query, options = {}) | ||
190 | - data = parse_query(query, options) | ||
191 | - data.total_hits | ||
192 | - end | ||
193 | - | ||
194 | - # It's used to rebuild the Solr index for a specific model. | ||
195 | - # Book.rebuild_solr_index | ||
196 | - # | ||
197 | - # If batch_size is greater than 0, adds will be done in batches. | ||
198 | - # NOTE: If using sqlserver, be sure to use a finder with an explicit order. | ||
199 | - # Non-edge versions of rails do not handle pagination correctly for sqlserver | ||
200 | - # without an order clause. | ||
201 | - # | ||
202 | - # If a finder block is given, it will be called to retrieve the items to index. | ||
203 | - # This can be very useful for things such as updating based on conditions or | ||
204 | - # using eager loading for indexed associations. | ||
205 | - def rebuild_solr_index(batch_size=300, options = {}, &finder) | ||
206 | - finder ||= lambda do |ar, sql_options| | ||
207 | - ar.all sql_options.merge!({:order => self.primary_key, :include => configuration[:solr_includes].keys}) | ||
208 | - end | ||
209 | - start_time = Time.now | ||
210 | - options[:offset] ||= 0 | ||
211 | - options[:threads] ||= 2 | ||
212 | - options[:delayed_job] &= defined?(Delayed::Job) | ||
213 | - | ||
214 | - if batch_size > 0 | ||
215 | - items_processed = 0 | ||
216 | - offset = options[:offset] | ||
217 | - end_reached = false | ||
218 | - threads = [] | ||
219 | - mutex = Mutex.new | ||
220 | - queue = Queue.new | ||
221 | - loop do | ||
222 | - items = finder.call(self, {:limit => batch_size, :offset => offset}) | ||
223 | - add_batch = items.collect { |content| content.to_solr_doc } | ||
224 | - offset += items.size | ||
225 | - end_reached = items.size == 0 | ||
226 | - break if end_reached | ||
227 | - | ||
228 | - if options[:threads] == threads.size | ||
229 | - threads.first.join | ||
230 | - threads.shift | ||
231 | - end | ||
232 | - | ||
233 | - queue << [items, add_batch] | ||
234 | - threads << Thread.new do | ||
235 | - iteration_start = Time.now | ||
236 | - | ||
237 | - iteration_items, iteration_add_batch = queue.pop(true) | ||
238 | - if options[:delayed_job] | ||
239 | - delay.solr_add iteration_add_batch | ||
240 | - else | ||
241 | - solr_add iteration_add_batch | ||
242 | - solr_commit | ||
243 | - end | ||
244 | - | ||
245 | - last_id = iteration_items.last.id | ||
246 | - time_so_far = Time.now - start_time | ||
247 | - iteration_time = Time.now - iteration_start | ||
248 | - mutex.synchronize do | ||
249 | - items_processed += iteration_items.size | ||
250 | - if options[:delayed_job] | ||
251 | - logger.info "#{Process.pid}: #{items_processed} items for #{self.name} have been sent to Delayed::Job in #{'%.3f' % time_so_far}s at #{'%.3f' % (items_processed / time_so_far)} items/sec. Last id: #{last_id}" | ||
252 | - else | ||
253 | - logger.info "#{Process.pid}: #{items_processed} items for #{self.name} have been batch added to index in #{'%.3f' % time_so_far}s at #{'%.3f' % (items_processed / time_so_far)} items/sec. Last id: #{last_id}" | ||
254 | - end | ||
255 | - end | ||
256 | - end | ||
257 | - end | ||
258 | - | ||
259 | - solr_commit if options[:delayed_job] | ||
260 | - threads.each{ |t| t.join } | ||
261 | - else | ||
262 | - items = finder.call(self, {}) | ||
263 | - items.each { |content| content.solr_save } | ||
264 | - items_processed = items.size | ||
265 | - end | ||
266 | - | ||
267 | - if items_processed > 0 | ||
268 | - solr_optimize | ||
269 | - time_elapsed = Time.now - start_time | ||
270 | - logger.info "Index for #{self.name} has been rebuilt (took #{'%.3f' % time_elapsed}s)" | ||
271 | - else | ||
272 | - "Nothing to index for #{self.name}" | ||
273 | - end | ||
274 | - end | ||
275 | - | ||
276 | - alias :rebuild_index :rebuild_solr_index | ||
277 | - end | ||
278 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/common_methods.rb
@@ -1,77 +0,0 @@ | @@ -1,77 +0,0 @@ | ||
1 | -module ActsAsSolr #:nodoc: | ||
2 | - | ||
3 | - module CommonMethods | ||
4 | - | ||
5 | - TypeMapping = { | ||
6 | - :double => "do", | ||
7 | - :float => "f", | ||
8 | - :decimal => "f", | ||
9 | - :integer => "i", | ||
10 | - :boolean => "b", | ||
11 | - :string => "s", | ||
12 | - :date => "d", | ||
13 | - :range_float => "rf", | ||
14 | - :range_integer => "ri", | ||
15 | - :facet => "facet", | ||
16 | - :text => "t", | ||
17 | - } | ||
18 | - | ||
19 | - # Converts field types into Solr types | ||
20 | - def get_solr_field_type(field_type) | ||
21 | - if field_type.is_a?(Symbol) | ||
22 | - t = TypeMapping[field_type] | ||
23 | - raise "Unknown field_type symbol: #{field_type}" if t.nil? | ||
24 | - t | ||
25 | - elsif field_type.is_a?(String) | ||
26 | - return field_type | ||
27 | - else | ||
28 | - raise "Unknown field_type class: #{field_type.class}: #{field_type}" | ||
29 | - end | ||
30 | - end | ||
31 | - | ||
32 | - def solr_batch_add(objects) | ||
33 | - solr_add objects.map{ |a| a.to_solr_doc } | ||
34 | - solr_commit if defined?(configuration) and configuration[:auto_commit] | ||
35 | - end | ||
36 | - | ||
37 | - def solr_batch_add_association(ar, association) | ||
38 | - result = ar.send(association) | ||
39 | - result = [result] unless result.is_a?(Array) | ||
40 | - solr_batch_add result | ||
41 | - end | ||
42 | - | ||
43 | - # Sends an add command to Solr | ||
44 | - def solr_add(add_xml) | ||
45 | - ActsAsSolr::Post.execute(Solr::Request::AddDocument.new(add_xml)) | ||
46 | - end | ||
47 | - | ||
48 | - # Sends the delete command to Solr | ||
49 | - def solr_delete(solr_ids) | ||
50 | - ActsAsSolr::Post.execute(Solr::Request::Delete.new(:id => solr_ids)) | ||
51 | - end | ||
52 | - | ||
53 | - # Sends the commit command to Solr | ||
54 | - def solr_commit | ||
55 | - ActsAsSolr::Post.execute(Solr::Request::Commit.new) | ||
56 | - end | ||
57 | - | ||
58 | - # Optimizes the Solr index. Solr says: | ||
59 | - # | ||
60 | - # Optimizations can take nearly ten minutes to run. | ||
61 | - # We are presuming optimizations should be run once following large | ||
62 | - # batch-like updates to the collection and/or once a day. | ||
63 | - # | ||
64 | - # One of the solutions for this would be to create a cron job that | ||
65 | - # runs every day at midnight and optmizes the index: | ||
66 | - # 0 0 * * * /your_rails_dir/script/runner -e production "Model.solr_optimize" | ||
67 | - # | ||
68 | - def solr_optimize | ||
69 | - ActsAsSolr::Post.execute(Solr::Request::Optimize.new) | ||
70 | - end | ||
71 | - | ||
72 | - # Returns the id for the given instance | ||
73 | - def record_id(object) | ||
74 | - eval "object.#{object.class.primary_key}" | ||
75 | - end | ||
76 | - end | ||
77 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/deprecation.rb
@@ -1,61 +0,0 @@ | @@ -1,61 +0,0 @@ | ||
1 | -module ActsAsSolr #:nodoc: | ||
2 | - | ||
3 | - class Post | ||
4 | - def initialize(body, mode = :search) | ||
5 | - @body = body | ||
6 | - @mode = mode | ||
7 | - puts "The method ActsAsSolr::Post.new(body, mode).execute_post is depracated. " + | ||
8 | - "Use ActsAsSolr::Post.execute(body, mode) instead!" | ||
9 | - end | ||
10 | - | ||
11 | - def execute_post | ||
12 | - ActsAsSolr::Post.execute(@body, @mode) | ||
13 | - end | ||
14 | - end | ||
15 | - | ||
16 | - module ClassMethods | ||
17 | - def find_with_facet(query, options={}) | ||
18 | - Deprecation.plog "The method find_with_facet is deprecated. Use find_by_solr instead, passing the " + | ||
19 | - "arguments the same way you used to do with find_with_facet." | ||
20 | - find_by_solr(query, options) | ||
21 | - end | ||
22 | - end | ||
23 | - | ||
24 | - class Deprecation | ||
25 | - # Validates the options passed during query | ||
26 | - def self.validate_query options={} | ||
27 | - if options[:field_types] | ||
28 | - plog "The option :field_types for searching is deprecated. " + | ||
29 | - "The field types are automatically traced back when you specify a field type in your model." | ||
30 | - end | ||
31 | - if options[:sort_by] | ||
32 | - plog "The option :sort_by is deprecated, use :sort instead!" | ||
33 | - options[:sort] ||= options[:sort_by] | ||
34 | - end | ||
35 | - if options[:start] | ||
36 | - plog "The option :start is deprecated, use :offset instead!" | ||
37 | - options[:offset] ||= options[:start] | ||
38 | - end | ||
39 | - if options[:rows] | ||
40 | - plog "The option :rows is deprecated, use :limit instead!" | ||
41 | - options[:limit] ||= options[:rows] | ||
42 | - end | ||
43 | - end | ||
44 | - | ||
45 | - # Validates the options passed during indexing | ||
46 | - def self.validate_index options={} | ||
47 | - if options[:background] | ||
48 | - plog "The :background option is being deprecated. There are better and more efficient " + | ||
49 | - "ways to handle delayed saving of your records." | ||
50 | - end | ||
51 | - end | ||
52 | - | ||
53 | - # This will print the text to stdout and log the text | ||
54 | - # if rails logger is available | ||
55 | - def self.plog text | ||
56 | - puts text | ||
57 | - RAILS_DEFAULT_LOGGER.warn text if defined? RAILS_DEFAULT_LOGGER | ||
58 | - end | ||
59 | - end | ||
60 | - | ||
61 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/dynamic_attribute.rb
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/instance_methods.rb
@@ -1,194 +0,0 @@ | @@ -1,194 +0,0 @@ | ||
1 | -module ActsAsSolr #:nodoc: | ||
2 | - | ||
3 | - module InstanceMethods | ||
4 | - | ||
5 | - # Solr id is <class.name>:<id> to be unique across all models | ||
6 | - def solr_id | ||
7 | - "#{self.class.name}:#{record_id(self)}" | ||
8 | - end | ||
9 | - | ||
10 | - # saves to the Solr index | ||
11 | - def solr_save | ||
12 | - return true if indexing_disabled? | ||
13 | - if evaluate_condition(:if, self) | ||
14 | - debug "solr_save: #{self.class.name} : #{record_id(self)}" | ||
15 | - solr_add to_solr_doc | ||
16 | - solr_commit if configuration[:auto_commit] | ||
17 | - true | ||
18 | - else | ||
19 | - solr_destroy | ||
20 | - end | ||
21 | - end | ||
22 | - | ||
23 | - def indexing_disabled? | ||
24 | - evaluate_condition(:offline, self) || !configuration[:if] | ||
25 | - end | ||
26 | - | ||
27 | - # remove from index | ||
28 | - def solr_destroy | ||
29 | - return true if indexing_disabled? | ||
30 | - debug "solr_destroy: #{self.class.name} : #{record_id(self)}" | ||
31 | - solr_delete solr_id | ||
32 | - solr_commit if configuration[:auto_commit] | ||
33 | - true | ||
34 | - end | ||
35 | - | ||
36 | - # convert instance to Solr document | ||
37 | - def to_solr_doc | ||
38 | - debug "to_solr_doc: creating doc for class: #{self.class.name}, id: #{record_id(self)}" | ||
39 | - doc = Solr::Document.new | ||
40 | - doc.boost = validate_boost(configuration[:boost]) if configuration[:boost] | ||
41 | - | ||
42 | - doc << {:id => solr_id, | ||
43 | - solr_configuration[:type_field] => self.class.name, | ||
44 | - solr_configuration[:primary_key_field] => record_id(self).to_s} | ||
45 | - | ||
46 | - # iterate through the fields and add them to the document, | ||
47 | - configuration[:solr_fields].each do |field_name, options| | ||
48 | - next if [self.class.primary_key, "type"].include?(field_name.to_s) | ||
49 | - | ||
50 | - field_boost = options[:boost] || solr_configuration[:default_boost] | ||
51 | - field_type = get_solr_field_type(options[:type]) | ||
52 | - solr_name = options[:as] || field_name | ||
53 | - | ||
54 | - value = self.send("#{field_name}_for_solr") rescue nil | ||
55 | - next if value.nil? | ||
56 | - | ||
57 | - suffix = get_solr_field_type(field_type) | ||
58 | - value = Array(value).map{ |v| ERB::Util.html_escape(v) } # escape each value | ||
59 | - value = value.first if value.size == 1 | ||
60 | - | ||
61 | - field = Solr::Field.new(:name => "#{solr_name}_#{suffix}", :value => value) | ||
62 | - processed_boost = validate_boost(field_boost) | ||
63 | - field.boost = processed_boost | ||
64 | - doc << field | ||
65 | - end | ||
66 | - | ||
67 | - add_dynamic_attributes(doc) | ||
68 | - add_includes(doc) | ||
69 | - add_tags(doc) | ||
70 | - add_space(doc) | ||
71 | - | ||
72 | - debug doc.to_json | ||
73 | - doc | ||
74 | - end | ||
75 | - | ||
76 | - private | ||
77 | - | ||
78 | - def debug(text) | ||
79 | - logger.debug text rescue nil | ||
80 | - end | ||
81 | - | ||
82 | - def add_space(doc) | ||
83 | - if configuration[:spatial] and local | ||
84 | - doc << Solr::Field.new(:name => "lat_f", :value => local.latitude) | ||
85 | - doc << Solr::Field.new(:name => "lng_f", :value => local.longitude) | ||
86 | - end | ||
87 | - end | ||
88 | - | ||
89 | - def add_tags(doc) | ||
90 | - taggings.each do |tagging| | ||
91 | - doc << Solr::Field.new(:name => "tag_facet", :value => tagging.tag.name) | ||
92 | - doc << Solr::Field.new(:name => "tag_t", :value => tagging.tag.name) | ||
93 | - end if configuration[:taggable] | ||
94 | - end | ||
95 | - | ||
96 | - def add_dynamic_attributes(doc) | ||
97 | - dynamic_attributes.each do |attribute| | ||
98 | - value = ERB::Util.html_escape(attribute.value) | ||
99 | - doc << Solr::Field.new(:name => "#{attribute.name.downcase}_t", :value => value) | ||
100 | - doc << Solr::Field.new(:name => "#{attribute.name.downcase}_facet", :value => value) | ||
101 | - end if configuration[:dynamic_attributes] | ||
102 | - end | ||
103 | - | ||
104 | - def add_includes(doc) | ||
105 | - if configuration[:solr_includes].respond_to?(:each) | ||
106 | - configuration[:solr_includes].each do |association, options| | ||
107 | - data = options[:multivalued] ? [] : "" | ||
108 | - field_name = options[:as] || association.to_s.singularize | ||
109 | - field_type = get_solr_field_type(options[:type]) | ||
110 | - field_boost = options[:boost] || solr_configuration[:default_boost] | ||
111 | - suffix = get_solr_field_type(field_type) | ||
112 | - case self.class.reflect_on_association(association).macro | ||
113 | - when :has_many, :has_and_belongs_to_many | ||
114 | - records = self.send(association).compact | ||
115 | - unless records.empty? | ||
116 | - records.each {|r| data << include_value(r, options)} | ||
117 | - Array(data).each do |value| | ||
118 | - field = Solr::Field.new(:name => "#{field_name}_#{suffix}", :value => value) | ||
119 | - processed_boost = validate_boost(field_boost) | ||
120 | - field.boost = processed_boost | ||
121 | - doc << field | ||
122 | - end | ||
123 | - end | ||
124 | - when :has_one, :belongs_to | ||
125 | - record = self.send(association) | ||
126 | - unless record.nil? | ||
127 | - doc["#{field_name}_#{suffix}"] = include_value(record, options) | ||
128 | - end | ||
129 | - end | ||
130 | - end | ||
131 | - end | ||
132 | - end | ||
133 | - | ||
134 | - def include_value(record, options) | ||
135 | - if options[:using].is_a? Proc | ||
136 | - options[:using].call(record) | ||
137 | - elsif options[:using].is_a? Symbol | ||
138 | - record.send(options[:using]) | ||
139 | - else | ||
140 | - if options[:fields] | ||
141 | - fields = {} | ||
142 | - options[:fields].each{ |f| fields[f] = record.send(f) } | ||
143 | - else | ||
144 | - fields = record.attributes | ||
145 | - end | ||
146 | - fields.map{ |k,v| ERB::Util.html_escape(v) }.join(" ") | ||
147 | - end | ||
148 | - end | ||
149 | - | ||
150 | - def validate_boost(boost) | ||
151 | - boost_value = case boost | ||
152 | - when Float | ||
153 | - return solr_configuration[:default_boost] if boost < 0 | ||
154 | - boost | ||
155 | - when Proc | ||
156 | - boost.call(self) | ||
157 | - when Symbol | ||
158 | - if self.respond_to?(boost) | ||
159 | - self.send(boost) | ||
160 | - end | ||
161 | - end | ||
162 | - | ||
163 | - boost_value || solr_configuration[:default_boost] | ||
164 | - end | ||
165 | - | ||
166 | - def condition_block?(condition) | ||
167 | - condition.respond_to?("call") && (condition.arity == 1 || condition.arity == -1) | ||
168 | - end | ||
169 | - | ||
170 | - def evaluate_condition(which_condition, field) | ||
171 | - condition = configuration[which_condition] | ||
172 | - case condition | ||
173 | - when Symbol | ||
174 | - field.send(condition) | ||
175 | - when String | ||
176 | - eval(condition, binding) | ||
177 | - when FalseClass, NilClass | ||
178 | - false | ||
179 | - when TrueClass | ||
180 | - true | ||
181 | - else | ||
182 | - if condition_block?(condition) | ||
183 | - condition.call(field) | ||
184 | - else | ||
185 | - raise( | ||
186 | - ArgumentError, | ||
187 | - "The :#{which_condition} option has to be either a symbol, string (to be eval'ed), proc/method, true/false, or " + | ||
188 | - "class implementing a static validation method" | ||
189 | - ) | ||
190 | - end | ||
191 | - end | ||
192 | - end | ||
193 | - end | ||
194 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/lazy_document.rb
@@ -1,18 +0,0 @@ | @@ -1,18 +0,0 @@ | ||
1 | -module ActsAsSolr | ||
2 | - class LazyDocument | ||
3 | - attr_reader :id, :clazz | ||
4 | - | ||
5 | - def initialize(id, clazz) | ||
6 | - @id = id | ||
7 | - @clazz = clazz | ||
8 | - end | ||
9 | - | ||
10 | - def method_missing(name, *args) | ||
11 | - unless @__instance | ||
12 | - @__instance = @clazz.find(@id) | ||
13 | - end | ||
14 | - | ||
15 | - @__instance.send(name, *args) | ||
16 | - end | ||
17 | - end | ||
18 | -end | ||
19 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/local.rb
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/mongo_mapper.rb
@@ -1,24 +0,0 @@ | @@ -1,24 +0,0 @@ | ||
1 | -module ActsAsSolr | ||
2 | - module MongoMapper | ||
3 | - def self.included(clazz) | ||
4 | - clazz.extend ActsAsSolr::ActsMethods | ||
5 | - clazz.extend ClassMethods | ||
6 | - end | ||
7 | - | ||
8 | - module ClassMethods | ||
9 | - def columns_hash | ||
10 | - keys | ||
11 | - end | ||
12 | - | ||
13 | - def primary_key | ||
14 | - 'id' | ||
15 | - end | ||
16 | - | ||
17 | - def merge_conditions(*args) | ||
18 | - ret = {} | ||
19 | - args.each{ |a| ret.merge!(a) if a.is_a?(Hash) } | ||
20 | - ret | ||
21 | - end | ||
22 | - end | ||
23 | - end | ||
24 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb
@@ -1,273 +0,0 @@ | @@ -1,273 +0,0 @@ | ||
1 | -module ActsAsSolr #:nodoc: | ||
2 | - module ParserMethods | ||
3 | - protected | ||
4 | - | ||
5 | - # Method used by mostly all the ClassMethods when doing a search | ||
6 | - def parse_query(query=nil, options={}) | ||
7 | - valid_options = [:models, :lazy, :core, :results_format, :sql_options, | ||
8 | - :alternate_query, :boost_functions, :filter_queries, :facets, :sort, | ||
9 | - :scores, :operator, :latitude, :longitude, :radius, :relevance, :highlight, | ||
10 | - :offset, :per_page, :limit, :page,] | ||
11 | - query_options = {} | ||
12 | - | ||
13 | - return if query.nil? | ||
14 | - raise "Query should be a string" unless query.is_a?(String) | ||
15 | - raise "Invalid parameters: #{(options.keys - valid_options).join(',')}" unless (options.keys - valid_options).empty? | ||
16 | - begin | ||
17 | - Deprecation.validate_query(options) | ||
18 | - | ||
19 | - query_options[:filter_queries] = [] | ||
20 | - query.strip! | ||
21 | - | ||
22 | - # using *:* disable index boosts, so use the type filter | ||
23 | - if query.blank? | ||
24 | - query = solr_type_condition(options) | ||
25 | - else | ||
26 | - query = sanitize_query(query) | ||
27 | - query_options[:filter_queries] << solr_type_condition(options) | ||
28 | - | ||
29 | - # put types on filtered fields | ||
30 | - query = replace_types([*query], ':').first | ||
31 | - end | ||
32 | - | ||
33 | - query_options[:filter_queries] += replace_types([*options[:filter_queries]], ':') if options[:filter_queries] | ||
34 | - | ||
35 | - options[:alternate_query] ||= '' | ||
36 | - options[:alternate_query].strip! | ||
37 | - query = "#{options[:alternate_query]} #{query}" unless options[:alternate_query].blank? | ||
38 | - | ||
39 | - query = add_relevance query, options[:relevance] | ||
40 | - | ||
41 | - query_options[:query] = query | ||
42 | - | ||
43 | - field_list = options[:models].nil? ? solr_configuration[:primary_key_field] : "id" | ||
44 | - query_options[:field_list] = [field_list, 'score'] | ||
45 | - | ||
46 | - per_page = options[:per_page] || options[:limit] || 30 | ||
47 | - offset = options[:offset] || (((options[:page] || 1).to_i - 1) * per_page) | ||
48 | - query_options[:rows] = per_page | ||
49 | - query_options[:start] = offset | ||
50 | - | ||
51 | - query_options[:operator] = options[:operator] | ||
52 | - | ||
53 | - query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions] | ||
54 | - | ||
55 | - # first steps on the facet parameter processing | ||
56 | - if options[:facets] | ||
57 | - query_options[:facets] = {} | ||
58 | - query_options[:facets][:limit] = -1 # TODO: make this configurable | ||
59 | - query_options[:facets][:sort] = :count if options[:facets][:sort] | ||
60 | - query_options[:facets][:mincount] = 0 | ||
61 | - query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false | ||
62 | - # override the :zeros (it's deprecated anyway) if :mincount exists | ||
63 | - query_options[:facets][:mincount] = options[:facets][:mincount] if options[:facets][:mincount] | ||
64 | - query_options[:facets][:fields] = options[:facets][:fields].map{ |k| "#{k}_facet" } if options[:facets][:fields] | ||
65 | - query_options[:filter_queries] += replace_types([*options[:facets][:browse]]) if options[:facets][:browse] | ||
66 | - query_options[:facets][:queries] = replace_types([*options[:facets][:query]]) if options[:facets][:query] | ||
67 | - | ||
68 | - if options[:facets][:dates] | ||
69 | - query_options[:date_facets] = {} | ||
70 | - # if options[:facets][:dates][:fields] exists then :start, :end, and :gap must be there | ||
71 | - if options[:facets][:dates][:fields] | ||
72 | - [:start, :end, :gap].each { |k| raise "#{k} must be present in faceted date query" unless options[:facets][:dates].include?(k) } | ||
73 | - query_options[:date_facets][:fields] = [] | ||
74 | - options[:facets][:dates][:fields].each { |f| | ||
75 | - if f.kind_of? Hash | ||
76 | - key = f.keys[0] | ||
77 | - query_options[:date_facets][:fields] << {"#{key}_d" => f[key]} | ||
78 | - validate_date_facet_other_options(f[key][:other]) if f[key][:other] | ||
79 | - else | ||
80 | - query_options[:date_facets][:fields] << "#{f}_d" | ||
81 | - end | ||
82 | - } | ||
83 | - end | ||
84 | - | ||
85 | - query_options[:date_facets][:start] = options[:facets][:dates][:start] if options[:facets][:dates][:start] | ||
86 | - query_options[:date_facets][:end] = options[:facets][:dates][:end] if options[:facets][:dates][:end] | ||
87 | - query_options[:date_facets][:gap] = options[:facets][:dates][:gap] if options[:facets][:dates][:gap] | ||
88 | - query_options[:date_facets][:hardend] = options[:facets][:dates][:hardend] if options[:facets][:dates][:hardend] | ||
89 | - query_options[:date_facets][:filter] = replace_types([*options[:facets][:dates][:filter]].collect{|k| "#{k.dup.sub!(/ *:(?!\d) */,"_d:")}"}) if options[:facets][:dates][:filter] | ||
90 | - | ||
91 | - if options[:facets][:dates][:other] | ||
92 | - validate_date_facet_other_options(options[:facets][:dates][:other]) | ||
93 | - query_options[:date_facets][:other] = options[:facets][:dates][:other] | ||
94 | - end | ||
95 | - | ||
96 | - end | ||
97 | - end | ||
98 | - | ||
99 | - if options[:highlight] | ||
100 | - query_options[:highlighting] = {} | ||
101 | - query_options[:highlighting][:field_list] = replace_types([*options[:highlight][:fields]], '') if options[:highlight][:fields] | ||
102 | - query_options[:highlighting][:require_field_match] = options[:highlight][:require_field_match] if options[:highlight][:require_field_match] | ||
103 | - query_options[:highlighting][:max_snippets] = options[:highlight][:max_snippets] if options[:highlight][:max_snippets] | ||
104 | - query_options[:highlighting][:prefix] = options[:highlight][:prefix] if options[:highlight][:prefix] | ||
105 | - query_options[:highlighting][:suffix] = options[:highlight][:suffix] if options[:highlight][:suffix] | ||
106 | - end | ||
107 | - | ||
108 | - query_options[:sort] = replace_types([*options[:sort]], '')[0] if options[:sort] | ||
109 | - | ||
110 | - if options[:radius] | ||
111 | - query_options[:radius] = options[:radius] | ||
112 | - query_options[:filter_queries] << '{!geofilt}' | ||
113 | - end | ||
114 | - query_options[:latitude] = options[:latitude] | ||
115 | - query_options[:longitude] = options[:longitude] | ||
116 | - | ||
117 | - not_dismax = query_options[:operator] == :or | ||
118 | - request = not_dismax ? Solr::Request::Standard.new(query_options) : Solr::Request::Dismax.new(query_options) | ||
119 | - ActsAsSolr::Post.execute(request, options[:core]) | ||
120 | - rescue | ||
121 | - raise "#{$query} There was a problem executing your search\n#{query_options.inspect}\n: #{$!} in #{$!.backtrace.first}" | ||
122 | - end | ||
123 | - end | ||
124 | - | ||
125 | - def solr_type_condition(options = {}) | ||
126 | - classes = [self] + (self.subclasses || []) + (options[:models] || []) | ||
127 | - classes.map do |klass| | ||
128 | - next if klass.name.empty? | ||
129 | - "#{solr_configuration[:type_field]}:\"#{klass.name}\"" | ||
130 | - end.compact.join(' OR ') | ||
131 | - end | ||
132 | - | ||
133 | - # Parses the data returned from Solr | ||
134 | - def parse_results(solr_data, options = {}) | ||
135 | - results = { | ||
136 | - :docs => [], | ||
137 | - :total => 0 | ||
138 | - } | ||
139 | - | ||
140 | - configuration = { | ||
141 | - :format => :objects | ||
142 | - } | ||
143 | - results.update(:spellcheck => solr_data.data['spellcheck']) unless solr_data.nil? | ||
144 | - results.update(:facets => {'facet_fields' => []}) if options[:facets] | ||
145 | - unless solr_data.nil? or solr_data.header['params'].nil? | ||
146 | - header = solr_data.header | ||
147 | - results.update :rows => header['params']['rows'] | ||
148 | - results.update :start => header['params']['start'] | ||
149 | - end | ||
150 | - return SearchResults.new(results) if (solr_data.nil? || solr_data.total_hits == 0) | ||
151 | - | ||
152 | - configuration.update(options) if options.is_a?(Hash) | ||
153 | - | ||
154 | - ids = solr_data.hits.collect {|doc| doc["#{solr_configuration[:primary_key_field]}"]}.flatten | ||
155 | - | ||
156 | - result = find_objects(ids, options, configuration) | ||
157 | - | ||
158 | - add_scores(result, solr_data) if configuration[:format] == :objects && options[:scores] | ||
159 | - | ||
160 | - highlighted = {} | ||
161 | - solr_data.highlighting.map do |x,y| | ||
162 | - e={} | ||
163 | - y1=y.map{|x1,y1| e[x1.gsub(/_[^_]*/,"")]=y1} unless y.nil? | ||
164 | - highlighted[x.gsub(/[^:]*:/,"").to_i]=e | ||
165 | - end unless solr_data.highlighting.nil? | ||
166 | - | ||
167 | - results.update(:facets => solr_data.data['facet_counts']) if options[:facets] | ||
168 | - results.update({:docs => result, :total => solr_data.total_hits, :max_score => solr_data.max_score, :query_time => solr_data.data['responseHeader']['QTime']}) | ||
169 | - results.update({:highlights=>highlighted}) | ||
170 | - SearchResults.new(results) | ||
171 | - end | ||
172 | - | ||
173 | - | ||
174 | - def find_objects(ids, options, configuration) | ||
175 | - result = if configuration[:lazy] && configuration[:format] != :ids | ||
176 | - ids.collect {|id| ActsAsSolr::LazyDocument.new(id, self)} | ||
177 | - elsif configuration[:format] == :objects | ||
178 | - find_options = options[:sql_options] || {} | ||
179 | - find_options[:conditions] = self.send :merge_conditions, {self.primary_key => ids}, (find_options[:conditions] || []) | ||
180 | - result = self.all(find_options) || [] | ||
181 | - result = reorder(result, ids) unless find_options[:order] | ||
182 | - result | ||
183 | - else | ||
184 | - ids | ||
185 | - end | ||
186 | - | ||
187 | - result | ||
188 | - end | ||
189 | - | ||
190 | - # Reorders the instances keeping the order returned from Solr | ||
191 | - def reorder(things, ids) | ||
192 | - ordered_things = [] | ||
193 | - ids.each do |id| | ||
194 | - thing = things.find{ |t| t.id.to_s == id.to_s } | ||
195 | - ordered_things |= [thing] if thing | ||
196 | - end | ||
197 | - ordered_things | ||
198 | - end | ||
199 | - | ||
200 | - # Replaces the field types based on the types (if any) specified | ||
201 | - # on the acts_as_solr call | ||
202 | - def replace_types(strings, suffix=':') | ||
203 | - if configuration[:solr_fields] | ||
204 | - configuration[:solr_fields].each do |name, options| | ||
205 | - solr_name = (options[:as] || name).to_s | ||
206 | - solr_type = get_solr_field_type(options[:type]) | ||
207 | - field = "#{solr_name}_#{solr_type}#{suffix}" | ||
208 | - strings.each_with_index {|s,i| strings[i] = s.gsub(/\b#{solr_name}\b#{suffix}/,field) } | ||
209 | - end | ||
210 | - end | ||
211 | - if configuration[:solr_includes] | ||
212 | - configuration[:solr_includes].each do |association, options| | ||
213 | - solr_name = options[:as] || association.to_s.singularize | ||
214 | - solr_type = get_solr_field_type(options[:type]) | ||
215 | - field = "#{solr_name}_#{solr_type}#{suffix}" | ||
216 | - strings.each_with_index {|s,i| strings[i] = s.gsub(/\b#{solr_name}\b#{suffix}/,field) } | ||
217 | - end | ||
218 | - end | ||
219 | - strings | ||
220 | - end | ||
221 | - | ||
222 | - # Adds the score to each one of the instances found | ||
223 | - def add_scores(results, solr_data) | ||
224 | - with_score = [] | ||
225 | - solr_data.hits.each do |doc| | ||
226 | - with_score.push([doc["score"], | ||
227 | - results.find {|record| scorable_record?(record, doc) }]) | ||
228 | - end | ||
229 | - with_score.each do |score, object| | ||
230 | - class << object; attr_accessor :solr_score; end | ||
231 | - object.solr_score = score | ||
232 | - end | ||
233 | - end | ||
234 | - | ||
235 | - def scorable_record?(record, doc) | ||
236 | - doc_id = doc["#{solr_configuration[:primary_key_field]}"] | ||
237 | - if doc_id.nil? | ||
238 | - doc_id = doc["id"] | ||
239 | - "#{record.class.name}:#{record_id(record)}" == doc_id.first.to_s | ||
240 | - else | ||
241 | - record_id(record).to_s == doc_id.to_s | ||
242 | - end | ||
243 | - end | ||
244 | - | ||
245 | - def validate_date_facet_other_options(options) | ||
246 | - valid_other_options = [:after, :all, :before, :between, :none] | ||
247 | - options = [options] unless options.kind_of? Array | ||
248 | - bad_options = options.map {|x| x.to_sym} - valid_other_options | ||
249 | - raise "Invalid option#{'s' if bad_options.size > 1} for faceted date's other param: #{bad_options.join(', ')}. May only be one of :after, :all, :before, :between, :none" if bad_options.size > 0 | ||
250 | - end | ||
251 | - | ||
252 | - def sanitize_query(query) | ||
253 | - fields = self.configuration[:solr_fields].keys | ||
254 | - fields += DynamicAttribute.all(:select => 'name', :group => 'name').map(&:name) if DynamicAttribute.table_exists? | ||
255 | - Solr::Util::query_parser_escape query, fields | ||
256 | - end | ||
257 | - | ||
258 | - private | ||
259 | - | ||
260 | - def add_relevance(query, relevance) | ||
261 | - return query if relevance.nil? or query.include? ':' | ||
262 | - | ||
263 | - query = [query] + relevance.map do |attribute, value| | ||
264 | - "#{attribute}:(#{query})^#{value}" | ||
265 | - end | ||
266 | - query = query.join(' OR ') | ||
267 | - | ||
268 | - replace_types([query], '').first | ||
269 | - end | ||
270 | - | ||
271 | - end | ||
272 | -end | ||
273 | - |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/post.rb
@@ -1,29 +0,0 @@ | @@ -1,29 +0,0 @@ | ||
1 | -module ActsAsSolr | ||
2 | - class Post | ||
3 | - class << self | ||
4 | - def config | ||
5 | - return @config if @config | ||
6 | - @config = {} | ||
7 | - YAML::load_file("#{Rails.root}/config/solr.yml")[Rails.env].each{ |k,v| @config[k.to_sym] = v } | ||
8 | - @config | ||
9 | - end | ||
10 | - | ||
11 | - def options | ||
12 | - @options ||= credentials.merge config | ||
13 | - end | ||
14 | - | ||
15 | - def credentials | ||
16 | - @credentials ||= {:username => config[:username], :password => config[:password]} | ||
17 | - end | ||
18 | - | ||
19 | - def url(core) | ||
20 | - core.nil? ? config[:url] : "#{config[:url]}/#{core}" | ||
21 | - end | ||
22 | - | ||
23 | - def execute(request, core = nil) | ||
24 | - connection = Solr::Connection.new(url(core), options) | ||
25 | - connection.send request | ||
26 | - end | ||
27 | - end | ||
28 | - end | ||
29 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/search_results.rb
@@ -1,136 +0,0 @@ | @@ -1,136 +0,0 @@ | ||
1 | -module ActsAsSolr #:nodoc: | ||
2 | - | ||
3 | - # TODO: Possibly looking into hooking it up with Solr::Response::Standard | ||
4 | - # | ||
5 | - # Class that returns the search results with four methods. | ||
6 | - # | ||
7 | - # books = Book.find_by_solr 'ruby' | ||
8 | - # | ||
9 | - # the above will return a SearchResults class with 4 methods: | ||
10 | - # | ||
11 | - # docs|results|records: will return an array of records found | ||
12 | - # | ||
13 | - # books.records.empty? | ||
14 | - # => false | ||
15 | - # | ||
16 | - # total|num_found|total_hits: will return the total number of records found | ||
17 | - # | ||
18 | - # books.total | ||
19 | - # => 2 | ||
20 | - # | ||
21 | - # facets: will return the facets when doing a faceted search | ||
22 | - # | ||
23 | - # max_score|highest_score: returns the highest score found | ||
24 | - # | ||
25 | - # books.max_score | ||
26 | - # => 1.3213213 | ||
27 | - # | ||
28 | - # | ||
29 | - class SearchResults | ||
30 | - | ||
31 | - include Enumerable | ||
32 | - | ||
33 | - def initialize(solr_data={}) | ||
34 | - @solr_data = solr_data | ||
35 | - end | ||
36 | - | ||
37 | - def each(&block) | ||
38 | - self.results.each &block | ||
39 | - end | ||
40 | - | ||
41 | - # Returns an array with the instances. This method | ||
42 | - # is also aliased as docs and records | ||
43 | - def results | ||
44 | - @solr_data[:docs] | ||
45 | - end | ||
46 | - | ||
47 | - # Returns the total records found. This method is | ||
48 | - # also aliased as num_found and total_hits | ||
49 | - def total | ||
50 | - @solr_data[:total] | ||
51 | - end | ||
52 | - | ||
53 | - # Returns the facets when doing a faceted search | ||
54 | - def facets | ||
55 | - @solr_data[:facets] | ||
56 | - end | ||
57 | - | ||
58 | - # Returns the highest score found. This method is | ||
59 | - # also aliased as highest_score | ||
60 | - def max_score | ||
61 | - @solr_data[:max_score] | ||
62 | - end | ||
63 | - | ||
64 | - def query_time | ||
65 | - @solr_data[:query_time] | ||
66 | - end | ||
67 | - | ||
68 | - # Returns the highlighted fields which one has asked for.. | ||
69 | - def highlights | ||
70 | - @solr_data[:highlights] | ||
71 | - end | ||
72 | - | ||
73 | - # Returns a suggested query | ||
74 | - def suggest | ||
75 | - Hash[@solr_data[:spellcheck]['suggestions']]['collation'] | ||
76 | - end | ||
77 | - | ||
78 | - # Returns the number of documents per page | ||
79 | - def per_page | ||
80 | - @solr_data[:rows].to_i | ||
81 | - end | ||
82 | - | ||
83 | - # Returns the number of pages found | ||
84 | - def total_pages | ||
85 | - per_page.zero? ? 0 : (total / per_page.to_f).ceil | ||
86 | - end | ||
87 | - | ||
88 | - # Returns the current page | ||
89 | - def current_page | ||
90 | - per_page.zero? ? 0 : (@solr_data[:start].to_i / per_page) + 1 | ||
91 | - end | ||
92 | - | ||
93 | - def blank? | ||
94 | - total_entries == 0 | ||
95 | - end | ||
96 | - | ||
97 | - def size | ||
98 | - total_entries | ||
99 | - end | ||
100 | - | ||
101 | - def offset | ||
102 | - (current_page - 1) * per_page | ||
103 | - end | ||
104 | - | ||
105 | - def previous_page | ||
106 | - if current_page > 1 | ||
107 | - current_page - 1 | ||
108 | - else | ||
109 | - false | ||
110 | - end | ||
111 | - end | ||
112 | - | ||
113 | - def next_page | ||
114 | - if current_page < total_pages | ||
115 | - current_page + 1 | ||
116 | - else | ||
117 | - false | ||
118 | - end | ||
119 | - end | ||
120 | - | ||
121 | - def method_missing(symbol, *args, &block) | ||
122 | - self.results.send(symbol, *args, &block) | ||
123 | - rescue NoMethodError | ||
124 | - raise NoMethodError, "There is no method called #{symbol} at #{self.class.name} - #{self.inspect}" | ||
125 | - end | ||
126 | - | ||
127 | - alias docs results | ||
128 | - alias records results | ||
129 | - alias num_found total | ||
130 | - alias total_hits total | ||
131 | - alias total_entries total | ||
132 | - alias highest_score max_score | ||
133 | - end | ||
134 | - | ||
135 | -end | ||
136 | - |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/solr_fixtures.rb
@@ -1,13 +0,0 @@ | @@ -1,13 +0,0 @@ | ||
1 | -module ActsAsSolr | ||
2 | - | ||
3 | - class SolrFixtures | ||
4 | - def self.load(table_names) | ||
5 | - [table_names].flatten.map { |n| n.to_s }.each do |table_name| | ||
6 | - klass = instance_eval(File.split(table_name.to_s).last.to_s.gsub('_',' ').split(" ").collect{|w| w.capitalize}.to_s.singularize) | ||
7 | - klass.rebuild_solr_index if klass.respond_to?(:rebuild_solr_index) | ||
8 | - end | ||
9 | - ActsAsSolr::Post.execute(Solr::Request::Commit.new) | ||
10 | - end | ||
11 | - end | ||
12 | - | ||
13 | -end | ||
14 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/tasks.rb
@@ -1,10 +0,0 @@ | @@ -1,10 +0,0 @@ | ||
1 | -dir = File.dirname(__FILE__) | ||
2 | -require 'rubygems' | ||
3 | -require 'rake' | ||
4 | -require 'net/http' | ||
5 | -require 'active_record' | ||
6 | -require File.expand_path("#{dir}/solr_fixtures") | ||
7 | - | ||
8 | -load File.expand_path("#{dir}/tasks/database.rake") | ||
9 | -load File.expand_path("#{dir}/tasks/solr.rake") | ||
10 | -load File.expand_path("#{dir}/tasks/test.rake") |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr_reloaded.rb
vendor/plugins/acts_as_solr_reloaded/lib/solr.rb
@@ -1,27 +0,0 @@ | @@ -1,27 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -module Solr; end | ||
14 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/exception") | ||
15 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/request") | ||
16 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/connection") | ||
17 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/response") | ||
18 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/util") | ||
19 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/xml") | ||
20 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/importer") | ||
21 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/indexer") | ||
22 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/xml") | ||
23 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/field") | ||
24 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/request/base") | ||
25 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/document") | ||
26 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/request/json_update") | ||
27 | -require File.expand_path("#{File.dirname(__FILE__)}/solr/request/update") |
vendor/plugins/acts_as_solr_reloaded/lib/solr/connection.rb
@@ -1,180 +0,0 @@ | @@ -1,180 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -# TODO: add a convenience method to POST a Solr .xml file, like Solr's example post.sh | ||
14 | - | ||
15 | -class Solr::Connection | ||
16 | - attr_reader :url, :autocommit, :connection | ||
17 | - | ||
18 | - # create a connection to a solr instance using the url for the solr | ||
19 | - # application context: | ||
20 | - # | ||
21 | - # conn = Solr::Connection.new("http://example.com:8080/solr") | ||
22 | - # | ||
23 | - # if you would prefer to have all adds/updates autocommitted, | ||
24 | - # use :autocommit => :on | ||
25 | - # | ||
26 | - # conn = Solr::Connection.new('http://example.com:8080/solr', | ||
27 | - # :autocommit => :on) | ||
28 | - | ||
29 | - def initialize(url="http://localhost:8983/solr", opts={}) | ||
30 | - @url = URI.parse(url) | ||
31 | - unless @url.kind_of? URI::HTTP | ||
32 | - raise "invalid http url: #{url}" | ||
33 | - end | ||
34 | - | ||
35 | - # TODO: Autocommit seems nice at one level, but it currently is confusing because | ||
36 | - # only calls to Connection#add/#update/#delete, though a Connection#send(AddDocument.new(...)) | ||
37 | - # does not autocommit. Maybe #send should check for the request types that require a commit and | ||
38 | - # commit in #send instead of the individual methods? | ||
39 | - @autocommit = opts[:autocommit] == :on | ||
40 | - | ||
41 | - # Not actually opening the connection yet, just setting up the persistent connection. | ||
42 | - @connection = Net::HTTP.new(@url.host, @url.port) | ||
43 | - | ||
44 | - @connection.read_timeout = opts[:timeout].to_i || 0 | ||
45 | - @username = opts[:username] if opts[:username] | ||
46 | - @password = opts[:password] if opts[:password] | ||
47 | - end | ||
48 | - | ||
49 | - # add a document to the index. you can pass in either a hash | ||
50 | - # | ||
51 | - # conn.add(:id => 123, :title => 'Tlon, Uqbar, Orbis Tertius') | ||
52 | - # | ||
53 | - # or a Solr::Document | ||
54 | - # | ||
55 | - # conn.add(Solr::Document.new(:id => 123, :title = 'On Writing') | ||
56 | - # | ||
57 | - # true/false will be returned to designate success/failure | ||
58 | - | ||
59 | - def add(doc) | ||
60 | - request = Solr::Request::AddDocument.new(doc) | ||
61 | - response = send(request) | ||
62 | - commit if @autocommit | ||
63 | - return response.ok? | ||
64 | - end | ||
65 | - | ||
66 | - # update a document in the index (really just an alias to add) | ||
67 | - | ||
68 | - def update(doc) | ||
69 | - return add(doc) | ||
70 | - end | ||
71 | - | ||
72 | - # performs a standard query and returns a Solr::Response::Standard | ||
73 | - # | ||
74 | - # response = conn.query('borges') | ||
75 | - # | ||
76 | - # alternative you can pass in a block and iterate over hits | ||
77 | - # | ||
78 | - # conn.query('borges') do |hit| | ||
79 | - # puts hit | ||
80 | - # end | ||
81 | - # | ||
82 | - # options include: | ||
83 | - # | ||
84 | - # :sort, :default_field, :rows, :filter_queries, :debug_query, | ||
85 | - # :explain_other, :facets, :highlighting, :mlt, | ||
86 | - # :operator => :or / :and | ||
87 | - # :start => defaults to 0 | ||
88 | - # :field_list => array, defaults to ["*", "score"] | ||
89 | - | ||
90 | - def query(query, options={}, &action) | ||
91 | - # TODO: Shouldn't this return an exception if the Solr status is not ok? (rather than true/false). | ||
92 | - create_and_send_query(Solr::Request::Standard, options.update(:query => query), &action) | ||
93 | - end | ||
94 | - | ||
95 | - # performs a dismax search and returns a Solr::Response::Standard | ||
96 | - # | ||
97 | - # response = conn.search('borges') | ||
98 | - # | ||
99 | - # options are same as query, but also include: | ||
100 | - # | ||
101 | - # :tie_breaker, :query_fields, :minimum_match, :phrase_fields, | ||
102 | - # :phrase_slop, :boost_query, :boost_functions | ||
103 | - | ||
104 | - def search(query, options={}, &action) | ||
105 | - create_and_send_query(Solr::Request::Dismax, options.update(:query => query), &action) | ||
106 | - end | ||
107 | - | ||
108 | - # sends a commit message to the server | ||
109 | - def commit(options={}) | ||
110 | - response = send(Solr::Request::Commit.new(options)) | ||
111 | - return response.ok? | ||
112 | - end | ||
113 | - | ||
114 | - # sends an optimize message to the server | ||
115 | - def optimize | ||
116 | - response = send(Solr::Request::Optimize.new) | ||
117 | - return response.ok? | ||
118 | - end | ||
119 | - | ||
120 | - # pings the connection and returns true/false if it is alive or not | ||
121 | - def ping | ||
122 | - begin | ||
123 | - response = send(Solr::Request::Ping.new) | ||
124 | - return response.ok? | ||
125 | - rescue | ||
126 | - return false | ||
127 | - end | ||
128 | - end | ||
129 | - | ||
130 | - # delete a document from the index using the document id | ||
131 | - def delete(document_id) | ||
132 | - response = send(Solr::Request::Delete.new(:id => document_id)) | ||
133 | - commit if @autocommit | ||
134 | - response.ok? | ||
135 | - end | ||
136 | - | ||
137 | - # delete using a query | ||
138 | - def delete_by_query(query) | ||
139 | - response = send(Solr::Request::Delete.new(:query => query)) | ||
140 | - commit if @autocommit | ||
141 | - response.ok? | ||
142 | - end | ||
143 | - | ||
144 | - def info | ||
145 | - send(Solr::Request::IndexInfo.new) | ||
146 | - end | ||
147 | - | ||
148 | - # send a given Solr::Request and return a RubyResponse or XmlResponse | ||
149 | - # depending on the type of request | ||
150 | - def send(request) | ||
151 | - data = post(request) | ||
152 | - Solr::Response::Base.make_response(request, data) | ||
153 | - end | ||
154 | - | ||
155 | - # send the http post request to solr; for convenience there are shortcuts | ||
156 | - # to some requests: add(), query(), commit(), delete() or send() | ||
157 | - def post(request) | ||
158 | - req = Net::HTTP::Post.new(@url.path + "/" + request.handler, | ||
159 | - { "Content-Type" => request.content_type }) | ||
160 | - req.basic_auth(@username, @password) if @username && @password | ||
161 | - response = @connection.request(req, request.to_s) | ||
162 | - | ||
163 | - case response | ||
164 | - when Net::HTTPSuccess then response.body | ||
165 | - else | ||
166 | - response.error! | ||
167 | - end | ||
168 | - | ||
169 | - end | ||
170 | - | ||
171 | -private | ||
172 | - | ||
173 | - def create_and_send_query(klass, options = {}, &action) | ||
174 | - request = klass.new(options) | ||
175 | - response = send(request) | ||
176 | - return response unless action | ||
177 | - response.each {|hit| action.call(hit)} | ||
178 | - end | ||
179 | - | ||
180 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/document.rb
@@ -1,85 +0,0 @@ | @@ -1,85 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Document | ||
14 | - include Enumerable | ||
15 | - attr_accessor :boost | ||
16 | - attr_reader :fields | ||
17 | - | ||
18 | - # Create a new Solr::Document, optionally passing in a hash of | ||
19 | - # key/value pairs for the fields | ||
20 | - # | ||
21 | - # doc = Solr::Document.new(:name => :creator, :value => 'Jorge Luis Borges') | ||
22 | - def initialize(hash={}) | ||
23 | - @fields = [] | ||
24 | - self << hash | ||
25 | - end | ||
26 | - | ||
27 | - # Append a Solr::Field | ||
28 | - # | ||
29 | - # doc << Solr::Field.new(:name => :creator, :value => 'Jorge Luis Borges') | ||
30 | - # | ||
31 | - # If you are truly lazy you can simply pass in a hash: | ||
32 | - # | ||
33 | - # doc << {:name => :creator, :value => 'Jorge Luis Borges'} | ||
34 | - def <<(fields) | ||
35 | - case fields | ||
36 | - when Hash | ||
37 | - fields.each_pair do |name,value| | ||
38 | - if value.respond_to?(:each) && !value.is_a?(String) | ||
39 | - value.each {|v| @fields << Solr::Field.new(:name => name, :value => v)} | ||
40 | - else | ||
41 | - @fields << Solr::Field.new(:name => name, :value => value) | ||
42 | - end | ||
43 | - end | ||
44 | - when Solr::Field | ||
45 | - @fields << fields | ||
46 | - else | ||
47 | - raise "must pass in Solr::Field or Hash" | ||
48 | - end | ||
49 | - end | ||
50 | - | ||
51 | - # shorthand to allow hash lookups | ||
52 | - # doc['name'] | ||
53 | - def [](name) | ||
54 | - field = @fields.find {|f| f.name == name.to_s} | ||
55 | - return field.value if field | ||
56 | - return nil | ||
57 | - end | ||
58 | - | ||
59 | - # shorthand to assign as a hash | ||
60 | - def []=(name,value) | ||
61 | - @fields << Solr::Field.new(:name => name, :value => value) | ||
62 | - end | ||
63 | - | ||
64 | - def to_jsonhash | ||
65 | - hash = {'doc' => {}} | ||
66 | - hash['boost'] = @boost if @boost | ||
67 | - @fields.each{ |f| hash['doc'][f.name] = f.value_to_jsonhash } | ||
68 | - hash | ||
69 | - end | ||
70 | - | ||
71 | - def to_json | ||
72 | - to_jsonhash.to_json | ||
73 | - end | ||
74 | - | ||
75 | - def to_xml | ||
76 | - e = Solr::XML::Element.new 'doc' | ||
77 | - e.attributes['boost'] = @boost.to_s if @boost | ||
78 | - @fields.each {|f| e.add_element(f.to_xml)} | ||
79 | - return e | ||
80 | - end | ||
81 | - | ||
82 | - def each(*args, &blk) | ||
83 | - fields.each(&blk) | ||
84 | - end | ||
85 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/exception.rb
@@ -1,13 +0,0 @@ | @@ -1,13 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Exception < Exception; end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/field.rb
@@ -1,44 +0,0 @@ | @@ -1,44 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Field | ||
14 | - VALID_PARAMS = [:boost] | ||
15 | - attr_accessor :name | ||
16 | - attr_accessor :value | ||
17 | - attr_accessor :boost | ||
18 | - | ||
19 | - # Accepts an optional <tt>:boost</tt> parameter, used to boost the relevance of a particular field. | ||
20 | - def initialize(params) | ||
21 | - boost = params[:boost] | ||
22 | - @name = params[:name].to_s | ||
23 | - @value = params[:value] | ||
24 | - # Convert any Time values into UTC/XML schema format (which Solr requires). | ||
25 | - @value = @value.respond_to?(:utc) ? @value.utc.xmlschema : @value | ||
26 | - end | ||
27 | - | ||
28 | - def value_to_jsonhash | ||
29 | - @boost.nil? ? @value : {'boost' => @boost, 'value' => @value} | ||
30 | - end | ||
31 | - | ||
32 | - def boost=(value) | ||
33 | - @boost = value == 1.0 ? nil : value | ||
34 | - end | ||
35 | - | ||
36 | - def to_xml | ||
37 | - e = Solr::XML::Element.new 'field' | ||
38 | - e.attributes['name'] = @name | ||
39 | - e.attributes['boost'] = @boost.to_s if @boost | ||
40 | - e.text = @value.to_str | ||
41 | - return e | ||
42 | - end | ||
43 | - | ||
44 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/importer.rb
@@ -1,19 +0,0 @@ | @@ -1,19 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -module Solr; module Importer; end; end | ||
14 | -require File.expand_path("#{File.dirname(__FILE__)}/importer/mapper") | ||
15 | -require File.expand_path("#{File.dirname(__FILE__)}/importer/array_mapper") | ||
16 | -require File.expand_path("#{File.dirname(__FILE__)}/importer/delimited_file_source") | ||
17 | -require File.expand_path("#{File.dirname(__FILE__)}/importer/hpricot_mapper") | ||
18 | -require File.expand_path("#{File.dirname(__FILE__)}/importer/xpath_mapper") | ||
19 | -require File.expand_path("#{File.dirname(__FILE__)}/importer/solr_source") | ||
20 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/plugins/acts_as_solr_reloaded/lib/solr/importer/array_mapper.rb
@@ -1,26 +0,0 @@ | @@ -1,26 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | - | ||
14 | - | ||
15 | -class Solr::Importer::ArrayMapper < Solr::Importer::Mapper | ||
16 | - # TODO document that initializer takes an array of Mappers [mapper1, mapper2, ... mapperN] | ||
17 | - | ||
18 | - # TODO: make merge conflict handling configurable. as is, the last map fields win. | ||
19 | - def map(orig_data_array) | ||
20 | - mapped_data = {} | ||
21 | - orig_data_array.each_with_index do |data,i| | ||
22 | - mapped_data.merge!(@mapping[i].map(data)) | ||
23 | - end | ||
24 | - mapped_data | ||
25 | - end | ||
26 | -end | ||
27 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/plugins/acts_as_solr_reloaded/lib/solr/importer/delimited_file_source.rb
@@ -1,38 +0,0 @@ | @@ -1,38 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -# For files with the first line containing field names | ||
14 | -# Currently not designed for enormous files, as all lines are | ||
15 | -# read into an array | ||
16 | -class Solr::Importer::DelimitedFileSource | ||
17 | - include Enumerable | ||
18 | - | ||
19 | - def initialize(filename, splitter=/\t/) | ||
20 | - @filename = filename | ||
21 | - @splitter = splitter | ||
22 | - end | ||
23 | - | ||
24 | - def each | ||
25 | - lines = IO.readlines(@filename) | ||
26 | - headers = lines[0].split(@splitter).collect{|h| h.chomp} | ||
27 | - | ||
28 | - lines[1..-1].each do |line| | ||
29 | - data = headers.zip(line.split(@splitter).collect{|s| s.chomp}) | ||
30 | - def data.[](key) | ||
31 | - self.assoc(key.to_s)[1] | ||
32 | - end | ||
33 | - | ||
34 | - yield(data) | ||
35 | - end | ||
36 | - end | ||
37 | - | ||
38 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/importer/hpricot_mapper.rb
@@ -1,27 +0,0 @@ | @@ -1,27 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -begin | ||
14 | - require 'hpricot' | ||
15 | - | ||
16 | - class Solr::Importer::HpricotMapper < Solr::Importer::Mapper | ||
17 | - def field_data(doc, path) | ||
18 | - doc.search(path.to_s).collect { |e| e.inner_html } | ||
19 | - end | ||
20 | - end | ||
21 | -rescue LoadError => e # If we can't load hpricot | ||
22 | - class Solr::Importer::HpricotMapper | ||
23 | - def initialize(mapping, options={}) | ||
24 | - raise "Hpricot not installed." | ||
25 | - end | ||
26 | - end | ||
27 | -end | ||
28 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/plugins/acts_as_solr_reloaded/lib/solr/importer/mapper.rb
@@ -1,51 +0,0 @@ | @@ -1,51 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Importer::Mapper | ||
14 | - def initialize(mapping, options={}) | ||
15 | - @mapping = mapping | ||
16 | - @options = options | ||
17 | - end | ||
18 | - | ||
19 | - def field_data(orig_data, field_name) | ||
20 | - orig_data[field_name] | ||
21 | - end | ||
22 | - | ||
23 | - def mapped_field_value(orig_data, field_mapping) | ||
24 | - case field_mapping | ||
25 | - when String | ||
26 | - field_mapping | ||
27 | - when Proc | ||
28 | - field_mapping.call(orig_data) # TODO pass in more context, like self or a function for field_data, etc | ||
29 | - when Symbol | ||
30 | - field_data(orig_data, @options[:stringify_symbols] ? field_mapping.to_s : field_mapping) | ||
31 | - when Enumerable | ||
32 | - field_mapping.collect {|orig_field_name| mapped_field_value(orig_data, orig_field_name)}.flatten | ||
33 | - else | ||
34 | - raise "Unknown mapping for #{field_mapping}" | ||
35 | - end | ||
36 | - end | ||
37 | - | ||
38 | - def map(orig_data) | ||
39 | - mapped_data = {} | ||
40 | - @mapping.each do |solr_name, field_mapping| | ||
41 | - value = mapped_field_value(orig_data, field_mapping) | ||
42 | - mapped_data[solr_name] = value if value | ||
43 | - end | ||
44 | - | ||
45 | - mapped_data | ||
46 | - end | ||
47 | - | ||
48 | - | ||
49 | - | ||
50 | - | ||
51 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/importer/solr_source.rb
@@ -1,41 +0,0 @@ | @@ -1,41 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Importer::SolrSource | ||
14 | - def initialize(solr_url, query, filter_queries=nil, options={}) | ||
15 | - @connection = Solr::Connection.new(solr_url) | ||
16 | - @query = query | ||
17 | - @filter_queries = filter_queries | ||
18 | - | ||
19 | - @page_size = options[:page_size] || 1000 | ||
20 | - @field_list = options[:field_list] || ["*"] | ||
21 | - end | ||
22 | - | ||
23 | - def each | ||
24 | - done = false | ||
25 | - start = 0 | ||
26 | - until done do | ||
27 | - # request N documents from a starting point | ||
28 | - request = Solr::Request::Standard.new(:query => @query, | ||
29 | - :rows => @page_size, | ||
30 | - :start => start, | ||
31 | - :field_list => @field_list, | ||
32 | - :filter_queries => @filter_queries) | ||
33 | - response = @connection.send(request) | ||
34 | - response.each do |doc| | ||
35 | - yield doc # TODO: perhaps convert to HashWithIndifferentAccess.new(doc), so stringify_keys isn't necessary | ||
36 | - end | ||
37 | - done = start + @page_size >= response.total_hits | ||
38 | - start = start + @page_size | ||
39 | - end | ||
40 | - end | ||
41 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/importer/xpath_mapper.rb
@@ -1,35 +0,0 @@ | @@ -1,35 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -begin | ||
14 | - require 'xml/libxml' | ||
15 | - | ||
16 | - # For files with the first line containing field names | ||
17 | - class Solr::Importer::XPathMapper < Solr::Importer::Mapper | ||
18 | - def field_data(doc, xpath) | ||
19 | - doc.find(xpath.to_s).collect do |node| | ||
20 | - case node | ||
21 | - when XML::Attr | ||
22 | - node.value | ||
23 | - when XML::Node | ||
24 | - node.content | ||
25 | - end | ||
26 | - end | ||
27 | - end | ||
28 | - end | ||
29 | -rescue LoadError => e # If we can't load libxml | ||
30 | - class Solr::Importer::XPathMapper | ||
31 | - def initialize(mapping, options={}) | ||
32 | - raise "libxml not installed" | ||
33 | - end | ||
34 | - end | ||
35 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/indexer.rb
@@ -1,52 +0,0 @@ | @@ -1,52 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Indexer | ||
14 | - attr_reader :solr | ||
15 | - | ||
16 | - # TODO: document options! | ||
17 | - def initialize(data_source, mapper_or_mapping, options={}) | ||
18 | - solr_url = options[:solr_url] || ENV["SOLR_URL"] || "http://localhost:8983/solr" | ||
19 | - @solr = Solr::Connection.new(solr_url, options) #TODO - these options contain the solr_url and debug keys also, so tidy up what gets passed | ||
20 | - | ||
21 | - @data_source = data_source | ||
22 | - @mapper = mapper_or_mapping.is_a?(Hash) ? Solr::Importer::Mapper.new(mapper_or_mapping) : mapper_or_mapping | ||
23 | - | ||
24 | - @buffer_docs = options[:buffer_docs] | ||
25 | - @debug = options[:debug] | ||
26 | - end | ||
27 | - | ||
28 | - def index | ||
29 | - buffer = [] | ||
30 | - @data_source.each do |record| | ||
31 | - document = @mapper.map(record) | ||
32 | - | ||
33 | - # TODO: check arrity of block, if 3, pass counter as 3rd argument | ||
34 | - yield(record, document) if block_given? # TODO check return of block, if not true then don't index, or perhaps if document.empty? | ||
35 | - | ||
36 | - buffer << document | ||
37 | - | ||
38 | - if !@buffer_docs || buffer.size == @buffer_docs | ||
39 | - add_docs(buffer) | ||
40 | - buffer.clear | ||
41 | - end | ||
42 | - end | ||
43 | - add_docs(buffer) if !buffer.empty? | ||
44 | - | ||
45 | - @solr.commit unless @debug | ||
46 | - end | ||
47 | - | ||
48 | - def add_docs(documents) | ||
49 | - @solr.add(documents) unless @debug | ||
50 | - puts documents.inspect if @debug | ||
51 | - end | ||
52 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request.rb
@@ -1,26 +0,0 @@ | @@ -1,26 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -module Solr; module Request; end; end | ||
14 | -require File.expand_path("#{File.dirname(__FILE__)}/request/base") | ||
15 | -require File.expand_path("#{File.dirname(__FILE__)}/request/update") | ||
16 | -require File.expand_path("#{File.dirname(__FILE__)}/request/add_document") | ||
17 | -require File.expand_path("#{File.dirname(__FILE__)}/request/modify_document") | ||
18 | -require File.expand_path("#{File.dirname(__FILE__)}/request/commit") | ||
19 | -require File.expand_path("#{File.dirname(__FILE__)}/request/delete") | ||
20 | -require File.expand_path("#{File.dirname(__FILE__)}/request/ping") | ||
21 | -require File.expand_path("#{File.dirname(__FILE__)}/request/select") | ||
22 | -require File.expand_path("#{File.dirname(__FILE__)}/request/standard") | ||
23 | -require File.expand_path("#{File.dirname(__FILE__)}/request/spellcheck") | ||
24 | -require File.expand_path("#{File.dirname(__FILE__)}/request/dismax") | ||
25 | -require File.expand_path("#{File.dirname(__FILE__)}/request/index_info") | ||
26 | -require File.expand_path("#{File.dirname(__FILE__)}/request/optimize") |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/add_document.rb
@@ -1,68 +0,0 @@ | @@ -1,68 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -require File.expand_path(File.dirname(__FILE__) + '/json_update') | ||
14 | - | ||
15 | -class Solr::Request::AddDocument < Solr::Request::JsonUpdate | ||
16 | - | ||
17 | - # create the request, optionally passing in a Solr::Document | ||
18 | - # | ||
19 | - # request = Solr::Request::AddDocument.new(doc) | ||
20 | - # | ||
21 | - # as a short cut you can pass in a Hash instead: | ||
22 | - # | ||
23 | - # request = Solr::Request::AddDocument.new(:creator => 'Jorge Luis Borges') | ||
24 | - # | ||
25 | - # or an array, to add multiple documents at the same time: | ||
26 | - # | ||
27 | - # request = Solr::Request::AddDocument.new([doc1, doc2, doc3])) | ||
28 | - | ||
29 | - def initialize(doc={}) | ||
30 | - @docs = [] | ||
31 | - if doc.is_a?(Array) | ||
32 | - doc.each { |d| add_doc(d) } | ||
33 | - else | ||
34 | - add_doc(doc) | ||
35 | - end | ||
36 | - end | ||
37 | - | ||
38 | - def to_json | ||
39 | - '{' + | ||
40 | - @docs.map{ |doc| "\"add\": #{doc.to_jsonhash.to_json}" }.join(',') + | ||
41 | - '}' | ||
42 | - end | ||
43 | - | ||
44 | - def to_xml | ||
45 | - e = Solr::XML::Element.new 'add' | ||
46 | - for doc in @docs | ||
47 | - e.add_element doc.to_xml | ||
48 | - end | ||
49 | - return e.to_s | ||
50 | - end | ||
51 | - | ||
52 | - def to_s | ||
53 | - to_json | ||
54 | - end | ||
55 | - | ||
56 | - private | ||
57 | - def add_doc(doc) | ||
58 | - case doc | ||
59 | - when Hash | ||
60 | - @docs << Solr::Document.new(doc) | ||
61 | - when Solr::Document | ||
62 | - @docs << doc | ||
63 | - else | ||
64 | - raise "must pass in Solr::Document or Hash" | ||
65 | - end | ||
66 | - end | ||
67 | - | ||
68 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/base.rb
@@ -1,36 +0,0 @@ | @@ -1,36 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Request::Base | ||
14 | - | ||
15 | - | ||
16 | - #TODO : Add base support for the debugQuery flag, and such that the response provides debug output easily | ||
17 | - | ||
18 | - # returns either :xml or :ruby depending on what the | ||
19 | - # response type is for a given request | ||
20 | - | ||
21 | - def response_format | ||
22 | - raise "unknown request type: #{self.class}" | ||
23 | - end | ||
24 | - | ||
25 | - def content_type | ||
26 | - 'text/xml; charset=utf-8' | ||
27 | - end | ||
28 | - | ||
29 | - # returns the solr handler or url fragment that can | ||
30 | - # respond to this type of request | ||
31 | - | ||
32 | - def handler | ||
33 | - raise "unknown request type: #{self.class}" | ||
34 | - end | ||
35 | - | ||
36 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/commit.rb
@@ -1,29 +0,0 @@ | @@ -1,29 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Request::Commit < Solr::Request::Update | ||
14 | - | ||
15 | - def initialize(options={}) | ||
16 | - @wait_searcher = options[:wait_searcher] || true | ||
17 | - @wait_flush = options[:wait_flush] || true | ||
18 | - end | ||
19 | - | ||
20 | - | ||
21 | - def to_s | ||
22 | - e = Solr::XML::Element.new('commit') | ||
23 | - e.attributes['waitSearcher'] = @wait_searcher ? 'true' : 'false' | ||
24 | - e.attributes['waitFlush'] = @wait_flush ? 'true' : 'false' | ||
25 | - | ||
26 | - e.to_s | ||
27 | - end | ||
28 | - | ||
29 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/delete.rb
@@ -1,48 +0,0 @@ | @@ -1,48 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Request::Delete < Solr::Request::Update | ||
14 | - | ||
15 | - # A delete request can be for a specific document id | ||
16 | - # | ||
17 | - # request = Solr::Request::Delete.new(:id => 1234) | ||
18 | - # | ||
19 | - # or by query: | ||
20 | - # | ||
21 | - # request = Solr::Request::Delete.new(:query => | ||
22 | - # | ||
23 | - def initialize(options) | ||
24 | - unless options.kind_of?(Hash) and (options[:id] or options[:query]) | ||
25 | - raise Solr::Exception.new("must pass in :id or :query") | ||
26 | - end | ||
27 | - if options[:id] and options[:query] | ||
28 | - raise Solr::Exception.new("can't pass in both :id and :query") | ||
29 | - end | ||
30 | - @document_id = options[:id] | ||
31 | - @query = options[:query] | ||
32 | - end | ||
33 | - | ||
34 | - def to_s | ||
35 | - delete_element = Solr::XML::Element.new('delete') | ||
36 | - if @document_id | ||
37 | - id_element = Solr::XML::Element.new('id') | ||
38 | - id_element.text = @document_id | ||
39 | - delete_element.add_element(id_element) | ||
40 | - elsif @query | ||
41 | - query = Solr::XML::Element.new('query') | ||
42 | - query.text = @query | ||
43 | - delete_element.add_element(query) | ||
44 | - end | ||
45 | - delete_element.to_s | ||
46 | - end | ||
47 | -end | ||
48 | - |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/dismax.rb
@@ -1,37 +0,0 @@ | @@ -1,37 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Request::Dismax < Solr::Request::Standard | ||
14 | - | ||
15 | - VALID_PARAMS.replace(VALID_PARAMS + [:tie_breaker, :query_fields, :minimum_match, :phrase_fields, :phrase_slop, | ||
16 | - :alternate_query, :boost_query, :boost_functions]) | ||
17 | - | ||
18 | - def initialize(params) | ||
19 | - super | ||
20 | - end | ||
21 | - | ||
22 | - def to_hash | ||
23 | - hash = super | ||
24 | - hash[:defType] = 'edismax' | ||
25 | - hash[:tie] = @params[:tie_breaker] | ||
26 | - hash[:mm] = @params[:minimum_match] | ||
27 | - hash[:qf] = @params[:query_fields] | ||
28 | - hash[:pf] = @params[:phrase_fields] | ||
29 | - hash[:ps] = @params[:phrase_slop] | ||
30 | - hash[:bq] = @params[:boost_query] | ||
31 | - hash[:boost] = @params[:boost_functions] | ||
32 | - hash["q.alt"] = @params[:alternate_query] | ||
33 | - | ||
34 | - return hash | ||
35 | - end | ||
36 | - | ||
37 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/index_info.rb
@@ -1,22 +0,0 @@ | @@ -1,22 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Request::IndexInfo < Solr::Request::Select | ||
14 | - | ||
15 | - def handler | ||
16 | - 'admin/luke' | ||
17 | - end | ||
18 | - | ||
19 | - def to_hash | ||
20 | - {:numTerms => 0}.merge(super.to_hash) | ||
21 | - end | ||
22 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/json_update.rb
@@ -1,23 +0,0 @@ | @@ -1,23 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -# a parent class for all requests that go through the solr update handler | ||
14 | -# TODO: Use new xml update handler for better error responses | ||
15 | -class Solr::Request::JsonUpdate < Solr::Request::Base | ||
16 | - def response_format | ||
17 | - :xml | ||
18 | - end | ||
19 | - | ||
20 | - def handler | ||
21 | - 'update/json' | ||
22 | - end | ||
23 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/modify_document.rb
@@ -1,46 +0,0 @@ | @@ -1,46 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Request::ModifyDocument < Solr::Request::Update | ||
14 | - | ||
15 | - # Example: ModifyDocument.new(:id => 10, :overwrite => {:field_name => "new value"}) | ||
16 | - def initialize(update_data) | ||
17 | - modes = [] | ||
18 | - @doc = {} | ||
19 | - [:overwrite, :append, :distinct, :increment, :delete].each do |mode| | ||
20 | - field_data = update_data[mode] | ||
21 | - if field_data | ||
22 | - field_data.each do |field_name, field_value| | ||
23 | - modes << "#{field_name}:#{mode.to_s.upcase}" | ||
24 | - @doc[field_name] = field_value if field_value # if value is nil, omit so it can be removed | ||
25 | - end | ||
26 | - update_data.delete mode | ||
27 | - end | ||
28 | - end | ||
29 | - @mode = modes.join(",") | ||
30 | - | ||
31 | - # only one key should be left over, the id | ||
32 | - @doc[update_data.keys[0].to_s] = update_data.values[0] | ||
33 | - end | ||
34 | - | ||
35 | - # returns the request as a string suitable for posting | ||
36 | - def to_s | ||
37 | - e = Solr::XML::Element.new 'add' | ||
38 | - e.add_element(Solr::Document.new(@doc).to_xml) | ||
39 | - return e.to_s | ||
40 | - end | ||
41 | - | ||
42 | - def handler | ||
43 | - "update?mode=#{@mode}" | ||
44 | - end | ||
45 | - | ||
46 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/optimize.rb
@@ -1,19 +0,0 @@ | @@ -1,19 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Request::Optimize < Solr::Request::Update | ||
14 | - | ||
15 | - def to_s | ||
16 | - Solr::XML::Element.new('optimize').to_s | ||
17 | - end | ||
18 | - | ||
19 | -end | ||
20 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/ping.rb
@@ -1,36 +0,0 @@ | @@ -1,36 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -# TODO: Consider something lazy like this? | ||
14 | -# Solr::Request::Ping = Solr::Request.simple_request :format=>:xml, :handler=>'admin/ping' | ||
15 | -# class Solr::Request | ||
16 | -# def self.simple_request(options) | ||
17 | -# Class.new do | ||
18 | -# def response_format | ||
19 | -# options[:format] | ||
20 | -# end | ||
21 | -# def handler | ||
22 | -# options[:handler] | ||
23 | -# end | ||
24 | -# end | ||
25 | -# end | ||
26 | -# end | ||
27 | - | ||
28 | -class Solr::Request::Ping < Solr::Request::Base | ||
29 | - def response_format | ||
30 | - :xml | ||
31 | - end | ||
32 | - | ||
33 | - def handler | ||
34 | - 'admin/ping' | ||
35 | - end | ||
36 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/select.rb
@@ -1,54 +0,0 @@ | @@ -1,54 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -# "Abstract" base class, only useful with subclasses that add parameters | ||
14 | -class Solr::Request::Select < Solr::Request::Base | ||
15 | - | ||
16 | - attr_reader :query_type | ||
17 | - | ||
18 | - def initialize(qt=nil, params={}) | ||
19 | - @query_type = qt | ||
20 | - @select_params = params | ||
21 | - end | ||
22 | - | ||
23 | - def response_format | ||
24 | - :ruby | ||
25 | - end | ||
26 | - | ||
27 | - def handler | ||
28 | - 'select' | ||
29 | - end | ||
30 | - | ||
31 | - def content_type | ||
32 | - 'application/x-www-form-urlencoded; charset=utf-8' | ||
33 | - end | ||
34 | - | ||
35 | - def to_hash | ||
36 | - return {:qt => query_type, :wt => 'ruby', 'json.nl' => 'arrarr'}.merge(@select_params) | ||
37 | - end | ||
38 | - | ||
39 | - def to_s | ||
40 | - raw_params = self.to_hash | ||
41 | - | ||
42 | - http_params = [] | ||
43 | - raw_params.each do |key,value| | ||
44 | - if value.respond_to? :each | ||
45 | - value.each { |v| http_params << "#{key}=#{ERB::Util::url_encode(v)}" unless v.nil?} | ||
46 | - else | ||
47 | - http_params << "#{key}=#{ERB::Util::url_encode(value)}" unless value.nil? | ||
48 | - end | ||
49 | - end | ||
50 | - | ||
51 | - http_params.join("&") | ||
52 | - end | ||
53 | - | ||
54 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/spellcheck.rb
@@ -1,30 +0,0 @@ | @@ -1,30 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Request::Spellcheck < Solr::Request::Select | ||
14 | - | ||
15 | - def initialize(params) | ||
16 | - super('spellchecker') | ||
17 | - @params = params | ||
18 | - end | ||
19 | - | ||
20 | - def to_hash | ||
21 | - hash = super | ||
22 | - hash[:q] = @params[:query] | ||
23 | - hash[:suggestionCount] = @params[:suggestion_count] | ||
24 | - hash[:accuracy] = @params[:accuracy] | ||
25 | - hash[:onlyMorePopular] = @params[:only_more_popular] | ||
26 | - hash[:cmd] = @params[:command] | ||
27 | - return hash | ||
28 | - end | ||
29 | - | ||
30 | -end | ||
31 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb
@@ -1,408 +0,0 @@ | @@ -1,408 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Request::Standard < Solr::Request::Select | ||
14 | - | ||
15 | - VALID_PARAMS = [:query, :sort, :default_field, :operator, :start, :rows, :shards, :date_facets, | ||
16 | - :filter_queries, :field_list, :debug_query, :explain_other, :facets, :highlighting, :mlt, :radius, | ||
17 | - :radius, :latitude, :longitude, :spellcheck] | ||
18 | - | ||
19 | - def initialize(params) | ||
20 | - super 'search' | ||
21 | - | ||
22 | - raise "Invalid parameters: #{(params.keys - VALID_PARAMS).join(',')}" unless | ||
23 | - (params.keys - VALID_PARAMS).empty? | ||
24 | - | ||
25 | - raise ":query parameter required" unless params[:query] | ||
26 | - | ||
27 | - @params = params.dup | ||
28 | - | ||
29 | - # Validate operator | ||
30 | - if params[:operator] | ||
31 | - raise "Only :and/:or operators allowed" unless | ||
32 | - [:and, :or].include?(params[:operator]) | ||
33 | - | ||
34 | - @params[:operator] = params[:operator].to_s.upcase | ||
35 | - end | ||
36 | - | ||
37 | - # Validate start, rows can be transformed to ints | ||
38 | - @params[:start] = params[:start].to_i if params[:start] | ||
39 | - @params[:rows] = params[:rows].to_i if params[:rows] | ||
40 | - | ||
41 | - @params[:field_list] ||= ["*","score"] | ||
42 | - | ||
43 | - @params[:shards] ||= [] | ||
44 | - end | ||
45 | - | ||
46 | - def to_hash | ||
47 | - hash = {} | ||
48 | - | ||
49 | - # standard request param processing | ||
50 | - hash[:sort] = @params[:sort] | ||
51 | - hash[:q] = @params[:query] | ||
52 | - hash["q.op"] = @params[:operator] | ||
53 | - hash[:df] = @params[:default_field] | ||
54 | - hash[:echoParams] = 'explicit' | ||
55 | - | ||
56 | - # common parameter processing | ||
57 | - hash[:start] = @params[:start] | ||
58 | - hash[:rows] = @params[:rows] | ||
59 | - hash[:fq] = @params[:filter_queries] | ||
60 | - hash[:fl] = @params[:field_list].join(',') | ||
61 | - hash[:debugQuery] = @params[:debug_query] | ||
62 | - hash[:explainOther] = @params[:explain_other] | ||
63 | - hash[:shards] = @params[:shards].join(',') unless @params[:shards].empty? | ||
64 | - | ||
65 | - hash[:sfield] = 'latlng' | ||
66 | - hash[:d] = @params[:radius] | ||
67 | - hash[:pt] = "#{@params[:latitude]}, #{@params[:longitude]}" if @params[:latitude] and @params[:longitude] | ||
68 | - | ||
69 | - # facet parameter processing | ||
70 | - if @params[:facets] | ||
71 | - # TODO need validation of all that is under the :facets Hash too | ||
72 | - hash[:facet] = true | ||
73 | - hash["facet.field"] = [] | ||
74 | - hash["facet.query"] = @params[:facets][:queries] | ||
75 | - hash["facet.sort"] = @params[:facets][:sort] | ||
76 | - hash["facet.limit"] = @params[:facets][:limit] | ||
77 | - hash["facet.missing"] = @params[:facets][:missing] | ||
78 | - hash["facet.mincount"] = @params[:facets][:mincount] | ||
79 | - hash["facet.prefix"] = @params[:facets][:prefix] | ||
80 | - hash["facet.offset"] = @params[:facets][:offset] | ||
81 | - if @params[:facets][:fields] # facet fields are optional (could be facet.query only) | ||
82 | - @params[:facets][:fields].each do |f| | ||
83 | - if f.kind_of? Hash | ||
84 | - key = f.keys[0] | ||
85 | - value = f[key] | ||
86 | - hash["facet.field"] << key | ||
87 | - hash["f.#{key}.facet.sort"] = value[:sort] | ||
88 | - hash["f.#{key}.facet.limit"] = value[:limit] | ||
89 | - hash["f.#{key}.facet.missing"] = value[:missing] | ||
90 | - hash["f.#{key}.facet.mincount"] = value[:mincount] | ||
91 | - hash["f.#{key}.facet.prefix"] = value[:prefix] | ||
92 | - hash["f.#{key}.facet.offset"] = value[:offset] | ||
93 | - else | ||
94 | - hash["facet.field"] << f | ||
95 | - end | ||
96 | - end | ||
97 | - end | ||
98 | - | ||
99 | - if @params[:date_facets] | ||
100 | - hash["facet.date"] = [] | ||
101 | - if @params[:date_facets][:fields] | ||
102 | - @params[:date_facets][:fields].each do |f| | ||
103 | - if f.kind_of? Hash | ||
104 | - key = f.keys[0] | ||
105 | - hash["facet.date"] << key | ||
106 | - f[key].each { |k, v| | ||
107 | - hash["f.#{key}.facet.date.#{k}"] = v | ||
108 | - } | ||
109 | - else | ||
110 | - hash["facet.date"] << f | ||
111 | - end | ||
112 | - end | ||
113 | - end | ||
114 | - hash["facet.date.start"] = @params[:date_facets][:start] | ||
115 | - hash["facet.date.end"] = @params[:date_facets][:end] | ||
116 | - hash["facet.date.gap"] = @params[:date_facets][:gap] | ||
117 | - hash["facet.date.other"] = @params[:date_facets][:other] | ||
118 | - hash["facet.date.hardend"] = @params[:date_facets][:hardend] | ||
119 | - if @params[:date_facets][:filter] | ||
120 | - if hash[:fq] | ||
121 | - hash[:fq] << @params[:date_facets][:filter] | ||
122 | - else | ||
123 | - hash[:fq] = @params[:date_facets][:filter] | ||
124 | - end | ||
125 | - end | ||
126 | - end | ||
127 | - end | ||
128 | - | ||
129 | - # highlighting parameter processing - http://wiki.apache.org/solr/HighlightingParameters | ||
130 | - if @params[:highlighting] | ||
131 | - hash[:hl] = true | ||
132 | - hash["hl.fl"] = @params[:highlighting][:field_list].join(',') if @params[:highlighting][:field_list] | ||
133 | - | ||
134 | - snippets = @params[:highlighting][:max_snippets] | ||
135 | - if snippets | ||
136 | - if snippets.kind_of? Hash | ||
137 | - if snippets[:default] | ||
138 | - hash["hl.snippets"] = snippets[:default] | ||
139 | - end | ||
140 | - if snippets[:fields] | ||
141 | - snippets[:fields].each do |k,v| | ||
142 | - hash["f.#{k}.hl.snippets"] = v | ||
143 | - end | ||
144 | - end | ||
145 | - else | ||
146 | - hash["hl.snippets"] = snippets | ||
147 | - end | ||
148 | - end | ||
149 | - | ||
150 | - fragsize = @params[:highlighting][:fragment_size] | ||
151 | - if fragsize | ||
152 | - if fragsize.kind_of? Hash | ||
153 | - if fragsize[:default] | ||
154 | - hash["hl.fragsize"] = fragsize[:default] | ||
155 | - end | ||
156 | - if fragsize[:fields] | ||
157 | - fragsize[:fields].each do |k,v| | ||
158 | - hash["f.#{k}.hl.fragsize"] = v | ||
159 | - end | ||
160 | - end | ||
161 | - else | ||
162 | - hash["hl.fragsize"] = fragsize | ||
163 | - end | ||
164 | - end | ||
165 | - | ||
166 | - rfm = @params[:highlighting][:require_field_match] | ||
167 | - if nil != rfm | ||
168 | - if rfm.kind_of? Hash | ||
169 | - if nil != rfm[:default] | ||
170 | - hash["hl.requireFieldMatch"] = rfm[:default] | ||
171 | - end | ||
172 | - if rfm[:fields] | ||
173 | - rfm[:fields].each do |k,v| | ||
174 | - hash["f.#{k}.hl.requireFieldMatch"] = v | ||
175 | - end | ||
176 | - end | ||
177 | - else | ||
178 | - hash["hl.requireFieldMatch"] = rfm | ||
179 | - end | ||
180 | - end | ||
181 | - | ||
182 | - mac = @params[:highlighting][:max_analyzed_chars] | ||
183 | - if mac | ||
184 | - if mac.kind_of? Hash | ||
185 | - if mac[:default] | ||
186 | - hash["hl.maxAnalyzedChars"] = mac[:default] | ||
187 | - end | ||
188 | - if mac[:fields] | ||
189 | - mac[:fields].each do |k,v| | ||
190 | - hash["f.#{k}.hl.maxAnalyzedChars"] = v | ||
191 | - end | ||
192 | - end | ||
193 | - else | ||
194 | - hash["hl.maxAnalyzedChars"] = mac | ||
195 | - end | ||
196 | - end | ||
197 | - | ||
198 | - prefix = @params[:highlighting][:prefix] | ||
199 | - if prefix | ||
200 | - if prefix.kind_of? Hash | ||
201 | - if prefix[:default] | ||
202 | - hash["hl.simple.pre"] = prefix[:default] | ||
203 | - end | ||
204 | - if prefix[:fields] | ||
205 | - prefix[:fields].each do |k,v| | ||
206 | - hash["f.#{k}.hl.simple.pre"] = v | ||
207 | - end | ||
208 | - end | ||
209 | - else | ||
210 | - hash["hl.simple.pre"] = prefix | ||
211 | - end | ||
212 | - end | ||
213 | - | ||
214 | - suffix = @params[:highlighting][:suffix] | ||
215 | - if suffix | ||
216 | - if suffix.kind_of? Hash | ||
217 | - if suffix[:default] | ||
218 | - hash["hl.simple.post"] = suffix[:default] | ||
219 | - end | ||
220 | - if suffix[:fields] | ||
221 | - suffix[:fields].each do |k,v| | ||
222 | - hash["f.#{k}.hl.simple.post"] = v | ||
223 | - end | ||
224 | - end | ||
225 | - else | ||
226 | - hash["hl.simple.post"] = suffix | ||
227 | - end | ||
228 | - end | ||
229 | - | ||
230 | - formatter = @params[:highlighting][:formatter] | ||
231 | - if formatter | ||
232 | - if formatter.kind_of? Hash | ||
233 | - if formatter[:default] | ||
234 | - hash["hl.formatter"] = formatter[:default] | ||
235 | - end | ||
236 | - if formatter[:fields] | ||
237 | - formatter[:fields].each do |k,v| | ||
238 | - hash["f.#{k}.hl.formatter"] = v | ||
239 | - end | ||
240 | - end | ||
241 | - else | ||
242 | - hash["hl.formatter"] = formatter | ||
243 | - end | ||
244 | - end | ||
245 | - | ||
246 | - fragmenter = @params[:highlighting][:fragmenter] | ||
247 | - if fragmenter | ||
248 | - if fragmenter.kind_of? Hash | ||
249 | - if fragmenter[:default] | ||
250 | - hash["hl.fragmenter"] = fragmenter[:default] | ||
251 | - end | ||
252 | - if fragmenter[:fields] | ||
253 | - fragmenter[:fields].each do |k,v| | ||
254 | - hash["f.#{k}.hl.fragmenter"] = v | ||
255 | - end | ||
256 | - end | ||
257 | - else | ||
258 | - hash["hl.fragmenter"] = fragmenter | ||
259 | - end | ||
260 | - end | ||
261 | - | ||
262 | - merge_contiguous = @params[:highlighting][:merge_contiguous] | ||
263 | - if nil != merge_contiguous | ||
264 | - if merge_contiguous.kind_of? Hash | ||
265 | - if nil != merge_contiguous[:default] | ||
266 | - hash["hl.mergeContiguous"] = merge_contiguous[:default] | ||
267 | - end | ||
268 | - if merge_contiguous[:fields] | ||
269 | - merge_contiguous[:fields].each do |k,v| | ||
270 | - hash["f.#{k}.hl.mergeContiguous"] = v | ||
271 | - end | ||
272 | - end | ||
273 | - else | ||
274 | - hash["hl.mergeContiguous"] = merge_contiguous | ||
275 | - end | ||
276 | - end | ||
277 | - | ||
278 | - increment = @params[:highlighting][:increment] | ||
279 | - if increment | ||
280 | - if increment.kind_of? Hash | ||
281 | - if increment[:default] | ||
282 | - hash["hl.increment"] = increment[:default] | ||
283 | - end | ||
284 | - if increment[:fields] | ||
285 | - increment[:fields].each do |k,v| | ||
286 | - hash["f.#{k}.hl.increment"] = v | ||
287 | - end | ||
288 | - end | ||
289 | - else | ||
290 | - hash["hl.increment"] = increment | ||
291 | - end | ||
292 | - end | ||
293 | - | ||
294 | - # support "old style" | ||
295 | - alternate_fields = @params[:highlighting][:alternate_fields] | ||
296 | - if alternate_fields | ||
297 | - alternate_fields.each do |f,v| | ||
298 | - hash["f.#{f}.hl.alternateField"] = v | ||
299 | - end | ||
300 | - end | ||
301 | - | ||
302 | - alternate_field = @params[:highlighting][:alternate_field] | ||
303 | - if alternate_field | ||
304 | - if alternate_field.kind_of? Hash | ||
305 | - if alternate_field[:default] | ||
306 | - hash["hl.alternateField"] = alternate_field[:default] | ||
307 | - end | ||
308 | - if alternate_field[:fields] | ||
309 | - alternate_field[:fields].each do |k,v| | ||
310 | - hash["f.#{k}.hl.alternateField"] = v | ||
311 | - end | ||
312 | - end | ||
313 | - else | ||
314 | - hash["hl.alternateField"] = alternate_field | ||
315 | - end | ||
316 | - end | ||
317 | - | ||
318 | - mafl = @params[:highlighting][:max_alternate_field_length] | ||
319 | - if mafl | ||
320 | - if mafl.kind_of? Hash | ||
321 | - if mafl[:default] | ||
322 | - hash["hl.maxAlternateFieldLength"] = mafl[:default] | ||
323 | - end | ||
324 | - if mafl[:fields] | ||
325 | - mafl[:fields].each do |k,v| | ||
326 | - hash["f.#{k}.hl.maxAlternateFieldLength"] = v | ||
327 | - end | ||
328 | - else | ||
329 | - # support "old style" | ||
330 | - mafl.each do |k,v| | ||
331 | - hash["f.#{k}.hl.maxAlternateFieldLength"] = v | ||
332 | - end | ||
333 | - end | ||
334 | - else | ||
335 | - hash["hl.maxAlternateFieldLength"] = mafl | ||
336 | - end | ||
337 | - end | ||
338 | - | ||
339 | - hash["hl.usePhraseHighlighter"] = @params[:highlighting][:use_phrase_highlighter] | ||
340 | - | ||
341 | - regex = @params[:highlighting][:regex] | ||
342 | - if regex | ||
343 | - if regex[:slop] | ||
344 | - if regex[:slop].kind_of? Hash | ||
345 | - if regex[:slop][:default] | ||
346 | - hash["hl.regex.slop"] = regex[:slop][:default] | ||
347 | - end | ||
348 | - if regex[:slop][:fields] | ||
349 | - regex[:slop][:fields].each do |k,v| | ||
350 | - hash["f.#{k}.hl.regex.slop"] = v | ||
351 | - end | ||
352 | - end | ||
353 | - else | ||
354 | - hash["hl.regex.slop"] = regex[:slop] | ||
355 | - end | ||
356 | - end | ||
357 | - if regex[:pattern] | ||
358 | - if regex[:pattern].kind_of? Hash | ||
359 | - if regex[:pattern][:default] | ||
360 | - hash["hl.regex.pattern"] = regex[:pattern][:default] | ||
361 | - end | ||
362 | - if regex[:pattern][:fields] | ||
363 | - regex[:pattern][:fields].each do |k,v| | ||
364 | - hash["f.#{k}.hl.regex.pattern"] = v | ||
365 | - end | ||
366 | - end | ||
367 | - else | ||
368 | - hash["hl.regex.pattern"] = regex[:pattern] | ||
369 | - end | ||
370 | - end | ||
371 | - if regex[:max_analyzed_chars] | ||
372 | - if regex[:max_analyzed_chars].kind_of? Hash | ||
373 | - if regex[:max_analyzed_chars][:default] | ||
374 | - hash["hl.regex.maxAnalyzedChars"] = regex[:max_analyzed_chars][:default] | ||
375 | - end | ||
376 | - if regex[:max_analyzed_chars][:fields] | ||
377 | - regex[:max_analyzed_chars][:fields].each do |k,v| | ||
378 | - hash["f.#{k}.hl.regex.maxAnalyzedChars"] = v | ||
379 | - end | ||
380 | - end | ||
381 | - else | ||
382 | - hash["hl.regex.maxAnalyzedChars"] = regex[:max_analyzed_chars] | ||
383 | - end | ||
384 | - end | ||
385 | - end | ||
386 | - | ||
387 | - end | ||
388 | - | ||
389 | - if @params[:mlt] | ||
390 | - hash[:mlt] = true | ||
391 | - hash["mlt.count"] = @params[:mlt][:count] | ||
392 | - hash["mlt.fl"] = @params[:mlt][:field_list].join(',') | ||
393 | - hash["mlt.mintf"] = @params[:mlt][:min_term_freq] | ||
394 | - hash["mlt.mindf"] = @params[:mlt][:min_doc_freq] | ||
395 | - hash["mlt.minwl"] = @params[:mlt][:min_word_length] | ||
396 | - hash["mlt.maxwl"] = @params[:mlt][:max_word_length] | ||
397 | - hash["mlt.maxqt"] = @params[:mlt][:max_query_terms] | ||
398 | - hash["mlt.maxntp"] = @params[:mlt][:max_tokens_parsed] | ||
399 | - hash["mlt.boost"] = @params[:mlt][:boost] | ||
400 | - end | ||
401 | - | ||
402 | - hash[:spellcheck] = true | ||
403 | - hash['spellcheck.collate'] = true | ||
404 | - | ||
405 | - hash.merge(super.to_hash) | ||
406 | - end | ||
407 | - | ||
408 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/request/update.rb
@@ -1,23 +0,0 @@ | @@ -1,23 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -# a parent class for all requests that go through the solr update handler | ||
14 | -# TODO: Use new xml update handler for better error responses | ||
15 | -class Solr::Request::Update < Solr::Request::Base | ||
16 | - def response_format | ||
17 | - :xml | ||
18 | - end | ||
19 | - | ||
20 | - def handler | ||
21 | - 'update' | ||
22 | - end | ||
23 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/response.rb
@@ -1,27 +0,0 @@ | @@ -1,27 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -module Solr; module Response; end; end | ||
14 | -require File.expand_path("#{File.dirname(__FILE__)}/response/base") | ||
15 | -require File.expand_path("#{File.dirname(__FILE__)}/response/xml") | ||
16 | -require File.expand_path("#{File.dirname(__FILE__)}/response/ruby") | ||
17 | -require File.expand_path("#{File.dirname(__FILE__)}/response/ping") | ||
18 | -require File.expand_path("#{File.dirname(__FILE__)}/response/add_document") | ||
19 | -require File.expand_path("#{File.dirname(__FILE__)}/response/modify_document") | ||
20 | -require File.expand_path("#{File.dirname(__FILE__)}/response/standard") | ||
21 | -require File.expand_path("#{File.dirname(__FILE__)}/response/spellcheck") | ||
22 | -require File.expand_path("#{File.dirname(__FILE__)}/response/dismax") | ||
23 | -require File.expand_path("#{File.dirname(__FILE__)}/response/commit") | ||
24 | -require File.expand_path("#{File.dirname(__FILE__)}/response/delete") | ||
25 | -require File.expand_path("#{File.dirname(__FILE__)}/response/index_info") | ||
26 | -require File.expand_path("#{File.dirname(__FILE__)}/response/optimize") | ||
27 | -require File.expand_path("#{File.dirname(__FILE__)}/response/select") | ||
28 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/plugins/acts_as_solr_reloaded/lib/solr/response/add_document.rb
@@ -1,17 +0,0 @@ | @@ -1,17 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Response::AddDocument < Solr::Response::Xml | ||
14 | - def initialize(xml) | ||
15 | - super | ||
16 | - end | ||
17 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/response/base.rb
@@ -1,42 +0,0 @@ | @@ -1,42 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Response::Base | ||
14 | - attr_reader :raw_response | ||
15 | - | ||
16 | - def initialize(raw_response) | ||
17 | - @raw_response = raw_response | ||
18 | - end | ||
19 | - | ||
20 | - # factory method for creating a Solr::Response::* from | ||
21 | - # a request and the raw response content | ||
22 | - def self.make_response(request, raw) | ||
23 | - | ||
24 | - # make sure response format seems sane | ||
25 | - unless [:xml, :ruby].include?(request.response_format) | ||
26 | - raise Solr::Exception.new("unknown response format: #{request.response_format}" ) | ||
27 | - end | ||
28 | - | ||
29 | - # TODO: Factor out this case... perhaps the request object should provide the response class instead? Or dynamically align by class name? | ||
30 | - # Maybe the request itself could have the response handling features that get mixed in with a single general purpose response object? | ||
31 | - | ||
32 | - begin | ||
33 | - klass = eval(request.class.name.sub(/Request/,'Response')) | ||
34 | - rescue NameError | ||
35 | - raise Solr::Exception.new("unknown request type: #{request.class}") | ||
36 | - else | ||
37 | - klass.new(raw) | ||
38 | - end | ||
39 | - | ||
40 | - end | ||
41 | - | ||
42 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/response/commit.rb
@@ -1,15 +0,0 @@ | @@ -1,15 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Response::Commit < Solr::Response::Xml | ||
14 | -end | ||
15 | - |
vendor/plugins/acts_as_solr_reloaded/lib/solr/response/delete.rb
@@ -1,13 +0,0 @@ | @@ -1,13 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Response::Delete < Solr::Response::Xml; end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/response/dismax.rb
@@ -1,8 +0,0 @@ | @@ -1,8 +0,0 @@ | ||
1 | -class Solr::Response::Dismax < Solr::Response::Standard | ||
2 | - # no need for special processing | ||
3 | - | ||
4 | - # FIXME: 2007-02-07 <coda.hale@gmail.com> -- The existence of this class indicates that | ||
5 | - # the Request/Response pair architecture is a little hinky. Perhaps we could refactor | ||
6 | - # out some of the most common functionality -- Common Query Parameters, Highlighting Parameters, | ||
7 | - # Simple Facet Parameters, etc. -- into modules? | ||
8 | -end | ||
9 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/plugins/acts_as_solr_reloaded/lib/solr/response/index_info.rb
@@ -1,26 +0,0 @@ | @@ -1,26 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Response::IndexInfo < Solr::Response::Ruby | ||
14 | - def initialize(ruby_code) | ||
15 | - super | ||
16 | - end | ||
17 | - | ||
18 | - def num_docs | ||
19 | - return @data['index']['numDocs'] | ||
20 | - end | ||
21 | - | ||
22 | - def field_names | ||
23 | - return @data['fields'].keys | ||
24 | - end | ||
25 | - | ||
26 | -end |
vendor/plugins/acts_as_solr_reloaded/lib/solr/response/modify_document.rb
@@ -1,17 +0,0 @@ | @@ -1,17 +0,0 @@ | ||
1 | -# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
2 | -# (the "License"); you may not use this file except in compliance with | ||
3 | -# the License. You may obtain a copy of the License at | ||
4 | -# | ||
5 | -# http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | -# | ||
7 | -# Unless required by applicable law or agreed to in writing, software | ||
8 | -# distributed under the License is distributed on an "AS IS" BASIS, | ||
9 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
10 | -# See the License for the specific language governing permissions and | ||
11 | -# limitations under the License. | ||
12 | - | ||
13 | -class Solr::Response::ModifyDocument < Solr::Response::Xml | ||
14 | - def initialize(xml) | ||
15 | - super | ||
16 | - end | ||
17 | -end |