erp_search 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,12 +18,12 @@ rake sunspot:solr:start
18
18
  Index Content:
19
19
  rake sunspot:reindex_content
20
20
 
21
+ Index DynamicFormModels:
22
+ rake sunspot:reindex_dynamic_form_models
23
+
21
24
  Index Parties:
22
25
  rake sunspot:reindex_party_search_facts
23
26
 
24
- Index Roles:
25
- rake sunspot:reindex_roles
26
-
27
27
  Stop Solr server:
28
28
  rake sunspot:solr:stop
29
29
 
@@ -1,15 +1,10 @@
1
- Content.class_eval do
2
- after_save :sunspot_commit
3
- after_destroy :sunspot_commit
1
+ if ErpSearch::Engine::USE_SOLR_FOR_CONTENT
4
2
 
5
- if $USE_SOLR_FOR_CONTENT
3
+ Content.class_eval do
4
+ after_save :sunspot_commit
5
+ after_destroy :sunspot_commit
6
6
 
7
7
  searchable do
8
- if $USE_TENANCY
9
- string :tenant_id do
10
- Thread.current[:tenant_id]
11
- end
12
- end
13
8
  text :title
14
9
  text :excerpt_html
15
10
  text :body_html
@@ -54,10 +49,6 @@ Content.class_eval do
54
49
  with(:website_section_id, website_section_id)
55
50
  end
56
51
 
57
- if $USE_TENANCY
58
- with(:tenant_id, Thread.current[:tenant_id])
59
- end
60
-
61
52
  with(:website_id, options[:website_id])
62
53
  paginate :page => options[:page], :per_page => options[:per_page]
63
54
  end
@@ -78,6 +69,7 @@ Content.class_eval do
78
69
  def sunspot_commit
79
70
  Sunspot.commit
80
71
  end
72
+
81
73
  end
82
-
83
- end
74
+
75
+ end
@@ -1,3 +1,7 @@
1
- DynamicFormDocument.class_eval do
2
- has_dynamic_solr_search
3
- end
1
+ if ErpSearch::Engine::USE_SOLR_FOR_DYNAMIC_FORM_MODELS
2
+
3
+ DynamicFormDocument.class_eval do
4
+ has_dynamic_solr_search
5
+ end
6
+
7
+ end
@@ -1,3 +1,7 @@
1
- Party.class_eval do
2
- has_one :party_search_fact, :dependent => :destroy
3
- end
1
+ if ErpSearch::Engine::USE_PARTY_SEARCH_FACTS
2
+
3
+ Party.class_eval do
4
+ has_one :party_search_fact, :dependent => :destroy
5
+ end
6
+
7
+ end
@@ -1,3 +1,7 @@
1
- Ticket.class_eval do
2
- has_dynamic_solr_search
3
- end
1
+ if ErpSearch::Engine::USE_SOLR_FOR_DYNAMIC_FORM_MODELS
2
+
3
+ Ticket.class_eval do
4
+ has_dynamic_solr_search
5
+ end
6
+
7
+ end
@@ -1,3 +1,7 @@
1
- WebsiteInquiry.class_eval do
2
- has_dynamic_solr_search
3
- end
1
+ if ErpSearch::Engine::USE_SOLR_FOR_DYNAMIC_FORM_MODELS
2
+
3
+ WebsiteInquiry.class_eval do
4
+ has_dynamic_solr_search
5
+ end
6
+
7
+ end
@@ -1,82 +1,86 @@
1
- class PartySearchFact < ActiveRecord::Base
2
- attr_protected :created_at, :updated_at
1
+ if ErpSearch::Engine::USE_PARTY_SEARCH_FACTS
3
2
 
4
- after_destroy :sunspot_commit
5
-
6
- belongs_to :party
7
-
8
- searchable do
9
- integer :party_id
10
- string :eid
11
- string :type
12
- string :roles, :multiple => true do
13
- roles.split(/,\s*/) unless roles.nil?
3
+ class PartySearchFact < ActiveRecord::Base
4
+ attr_protected :created_at, :updated_at
5
+
6
+ after_destroy :sunspot_commit
7
+
8
+ belongs_to :party
9
+
10
+ searchable do
11
+ integer :party_id
12
+ string :eid
13
+ string :type
14
+ string :roles, :multiple => true do
15
+ roles.split(/,\s*/) unless roles.nil?
16
+ end
17
+ text :party_description
18
+ string :party_description
19
+ string :party_business_party_type
20
+ text :user_login
21
+ text :individual_current_last_name
22
+ text :individual_current_first_name
23
+ string :individual_current_middle_name
24
+ string :individual_birth_date
25
+ text :individual_ssn
26
+ text :party_phone_number
27
+ text :party_email_address
28
+ string :party_address_1
29
+ string :party_address_2
30
+ string :party_primary_address_city
31
+ string :party_primary_address_state
32
+ text :party_primary_address_zip
33
+ string :party_primary_address_country
34
+ string :user_enabled
35
+ string :user_type
14
36
  end
