erp_search 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/GPL-3-LICENSE +674 -0
- data/README.rdoc +46 -0
- data/Rakefile +32 -0
- data/app/assets/javascripts/erp_search/application.js +9 -0
- data/app/assets/stylesheets/erp_search/application.css +7 -0
- data/app/controllers/erp_search/application_controller.rb +4 -0
- data/app/helpers/erp_search/application_helper.rb +4 -0
- data/app/models/extensions/content.rb +83 -0
- data/app/models/extensions/party.rb +3 -0
- data/app/models/party_search_fact.rb +80 -0
- data/app/observers/contact_observer.rb +16 -0
- data/app/observers/email_address_observer.rb +5 -0
- data/app/observers/individual_observer.rb +6 -0
- data/app/observers/organization_observer.rb +6 -0
- data/app/observers/party_observer.rb +10 -0
- data/app/observers/phone_number_observer.rb +4 -0
- data/app/observers/postal_address_observer.rb +6 -0
- data/app/views/layouts/erp_search/application.html.erb +14 -0
- data/config/routes.rb +2 -0
- data/config/sunspot.yml +29 -0
- data/db/migrate/20110817165116_recreate_party_search_facts_table.rb +39 -0
- data/lib/erp_search.rb +6 -0
- data/lib/erp_search/engine.rb +13 -0
- data/lib/erp_search/version.rb +3 -0
- data/lib/tasks/solr_index.rake +128 -0
- metadata +108 -0
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            require 'sunspot_rails'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module ErpSearch
         | 
| 4 | 
            +
              class Engine < Rails::Engine
         | 
| 5 | 
            +
                isolate_namespace ErpSearch
         | 
| 6 | 
            +
                
         | 
| 7 | 
            +
                #add observers
         | 
| 8 | 
            +
            	  #this is ugly need a better way
         | 
| 9 | 
            +
            	  observers = [:party_observer, :contact_observer]
         | 
| 10 | 
            +
            	  (config.active_record.observers.nil?) ? config.active_record.observers = observers : config.active_record.observers += observers
         | 
| 11 | 
            +
            	     
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| @@ -0,0 +1,128 @@ | |
| 1 | 
            +
            require 'action_controller'
         | 
| 2 | 
            +
            require 'sunspot/rails/tasks'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            namespace :sunspot do
         | 
| 5 | 
            +
              task :reindex_party_search_facts, [:batch_size, :batch_commit] => :environment do |t,args|
         | 
| 6 | 
            +
                default_batch_commit = true
         | 
| 7 | 
            +
                default_batch_size = 1000
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                batch_size = (args.batch_size || default_batch_size).to_i
         | 
| 10 | 
            +
                batch_commit = (args.batch_commit || default_batch_commit)
         | 
| 11 | 
            +
                start_time = Time.now
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                puts "Starting Indexing with batch size of #{batch_size} at #{start_time} ..." 
         | 
| 14 | 
            +
                puts "Batch commit is set to #{batch_commit}"
         | 
| 15 | 
            +
                puts "There are #{PartySearchFact.count} parties to index"
         | 
| 16 | 
            +
                puts "This takes roughly 30 minutes per 500,000 parties"
         | 
| 17 | 
            +
                PartySearchFact.solr_reindex(:batch_size => batch_size, :batch_commit => batch_commit)
         | 
| 18 | 
            +
                end_time = Time.now
         | 
| 19 | 
            +
                puts "Done. Finished at: #{end_time}"
         | 
| 20 | 
            +
                puts "Elapsed time: #{(end_time - start_time)/60} minutes"
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              task :delete_party_search_facts => :environment do
         | 
| 24 | 
            +
                puts "Removing Indexes ..."
         | 
| 25 | 
            +
                PartySearchFact.solr_remove_all_from_index!
         | 
| 26 | 
            +
                puts "Done."
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              task :reindex_content => :environment do
         | 
| 30 | 
            +
                puts "Indexing ..."
         | 
| 31 | 
            +
                Content.solr_reindex
         | 
| 32 | 
            +
                puts "Done."
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              task :delete_content => :environment do
         | 
| 36 | 
            +
                puts "Removing Indexes ..."
         | 
| 37 | 
            +
                Content.solr_remove_all_from_index!
         | 
| 38 | 
            +
                puts "Done."
         | 
| 39 | 
            +
              end
         | 
| 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 | 
            +
            end
         | 
| 128 | 
            +
             | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,108 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: erp_search
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 3.0.0
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 | 
            +
            platform: ruby
         | 
| 7 | 
            +
            authors:
         | 
| 8 | 
            +
            - Rick Koloski, Russell Holmes
         | 
| 9 | 
            +
            autorequire: 
         | 
| 10 | 
            +
            bindir: bin
         | 
| 11 | 
            +
            cert_chain: []
         | 
| 12 | 
            +
            date: 2012-01-06 00:00:00.000000000Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              name: sunspot_rails
         | 
| 16 | 
            +
              requirement: &2161006980 !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
                none: false
         | 
| 18 | 
            +
                requirements:
         | 
| 19 | 
            +
                - - =
         | 
| 20 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            +
                    version: 1.3.0
         | 
| 22 | 
            +
              type: :runtime
         | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              version_requirements: *2161006980
         | 
| 25 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 26 | 
            +
              name: sunspot_solr
         | 
