thinking-sphinx 2.0.5 → 2.0.6

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.
Files changed (70) hide show
  1. data/README.textile +7 -1
  2. data/features/searching_by_model.feature +24 -30
  3. data/features/step_definitions/common_steps.rb +5 -5
  4. data/features/thinking_sphinx/db/.gitignore +1 -0
  5. data/features/thinking_sphinx/db/fixtures/post_keywords.txt +1 -0
  6. data/spec/fixtures/data.sql +32 -0
  7. data/spec/fixtures/database.yml.default +3 -0
  8. data/spec/fixtures/models.rb +161 -0
  9. data/spec/fixtures/structure.sql +146 -0
  10. data/spec/spec_helper.rb +62 -0
  11. data/spec/sphinx_helper.rb +61 -0
  12. data/spec/support/rails.rb +18 -0
  13. data/spec/thinking_sphinx/active_record/delta_spec.rb +24 -24
  14. data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +27 -0
  15. data/spec/thinking_sphinx/active_record/scopes_spec.rb +25 -25
  16. data/spec/thinking_sphinx/active_record_spec.rb +108 -107
  17. data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +38 -38
  18. data/spec/thinking_sphinx/association_spec.rb +69 -35
  19. data/spec/thinking_sphinx/context_spec.rb +61 -64
  20. data/spec/thinking_sphinx/search_spec.rb +7 -0
  21. data/spec/thinking_sphinx_spec.rb +47 -46
  22. metadata +49 -141
  23. data/VERSION +0 -1
  24. data/lib/cucumber/thinking_sphinx/external_world.rb +0 -12
  25. data/lib/cucumber/thinking_sphinx/internal_world.rb +0 -127
  26. data/lib/cucumber/thinking_sphinx/sql_logger.rb +0 -20
  27. data/lib/thinking-sphinx.rb +0 -1
  28. data/lib/thinking_sphinx.rb +0 -301
  29. data/lib/thinking_sphinx/action_controller.rb +0 -31
  30. data/lib/thinking_sphinx/active_record.rb +0 -384
  31. data/lib/thinking_sphinx/active_record/attribute_updates.rb +0 -52
  32. data/lib/thinking_sphinx/active_record/delta.rb +0 -65
  33. data/lib/thinking_sphinx/active_record/has_many_association.rb +0 -36
  34. data/lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb +0 -21
  35. data/lib/thinking_sphinx/active_record/log_subscriber.rb +0 -61
  36. data/lib/thinking_sphinx/active_record/scopes.rb +0 -93
  37. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +0 -87
  38. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +0 -62
  39. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +0 -157
  40. data/lib/thinking_sphinx/association.rb +0 -219
  41. data/lib/thinking_sphinx/attribute.rb +0 -396
  42. data/lib/thinking_sphinx/auto_version.rb +0 -38
  43. data/lib/thinking_sphinx/bundled_search.rb +0 -44
  44. data/lib/thinking_sphinx/class_facet.rb +0 -20
  45. data/lib/thinking_sphinx/configuration.rb +0 -339
  46. data/lib/thinking_sphinx/context.rb +0 -76
  47. data/lib/thinking_sphinx/core/string.rb +0 -15
  48. data/lib/thinking_sphinx/deltas.rb +0 -28
  49. data/lib/thinking_sphinx/deltas/default_delta.rb +0 -62
  50. data/lib/thinking_sphinx/deploy/capistrano.rb +0 -101
  51. data/lib/thinking_sphinx/excerpter.rb +0 -23
  52. data/lib/thinking_sphinx/facet.rb +0 -128
  53. data/lib/thinking_sphinx/facet_search.rb +0 -170
  54. data/lib/thinking_sphinx/field.rb +0 -98
  55. data/lib/thinking_sphinx/index.rb +0 -157
  56. data/lib/thinking_sphinx/index/builder.rb +0 -312
  57. data/lib/thinking_sphinx/index/faux_column.rb +0 -118
  58. data/lib/thinking_sphinx/join.rb +0 -37
  59. data/lib/thinking_sphinx/property.rb +0 -185
  60. data/lib/thinking_sphinx/railtie.rb +0 -46
  61. data/lib/thinking_sphinx/search.rb +0 -972
  62. data/lib/thinking_sphinx/search_methods.rb +0 -439
  63. data/lib/thinking_sphinx/sinatra.rb +0 -7
  64. data/lib/thinking_sphinx/source.rb +0 -194
  65. data/lib/thinking_sphinx/source/internal_properties.rb +0 -51
  66. data/lib/thinking_sphinx/source/sql.rb +0 -157
  67. data/lib/thinking_sphinx/tasks.rb +0 -130
  68. data/lib/thinking_sphinx/test.rb +0 -55
  69. data/tasks/distribution.rb +0 -33
  70. data/tasks/testing.rb +0 -80