15
- text :party_description
16
- string :party_description
17
- string :party_business_party_type
18
- text :user_login
19
- text :individual_current_last_name
20
- text :individual_current_first_name
21
- string :individual_current_middle_name
22
- string :individual_birth_date
23
- text :individual_ssn
24
- text :party_phone_number
25
- text :party_email_address
26
- string :party_address_1
27
- string :party_address_2
28
- string :party_primary_address_city
29
- string :party_primary_address_state
30
- text :party_primary_address_zip
31
- string :party_primary_address_country
32
- string :user_enabled
33
- string :user_type
34
- end
35
-
36
- def self.update_search_fact(party)
37
- sf = PartySearchFact.find(:first, :conditions => ["party_id = ?", party.id])
37
+
38
+ def self.update_search_fact(party)
39
+ sf = PartySearchFact.find(:first, :conditions => ["party_id = ?", party.id])
38
40
 
39
- sf = PartySearchFact.create(:party_id => party.id) if sf.nil?
40
- sf.update_search_fact(party)
41
- end
41
+ sf = PartySearchFact.create(:party_id => party.id) if sf.nil?
42
+ sf.update_search_fact(party)
43
+ end
42
44
 
43
- def self.destroy_search_fact(party)
44
- sf = PartySearchFact.find(:first, :conditions => ["party_id = ?", party.id])
45
+ def self.destroy_search_fact(party)
46
+ sf = PartySearchFact.find(:first, :conditions => ["party_id = ?", party.id])
45
47
 
46
- return if sf.nil?
48
+ return if sf.nil?
47
49
 
48
- sf.destroy
49
- end
50
+ sf.destroy
51
+ end
50
52
 
51
- def update_search_fact(party)
52
- self.update_attributes(
53
- :party_id => party.id,
54
- :eid => party.enterprise_identifier,
55
- :roles => (party.user.roles.map { |role| role.internal_identifier }.join(',') rescue ''),
56
- :party_description => party.description,
57
- :party_business_party_type => party.business_party_type,
58
- :user_login => (party.user.username rescue ''),
59
- :individual_current_last_name => (party.business_party.current_last_name rescue ''),
60
- :individual_current_first_name => (party.business_party.current_first_name rescue ''),
61
- :individual_current_middle_name => (party.business_party.current_middle_name rescue ''),
62
- :individual_birth_date => (party.business_party.birth_date rescue ''),
63
- :individual_ssn => (party.business_party.ssn_last_four rescue ''),
64
- :party_phone_number => (party.personal_phone_number.phone_number rescue ''),
65
- :party_email_address => (party.personal_email_address.email_address rescue ''),
66
- :party_address_1 => (party.home_postal_address.address_line_1 rescue ''),
67
- :party_address_2 => (party.home_postal_address.address_line_2 rescue ''),
68
- :party_primary_address_city => (party.home_postal_address.city rescue ''),
69
- :party_primary_address_state => (party.home_postal_address.state rescue ''),
70
- :party_primary_address_zip => (party.home_postal_address.zip rescue ''),
71
- :party_primary_address_country => (party.home_postal_address.country rescue ''),
72
- :user_enabled => (party.user.enabled rescue false),
73
- :user_type => (party.user.attributes['type'] rescue '')
74
- )
75
- Sunspot.commit
76
- end
53
+ def update_search_fact(party)
54
+ self.update_attributes(
55
+ :party_id => party.id,
56
+ :eid => party.enterprise_identifier,
57
+ :roles => (party.user.roles.map { |role| role.internal_identifier }.join(',') rescue ''),
58
+ :party_description => party.description,
59
+ :party_business_party_type => party.business_party_type,
60
+ :user_login => (party.user.username rescue ''),
61
+ :individual_current_last_name => (party.business_party.current_last_name rescue ''),
62
+ :individual_current_first_name => (party.business_party.current_first_name rescue ''),
63
+ :individual_current_middle_name => (party.business_party.current_middle_name rescue ''),
64
+ :individual_birth_date => (party.business_party.birth_date rescue ''),
65
+ :individual_ssn => (party.business_party.ssn_last_four rescue ''),
66
+ :party_phone_number => (party.personal_phone_number.phone_number rescue ''),
67
+ :party_email_address => (party.personal_email_address.email_address rescue ''),
68
+ :party_address_1 => (party.home_postal_address.address_line_1 rescue ''),
69
+ :party_address_2 => (party.home_postal_address.address_line_2 rescue ''),
70
+ :party_primary_address_city => (party.home_postal_address.city rescue ''),
71
+ :party_primary_address_state => (party.home_postal_address.state rescue ''),
72
+ :party_primary_address_zip => (party.home_postal_address.zip rescue ''),
73
+ :party_primary_address_country => (party.home_postal_address.country rescue ''),
74
+ :user_enabled => (party.user.enabled rescue false),
75
+ :user_type => (party.user.attributes['type'] rescue '')
76
+ )
77
+ Sunspot.commit
78
+ end
77
79
 