| 27 | 
            +
              requirement: &2161006460 !ruby/object:Gem::Requirement
         | 
| 28 | 
            +
                none: false
         | 
| 29 | 
            +
                requirements:
         | 
| 30 | 
            +
                - - =
         | 
| 31 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            +
                    version: 1.3.0
         | 
| 33 | 
            +
              type: :runtime
         | 
| 34 | 
            +
              prerelease: false
         | 
| 35 | 
            +
              version_requirements: *2161006460
         | 
| 36 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 37 | 
            +
              name: knitkit
         | 
| 38 | 
            +
              requirement: &2161005960 !ruby/object:Gem::Requirement
         | 
| 39 | 
            +
                none: false
         | 
| 40 | 
            +
                requirements:
         | 
| 41 | 
            +
                - - ! '>='
         | 
| 42 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 43 | 
            +
                    version: '0'
         | 
| 44 | 
            +
              type: :runtime
         | 
| 45 | 
            +
              prerelease: false
         | 
| 46 | 
            +
              version_requirements: *2161005960
         | 
| 47 | 
            +
            description: The CompassAE Search Engine provides functionality to facilitate both
         | 
| 48 | 
            +
              dimensional and index-based searches. CompassAE by default will search for an instance
         | 
| 49 | 
            +
              of SOLR/Sunspot and use it if it is available, otherwise it will attempt to use
         | 
| 50 | 
            +
              SQL to implement content searches. This engine also contains a demonstration of
         | 
| 51 | 
            +
              how to implement a denormalized search fact table using the Party entity.
         | 
| 52 | 
            +
            email:
         | 
| 53 | 
            +
            - russonrails@gmail.com
         | 
| 54 | 
            +
            executables: []
         | 
| 55 | 
            +
            extensions: []
         | 
| 56 | 
            +
            extra_rdoc_files: []
         | 
| 57 | 
            +
            files:
         | 
| 58 | 
            +
            - app/assets/javascripts/erp_search/application.js
         | 
| 59 | 
            +
            - app/assets/stylesheets/erp_search/application.css
         | 
| 60 | 
            +
            - app/controllers/erp_search/application_controller.rb
         | 
| 61 | 
            +
            - app/helpers/erp_search/application_helper.rb
         | 
| 62 | 
            +
            - app/models/extensions/content.rb
         | 
| 63 | 
            +
            - app/models/extensions/party.rb
         | 
| 64 | 
            +
            - app/models/party_search_fact.rb
         | 
| 65 | 
            +
            - app/observers/contact_observer.rb
         | 
| 66 | 
            +
            - app/observers/email_address_observer.rb
         | 
| 67 | 
            +
            - app/observers/individual_observer.rb
         | 
| 68 | 
            +
            - app/observers/organization_observer.rb
         | 
| 69 | 
            +
            - app/observers/party_observer.rb
         | 
| 70 | 
            +
            - app/observers/phone_number_observer.rb
         | 
| 71 | 
            +
            - app/observers/postal_address_observer.rb
         | 
| 72 | 
            +
            - app/views/layouts/erp_search/application.html.erb
         | 
| 73 | 
            +
            - config/routes.rb
         | 
| 74 | 
            +
            - config/sunspot.yml
         | 
| 75 | 
            +
            - db/migrate/20110817165116_recreate_party_search_facts_table.rb
         | 
| 76 | 
            +
            - lib/erp_search/engine.rb
         | 
| 77 | 
            +
            - lib/erp_search/version.rb
         | 
| 78 | 
            +
            - lib/erp_search.rb
         | 
| 79 | 
            +
            - lib/tasks/solr_index.rake
         | 
| 80 | 
            +
            - GPL-3-LICENSE
         | 
| 81 | 
            +
            - Rakefile
         | 
| 82 | 
            +
            - README.rdoc
         | 
| 83 | 
            +
            homepage: http://development.compassagile.com
         | 
| 84 | 
            +
            licenses: []
         | 
| 85 | 
            +
            post_install_message: 
         | 
| 86 | 
            +
            rdoc_options: []
         | 
| 87 | 
            +
            require_paths:
         | 
| 88 | 
            +
            - lib
         | 
| 89 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 90 | 
            +
              none: false
         | 
| 91 | 
            +
              requirements:
         | 
| 92 | 
            +
              - - ! '>='
         | 
| 93 | 
            +
                - !ruby/object:Gem::Version
         | 
| 94 | 
            +
                  version: '0'
         | 
| 95 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 96 | 
            +
              none: false
         | 
| 97 | 
            +
              requirements:
         | 
| 98 | 
            +
              - - ! '>='
         | 
| 99 | 
            +
                - !ruby/object:Gem::Version
         | 
| 100 | 
            +
                  version: '0'
         | 
| 101 | 
            +
            requirements: []
         | 
| 102 | 
            +
            rubyforge_project: 
         | 
| 103 | 
            +
            rubygems_version: 1.8.10
         | 
| 104 | 
            +
            signing_key: 
         | 
| 105 | 
            +
            specification_version: 3
         | 
| 106 | 
            +
            summary: The CompassAE Search Engine provides functionality to facilitate both dimensional
         | 
| 107 | 
            +
              and index-based searches.
         | 
| 108 | 
            +
            test_files: []
         |