@@ -0,0 +1,146 @@
1
+ DROP TABLE IF EXISTS `people`;
2
+
3
+ CREATE TABLE `people` (
4
+ `id` int(11) NOT NULL auto_increment,
5
+ `first_name` varchar(50) NULL,
6
+ `middle_initial` varchar(10) NULL,
7
+ `last_name` varchar(50) NULL,
8
+ `gender` varchar(10) NULL,
9
+ `street_address` varchar(200) NULL,
10
+ `city` varchar(100) NULL,
11
+ `state` varchar(100) NULL,
12
+ `postcode` varchar(10) NULL,
13
+ `email` varchar(100) NULL,
14
+ `birthday` datetime NULL,
15
+ `team_id` int(11) NULL,
16
+ `team_type` varchar(50) NULL,
17
+ `type` varchar(50) NULL,
18
+ `parent_id` varchar(50) NULL,
19
+ `source_id` int(11) NULL,
20
+ `source_type` varchar(50) NULL,
21
+ `delta` tinyint(1) NOT NULL DEFAULT 0,
22
+ PRIMARY KEY (`id`)
23
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
24
+
25
+ DROP TABLE IF EXISTS `friendships`;
26
+
27
+ CREATE TABLE `friendships` (
28
+ `id` int(11) NOT NULL auto_increment,
29
+ `person_id` int(11) NOT NULL,
30
+ `friend_id` int(11) NOT NULL,
31
+ `created_at` datetime NOT NULL,
32
+ `created_on` date NULL,
33
+ `updated_at` datetime NOT NULL,
34
+ PRIMARY KEY (`id`)
35
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
36
+
37
+ DROP TABLE IF EXISTS `football_teams`;
38
+
39
+ CREATE TABLE `football_teams` (
40
+ `id` int(11) NOT NULL auto_increment,
41
+ `name` varchar(50) NOT NULL,
42
+ `state` varchar(50) NOT NULL,
43
+ `league` varchar(50) NOT NULL,
44
+ PRIMARY KEY (`id`)
45
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
46
+
47
+ DROP TABLE IF EXISTS `cricket_teams`;
48
+
49
+ CREATE TABLE `cricket_teams` (
50
+ `id` int(11) NOT NULL auto_increment,
51
+ `name` varchar(50) NOT NULL,
52
+ `state` varchar(50) NOT NULL,
53
+ PRIMARY KEY (`id`)
54
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
55
+
56
+ DROP TABLE IF EXISTS `contacts`;
57
+
58
+ CREATE TABLE `contacts` (
59
+ `id` int(11) NOT NULL auto_increment,
60
+ `phone_number` varchar(50) NOT NULL,
61
+ `person_id` int(11) NOT NULL,
62
+ PRIMARY KEY (`id`)
63
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
64
+
65
+ DROP TABLE IF EXISTS `alphas`;
66
+
67
+ CREATE TABLE `alphas` (
68
+ `id` int(11) NOT NULL auto_increment,
69
+ `name` varchar(50) NOT NULL,
70
+ `value` int(11),
71
+ `cost` decimal(10,6),
72
+ PRIMARY KEY (`id`)
73
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
74
+
75
+ DROP TABLE IF EXISTS `betas`;
76
+
77
+ CREATE TABLE `betas` (
78
+ `id` int(11) NOT NULL auto_increment,
79
+ `name` varchar(50) NOT NULL,
80
+ `alpha_id` int(11),
81
+ `delta` tinyint(1) NOT NULL DEFAULT 0,
82
+ PRIMARY KEY (`id`)
83
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
84
+
85
+ DROP TABLE IF EXISTS `gammas`;
86
+
87
+ CREATE TABLE `gammas` (
88
+ `id` int(11) NOT NULL auto_increment,
89
+ `name` varchar(50) NOT NULL,
90
+ `value` int(11),
91
+ `beta_id` int(11),
92
+ PRIMARY KEY (`id`)
93
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
94
+
95
+ DROP TABLE IF EXISTS `thetas`;
96
+
97
+ CREATE TABLE `thetas` (
98
+ `id` int(11) NOT NULL auto_increment,
99
+ `name` varchar(50) NOT NULL,
100
+ `value` int(11),
101
+ `alpha_id` int(11),
102
+ PRIMARY KEY (`id`)
103
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
104
+
105
+ DROP TABLE IF EXISTS `searches`;
106
+
107
+ CREATE TABLE `searches` (
108
+ `id` int(11) NOT NULL auto_increment,
109
+ `name` varchar(50) NOT NULL,
110
+ PRIMARY KEY (`id`)
111
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
112
+
113
+ DROP TABLE IF EXISTS `tags`;
114
+
115
+ CREATE TABLE `tags` (
116
+ `id` int(11) NOT NULL auto_increment,
117
+ `person_id` int(11) NOT NULL,
118
+ `football_team_id` int(11) NOT NULL,
119
+ `cricket_team_id` int(11) NOT NULL,
120
+ `name` varchar(50) NOT NULL,
121
+ PRIMARY KEY (`id`)
122
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
123
+
124
+ DROP TABLE IF EXISTS `links`;
125
+
126
+ CREATE TABLE `links` (
127
+ `id` int(11) NOT NULL auto_increment,
128
+ `url` varchar(50) NOT NULL,
129
+ `description` varchar(200),
130
+ PRIMARY KEY (`id`)
131
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
132
+
133
+ DROP TABLE IF EXISTS `links_people`;
134
+
135
+ CREATE TABLE `links_people` (
136
+ `link_id` int(11) NOT NULL,
137
+ `person_id` int(11) NOT NULL
138
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
139
+
140
+ DROP TABLE IF EXISTS `big_foos`;
141
+
142
+ CREATE TABLE `big_foos` (
143
+ `id` bigint NOT NULL auto_increment,
144
+ `name` varchar(50) NOT NULL,
145
+ PRIMARY KEY (`id`)
146
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -0,0 +1,62 @@
1
+ $:.unshift File.dirname(__FILE__) + '/../lib'
2
+ Dir[File.join(File.dirname(__FILE__), '../vendor/*/lib')].each do |path|
3
+ $:.unshift path
4
+ end
5
+
6
+ require 'fileutils'
7
+ require 'logger'
8
+ require 'bundler'
9
+
10
+ Bundler.require :default, :development
11
+
12
+ require 'active_support/core_ext/module/attribute_accessors'
13
+ require 'active_support/core_ext/class/inheritable_attributes'
14
+ require "#{File.dirname(__FILE__)}/sphinx_helper"
15
+
16
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
17
+
18
+ ThinkingSphinx::Configuration.instance
19
+ ThinkingSphinx::ActiveRecord::LogSubscriber.logger = Logger.new(StringIO.new)
20
+
21
+ RSpec.configure do |config|
22
+ %w( tmp tmp/config tmp/log tmp/db ).each do |path|
23
+ FileUtils.mkdir_p "#{Dir.pwd}/#{path}"
24
+ end
25
+
26
+ sphinx = SphinxHelper.new
27
+ sphinx.setup_mysql
28
+
29
+ ActiveRecord::Base.send(:include, ThinkingSphinx::ActiveRecord)
30
+
31
+ require "#{File.dirname(__FILE__)}/fixtures/models"
32
+ ThinkingSphinx.context.define_indexes
33
+
34
+ config.before :each do
35
+ %w( tmp tmp/config tmp/log tmp/db ).each do |path|
36
+ FileUtils.mkdir_p "#{Dir.pwd}/#{path}"
37
+ end
38
+
39
+ ThinkingSphinx.updates_enabled = true
40
+ ThinkingSphinx.deltas_enabled = true
41
+ ThinkingSphinx.suppress_delta_output = true
42
+
43
+ ThinkingSphinx::Configuration.instance.reset
44
+ end
45
+
46
+ config.after :all do
47
+ FileUtils.rm_r "#{Dir.pwd}/tmp" rescue nil
48
+ end
49
+ end
50
+
51
+ def minimal_result_hashes(*instances)
52
+ instances.collect do |instance|
53
+ {
54
+ :weight => 21,
55
+ :attributes => {
56
+ 'sphinx_internal_id' => instance.id,
57
+ 'sphinx_internal_class' => instance.class.name,
58
+ 'class_crc' => instance.class.name.to_crc32
59
+ }
60
+ }
61
+ end
62
+ end
@@ -0,0 +1,61 @@
1
+ require 'active_record'
2
+ prefix = defined?(JRUBY_VERSION) ? "jdbc" : ""
3
+ require "active_record/connection_adapters/#{prefix}mysql_adapter"
4
+ require "active_record/connection_adapters/mysql2_adapter"
5
+
6
+ begin
7
+ require "active_record/connection_adapters/#{prefix}postgresql_adapter"
8
+ rescue LoadError
9
+ # No postgres? no prob...
10
+ end
11
+ require 'yaml'
12
+
13
+ class SphinxHelper
14
+ attr_accessor :host, :username, :password, :socket
15
+ attr_reader :path
16
+
17
+ def initialize
18
+ @host = 'localhost'
19
+ @username = 'root'
20
+ @password = ''
21
+
22
+ if File.exist?('spec/fixtures/database.yml')
23
+ config = YAML.load(File.open('spec/fixtures/database.yml'))
24
+ @host = config['host']
25
+ @username = config['username']
26
+ @password = config['password']
27
+ @socket = config['socket']
28
+ end
29
+
30
+ @path = File.expand_path(File.dirname(__FILE__))
31
+ end
32
+
33
+ def setup_mysql
34
+ ActiveRecord::Base.establish_connection(
35
+ :adapter => mysql_adapter,
36
+ :database => 'thinking_sphinx',
37
+ :username => @username,
38
+ :password => @password,
39
+ :host => @host,
40
+ :socket => @socket
41
+ )
42
+ ActiveRecord::Base.logger = Logger.new(File.open('tmp/activerecord.log', 'a'))
43
+
44
+ structure = File.open('spec/fixtures/structure.sql') { |f| f.read.chomp }
45
+ structure.split(';').each { |table|
46
+ ActiveRecord::Base.connection.execute table
47
+ }
48
+
49
+ File.open('spec/fixtures/data.sql') { |f|
50
+ while line = f.gets
51
+ ActiveRecord::Base.connection.execute line unless line.blank?
52
+ end
53
+ }
54
+ end
55
+
56
+ private
57
+
58
+ def mysql_adapter
59
+ defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql2'
60
+ end
61
+ end
@@ -0,0 +1,18 @@
1
+ module Rails
2
+ def self.root
3
+ File.join(Dir.pwd, 'tmp')
4
+ end
5
+
6
+ def self.env
7
+ @@environment ||= 'development'
8
+ end
9
+
10
+ def self.env=(env)
11
+ @@environment = env
12
+ end
13
+ end
14
+
15
+ ActiveSupport::Inflector.inflections do |inflect|
16
+ inflect.plural /^beta$/i, 'betas'
17
+ inflect.singular /^betas$/i, 'beta'
18
+ end
@@ -3,18 +3,18 @@ require 'spec_helper'
3
3
  describe "ThinkingSphinx::ActiveRecord::Delta" do
4
4
  it "should call the toggle_delta method after a save" do
5
5
  @beta = Beta.new(:name => 'beta')
6
- @beta.should_receive(:toggle_delta).and_return(true)
7
-
6
+ @beta.should_receive(:toggle_delta).at_least(1).times.and_return(true)
7
+
8
8
  @beta.save
9
9
  end
10
-
10
+
11
11
  it "should call the toggle_delta method after a save!" do
12
12
  @beta = Beta.new(:name => 'beta')
13
- @beta.should_receive(:toggle_delta).and_return(true)
14
-
13
+ @beta.should_receive(:toggle_delta).at_least(1).times.and_return(true)
14
+
15
15
  @beta.save!
16
16
  end
17
-
17
+
18
18
  describe "suspended_delta method" do
19
19
  before :each do
20
20
  ThinkingSphinx.deltas_suspended = false
@@ -47,23 +47,23 @@ describe "ThinkingSphinx::ActiveRecord::Delta" do
47
47
  Person.should_receive(:index_delta)
48
48
  Person.suspended_delta { 'no-op' }
49
49
  end
50
-
50
+
51
51
  it "should not reindex after the code block if false is passed in" do
52
52
  Person.should_not_receive(:index_delta)
53
53
  Person.suspended_delta(false) { 'no-op' }
54
54
  end
55
55
  end
56
-
56
+
57
57
  describe "toggle_delta method" do
58
58
  it "should set the delta value to true" do
59
59
  @person = Person.new
60
-
60
+
61
61
  @person.delta.should be_false
62
62
  @person.send(:toggle_delta)
63
63
  @person.delta.should be_true
64
64
  end
65
65
  end
66
-
66
+
67
67
  describe "index_delta method" do
68
68
  before :each do
69
69
  ThinkingSphinx::Configuration.stub!(:environment => "spec")
@@ -71,57 +71,57 @@ describe "ThinkingSphinx::ActiveRecord::Delta" do
71
71
  ThinkingSphinx.updates_enabled = true
72
72
  ThinkingSphinx.stub!(:sphinx_running? => true)
73
73
  Person.delta_objects.first.stub!(:` => "", :toggled => true)
74
-
74
+
75
75
  @person = Person.new
76
76
  Person.stub!(:search_for_id => false)
77
77
  @person.stub!(:sphinx_document_id => 1)
78
-
78
+
79
79
  @client = Riddle::Client.new
80
80
  @client.stub!(:update => true)
81
81
  ThinkingSphinx::Configuration.instance.stub!(:client => @client)
82
82
  end
83
-
83
+
84
84
  it "shouldn't index if delta indexing is disabled" do
85
85
  ThinkingSphinx.deltas_enabled = false
86
86
  Person.sphinx_indexes.first.delta_object.should_not_receive(:`)
87
87
  @client.should_not_receive(:update)
88
-
88
+
89
89
  @person.send(:index_delta)
90
90
  end
91
-
91
+
92
92
  it "shouldn't index if index updating is disabled" do
93
93
  ThinkingSphinx.updates_enabled = false
94
94
  Person.sphinx_indexes.first.delta_object.should_not_receive(:`)
95
-
95
+
96
96
  @person.send(:index_delta)
97
97
  end
98
-
98
+
99
99
  it "shouldn't index if the environment is 'test'" do
100
100
  ThinkingSphinx.deltas_enabled = nil
101
101
  ThinkingSphinx::Configuration.stub!(:environment => "test")
102
102
  Person.sphinx_indexes.first.delta_object.should_not_receive(:`)
103
-
103
+
104
104
  @person.send(:index_delta)
105
105
  end
106
-
106
+
107
107
  it "should call indexer for the delta index" do
108
108
  Person.sphinx_indexes.first.delta_object.should_receive(:`).with(
109
109
  "#{ThinkingSphinx::Configuration.instance.bin_path}indexer --config \"#{ThinkingSphinx::Configuration.instance.config_file}\" --rotate person_delta"
110
110
  )
111
-
111
+
112
112
  @person.send(:index_delta)
113
113
  end
114
-
114
+
115
115
  it "shouldn't update the deleted attribute if not in the index" do
116
116
  @client.should_not_receive(:update)
117
-
117
+
118
118
  @person.send(:index_delta)
119
119
  end
120
-
120
+
121
121
  it "should update the deleted attribute if in the core index" do
122
122
  Person.stub!(:search_for_id => true)
123
123
  @client.should_receive(:update)
124
-
124
+
125
125
  @person.send(:index_delta)
126
126
  end
127
127
  end
@@ -23,6 +23,17 @@ describe 'ThinkingSphinx::ActiveRecord::HasManyAssociation' do
23
23
  @person.friendships.search "test"
24
24
  end
25
25
 
26
+ it "should add a filter for an aliased attribute into a normal search call" do
27
+ @team = CricketTeam.new
28
+ @team.stub!(:id => 1)
29
+
30
+ Person.should_receive(:search).with do |query, options|
31
+ options[:with][:team_id].should == @team.id
32
+ end
33
+
34
+ @team.people.search "test"
35
+ end
36
+
26
37
  it "should define indexes for the reflection class" do
27
38
  Friendship.should_receive(:define_indexes)
28
39
 
@@ -51,6 +62,17 @@ describe 'ThinkingSphinx::ActiveRecord::HasManyAssociation' do
51
62
 
52
63
  @person.friends.search "test"
53
64
  end
65
+
66
+ it "should add a filter for an aliased attribute into a normal search call" do
67
+ @team = FootballTeam.new
68
+ @team.stub!(:id => 1)
69
+
70
+ Person.should_receive(:search).with do |query, options|
71
+ options[:with][:football_team_id].should == @team.id
72
+ end
73
+
74
+ @team.people.search "test"
75
+ end
54
76
  end
55
77
 
56
78
  describe 'filtering sphinx scopes' do
@@ -68,5 +90,10 @@ describe 'ThinkingSphinx::ActiveRecord::HasManyAssociation' do
68
90
 
69
91
  @person.friendships.reverse
70
92
  end
93
+
94
+ it "should pass method_missing onto CollectionProxy" do
95
+ Friendship.stub!(:missing_method => true)
96
+ @person.friendships.missing_method.should == true
97
+ end
71
98
  end
72
99
  end