78
- def sunspot_commit
79
- Sunspot.commit
80
- end
80
+ def sunspot_commit
81
+ Sunspot.commit
82
+ end
81
83
 
84
+ end
85
+
82
86
  end
@@ -0,0 +1,4 @@
1
+ ---
2
+ use_solr_for_content: true
3
+ use_solr_for_dynamic_form_models: true
4
+ use_party_search_facts: true
@@ -1,14 +1,12 @@
1
+ require 'sunspot_rails'
1
2
  require 'erp_base_erp_svcs'
2
-
3
- require 'sunspot'
4
-
5
- require "erp_search/extensions"
6
3
  require "erp_search/version"
7
4
  require "erp_search/engine"
8
5
 
9
-
10
- $USE_SOLR_FOR_CONTENT = true
11
- $USE_SOLR_FOR_DYNAMIC_FORM_MODELS = true
12
-
13
6
  module ErpSearch
7
+
8
+ def self.use_tenancy?
9
+ Object.const_defined?('Tenancy')
10
+ end
11
+
14
12
  end
@@ -0,0 +1,31 @@
1
+ module ErpSearch
2
+ module Config
3
+ class << self
4
+ attr_accessor :use_solr_for_content, :use_solr_for_dynamic_form_models
5
+
6
+ def init!
7
+ @defaults = {
8
+ :@use_solr_for_content => ErpSearch::Engine::USE_SOLR_FOR_CONTENT,
9
+ :@use_solr_for_dynamic_form_models => ErpSearch::Engine::USE_SOLR_FOR_DYNAMIC_FORM_MODELS,
10
+ :@use_party_search_facts => ErpSearch::Engine::USE_PARTY_SEARCH_FACTS
11
+ }
12
+ end
13
+
14
+ def reset!
15
+ @defaults.each do |k, v|
16
+ instance_variable_set(k, v)
17
+ end
18
+ end
19
+
20
+ def configure(&blk)
21
+ @configure_blk = blk
22
+ end
23
+
24
+ def configure!
25
+ @configure_blk.call(self) if @configure_blk
26
+ end
27
+ end
28
+ init!
29
+ reset!
30
+ end
31
+ end
@@ -1,17 +1,41 @@
1
- require 'sunspot_rails'
2
-
3
1
  module ErpSearch
4
2
  class Engine < Rails::Engine
5
3
  isolate_namespace ErpSearch
6
4
 
7
- ActiveSupport.on_load(:active_record) do
8
- include ErpSearch::Extensions::ActiveRecord::HasDynamicSolrSearch
9
- end
5
+ initializer "erp_search.load_app_root" do |app|
6
+ filename = File.join(app.root,"config/erp_search.yml")
7
+ if File.exists?(filename)
8
+ config = YAML.load_file(filename)
9
+ USE_SOLR_FOR_CONTENT = (config["use_solr_for_content"].nil? ? true : config["use_solr_for_content"])
10
+ USE_SOLR_FOR_DYNAMIC_FORM_MODELS = (config["use_solr_for_dynamic_form_models"].nil? ? true : config["use_solr_for_dynamic_form_models"])
11
+ USE_PARTY_SEARCH_FACTS = (config["use_party_search_facts"].nil? ? true : config["use_party_search_facts"])
12
+ else
13
+ USE_SOLR_FOR_CONTENT = true
14
+ USE_SOLR_FOR_DYNAMIC_FORM_MODELS = true
15
+ USE_PARTY_SEARCH_FACTS = true
16
+ end
17
+
18
+ require "erp_search/config"
19
+ ErpSearch::Engine.config.erp_search = ErpSearch::Config
10
20
 
