escargot 0.0.2

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.
@@ -0,0 +1,87 @@
1
+ # tests the Near Real Time support in the :updates => true mode
2
+ require 'test_helper'
3
+
4
+ class NrtEnqueue < Test::Unit::TestCase
5
+ load_schema
6
+ resque_available
7
+
8
+ class User < ActiveRecord::Base
9
+ elastic_index :updates => :enqueue
10
+ end
11
+
12
+ def setup
13
+ User.delete_all
14
+ Escargot::LocalIndexing.create_index_for_model(User)
15
+
16
+ @tim = User.create(:name => 'Tim the Wise')
17
+ User.create(:name => 'Peter the Young')
18
+ User.create(:name => 'Peter the Old')
19
+ User.create(:name => 'Bob the Skinny')
20
+ User.create(:name => 'Jamie the Flying Machine')
21
+ end
22
+
23
+ def teardown
24
+ User.delete_all
25
+ User.delete_index
26
+ end
27
+
28
+ def test_document_creation
29
+ # the Resque tasks have not run yet, so there should be nothing in the index
30
+ # but now run the Resque tasks and check that the index is good
31
+ Resque.run!
32
+ User.refresh_index
33
+
34
+ assert_equal 5, User.search("*").total_entries
35
+ results = User.search("wise")
36
+ assert_equal results.total_entries, 1
37
+ assert_equal results.first.name, 'Tim the Wise'
38
+ end
39
+
40
+ def test_document_updates
41
+ # now run the Resque tasks and check that the index is good
42
+ Resque.run!
43
+ User.refresh_index
44
+
45
+ assert_equal 5, User.search("*").total_entries
46
+
47
+ # make a change in a document
48
+ @tim.name = 'Tim the Reborn'
49
+ @tim.save!
50
+ User.refresh_index
51
+
52
+ # check that it's not in the index yet
53
+ assert_equal User.search_count("wise"), 1
54
+ assert_equal User.search_count("reborn"), 0
55
+
56
+ # but when we run the Resque tasks, all is well
57
+ Resque.run!
58
+ User.refresh_index
59
+
60
+ assert_equal User.search_count("wise"), 0
61
+ assert_equal User.search_count("reborn"), 1
62
+ end
63
+
64
+ def test_document_deletes
65
+ # now run the Resque tasks and check that the index is good
66
+ Resque.run!
67
+ User.refresh_index
68
+
69
+ assert_equal User.search("*").total_entries, 5
70
+
71
+ # Destroy the element
72
+ @tim.destroy
73
+ User.refresh_index
74
+
75
+ # but still there until run Resque
76
+ assert_equal User.search("*").total_entries, 5
77
+
78
+ # but when we run the Resque tasks, all is well
79
+ Resque.run!
80
+ User.refresh_index
81
+ assert_equal User.search("*").total_entries, 4
82
+ end
83
+
84
+ def test_changes_are_updated_in_all_versions
85
+
86
+ end
87
+ end
@@ -0,0 +1,57 @@
1
+ # tests the Near Real Time support in the :updates => true mode
2
+
3
+ require 'test_helper'
4
+
5
+ class NrtImmediate < Test::Unit::TestCase
6
+ load_schema
7
+ resque_available
8
+
9
+ class User < ActiveRecord::Base
10
+ elastic_index
11
+ end
12
+
13
+ def setup
14
+ User.delete_all
15
+ User.delete_index
16
+ Escargot::LocalIndexing.create_index_for_model(User)
17
+
18
+ @tim = User.create(:name => 'Tim the Wise')
19
+ User.create(:name => 'Peter the Young')
20
+ User.create(:name => 'Peter the Old')
21
+ User.create(:name => 'Bob the Skinny')
22
+ User.create(:name => 'Jamie the Flying Machine')
23
+ end
24
+
25
+ def teardown
26
+ User.delete_all
27
+ User.delete_index
28
+ end
29
+
30
+ def test_document_creation
31
+ User.refresh_index
32
+ assert_equal 5, User.search_count
33
+ results = User.search("wise")
34
+ assert_equal results.total_entries, 1
35
+ assert_equal results.first.name, 'Tim the Wise'
36
+ end
37
+
38
+ def test_document_updates
39
+ # make a change in a document
40
+ @tim.name = 'Tim the Reborn'
41
+ @tim.save!
42
+ User.refresh_index
43
+
44
+ assert_equal User.search_count("wise"), 0
45
+ assert_equal User.search_count("reborn"), 1
46
+ end
47
+
48
+ def test_document_deletes
49
+ User.refresh_index
50
+ assert_equal 5, User.search_count
51
+
52
+ @tim.destroy
53
+ User.refresh_index
54
+
55
+ assert_equal 4, User.search_count
56
+ end
57
+ end
@@ -0,0 +1,49 @@
1
+ # tests the Near Real Time support in the :updates => :immediate_with_refresh mode
2
+
3
+ require 'test_helper'
4
+
5
+ class NrtImmediateWithRefreshTest < Test::Unit::TestCase
6
+ load_schema
7
+ resque_available
8
+
9
+ class User < ActiveRecord::Base
10
+ elastic_index :updates => :immediate_with_refresh
11
+ end
12
+
13
+ def setup
14
+ User.delete_all
15
+ User.delete_index
16
+ Escargot::LocalIndexing.create_index_for_model(User)
17
+
18
+ @tim = User.create(:name => 'Tim the Wise')
19
+ User.create(:name => 'Peter the Young')
20
+ User.create(:name => 'Peter the Old')
21
+ User.create(:name => 'Bob the Skinny')
22
+ User.create(:name => 'Jamie the Flying Machine')
23
+ end
24
+
25
+ def teardown
26
+ User.delete_all
27
+ User.delete_index
28
+ end
29
+
30
+ def test_document_creation
31
+ assert_equal 5, User.search_count
32
+ results = User.search("wise")
33
+ assert_equal results.total_entries, 1
34
+ assert_equal results.first.name, 'Tim the Wise'
35
+ end
36
+
37
+ def test_document_updates
38
+ @tim.name = 'Tim the Reborn'
39
+ @tim.save!
40
+ assert_equal User.search_count("wise"), 0
41
+ assert_equal User.search_count("reborn"), 1
42
+ end
43
+
44
+ def test_document_deletes
45
+ @tim.destroy
46
+ assert_equal 4, User.search_count
47
+ end
48
+
49
+ end
data/test/schema.rb ADDED
@@ -0,0 +1,20 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table :users, :force => true do |t|
3
+ t.string :name
4
+ t.string :country_code
5
+ t.date :created_at
6
+ end
7
+
8
+ create_table :legacy_users, :force => true, :primary_key => :legacy_id do |t|
9
+ t.string :name
10
+ t.string :country_code
11
+ t.date :created_at
12
+ end
13
+
14
+ create_table :renew_users, :force => true, :primary_key => :renew_id do |t|
15
+ t.string :name
16
+ t.string :country_code
17
+ t.date :created_at
18
+ end
19
+
20
+ end
@@ -0,0 +1,74 @@
1
+ require 'test_helper'
2
+ # tests the behaviour of Searching multiple models
3
+
4
+ class SearchMultipleModels < Test::Unit::TestCase
5
+
6
+ load_schema
7
+ flush_indexes_models
8
+
9
+ class User < ActiveRecord::Base
10
+ elastic_index
11
+ end
12
+
13
+ class LegacyUser < ActiveRecord::Base
14
+ set_primary_key :legacy_id
15
+ elastic_index
16
+ end
17
+
18
+ class RenewUser < ActiveRecord::Base
19
+ set_primary_key :renew_id
20
+ elastic_index
21
+ end
22
+
23
+ def setup
24
+
25
+ Escargot.flush_all_indexed_models
26
+
27
+ User.new(:name => 'Cote').save!
28
+ User.new(:name => 'Grillo').save!
29
+ User.new(:name => 'Mencho').save!
30
+
31
+ LegacyUser.new(:name => 'Cote').save!
32
+ LegacyUser.new(:name => 'Cote').save!
33
+ LegacyUser.new(:name => 'Grillo').save!
34
+
35
+ RenewUser.new(:name => 'Cote').save!
36
+ RenewUser.new(:name => 'Cote').save!
37
+ RenewUser.new(:name => 'Mencho').save!
38
+
39
+ User.refresh_index
40
+ LegacyUser.refresh_index
41
+ RenewUser.refresh_index
42
+
43
+ end
44
+
45
+
46
+ def teardown
47
+ User.delete_all
48
+ User.delete_index
49
+ LegacyUser.delete_all
50
+ LegacyUser.delete_index
51
+ RenewUser.delete_all
52
+ RenewUser.delete_index
53
+ Escargot.flush_all_indexed_models
54
+ end
55
+
56
+
57
+ def test_search_multiple_models
58
+
59
+ # Search "Cote" in all Models
60
+ assert_equal Escargot.search("Cote").total_entries, 5
61
+
62
+ # Search "Cote" in model User
63
+ assert_equal Escargot.search("Cote", :classes =>[User]).total_entries, 1
64
+
65
+ # Search "Cote" in model User, if it's only one model you don't need pass like array
66
+ assert_equal Escargot.search("Cote", :classes => User).total_entries, 1
67
+
68
+ # Search "Cote" in model LegacyUser
69
+ assert_equal Escargot.search("Cote", :classes =>[LegacyUser]).total_entries, 2
70
+
71
+ # Search "Cote" in model User, LegacyUser
72
+ assert_equal Escargot.search("Cote", :classes =>[User,LegacyUser]).total_entries, 3
73
+ end
74
+ end
@@ -0,0 +1,84 @@
1
+ require 'test_helper'
2
+ #require File.dirname(__FILE__) + '/test_helper.rb'
3
+
4
+ # tests the behaviour of the index creation tasks that run locally (in the "simple" mode)
5
+ # without real time support
6
+
7
+ class BasicSearchTest < Test::Unit::TestCase
8
+ load_schema
9
+
10
+ class ::User < ActiveRecord::Base
11
+ elastic_index :updates => false, :mapping => {
12
+ :properties => {
13
+ :country_code => {:type => "string", :index => "not_analyzed"}
14
+ }
15
+ }
16
+
17
+ end
18
+
19
+ def setup
20
+ User.delete_all
21
+ User.delete_index
22
+
23
+ User.create(:name => 'John the Long', :country_code => 'ca')
24
+ User.create(:name => 'Peter the Young', :created_at => Date.today, :country_code => 'uk')
25
+ User.create(:name => 'Peter the Old', :created_at => Date.today - 1, :country_code => 'us')
26
+ User.create(:name => 'Bob the Skinny', :country_code => 'ca')
27
+ User.create(:name => 'John the Skinny Too', :country_code => 'it')
28
+ User.create(:name => 'Jamie the Amazing Flying Machine', :country_code => 'es')
29
+
30
+ Escargot::LocalIndexing.create_index_for_model(User)
31
+ end
32
+
33
+ def teardown
34
+ User.delete_all
35
+ User.delete_index
36
+ end
37
+
38
+ def test_search_count
39
+ results = User.search("peter")
40
+ assert_equal results.total_entries, 2
41
+ assert_equal User.search_count("peter"), 2
42
+ end
43
+
44
+ def test_search_count_with_query
45
+ results = User.search(:term => {:name => "john"})
46
+ assert_equal results.total_entries, 2
47
+ assert_equal User.search_count(:term => {:name => "john"}), 2
48
+ end
49
+
50
+ def test_facets
51
+ assert_equal User.facets(:country_code)[:country_code]["ca"], 2
52
+ facets = User.facets([:name, :country_code], :query => "LONG or SKINNY", :size => 100)
53
+ assert_equal facets[:name]["john"], 2
54
+ assert_equal facets[:country_code]["it"], 1
55
+ end
56
+
57
+ def test_facets_size
58
+ assert_equal User.facets(:name)[:name].keys.size, 10
59
+ assert_equal User.facets(:name, :size => 1000)[:name].keys.size, 12
60
+ end
61
+
62
+ def test_search
63
+ results = User.search("peter")
64
+ assert_equal [results.first.name, results.second.name].sort, ['Peter the Old', 'Peter the Young']
65
+ end
66
+
67
+ def test_wildcard
68
+ results = User.search("*")
69
+ assert_equal results.total_entries, 6
70
+ end
71
+
72
+ def test_paging
73
+ results = User.search("*", :per_page => 3, :page => 2)
74
+ assert_equal 6, results.total_entries
75
+ assert_equal 2, results.current_page
76
+ assert_equal 3, results.per_page
77
+ end
78
+
79
+ def test_sort
80
+ assert_equal User.search("peter", :sort => 'created_at').first.name, "Peter the Old"
81
+ assert_equal User.search("peter", :sort => 'created_at:desc').first.name, "Peter the Young"
82
+ end
83
+
84
+ end
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
4
+ require 'active_support/test_case'
5
+
6
+ ENV['RAILS_ENV'] = 'test'
7
+ ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
8
+
9
+ require 'test/unit'
10
+ require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
11
+
12
+ def load_schema
13
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
14
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
15
+
16
+ db_adapter = ENV['DB']
17
+
18
+ # no db passed, try one of these fine config-free DBs before bombing.
19
+ db_adapter ||=
20
+ begin
21
+ require 'rubygems'
22
+ require 'sqlite'
23
+ 'sqlite'
24
+ rescue MissingSourceFile
25
+ begin
26
+ require 'sqlite3'
27
+ 'sqlite3'
28
+ rescue MissingSourceFile
29
+ end
30
+ end
31
+
32
+ if db_adapter.nil?
33
+ raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
34
+ end
35
+
36
+ ActiveRecord::Base.establish_connection(config[db_adapter])
37
+ load(File.dirname(__FILE__) + "/schema.rb")
38
+ require File.dirname(__FILE__) + '/../rails/init.rb'
39
+ end
40
+
41
+ def resque_available
42
+ begin
43
+ require 'resque'
44
+ require 'resque_unit'
45
+ Resque.reset!
46
+ return true
47
+ rescue NameError, MissingSourceFile
48
+ puts "Please install the 'resque' and 'resque_unit' gems to test the distributed mode."
49
+ exit
50
+ end
51
+ end
52
+
53
+ def flush_indexes_models
54
+ Escargot.flush_all_indexed_models
55
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: escargot
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Angel Faus
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-03 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bundler
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ version: 1.0.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rubberband
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 21
46
+ segments:
47
+ - 0
48
+ - 0
49
+ - 5
50
+ version: 0.0.5
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: Connects any Rails model with ElasticSearch, supports near real time updates, distributed indexing and models that integrate data from many databases.
54
+ email:
55
+ - angel@vlex.com
56
+ executables: []
57
+
58
+ extensions: []
59
+
60
+ extra_rdoc_files: []
61
+
62
+ files:
63
+ - .gitignore
64
+ - MIT-LICENSE
65
+ - README.markdown
66
+ - Rakefile
67
+ - escargot.gemspec
68
+ - init.rb
69
+ - install.rb
70
+ - lib/escargot.rb
71
+ - lib/escargot/activerecord_ex.rb
72
+ - lib/escargot/distributed_indexing.rb
73
+ - lib/escargot/elasticsearch_ex.rb
74
+ - lib/escargot/local_indexing.rb
75
+ - lib/escargot/queue_backend/base.rb
76
+ - lib/escargot/queue_backend/resque.rb
77
+ - lib/escargot/version.rb
78
+ - lib/tasks/escargot.rake
79
+ - rails/init.rb
80
+ - test/admin_index_test.rb
81
+ - test/database.yml
82
+ - test/define_index_test.rb
83
+ - test/distributed_index_creation_test.rb
84
+ - test/index_options_test.rb
85
+ - test/indexed_content_test.rb
86
+ - test/local_index_creation_test.rb
87
+ - test/mappings_test.rb
88
+ - test/nrt_enqueue_test.rb
89
+ - test/nrt_immediate_test.rb
90
+ - test/nrt_immediate_with_refresh_test.rb
91
+ - test/schema.rb
92
+ - test/search_multiple_models_test.rb
93
+ - test/search_test.rb
94
+ - test/test_helper.rb
95
+ - uninstall.rb
96
+ has_rdoc: true
97
+ homepage: http://github.com/angelf/escargot
98
+ licenses: []
99
+
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 23
120
+ segments:
121
+ - 1
122
+ - 3
123
+ - 6
124
+ version: 1.3.6
125
+ requirements: []
126
+
127
+ rubyforge_project: escargot
128
+ rubygems_version: 1.4.2
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: ElasticSearch connector for Rails
132
+ test_files: []
133
+