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
data/README.rdoc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
ErpSearch
|
2
|
+
=========
|
3
|
+
|
4
|
+
ERP Search adds Solr extensions to Compass using Sunspot.
|
5
|
+
|
6
|
+
Setup
|
7
|
+
=====
|
8
|
+
Copy vendor/plugins/erp_search/config/sunspot.yml to config/sunspot.yml
|
9
|
+
Edit config/sunspot.yml to your desired configuration if different from default
|
10
|
+
|
11
|
+
|
12
|
+
Example Usage
|
13
|
+
=============
|
14
|
+
|
15
|
+
Start Solr server:
|
16
|
+
rake sunspot:solr:start
|
17
|
+
|
18
|
+
Index Content:
|
19
|
+
rake sunspot:reindex_content
|
20
|
+
|
21
|
+
Index Parties:
|
22
|
+
rake sunspot:reindex_party_search_facts
|
23
|
+
|
24
|
+
Index Roles:
|
25
|
+
rake sunspot:reindex_roles
|
26
|
+
|
27
|
+
Stop Solr server:
|
28
|
+
rake sunspot:solr:stop
|
29
|
+
|
30
|
+
|
31
|
+
Example Usage if using Tenancy
|
32
|
+
==============================
|
33
|
+
|
34
|
+
Index Content for All Tenants:
|
35
|
+
rake sunspot:tenants:reindex_content
|
36
|
+
|
37
|
+
Index Content for a single Tenant:
|
38
|
+
rake sunspot:tenant:reindex_content['schema_name']
|
39
|
+
|
40
|
+
|
41
|
+
Gem Dependencies
|
42
|
+
================
|
43
|
+
sunspot_rails
|
44
|
+
sunspot
|
45
|
+
|
46
|
+
Copyright (c) 2011 Adam Hull, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'ErpSearch'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
28
|
+
require "rspec/core/rake_task"
|
29
|
+
RSpec::Core::RakeTask.new(:spec)
|
30
|
+
task :default => :spec
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require_tree .
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require_self
|
6
|
+
*= require_tree .
|
7
|
+
*/
|
@@ -0,0 +1,83 @@
|
|
1
|
+
Content.class_eval do
|
2
|
+
after_save :sunspot_commit
|
3
|
+
after_destroy :sunspot_commit
|
4
|
+
|
5
|
+
if $USE_SOLR_FOR_CONTENT
|
6
|
+
|
7
|
+
searchable do
|
8
|
+
if $USE_TENANCY
|
9
|
+
string :tenant_id do
|
10
|
+
Thread.current[:tenant_id]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
text :title
|
14
|
+
text :excerpt_html
|
15
|
+
text :body_html
|
16
|
+
string :website_section_id do
|
17
|
+
# index website_section_id so solr does not need reindexed when section title/permalink changes
|
18
|
+
website_sections.first.id rescue 0
|
19
|
+
end
|
20
|
+
string :type do
|
21
|
+
website_sections.first.type rescue ''
|
22
|
+
end
|
23
|
+
string :website_id do
|
24
|
+
website_sections.first.website_id rescue 0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# alias_method :search, :solr_search unless method_defined? :search
|
29
|
+
# the above line in sunspot plugin doesn't allow you to overwrite the search method in content base model.
|
30
|
+
# add this to force overwriting it.
|
31
|
+
def self.search(options = {}, &block)
|
32
|
+
self.solr_search(options = {}, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
# overwrite and add solr functionality.
|
36
|
+
def self.do_search(options = {})
|
37
|
+
|
38
|
+
if options[:section_permalink].nil? or options[:section_permalink].blank?
|
39
|
+
website_section_id = nil
|
40
|
+
else
|
41
|
+
website_section_id = WebsiteSection.find_by_permalink_and_website_id(options[:section_permalink], options[:website_id]).id rescue nil
|
42
|
+
end
|
43
|
+
|
44
|
+
@results = Content.search do
|
45
|
+
unless options[:query].empty?
|
46
|
+
keywords options[:query]
|
47
|
+
end
|
48
|
+
|
49
|
+
unless options[:content_type].nil? or options[:content_type].empty?
|
50
|
+
with(:type, options[:content_type])
|
51
|
+
end
|
52
|
+
|
53
|
+
unless website_section_id.nil?
|
54
|
+
with(:website_section_id, website_section_id)
|
55
|
+
end
|
56
|
+
|
57
|
+
if $USE_TENANCY
|
58
|
+
with(:tenant_id, Thread.current[:tenant_id])
|
59
|
+
end
|
60
|
+
|
61
|
+
with(:website_id, options[:website_id])
|
62
|
+
paginate :page => options[:page], :per_page => options[:per_page]
|
63
|
+
end
|
64
|
+
|
65
|
+
@search_results = build_search_results(@results.results)
|
66
|
+
|
67
|
+
@page_results = WillPaginate::Collection.create(options[:page], options[:per_page], @results.results.total_entries) do |pager|
|
68
|
+
pager.replace(@search_results)
|
69
|
+
end
|
70
|
+
|
71
|
+
return @page_results
|
72
|
+
end
|
73
|
+
|
74
|
+
def total_pages
|
75
|
+
page_count
|
76
|
+
end
|
77
|
+
|
78
|
+
def sunspot_commit
|
79
|
+
Sunspot.commit
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class PartySearchFact < ActiveRecord::Base
|
2
|
+
after_destroy :sunspot_commit
|
3
|
+
|
4
|
+
belongs_to :party
|
5
|
+
|
6
|
+
searchable do
|
7
|
+
integer :party_id
|
8
|
+
string :eid
|
9
|
+
string :type
|
10
|
+
string :roles, :multiple => true do
|
11
|
+
roles.split(/,\s*/) unless roles.nil?
|
12
|
+
end
|
13
|
+
text :party_description
|
14
|
+
string :party_description
|
15
|
+
string :party_business_party_type
|
16
|
+
text :user_login
|
17
|
+
text :individual_current_last_name
|
18
|
+
text :individual_current_first_name
|
19
|
+
string :individual_current_middle_name
|
20
|
+
string :individual_birth_date
|
21
|
+
text :individual_ssn
|
22
|
+
text :party_phone_number
|
23
|
+
text :party_email_address
|
24
|
+
string :party_address_1
|
25
|
+
string :party_address_2
|
26
|
+
string :party_primary_address_city
|
27
|
+
string :party_primary_address_state
|
28
|
+
text :party_primary_address_zip
|
29
|
+
string :party_primary_address_country
|
30
|
+
string :user_enabled
|
31
|
+
string :user_type
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.update_search_fact(party)
|
35
|
+
sf = PartySearchFact.find(:first, :conditions => ["party_id = ?", party.id])
|
36
|
+
|
37
|
+
sf = PartySearchFact.create(:party_id => party.id) if sf.nil?
|
38
|
+
sf.update_search_fact(party)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.destroy_search_fact(party)
|
42
|
+
sf = PartySearchFact.find(:first, :conditions => ["party_id = ?", party.id])
|
43
|
+
|
44
|
+
return if sf.nil?
|
45
|
+
|
46
|
+
sf.destroy
|
47
|
+
end
|
48
|
+
|
49
|
+
def update_search_fact(party)
|
50
|
+
self.update_attributes(
|
51
|
+
:party_id => party.id,
|
52
|
+
:eid => party.enterprise_identifier,
|
53
|
+
:roles => (party.user.roles.map { |role| role.internal_identifier }.join(',') rescue ''),
|
54
|
+
:party_description => party.description,
|
55
|
+
:party_business_party_type => party.business_party_type,
|
56
|
+
:user_login => (party.user.login rescue ''),
|
57
|
+
:individual_current_last_name => (party.business_party.current_last_name rescue ''),
|
58
|
+
:individual_current_first_name => (party.business_party.current_first_name rescue ''),
|
59
|
+
:individual_current_middle_name => (party.business_party.current_middle_name rescue ''),
|
60
|
+
:individual_birth_date => (party.business_party.birth_date rescue ''),
|
61
|
+
:individual_ssn => (party.business_party.ssn_last_four rescue ''),
|
62
|
+
:party_phone_number => (party.personal_phone_number.phone_number rescue ''),
|
63
|
+
:party_email_address => (party.personal_email_address.email_address rescue ''),
|
64
|
+
:party_address_1 => (party.home_postal_address.address_line_1 rescue ''),
|
65
|
+
:party_address_2 => (party.home_postal_address.address_line_2 rescue ''),
|
66
|
+
:party_primary_address_city => (party.home_postal_address.city rescue ''),
|
67
|
+
:party_primary_address_state => (party.home_postal_address.state rescue ''),
|
68
|
+
:party_primary_address_zip => (party.home_postal_address.zip rescue ''),
|
69
|
+
:party_primary_address_country => (party.home_postal_address.country rescue ''),
|
70
|
+
:user_enabled => (party.user.enabled rescue false),
|
71
|
+
:user_type => (party.user.attributes['type'] rescue '')
|
72
|
+
)
|
73
|
+
Sunspot.commit
|
74
|
+
end
|
75
|
+
|
76
|
+
def sunspot_commit
|
77
|
+
Sunspot.commit
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class ContactObserver < ActiveRecord::Observer
|
2
|
+
|
3
|
+
def after_save(contact)
|
4
|
+
begin
|
5
|
+
PartySearchFact.update_search_fact(contact.party)
|
6
|
+
rescue
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def after_destroy(contact)
|
11
|
+
begin
|
12
|
+
PartySearchFact.update_search_fact(contact.party)
|
13
|
+
rescue
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>ErpSearch</title>
|
5
|
+
<%= stylesheet_link_tag "erp_search/application" %>
|
6
|
+
<%= javascript_include_tag "erp_search/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
data/config/sunspot.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#Defaults to 8981 in test, 8982 in development and 8983 in production.
|
2
|
+
|
3
|
+
development:
|
4
|
+
solr:
|
5
|
+
hostname: 127.0.0.1
|
6
|
+
port: 8982
|
7
|
+
path: /solr
|
8
|
+
log_level: INFO
|
9
|
+
|
10
|
+
test:
|
11
|
+
solr:
|
12
|
+
hostname: 127.0.0.1
|
13
|
+
port: 8981
|
14
|
+
path: /solr
|
15
|
+
log_level: WARNING
|
16
|
+
|
17
|
+
production:
|
18
|
+
solr:
|
19
|
+
hostname: 127.0.0.1
|
20
|
+
port: 8983
|
21
|
+
path: /solr
|
22
|
+
log_level: WARNING
|
23
|
+
|
24
|
+
adam:
|
25
|
+
solr:
|
26
|
+
port: 8982
|
27
|
+
hostname: 127.0.0.1
|
28
|
+
path: /solr
|
29
|
+
log_level: INFO
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class RecreatePartySearchFactsTable < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
drop_table :party_search_facts if table_exists?(:party_search_facts)
|
4
|
+
|
5
|
+
unless table_exists?(:party_search_facts)
|
6
|
+
create_table :party_search_facts do |t|
|
7
|
+
t.column :party_id, :integer
|
8
|
+
t.column :eid, :string
|
9
|
+
t.column :type, :string
|
10
|
+
t.column :roles, :text
|
11
|
+
t.column :party_description, :string
|
12
|
+
t.column :party_business_party_type, :string
|
13
|
+
t.column :user_login, :string
|
14
|
+
t.column :individual_current_last_name, :string
|
15
|
+
t.column :individual_current_first_name, :string
|
16
|
+
t.column :individual_current_middle_name, :string
|
17
|
+
t.column :individual_birth_date, :string
|
18
|
+
t.column :individual_ssn, :string
|
19
|
+
t.column :party_phone_number, :string
|
20
|
+
t.column :party_email_address, :string
|
21
|
+
t.column :party_address_1, :string
|
22
|
+
t.column :party_address_2, :string
|
23
|
+
t.column :party_primary_address_city, :string
|
24
|
+
t.column :party_primary_address_state, :string
|
25
|
+
t.column :party_primary_address_zip, :string
|
26
|
+
t.column :party_primary_address_country, :string
|
27
|
+
t.column :user_enabled, :boolean
|
28
|
+
t.column :user_type, :string
|
29
|
+
t.column :reindex, :boolean
|
30
|
+
|
31
|
+
t.timestamps
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.down
|
37
|
+
drop_table :party_search_facts if table_exists?(:party_search_facts)
|
38
|
+
end
|
39
|
+
end
|