11
- #add observers
12
- #this is ugly need a better way
13
- observers = [:party_observer, :contact_observer]
14
- (config.active_record.observers.nil?) ? config.active_record.observers = observers : config.active_record.observers += observers
21
+ ErpSearch::Engine.config.to_prepare do
22
+ require "erp_search/extensions"
23
+ ActiveSupport.on_load(:active_record) do
24
+ include ErpSearch::Extensions::ActiveRecord::HasDynamicSolrSearch
25
+ end
26
+ end
27
+
28
+ ErpSearch::Engine.config.after_initialize do
29
+ # setup sunspot for all dynamic form models if we're using USE_SOLR_FOR_DYNAMIC_FORM_MODELS
30
+ DynamicFormModel.sunspot_setup_all if Object.const_defined?('ErpForms') and ErpForms.use_solr? and ActiveRecord::Base.connection.table_exists?('dynamic_form_models')
31
+ end
32
+
33
+ if USE_PARTY_SEARCH_FACTS
34
+ # Add observers (this is ugly need a better way)
35
+ observers = [:party_observer, :contact_observer]
36
+ (ErpSearch::Engine.config.active_record.observers.nil?) ? ErpSearch::Engine.config.active_record.observers = observers : ErpSearch::Engine.config.active_record.observers += observers
37
+ end
38
+ end
15
39
 
16
40
  ErpBaseErpSvcs.register_as_compass_ae_engine(config, self)
17
41
  end
@@ -1,16 +1,13 @@
1
- # require 'sunspot'
2
- # Sunspot::Setup.class_eval do
3
- # def self.clear_setup_for_class(klass)
4
- # Rails.logger.info "clear_setup_for_class"
5
- # Sunspot.searchable.delete!(klass)
6
- # Rails.logger.info "searchable #{Sunspot.searchable.inspect}"
7
- # #Rails.logger.info "field_factories #{field_factories.inspect}"
8
- # Rails.logger.info "setups[klass.name.to_sym] #{setups.keys}"
9
- # setups.delete_if{|key, value| key == klass.name.to_sym }
10
- # #setups[klass.name.to_sym] = new(clazz)
11
- # Rails.logger.info "setups[klass.name.to_sym] #{setups.keys}"
12
- # end
13
- # end
1
+ Sunspot::Setup.class_eval do
2
+ def self.clear_setup_for_class(klass)
3
+ #Rails.logger.info "clear_setup_for_class"
4
+ #Sunspot.searchable.delete!(klass)
5
+ #Rails.logger.info "searchable #{Sunspot.searchable.inspect}"
6
+ #Rails.logger.info "setups[klass.name.to_sym] #{setups.keys}"
7
+ setups.delete_if{|key, value| key == klass.name.to_sym }
8
+ #Rails.logger.info "setups[klass.name.to_sym] #{setups.keys}"
9
+ end
10
+ end
14
11
 
15
12
  # Sunspot::ClassSet.class_eval do
16
13
  # def delete!(klass)
@@ -52,7 +49,7 @@ module ErpSearch
52
49
 
53
50
  def sunspot_setup(options={})
54
51
  klass = DynamicFormModel.get_constant(self.name)
55
- #Sunspot::Setup.clear_setup_for_class(klass)
52
+ Sunspot::Setup.clear_setup_for_class(klass)
56
53
  definition = DynamicForm.get_form(self.name).definition_object rescue nil
57
54
 
58
55
  unless definition.nil?
@@ -2,7 +2,7 @@ module ErpSearch
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
8
  end
@@ -7,7 +7,6 @@ namespace :sunspot do
7
7
  DynamicFormModel.order('id asc').all.each do |m|
8
8
  next if m.model_name == 'DynamicFormDocument'
9
9
  if m.get_constant.is_searchable?
10
- m.get_constant.sunspot_setup
11
10
  puts "Indexing #{m.model_name} ..."
12
11
  m.get_constant.solr_reindex
13
12
  puts "Done."
@@ -21,7 +20,6 @@ namespace :sunspot do
21
20
  DynamicFormModel.all.each do |m|
22
21
  next if m.model_name == 'DynamicFormDocument'
23
22
  if m.get_constant.is_searchable?
24
- m.get_constant.sunspot_setup
25
23
  puts "Removing Indexes for #{m.model_name} ..."
26
24
  m.get_constant.solr_remove_all_from_index!
27
25
  puts "Done."
@@ -30,12 +28,11 @@ namespace :sunspot do
30
28
  end
31
29
  end
32
30
 
33
-
34
31
  def use_solr?
35
- if $USE_SOLR_FOR_DYNAMIC_FORM_MODELS
32
+ if ErpSearch::Engine::USE_SOLR_FOR_DYNAMIC_FORM_MODELS
36
33
  return true
