thinking-sphinx 1.2.13 → 1.4.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/README.textile +37 -4
- data/VERSION +1 -0
- data/features/abstract_inheritance.feature +10 -0
- data/features/alternate_primary_key.feature +1 -1
- data/features/attribute_updates.feature +49 -5
- data/features/deleting_instances.feature +3 -0
- data/features/excerpts.feature +8 -0
- data/features/facets.feature +15 -1
- data/features/facets_across_model.feature +2 -2
- data/features/field_sorting.feature +18 -0
- data/features/handling_edits.feature +1 -1
- data/features/searching_across_models.feature +2 -2
- data/features/searching_by_index.feature +40 -0
- data/features/searching_by_model.feature +1 -8
- data/features/sphinx_scopes.feature +33 -0
- data/features/step_definitions/alpha_steps.rb +14 -1
- data/features/step_definitions/beta_steps.rb +1 -1
- data/features/step_definitions/common_steps.rb +21 -2
- data/features/step_definitions/facet_steps.rb +4 -0
- data/features/step_definitions/scope_steps.rb +8 -0
- data/features/step_definitions/search_steps.rb +5 -0
- data/features/step_definitions/sphinx_steps.rb +8 -4
- data/features/sti_searching.feature +5 -0
- data/features/support/env.rb +7 -6
- data/features/{support → thinking_sphinx}/db/fixtures/betas.rb +1 -0
- data/features/{support → thinking_sphinx}/db/fixtures/comments.rb +1 -1
- data/features/{support → thinking_sphinx}/db/fixtures/developers.rb +2 -0
- data/features/thinking_sphinx/db/fixtures/foxes.rb +3 -0
- data/features/thinking_sphinx/db/fixtures/music.rb +4 -0
- data/features/{support → thinking_sphinx}/db/fixtures/people.rb +1 -1
- data/features/{support → thinking_sphinx}/db/fixtures/tags.rb +1 -1
- data/features/{support → thinking_sphinx}/db/migrations/create_alphas.rb +1 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_developers.rb +0 -2
- data/features/thinking_sphinx/db/migrations/create_genres.rb +3 -0
- data/features/thinking_sphinx/db/migrations/create_music.rb +6 -0
- data/features/thinking_sphinx/models/alpha.rb +23 -0
- data/features/thinking_sphinx/models/andrew.rb +17 -0
- data/features/{support → thinking_sphinx}/models/beta.rb +1 -1
- data/features/{support → thinking_sphinx}/models/developer.rb +2 -2
- data/features/{support → thinking_sphinx}/models/extensible_beta.rb +1 -1
- data/features/thinking_sphinx/models/fox.rb +5 -0
- data/features/thinking_sphinx/models/genre.rb +3 -0
- data/features/thinking_sphinx/models/medium.rb +5 -0
- data/features/thinking_sphinx/models/music.rb +8 -0
- data/features/{support → thinking_sphinx}/models/person.rb +2 -1
- data/features/{support → thinking_sphinx}/models/post.rb +2 -1
- data/lib/cucumber/thinking_sphinx/external_world.rb +12 -0
- data/lib/cucumber/thinking_sphinx/internal_world.rb +13 -11
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +17 -15
- data/lib/thinking_sphinx/active_record/delta.rb +0 -26
- data/lib/thinking_sphinx/active_record/has_many_association.rb +34 -11
- data/lib/thinking_sphinx/active_record/scopes.rb +46 -3
- data/lib/thinking_sphinx/active_record.rb +271 -193
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +45 -9
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +5 -1
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +9 -1
- data/lib/thinking_sphinx/attribute.rb +67 -23
- data/lib/thinking_sphinx/auto_version.rb +24 -0
- data/lib/thinking_sphinx/bundled_search.rb +44 -0
- data/lib/thinking_sphinx/class_facet.rb +3 -2
- data/lib/thinking_sphinx/configuration.rb +78 -64
- data/lib/thinking_sphinx/context.rb +76 -0
- data/lib/thinking_sphinx/deltas/default_delta.rb +14 -20
- data/lib/thinking_sphinx/deltas.rb +0 -2
- data/lib/thinking_sphinx/deploy/capistrano.rb +1 -1
- data/lib/thinking_sphinx/excerpter.rb +1 -1
- data/lib/thinking_sphinx/facet.rb +6 -5
- data/lib/thinking_sphinx/facet_search.rb +54 -24
- data/lib/thinking_sphinx/field.rb +2 -4
- data/lib/thinking_sphinx/index/builder.rb +36 -20
- data/lib/thinking_sphinx/index/faux_column.rb +8 -0
- data/lib/thinking_sphinx/index.rb +77 -19
- data/lib/thinking_sphinx/join.rb +37 -0
- data/lib/thinking_sphinx/property.rb +9 -2
- data/lib/thinking_sphinx/rails_additions.rb +4 -4
- data/lib/thinking_sphinx/search.rb +212 -66
- data/lib/thinking_sphinx/search_methods.rb +22 -4
- data/lib/thinking_sphinx/source/internal_properties.rb +2 -2
- data/lib/thinking_sphinx/source/sql.rb +5 -3
- data/lib/thinking_sphinx/source.rb +21 -12
- data/lib/thinking_sphinx/tasks.rb +26 -58
- data/lib/thinking_sphinx/test.rb +55 -0
- data/lib/thinking_sphinx.rb +70 -38
- data/rails/init.rb +4 -2
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record/delta_spec.rb +6 -8
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record/has_many_association_spec.rb +26 -3
- data/spec/thinking_sphinx/active_record/scopes_spec.rb +176 -0
- data/spec/thinking_sphinx/active_record_spec.rb +618 -0
- data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +134 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/association_spec.rb +1 -1
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/attribute_spec.rb +87 -46
- data/spec/thinking_sphinx/auto_version_spec.rb +47 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/configuration_spec.rb +73 -63
- data/spec/thinking_sphinx/context_spec.rb +127 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/core/array_spec.rb +1 -1
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/core/string_spec.rb +1 -1
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/excerpter_spec.rb +1 -9
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/facet_search_spec.rb +76 -82
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/facet_spec.rb +5 -5
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/field_spec.rb +1 -42
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/index/builder_spec.rb +71 -31
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/index/faux_column_spec.rb +8 -2
- data/spec/thinking_sphinx/index_spec.rb +183 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/rails_additions_spec.rb +5 -5
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/search_methods_spec.rb +5 -1
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/search_spec.rb +183 -31
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/source_spec.rb +18 -2
- data/spec/thinking_sphinx/test_spec.rb +20 -0
- data/spec/thinking_sphinx_spec.rb +204 -0
- data/tasks/distribution.rb +7 -26
- data/tasks/testing.rb +32 -20
- metadata +488 -147
- data/VERSION.yml +0 -5
- data/features/datetime_deltas.feature +0 -66
- data/features/delayed_delta_indexing.feature +0 -37
- data/features/step_definitions/datetime_delta_steps.rb +0 -15
- data/features/step_definitions/delayed_delta_indexing_steps.rb +0 -7
- data/features/support/database.yml +0 -5
- data/features/support/db/active_record.rb +0 -40
- data/features/support/db/database.yml +0 -5
- data/features/support/db/fixtures/delayed_betas.rb +0 -10
- data/features/support/db/fixtures/thetas.rb +0 -10
- data/features/support/db/migrations/create_delayed_betas.rb +0 -17
- data/features/support/db/migrations/create_thetas.rb +0 -5
- data/features/support/db/mysql.rb +0 -3
- data/features/support/db/postgresql.rb +0 -3
- data/features/support/models/alpha.rb +0 -10
- data/features/support/models/delayed_beta.rb +0 -7
- data/features/support/models/theta.rb +0 -7
- data/features/support/post_database.rb +0 -43
- data/lib/thinking_sphinx/deltas/datetime_delta.rb +0 -50
- data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +0 -24
- data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +0 -27
- data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +0 -26
- data/lib/thinking_sphinx/deltas/delayed_delta.rb +0 -30
- data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +0 -96
- data/spec/lib/thinking_sphinx/active_record_spec.rb +0 -353
- data/spec/lib/thinking_sphinx/deltas/job_spec.rb +0 -32
- data/spec/lib/thinking_sphinx/index_spec.rb +0 -45
- data/spec/lib/thinking_sphinx_spec.rb +0 -162
- data/vendor/after_commit/LICENSE +0 -20
- data/vendor/after_commit/README +0 -16
- data/vendor/after_commit/Rakefile +0 -22
- data/vendor/after_commit/init.rb +0 -8
- data/vendor/after_commit/lib/after_commit/active_record.rb +0 -114
- data/vendor/after_commit/lib/after_commit/connection_adapters.rb +0 -103
- data/vendor/after_commit/lib/after_commit.rb +0 -45
- data/vendor/after_commit/test/after_commit_test.rb +0 -53
- data/vendor/delayed_job/lib/delayed/job.rb +0 -251
- data/vendor/delayed_job/lib/delayed/message_sending.rb +0 -7
- data/vendor/delayed_job/lib/delayed/performable_method.rb +0 -55
- data/vendor/delayed_job/lib/delayed/worker.rb +0 -54
- data/vendor/riddle/lib/riddle/client/filter.rb +0 -53
- data/vendor/riddle/lib/riddle/client/message.rb +0 -66
- data/vendor/riddle/lib/riddle/client/response.rb +0 -84
- data/vendor/riddle/lib/riddle/client.rb +0 -635
- data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +0 -48
- data/vendor/riddle/lib/riddle/configuration/index.rb +0 -142
- data/vendor/riddle/lib/riddle/configuration/indexer.rb +0 -19
- data/vendor/riddle/lib/riddle/configuration/remote_index.rb +0 -17
- data/vendor/riddle/lib/riddle/configuration/searchd.rb +0 -25
- data/vendor/riddle/lib/riddle/configuration/section.rb +0 -43
- data/vendor/riddle/lib/riddle/configuration/source.rb +0 -23
- data/vendor/riddle/lib/riddle/configuration/sql_source.rb +0 -34
- data/vendor/riddle/lib/riddle/configuration/xml_source.rb +0 -28
- data/vendor/riddle/lib/riddle/configuration.rb +0 -33
- data/vendor/riddle/lib/riddle/controller.rb +0 -53
- data/vendor/riddle/lib/riddle.rb +0 -30
- data/features/{support → thinking_sphinx}/database.example.yml +0 -0
- data/features/{support → thinking_sphinx}/db/fixtures/alphas.rb +0 -0
- data/features/{support → thinking_sphinx}/db/fixtures/authors.rb +0 -0
- data/features/{support → thinking_sphinx}/db/fixtures/boxes.rb +0 -0
- data/features/{support → thinking_sphinx}/db/fixtures/categories.rb +0 -0
- data/features/{support → thinking_sphinx}/db/fixtures/cats.rb +0 -0
- data/features/{support → thinking_sphinx}/db/fixtures/dogs.rb +0 -0
- data/features/{support → thinking_sphinx}/db/fixtures/extensible_betas.rb +0 -0
- data/features/{support → thinking_sphinx}/db/fixtures/gammas.rb +0 -0
- data/features/{support → thinking_sphinx}/db/fixtures/posts.rb +0 -0
- data/features/{support → thinking_sphinx}/db/fixtures/robots.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_animals.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_authors.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_authors_posts.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_betas.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_boxes.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_categories.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_comments.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_extensible_betas.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_gammas.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_people.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_posts.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_robots.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_taggings.rb +0 -0
- data/features/{support → thinking_sphinx}/db/migrations/create_tags.rb +0 -0
- data/features/{support → thinking_sphinx}/models/animal.rb +0 -0
- data/features/{support → thinking_sphinx}/models/author.rb +0 -0
- data/features/{support → thinking_sphinx}/models/box.rb +0 -0
- data/features/{support → thinking_sphinx}/models/cat.rb +0 -0
- data/features/{support → thinking_sphinx}/models/category.rb +0 -0
- data/features/{support → thinking_sphinx}/models/comment.rb +3 -3
- /data/features/{support → thinking_sphinx}/models/dog.rb +0 -0
- /data/features/{support → thinking_sphinx}/models/gamma.rb +0 -0
- /data/features/{support → thinking_sphinx}/models/robot.rb +0 -0
- /data/features/{support → thinking_sphinx}/models/tag.rb +0 -0
- /data/features/{support → thinking_sphinx}/models/tagging.rb +0 -0
data/VERSION.yml
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
Feature: Datetime Delta Indexing
|
|
2
|
-
In order to have delta indexing on frequently-updated sites
|
|
3
|
-
Developers
|
|
4
|
-
Should be able to use an existing datetime column to track changes
|
|
5
|
-
|
|
6
|
-
Scenario: Delta Index should not fire automatically
|
|
7
|
-
Given Sphinx is running
|
|
8
|
-
And I am searching on thetas
|
|
9
|
-
When I search for one
|
|
10
|
-
Then I should get 1 result
|
|
11
|
-
|
|
12
|
-
When I change the name of theta one to eleven
|
|
13
|
-
And I wait for Sphinx to catch up
|
|
14
|
-
And I search for one
|
|
15
|
-
Then I should get 1 result
|
|
16
|
-
|
|
17
|
-
When I search for eleven
|
|
18
|
-
Then I should get 0 results
|
|
19
|
-
|
|
20
|
-
Scenario: Delta Index should fire when jobs are run
|
|
21
|
-
Given Sphinx is running
|
|
22
|
-
And I am searching on thetas
|
|
23
|
-
When I search for two
|
|
24
|
-
Then I should get 1 result
|
|
25
|
-
|
|
26
|
-
When I change the name of theta two to twelve
|
|
27
|
-
And I wait for Sphinx to catch up
|
|
28
|
-
And I search for twelve
|
|
29
|
-
Then I should get 0 results
|
|
30
|
-
|
|
31
|
-
When I index the theta datetime delta
|
|
32
|
-
And I wait for Sphinx to catch up
|
|
33
|
-
And I search for twelve
|
|
34
|
-
Then I should get 1 result
|
|
35
|
-
|
|
36
|
-
When I search for two
|
|
37
|
-
Then I should get 0 results
|
|
38
|
-
|
|
39
|
-
Scenario: New records should be merged into the core index
|
|
40
|
-
Given Sphinx is running
|
|
41
|
-
And I am searching on thetas
|
|
42
|
-
When I search for thirteen
|
|
43
|
-
Then I should get 0 results
|
|
44
|
-
|
|
45
|
-
When I create a new theta named thirteen
|
|
46
|
-
And I search for thirteen
|
|
47
|
-
Then I should get 0 results
|
|
48
|
-
|
|
49
|
-
When I index the theta datetime delta
|
|
50
|
-
And I wait for Sphinx to catch up
|
|
51
|
-
And I search for thirteen
|
|
52
|
-
Then I should get 1 result
|
|
53
|
-
|
|
54
|
-
When I search for the document id of theta thirteen in the theta_core index
|
|
55
|
-
Then it should exist
|
|
56
|
-
|
|
57
|
-
Scenario: Deleting records
|
|
58
|
-
Given Sphinx is running
|
|
59
|
-
And I am searching on thetas
|
|
60
|
-
When I search for three
|
|
61
|
-
Then I should get 1 result
|
|
62
|
-
|
|
63
|
-
When I delete the theta named three
|
|
64
|
-
And I wait for Sphinx to catch up
|
|
65
|
-
And I search for three
|
|
66
|
-
Then I should get 0 results
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
Feature: Delayed Delta Indexing
|
|
2
|
-
In order to have delta indexing on frequently-updated sites
|
|
3
|
-
Developers
|
|
4
|
-
Should be able to use delayed_job to handle delta indexes to lower system load
|
|
5
|
-
|
|
6
|
-
Scenario: Delta Index should not fire automatically
|
|
7
|
-
Given Sphinx is running
|
|
8
|
-
And I am searching on delayed betas
|
|
9
|
-
When I search for one
|
|
10
|
-
Then I should get 1 result
|
|
11
|
-
|
|
12
|
-
When I change the name of delayed beta one to eleven
|
|
13
|
-
And I wait for Sphinx to catch up
|
|
14
|
-
And I search for one
|
|
15
|
-
Then I should get 1 result
|
|
16
|
-
|
|
17
|
-
When I search for eleven
|
|
18
|
-
Then I should get 0 results
|
|
19
|
-
|
|
20
|
-
Scenario: Delta Index should fire when jobs are run
|
|
21
|
-
Given Sphinx is running
|
|
22
|
-
And I am searching on delayed betas
|
|
23
|
-
When I search for one
|
|
24
|
-
Then I should get 1 result
|
|
25
|
-
|
|
26
|
-
When I change the name of delayed beta two to twelve
|
|
27
|
-
And I wait for Sphinx to catch up
|
|
28
|
-
And I search for twelve
|
|
29
|
-
Then I should get 0 results
|
|
30
|
-
|
|
31
|
-
When I run the delayed jobs
|
|
32
|
-
And I wait for Sphinx to catch up
|
|
33
|
-
And I search for twelve
|
|
34
|
-
Then I should get 1 result
|
|
35
|
-
|
|
36
|
-
When I search for two
|
|
37
|
-
Then I should get 0 results
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
When /^I index the theta datetime delta$/ do
|
|
2
|
-
Theta.sphinx_indexes.first.delta_object.delayed_index(Theta)
|
|
3
|
-
end
|
|
4
|
-
|
|
5
|
-
When /^I change the name of theta (\w+) to (\w+)$/ do |current, replacement|
|
|
6
|
-
Theta.find_by_name(current).update_attributes(:name => replacement)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
When /^I create a new theta named (\w+)$/ do |name|
|
|
10
|
-
Theta.create(:name => name)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
When /^I delete the theta named (\w+)$/ do |name|
|
|
14
|
-
Theta.find_by_name(name).destroy
|
|
15
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require 'yaml'
|
|
2
|
-
require 'active_record'
|
|
3
|
-
|
|
4
|
-
# Database Defaults
|
|
5
|
-
host = "localhost"
|
|
6
|
-
username = "thinking_sphinx"
|
|
7
|
-
password = nil
|
|
8
|
-
|
|
9
|
-
# Read in YAML file
|
|
10
|
-
if File.exist?("features/support/db/database.yml")
|
|
11
|
-
config = YAML.load open("features/support/db/database.yml")
|
|
12
|
-
host = config["host"] || host
|
|
13
|
-
username = config["username"] || username
|
|
14
|
-
password = config["password"] || password
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Set up Connection
|
|
18
|
-
ActiveRecord::Base.establish_connection(
|
|
19
|
-
:adapter => Database,
|
|
20
|
-
:database => 'thinking_sphinx',
|
|
21
|
-
:username => username,
|
|
22
|
-
:password => password,
|
|
23
|
-
:host => host
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
# Copied from ActiveRecord's test suite
|
|
27
|
-
ActiveRecord::Base.connection.class.class_eval do
|
|
28
|
-
IGNORED_SQL = [
|
|
29
|
-
/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/,
|
|
30
|
-
/^SELECT @@ROWCOUNT/, /^SHOW FIELDS/
|
|
31
|
-
]
|
|
32
|
-
|
|
33
|
-
def execute_with_query_record(sql, name = nil, &block)
|
|
34
|
-
$queries_executed ||= []
|
|
35
|
-
$queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r }
|
|
36
|
-
execute_without_query_record(sql, name, &block)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
alias_method_chain :execute, :query_record
|
|
40
|
-
end
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
DelayedBeta.create :name => "one"
|
|
2
|
-
DelayedBeta.create :name => "two"
|
|
3
|
-
DelayedBeta.create :name => "three"
|
|
4
|
-
DelayedBeta.create :name => "four"
|
|
5
|
-
DelayedBeta.create :name => "five"
|
|
6
|
-
DelayedBeta.create :name => "six"
|
|
7
|
-
DelayedBeta.create :name => "seven"
|
|
8
|
-
DelayedBeta.create :name => "eight"
|
|
9
|
-
DelayedBeta.create :name => "nine"
|
|
10
|
-
DelayedBeta.create :name => "ten"
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Theta.create :name => "one"
|
|
2
|
-
Theta.create :name => "two"
|
|
3
|
-
Theta.create :name => "three"
|
|
4
|
-
Theta.create :name => "four"
|
|
5
|
-
Theta.create :name => "five"
|
|
6
|
-
Theta.create :name => "six"
|
|
7
|
-
Theta.create :name => "seven"
|
|
8
|
-
Theta.create :name => "eight"
|
|
9
|
-
Theta.create :name => "nine"
|
|
10
|
-
Theta.create :name => "ten"
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
ActiveRecord::Base.connection.create_table :delayed_betas, :force => true do |t|
|
|
2
|
-
t.column :name, :string, :null => false
|
|
3
|
-
t.column :delta, :boolean, :null => false, :default => false
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
ActiveRecord::Base.connection.create_table :delayed_jobs, :force => true do |t|
|
|
7
|
-
t.column :priority, :integer, :default => 0
|
|
8
|
-
t.column :attempts, :integer, :default => 0
|
|
9
|
-
t.column :handler, :text
|
|
10
|
-
t.column :last_error, :string
|
|
11
|
-
t.column :run_at, :datetime
|
|
12
|
-
t.column :locked_at, :datetime
|
|
13
|
-
t.column :failed_at, :datetime
|
|
14
|
-
t.column :locked_by, :string
|
|
15
|
-
t.column :created_at, :datetime
|
|
16
|
-
t.column :updated_at, :datetime
|
|
17
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
$:.unshift File.dirname(__FILE__) + '/../../lib'
|
|
2
|
-
|
|
3
|
-
require 'lib/thinking_sphinx'
|
|
4
|
-
|
|
5
|
-
%w( tmp/config tmp/log tmp/db/sphinx/development ).each do |path|
|
|
6
|
-
FileUtils.mkdir_p "#{Dir.pwd}/#{path}"
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
Kernel.const_set :RAILS_ROOT, "#{Dir.pwd}/tmp" unless defined?(RAILS_ROOT)
|
|
10
|
-
|
|
11
|
-
at_exit do
|
|
12
|
-
ThinkingSphinx::Configuration.instance.controller.stop
|
|
13
|
-
sleep(1) # Ensure Sphinx has shut down completely
|
|
14
|
-
ActiveRecord::Base.logger.close
|
|
15
|
-
FileUtils.rm_r "#{Dir.pwd}/tmp"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# Add log file
|
|
19
|
-
ActiveRecord::Base.logger = Logger.new open("tmp/active_record.log", "a")
|
|
20
|
-
|
|
21
|
-
# Set up database tables
|
|
22
|
-
Dir["features/support/db/migrations/*.rb"].each do |file|
|
|
23
|
-
require file.gsub(/\.rb$/, '')
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Load Models
|
|
27
|
-
Dir["features/support/models/*.rb"].sort.each do |file|
|
|
28
|
-
require file.gsub(/\.rb$/, '')
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
ThinkingSphinx.deltas_enabled = false
|
|
32
|
-
|
|
33
|
-
# Load Fixtures
|
|
34
|
-
Dir["features/support/db/fixtures/*.rb"].each do |file|
|
|
35
|
-
require file.gsub(/\.rb$/, '')
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
ThinkingSphinx.deltas_enabled = true
|
|
39
|
-
ThinkingSphinx.suppress_delta_output = true
|
|
40
|
-
|
|
41
|
-
ThinkingSphinx::Configuration.instance.build
|
|
42
|
-
ThinkingSphinx::Configuration.instance.controller.index
|
|
43
|
-
ThinkingSphinx::Configuration.instance.controller.start
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
module ThinkingSphinx
|
|
2
|
-
module Deltas
|
|
3
|
-
class DatetimeDelta < ThinkingSphinx::Deltas::DefaultDelta
|
|
4
|
-
attr_accessor :column, :threshold
|
|
5
|
-
|
|
6
|
-
def initialize(index, options)
|
|
7
|
-
@index = index
|
|
8
|
-
@column = options.delete(:delta_column) || :updated_at
|
|
9
|
-
@threshold = options.delete(:threshold) || 1.day
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def index(model, instance = nil)
|
|
13
|
-
# do nothing
|
|
14
|
-
true
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def delayed_index(model)
|
|
18
|
-
config = ThinkingSphinx::Configuration.instance
|
|
19
|
-
rotate = ThinkingSphinx.sphinx_running? ? "--rotate" : ""
|
|
20
|
-
|
|
21
|
-
output = `#{config.bin_path}#{config.indexer_binary_name} --config #{config.config_file} #{rotate} #{delta_index_name model}`
|
|
22
|
-
output += `#{config.bin_path}#{config.indexer_binary_name} --config #{config.config_file} #{rotate} --merge #{core_index_name model} #{delta_index_name model} --merge-dst-range sphinx_deleted 0 0`
|
|
23
|
-
puts output unless ThinkingSphinx.suppress_delta_output?
|
|
24
|
-
|
|
25
|
-
true
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def toggle(instance)
|
|
29
|
-
# do nothing
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def toggled(instance)
|
|
33
|
-
instance.send(@column) > @threshold.ago
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def reset_query(model)
|
|
37
|
-
nil
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def clause(model, toggled)
|
|
41
|
-
if toggled
|
|
42
|
-
"#{model.quoted_table_name}.#{model.connection.quote_column_name(@column.to_s)}" +
|
|
43
|
-
" > #{adapter.time_difference(@threshold)}"
|
|
44
|
-
else
|
|
45
|
-
nil
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module ThinkingSphinx
|
|
2
|
-
module Deltas
|
|
3
|
-
class DeltaJob
|
|
4
|
-
attr_accessor :index
|
|
5
|
-
|
|
6
|
-
def initialize(index)
|
|
7
|
-
@index = index
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def perform
|
|
11
|
-
return true unless ThinkingSphinx.updates_enabled? &&
|
|
12
|
-
ThinkingSphinx.deltas_enabled?
|
|
13
|
-
|
|
14
|
-
config = ThinkingSphinx::Configuration.instance
|
|
15
|
-
client = Riddle::Client.new config.address, config.port
|
|
16
|
-
|
|
17
|
-
output = `#{config.bin_path}#{config.indexer_binary_name} --config #{config.config_file} --rotate #{index}`
|
|
18
|
-
puts output unless ThinkingSphinx.suppress_delta_output?
|
|
19
|
-
|
|
20
|
-
true
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
module ThinkingSphinx
|
|
2
|
-
module Deltas
|
|
3
|
-
class FlagAsDeletedJob
|
|
4
|
-
attr_accessor :index, :document_id
|
|
5
|
-
|
|
6
|
-
def initialize(index, document_id)
|
|
7
|
-
@index, @document_id = index, document_id
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def perform
|
|
11
|
-
return true unless ThinkingSphinx.updates_enabled?
|
|
12
|
-
|
|
13
|
-
config = ThinkingSphinx::Configuration.instance
|
|
14
|
-
client = Riddle::Client.new config.address, config.port
|
|
15
|
-
|
|
16
|
-
client.update(
|
|
17
|
-
@index,
|
|
18
|
-
['sphinx_deleted'],
|
|
19
|
-
{@document_id => [1]}
|
|
20
|
-
) if ThinkingSphinx.sphinx_running? &&
|
|
21
|
-
ThinkingSphinx::Search.search_for_id(@document_id, @index)
|
|
22
|
-
|
|
23
|
-
true
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
module ThinkingSphinx
|
|
2
|
-
module Deltas
|
|
3
|
-
class Job < Delayed::Job
|
|
4
|
-
def self.enqueue(object, priority = 0)
|
|
5
|
-
super unless duplicates_exist(object)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def self.cancel_thinking_sphinx_jobs
|
|
9
|
-
if connection.tables.include?("delayed_jobs")
|
|
10
|
-
delete_all("handler LIKE '--- !ruby/object:ThinkingSphinx::Deltas::%'")
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
def self.duplicates_exist(object)
|
|
17
|
-
count(
|
|
18
|
-
:conditions => {
|
|
19
|
-
:handler => object.to_yaml,
|
|
20
|
-
:locked_at => nil
|
|
21
|
-
}
|
|
22
|
-
) > 0
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
require 'delayed/job'
|
|
2
|
-
|
|
3
|
-
require 'thinking_sphinx/deltas/delayed_delta/delta_job'
|
|
4
|
-
require 'thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job'
|
|
5
|
-
require 'thinking_sphinx/deltas/delayed_delta/job'
|
|
6
|
-
|
|
7
|
-
module ThinkingSphinx
|
|
8
|
-
module Deltas
|
|
9
|
-
class DelayedDelta < ThinkingSphinx::Deltas::DefaultDelta
|
|
10
|
-
def index(model, instance = nil)
|
|
11
|
-
return true unless ThinkingSphinx.updates_enabled? && ThinkingSphinx.deltas_enabled?
|
|
12
|
-
return true if instance && !toggled(instance)
|
|
13
|
-
|
|
14
|
-
ThinkingSphinx::Deltas::Job.enqueue(
|
|
15
|
-
ThinkingSphinx::Deltas::DeltaJob.new(delta_index_name(model)),
|
|
16
|
-
ThinkingSphinx::Configuration.instance.delayed_job_priority
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
Delayed::Job.enqueue(
|
|
20
|
-
ThinkingSphinx::Deltas::FlagAsDeletedJob.new(
|
|
21
|
-
core_index_name(model), instance.sphinx_document_id
|
|
22
|
-
),
|
|
23
|
-
ThinkingSphinx::Configuration.instance.delayed_job_priority
|
|
24
|
-
) if instance
|
|
25
|
-
|
|
26
|
-
true
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
require 'spec/spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ThinkingSphinx::ActiveRecord::Scopes do
|
|
4
|
-
after :each do
|
|
5
|
-
Alpha.remove_sphinx_scopes
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it "should be included into models with indexes" do
|
|
9
|
-
Alpha.included_modules.should include(ThinkingSphinx::ActiveRecord::Scopes)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "should not be included into models without indexes" do
|
|
13
|
-
Gamma.included_modules.should_not include(
|
|
14
|
-
ThinkingSphinx::ActiveRecord::Scopes
|
|
15
|
-
)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
describe '.sphinx_scope' do
|
|
19
|
-
before :each do
|
|
20
|
-
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "should define a method on the model" do
|
|
24
|
-
Alpha.should respond_to(:by_name)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
describe '.sphinx_scopes' do
|
|
29
|
-
before :each do
|
|
30
|
-
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "should return an array of defined scope names as symbols" do
|
|
34
|
-
Alpha.sphinx_scopes.should == [:by_name]
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe '.remove_sphinx_scopes' do
|
|
39
|
-
before :each do
|
|
40
|
-
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
|
41
|
-
Alpha.remove_sphinx_scopes
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "should remove sphinx scope methods" do
|
|
45
|
-
Alpha.should_not respond_to(:by_name)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "should empty the list of sphinx scopes" do
|
|
49
|
-
Alpha.sphinx_scopes.should be_empty
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
describe '.example_scope' do
|
|
54
|
-
before :each do
|
|
55
|
-
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
|
56
|
-
Alpha.sphinx_scope(:by_foo) { |foo| {:conditions => {:foo => foo}} }
|
|
57
|
-
Alpha.sphinx_scope(:with_betas) { {:classes => [Beta]} }
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "should return a ThinkingSphinx::Search object" do
|
|
61
|
-
Alpha.by_name('foo').should be_a(ThinkingSphinx::Search)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "should set the classes option" do
|
|
65
|
-
Alpha.by_name('foo').options[:classes].should == [Alpha]
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "should be able to be called on a ThinkingSphinx::Search object" do
|
|
69
|
-
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
|
70
|
-
lambda {
|
|
71
|
-
search.by_name('foo')
|
|
72
|
-
}.should_not raise_error
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "should return the search object it gets called upon" do
|
|
76
|
-
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
|
77
|
-
search.by_name('foo').should == search
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "should apply the scope options to the underlying search object" do
|
|
81
|
-
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
|
82
|
-
search.by_name('foo').options[:conditions].should == {:name => 'foo'}
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "should combine hash option scopes such as :conditions" do
|
|
86
|
-
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
|
87
|
-
search.by_name('foo').by_foo('bar').options[:conditions].
|
|
88
|
-
should == {:name => 'foo', :foo => 'bar'}
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it "should combine array option scopes such as :classes" do
|
|
92
|
-
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
|
93
|
-
search.with_betas.options[:classes].should == [Alpha, Beta]
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|