37
34
  else
38
- puts "USE_SOLR_FOR_DYNAMIC_FORM_MODELS is off. You likely need to install erp_search."
35
+ puts "USE_SOLR_FOR_DYNAMIC_FORM_MODELS is off."
39
36
  return false
40
37
  end
41
38
  end
@@ -38,91 +38,4 @@ namespace :sunspot do
38
38
  puts "Done."
39
39
  end
40
40
 
41
- namespace :tenants do
42
- def get_all_tenants
43
- # get all tenants
44
- tenants = Tenant.all
45
-
46
- # add public schema if it is in list
47
- public_schema = Tenant.new
48
- public_schema.id = 0
49
- public_schema.schema = 'public'
50
- schemas = tenants.collect{|t| t.schema }
51
- tenants << public_schema unless schemas.include?('public')
52
- tenants
53
- end
54
-
55
- task :reindex_content => :environment do
56
- # loop thru tenants
57
- get_all_tenants.each do |t|
58
- puts "Indexing #{t.schema} ..."
59
-
60
- set_current_schema(t.schema)
61
-
62
- remove_tenant_indexes(Content, t.id)
63
-
64
- # reindex content for tenant
65
- Content.solr_index
66
- Sunspot.commit
67
- end
68
-
69
- puts "Done."
70
- end
71
-
72
- task :delete_content => :environment do
73
- puts "Removing Indexes for All Tenants! ..."
74
- Content.solr_remove_all_from_index!
75
- puts "Done."
76
- end
77
- end
78
-
79
- def get_tenant_id_by_schema(schema)
80
- tenant_id = Tenant.find_by_schema(schema).id rescue 0
81
- puts "tenant id is zero which means public schema!" if tenant_id == 0
82
- return tenant_id
83
- end
84
-
85
- def set_current_schema(schema)
86
- # set current tenant_id in Thread
87
- if schema == 'public'
88
- Thread.current[:tenant_id] = 0
89
- else
90
- Thread.current[:tenant_id] = get_tenant_id_by_schema(schema)
91
- end
92
-
93
- #set schema
94
- Tenancy::SchemaUtil.set_search_path(schema)
95
- end
96
-
97
- def remove_tenant_indexes(object, tenant_id)
98
- # remove by query
99
- Sunspot.remove(object) do
100
- with(:tenant_id).equal_to(tenant_id)
101
- end
102
- Sunspot.commit
103
- end
104
-
105
- namespace :tenant do
106
- task :reindex_content, [:schema] => :environment do |t,args|
107
- puts "Indexing #{args.schema} ..."
108
-
109
- set_current_schema(args.schema)
110
-
111
- remove_tenant_indexes(Content, get_tenant_id_by_schema(args.schema))
112
-
113
- Content.solr_index
114
- Sunspot.commit
115
- puts "Done."
116
- end
117
-
118
- task :delete_content, [:schema] => :environment do |t,args|
119
- puts "Removing Indexes ..."
120
-
121
- set_current_schema(args.schema)
122
-
123
- remove_tenant_indexes(Content, get_tenant_id_by_schema(args.schema))
124
- puts "Done."
125
- end
126
- end
127
41
  end
128
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erp_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-11 00:00:00.000000000 Z
12
+ date: 2013-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: knitkit
@@ -104,9 +104,11 @@ files:
104
104
  - app/observers/phone_number_observer.rb
105
105
  - app/observers/postal_address_observer.rb
106
106
  - app/views/layouts/erp_search/application.html.erb
107
+ - config/erp_search.yml
107
108
  - config/routes.rb
108
109
  - config/sunspot.yml
109
110
  - db/migrate/20110817165116_recreate_party_search_facts_table.rb
111
+ - lib/erp_search/config.rb
110
112
  - lib/erp_search/engine.rb
111
113
  - lib/erp_search/extensions/active_record/has_dynamic_solr_search.rb
112
114
  - lib/erp_search/extensions.rb
@@ -226,18 +228,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
226
228
  - - ! '>='
227
229
  - !ruby/object:Gem::Version
228
230
  version: '0'
229
- segments:
230
- - 0
231
- hash: 3467136001356662011
232
231
  required_rubygems_version: !ruby/object:Gem::Requirement
233
232
  none: false
234
233
  requirements:
235
234
  - - ! '>='
236
235
  - !ruby/object:Gem::Version
237
236
  version: '0'
238
- segments:
239
- - 0
240
- hash: 3467136001356662011
241
237
  requirements: []
242
238
  rubyforge_project:
243
239
  rubygems_version: 1.8.24