thinking-sphinx 5.5.1 → 6.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +34 -89
  3. data/Appraisals +24 -0
  4. data/CHANGELOG.markdown +30 -0
  5. data/Gemfile +1 -0
  6. data/README.textile +26 -11
  7. data/bin/loadsphinx +15 -4
  8. data/bin/testmatrix +48 -0
  9. data/lib/thinking_sphinx/active_record/base.rb +23 -4
  10. data/lib/thinking_sphinx/active_record/filter_reflection.rb +1 -1
  11. data/lib/thinking_sphinx/active_record/log_subscriber.rb +16 -4
  12. data/lib/thinking_sphinx/commands/clear_real_time.rb +1 -1
  13. data/lib/thinking_sphinx/commands/clear_sql.rb +1 -1
  14. data/lib/thinking_sphinx/configuration/minimum_fields.rb +8 -8
  15. data/lib/thinking_sphinx/masks/scopes_mask.rb +6 -0
  16. data/lib/thinking_sphinx/processor.rb +34 -8
  17. data/lib/thinking_sphinx/search/context.rb +1 -0
  18. data/lib/thinking_sphinx/search.rb +2 -2
  19. data/lib/thinking_sphinx/test.rb +1 -1
  20. data/lib/thinking_sphinx.rb +4 -0
  21. data/spec/acceptance/attribute_access_spec.rb +4 -4
  22. data/spec/acceptance/excerpts_spec.rb +2 -2
  23. data/spec/acceptance/grouping_by_attributes_spec.rb +20 -20
  24. data/spec/acceptance/real_time_updates_spec.rb +61 -1
  25. data/spec/acceptance/searching_across_models_spec.rb +7 -0
  26. data/spec/acceptance/searching_with_filters_spec.rb +8 -8
  27. data/spec/acceptance/searching_within_a_model_spec.rb +14 -0
  28. data/spec/acceptance/sorting_search_results_spec.rb +15 -15
  29. data/spec/acceptance/sphinx_scopes_spec.rb +23 -16
  30. data/spec/internal/app/indices/article_index.rb +6 -0
  31. data/spec/internal/app/indices/book_index.rb +1 -1
  32. data/spec/internal/app/models/book.rb +5 -5
  33. data/spec/internal/db/schema.rb +1 -1
  34. data/spec/spec_helper.rb +1 -0
  35. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +1 -1
  36. data/spec/thinking_sphinx/active_record/interpreter_spec.rb +5 -5
  37. data/spec/thinking_sphinx/commands/clear_real_time_spec.rb +2 -2
  38. data/spec/thinking_sphinx/commands/clear_sql_spec.rb +2 -2
  39. data/spec/thinking_sphinx/configuration/minimum_fields_spec.rb +12 -2
  40. data/spec/thinking_sphinx/excerpter_spec.rb +3 -2
  41. data/spec/thinking_sphinx/index_spec.rb +2 -2
  42. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +4 -4
  43. data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +1 -1
  44. data/spec/thinking_sphinx/real_time/interpreter_spec.rb +5 -5
  45. data/spec/thinking_sphinx_spec.rb +2 -2
  46. data/thinking-sphinx.gemspec +14 -8
  47. metadata +23 -31
@@ -42,7 +42,7 @@ class ThinkingSphinx::Test
42
42
  config.indices_location,
43
43
  config.searchd.binlog_path
44
44
  ].each do |path|
45
- FileUtils.rm_r(path) if File.exist?(path)
45
+ FileUtils.rm_rf(path) if File.exist?(path)
46
46
  end
47
47
  end
48
48
 
@@ -34,6 +34,10 @@ module ThinkingSphinx
34
34
  ThinkingSphinx::Search::Merger.new(search).merge! nil, :ids_only => true
35
35
  end
36
36
 
37
+ def self.none
38
+ ThinkingSphinx::Search.new nil, :none => true
39
+ end
40
+
37
41
  def self.before_index_hooks
38
42
  @before_index_hooks
39
43
  end
@@ -4,17 +4,17 @@ require 'acceptance/spec_helper'
4
4
 
5
5
  describe 'Accessing attributes directly via search results', :live => true do
6
6
  it "allows access to attribute values" do
7
- Book.create! :title => 'American Gods', :year => 2001
7
+ Book.create! :title => 'American Gods', :publishing_year => 2001
8
8
  index
9
9
 
10
10
  search = Book.search('gods')
11
11
  search.context[:panes] << ThinkingSphinx::Panes::AttributesPane
12
12
 
13
- expect(search.first.sphinx_attributes['year']).to eq(2001)
13
+ expect(search.first.sphinx_attributes['publishing_year']).to eq(2001)
14
14
  end
15
15
 
16
16
  it "provides direct access to the search weight/relevance scores" do
17
- Book.create! :title => 'American Gods', :year => 2001
17
+ Book.create! :title => 'American Gods', :publishing_year => 2001
18
18
  index
19
19
 
20
20
  search = Book.search 'gods', :select => "*, weight()"
@@ -37,7 +37,7 @@ describe 'Accessing attributes directly via search results', :live => true do
37
37
  end
38
38
 
39
39
  it "can enumerate with the weight" do
40
- gods = Book.create! :title => 'American Gods', :year => 2001
40
+ gods = Book.create! :title => 'American Gods', :publishing_year => 2001
41
41
  index
42
42
 
43
43
  search = Book.search 'gods', :select => "*, weight()"
@@ -5,7 +5,7 @@ require 'acceptance/spec_helper'
5
5
 
6
6
  describe 'Accessing excerpts for methods on a search result', :live => true do
7
7
  it "returns excerpts for a given method" do
8
- Book.create! :title => 'American Gods', :year => 2001
8
+ Book.create! :title => 'American Gods', :publishing_year => 2001
9
9
  index
10
10
 
11
11
  search = Book.search('gods')
@@ -16,7 +16,7 @@ describe 'Accessing excerpts for methods on a search result', :live => true do
16
16
  end
17
17
 
18
18
  it "handles UTF-8 text for excerpts" do
19
- Book.create! :title => 'Война и миръ', :year => 1869
19
+ Book.create! :title => 'Война и миръ', :publishing_year => 1869
20
20
  index
21
21
 
22
22
  search = Book.search 'миръ'
@@ -4,36 +4,36 @@ require 'acceptance/spec_helper'
4
4
 
5
5
  describe 'Grouping search results by attributes', :live => true do
6
6
  it "groups by the provided attribute" do
7
- snuff = Book.create! :title => 'Snuff', :year => 2011
8
- earth = Book.create! :title => 'The Long Earth', :year => 2012
9
- dodger = Book.create! :title => 'Dodger', :year => 2012
7
+ snuff = Book.create! :title => 'Snuff', :publishing_year => 2011
8
+ earth = Book.create! :title => 'The Long Earth', :publishing_year => 2012
9
+ dodger = Book.create! :title => 'Dodger', :publishing_year => 2012
10
10
 
11
11
  index
12
12
 
13
- expect(Book.search(:group_by => :year).to_a).to eq([snuff, earth])
13
+ expect(Book.search(:group_by => :publishing_year).to_a).to eq([snuff, earth])
14
14
  end
15
15
 
16
16
  it "allows sorting within the group" do
17
- snuff = Book.create! :title => 'Snuff', :year => 2011
18
- earth = Book.create! :title => 'The Long Earth', :year => 2012
19
- dodger = Book.create! :title => 'Dodger', :year => 2012
17
+ snuff = Book.create! :title => 'Snuff', :publishing_year => 2011
18
+ earth = Book.create! :title => 'The Long Earth', :publishing_year => 2012
19
+ dodger = Book.create! :title => 'Dodger', :publishing_year => 2012
20
20
 
21
21
  index
22
22
 
23
- expect(Book.search(:group_by => :year, :order_group_by => 'title ASC').to_a).
23
+ expect(Book.search(:group_by => :publishing_year, :order_group_by => 'title ASC').to_a).
24
24
  to eq([snuff, dodger])
25
25
  end
26
26
 
27
27
  it "allows enumerating by count" do
28
- snuff = Book.create! :title => 'Snuff', :year => 2011
29
- earth = Book.create! :title => 'The Long Earth', :year => 2012
30
- dodger = Book.create! :title => 'Dodger', :year => 2012
28
+ snuff = Book.create! :title => 'Snuff', :publishing_year => 2011
29
+ earth = Book.create! :title => 'The Long Earth', :publishing_year => 2012
30
+ dodger = Book.create! :title => 'Dodger', :publishing_year => 2012
31
31
 
32
32
  index
33
33
 
34
34
  expectations = [[snuff, 1], [earth, 2]]
35
35
 
36
- Book.search(:group_by => :year).each_with_count do |book, count|
36
+ Book.search(:group_by => :publishing_year).each_with_count do |book, count|
37
37
  expectation = expectations.shift
38
38
 
39
39
  expect(book).to eq(expectation.first)
@@ -42,15 +42,15 @@ describe 'Grouping search results by attributes', :live => true do
42
42
  end
43
43
 
44
44
  it "allows enumerating by group" do
45
- snuff = Book.create! :title => 'Snuff', :year => 2011
46
- earth = Book.create! :title => 'The Long Earth', :year => 2012
47
- dodger = Book.create! :title => 'Dodger', :year => 2012
45
+ snuff = Book.create! :title => 'Snuff', :publishing_year => 2011
46
+ earth = Book.create! :title => 'The Long Earth', :publishing_year => 2012
47
+ dodger = Book.create! :title => 'Dodger', :publishing_year => 2012
48
48
 
49
49
  index
50
50
 
51
51
  expectations = [[snuff, 2011], [earth, 2012]]
52
52
 
53
- Book.search(:group_by => :year).each_with_group do |book, group|
53
+ Book.search(:group_by => :publishing_year).each_with_group do |book, group|
54
54
  expectation = expectations.shift
55
55
 
56
56
  expect(book).to eq(expectation.first)
@@ -59,14 +59,14 @@ describe 'Grouping search results by attributes', :live => true do
59
59
  end
60
60
 
61
61
  it "allows enumerating by group and count" do
62
- snuff = Book.create! :title => 'Snuff', :year => 2011
63
- earth = Book.create! :title => 'The Long Earth', :year => 2012
64
- dodger = Book.create! :title => 'Dodger', :year => 2012
62
+ snuff = Book.create! :title => 'Snuff', :publishing_year => 2011
63
+ earth = Book.create! :title => 'The Long Earth', :publishing_year => 2012
64
+ dodger = Book.create! :title => 'Dodger', :publishing_year => 2012
65
65
 
66
66
  index
67
67
 
68
68
  expectations = [[snuff, 2011, 1], [earth, 2012, 2]]
69
- search = Book.search(:group_by => :year)
69
+ search = Book.search(:group_by => :publishing_year)
70
70
 
71
71
  search.each_with_group_and_count do |book, group, count|
72
72
  expectation = expectations.shift
@@ -28,7 +28,7 @@ describe 'Updates to records in real-time indices', :live => true do
28
28
  expect(Admin::Person.search('Mort').to_a).to eq([person])
29
29
  end
30
30
 
31
- it "can use a direct interface for processing records" do
31
+ it "can use direct interface for upserting records" do
32
32
  Admin::Person.connection.execute <<~SQL
33
33
  INSERT INTO admin_people (name, created_at, updated_at)
34
34
  VALUES ('Pat', now(), now());
@@ -52,4 +52,64 @@ describe 'Updates to records in real-time indices', :live => true do
52
52
 
53
53
  expect(Admin::Person.search('Patrick').to_a).to eq([instance])
54
54
  end
55
+
56
+ it "can use direct interface for processing records outside scope" do
57
+ Article.connection.execute <<~SQL
58
+ INSERT INTO articles (title, published, created_at, updated_at)
59
+ VALUES ('Nice Title', TRUE, now(), now());
60
+ SQL
61
+
62
+ article = Article.last
63
+
64
+ ThinkingSphinx::Processor.new(model: article.class, id: article.id).sync
65
+
66
+ expect(ThinkingSphinx.search('Nice', :indices => ["published_articles_core"])).to include(article)
67
+
68
+ Article.connection.execute <<~SQL
69
+ UPDATE articles SET published = FALSE WHERE title = 'Nice Title';
70
+ SQL
71
+ ThinkingSphinx::Processor.new(model: article.class, id: article.id).sync
72
+
73
+ expect(ThinkingSphinx.search('Nice', :indices => ["published_articles_core"])).to be_empty
74
+ end
75
+
76
+ it "can use direct interface for processing deleted records" do
77
+ Article.connection.execute <<~SQL
78
+ INSERT INTO articles (title, published, created_at, updated_at)
79
+ VALUES ('Nice Title', TRUE, now(), now());
80
+ SQL
81
+
82
+ article = Article.last
83
+ ThinkingSphinx::Processor.new(:instance => article).sync
84
+
85
+ expect(ThinkingSphinx.search('Nice', :indices => ["published_articles_core"])).to include(article)
86
+
87
+ Article.connection.execute <<~SQL
88
+ DELETE FROM articles where title = 'Nice Title';
89
+ SQL
90
+
91
+ ThinkingSphinx::Processor.new(:instance => article).sync
92
+
93
+ expect(ThinkingSphinx.search('Nice', :indices => ["published_articles_core"])).to be_empty
94
+ end
95
+
96
+ it "syncs records in real-time index with alternate ids" do
97
+ Album.connection.execute <<~SQL
98
+ INSERT INTO albums (id, name, artist, integer_id)
99
+ VALUES ('#{("a".."z").to_a.sample}', 'Sing to the Moon', 'Laura Mvula', #{rand(10000)});
100
+ SQL
101
+
102
+ album = Album.last
103
+ ThinkingSphinx::Processor.new(:model => Album, id: album.integer_id).sync
104
+
105
+ expect(ThinkingSphinx.search('Laura', :indices => ["album_real_core"])).to include(album)
106
+
107
+ Article.connection.execute <<~SQL
108
+ DELETE FROM albums where id = '#{album.id}';
109
+ SQL
110
+
111
+ ThinkingSphinx::Processor.new(:instance => album).sync
112
+
113
+ expect(ThinkingSphinx.search('Laura', :indices => ["album_real_core"])).to be_empty
114
+ end
55
115
  end
@@ -37,4 +37,11 @@ describe 'Searching across models', :live => true do
37
37
  expect(ThinkingSphinx.search(:classes => [User, Article]).to_a).
38
38
  to match_array([article, user])
39
39
  end
40
+
41
+ it "has a 'none' default scope" do
42
+ article = Article.create! :title => 'Pancakes'
43
+ index
44
+
45
+ expect(ThinkingSphinx.none).to be_empty
46
+ end
40
47
  end
@@ -12,12 +12,12 @@ describe 'Searching with filters', :live => true do
12
12
  end
13
13
 
14
14
  it "limits results by an array of values" do
15
- gods = Book.create! :title => 'American Gods', :year => 2001
16
- boys = Book.create! :title => 'Anansi Boys', :year => 2005
17
- grave = Book.create! :title => 'The Graveyard Book', :year => 2009
15
+ gods = Book.create! :title => 'American Gods', :publishing_year => 2001
16
+ boys = Book.create! :title => 'Anansi Boys', :publishing_year => 2005
17
+ grave = Book.create! :title => 'The Graveyard Book', :publishing_year => 2009
18
18
  index
19
19
 
20
- expect(Book.search(:with => {:year => [2001, 2005]}).to_a).to match_array([gods, boys])
20
+ expect(Book.search(:with => {:publishing_year => [2001, 2005]}).to_a).to match_array([gods, boys])
21
21
  end
22
22
 
23
23
  it "limits results by a ranged filter" do
@@ -43,12 +43,12 @@ describe 'Searching with filters', :live => true do
43
43
  end
44
44
 
45
45
  it "limits results by exclusive filters on arrays of values" do
46
- gods = Book.create! :title => 'American Gods', :year => 2001
47
- boys = Book.create! :title => 'Anansi Boys', :year => 2005
48
- grave = Book.create! :title => 'The Graveyard Book', :year => 2009
46
+ gods = Book.create! :title => 'American Gods', :publishing_year => 2001
47
+ boys = Book.create! :title => 'Anansi Boys', :publishing_year => 2005
48
+ grave = Book.create! :title => 'The Graveyard Book', :publishing_year => 2009
49
49
  index
50
50
 
51
- expect(Book.search(:without => {:year => [2001, 2005]}).to_a).to eq([grave])
51
+ expect(Book.search(:without => {:publishing_year => [2001, 2005]}).to_a).to eq([grave])
52
52
  end
53
53
 
54
54
  it "limits results by ranged filters on timestamp MVAs" do
@@ -92,6 +92,20 @@ describe 'Searching within a model', :live => true do
92
92
  expect(Album.search(:indices => ['album_real_core']).first).
93
93
  to eq(album)
94
94
  end
95
+
96
+ it "is available via a sphinx-prefixed method" do
97
+ article = Article.create! :title => 'Pancakes'
98
+ index
99
+
100
+ expect(Article.sphinx_search.first).to eq(article)
101
+ end
102
+
103
+ it "has a 'none' default scope" do
104
+ article = Article.create! :title => 'Pancakes'
105
+ index
106
+
107
+ expect(Article.search_none).to be_empty
108
+ end
95
109
  end
96
110
 
97
111
  describe 'Searching within a model with a realtime index', :live => true do
@@ -4,27 +4,27 @@ require 'acceptance/spec_helper'
4
4
 
5
5
  describe 'Sorting search results', :live => true do
6
6
  it "sorts by a given clause" do
7
- gods = Book.create! :title => 'American Gods', :year => 2001
8
- grave = Book.create! :title => 'The Graveyard Book', :year => 2009
9
- boys = Book.create! :title => 'Anansi Boys', :year => 2005
7
+ gods = Book.create! :title => 'American Gods', :publishing_year => 2001
8
+ grave = Book.create! :title => 'The Graveyard Book', :publishing_year => 2009
9
+ boys = Book.create! :title => 'Anansi Boys', :publishing_year => 2005
10
10
  index
11
11
 
12
- expect(Book.search(:order => 'year ASC').to_a).to eq([gods, boys, grave])
12
+ expect(Book.search(:order => 'publishing_year ASC').to_a).to eq([gods, boys, grave])
13
13
  end
14
14
 
15
15
  it "sorts by a given attribute in ascending order" do
16
- gods = Book.create! :title => 'American Gods', :year => 2001
17
- grave = Book.create! :title => 'The Graveyard Book', :year => 2009
18
- boys = Book.create! :title => 'Anansi Boys', :year => 2005
16
+ gods = Book.create! :title => 'American Gods', :publishing_year => 2001
17
+ grave = Book.create! :title => 'The Graveyard Book', :publishing_year => 2009
18
+ boys = Book.create! :title => 'Anansi Boys', :publishing_year => 2005
19
19
  index
20
20
 
21
- expect(Book.search(:order => :year).to_a).to eq([gods, boys, grave])
21
+ expect(Book.search(:order => :publishing_year).to_a).to eq([gods, boys, grave])
22
22
  end
23
23
 
24
24
  it "sorts by a given sortable field" do
25
- gods = Book.create! :title => 'American Gods', :year => 2001
26
- grave = Book.create! :title => 'The Graveyard Book', :year => 2009
27
- boys = Book.create! :title => 'Anansi Boys', :year => 2005
25
+ gods = Book.create! :title => 'American Gods', :publishing_year => 2001
26
+ grave = Book.create! :title => 'The Graveyard Book', :publishing_year => 2009
27
+ boys = Book.create! :title => 'Anansi Boys', :publishing_year => 2005
28
28
  index
29
29
 
30
30
  expect(Book.search(:order => :title).to_a).to eq([gods, boys, grave])
@@ -38,13 +38,13 @@ describe 'Sorting search results', :live => true do
38
38
  end
39
39
 
40
40
  it "can sort with a provided expression" do
41
- gods = Book.create! :title => 'American Gods', :year => 2001
42
- grave = Book.create! :title => 'The Graveyard Book', :year => 2009
43
- boys = Book.create! :title => 'Anansi Boys', :year => 2005
41
+ gods = Book.create! :title => 'American Gods', :publishing_year => 2001
42
+ grave = Book.create! :title => 'The Graveyard Book', :publishing_year => 2009
43
+ boys = Book.create! :title => 'Anansi Boys', :publishing_year => 2005
44
44
  index
45
45
 
46
46
  expect(Book.search(
47
- :select => '*, year MOD 2004 as mod_year', :order => 'mod_year ASC'
47
+ :select => '*, publishing_year MOD 2004 as mod_year', :order => 'mod_year ASC'
48
48
  ).to_a).to eq([boys, grave, gods])
49
49
  end
50
50
  end
@@ -4,39 +4,39 @@ require 'acceptance/spec_helper'
4
4
 
5
5
  describe 'Sphinx scopes', :live => true do
6
6
  it "allows calling sphinx scopes from models" do
7
- gods = Book.create! :title => 'American Gods', :year => 2001
8
- boys = Book.create! :title => 'Anansi Boys', :year => 2005
9
- grave = Book.create! :title => 'The Graveyard Book', :year => 2009
7
+ gods = Book.create! :title => 'American Gods', :publishing_year => 2001
8
+ boys = Book.create! :title => 'Anansi Boys', :publishing_year => 2005
9
+ grave = Book.create! :title => 'The Graveyard Book', :publishing_year => 2009
10
10
  index
11
11
 
12
- expect(Book.by_year(2009).to_a).to eq([grave])
12
+ expect(Book.by_publishing_year(2009).to_a).to eq([grave])
13
13
  end
14
14
 
15
15
  it "allows scopes to return both query and options" do
16
- gods = Book.create! :title => 'American Gods', :year => 2001
17
- boys = Book.create! :title => 'Anansi Boys', :year => 2005
18
- grave = Book.create! :title => 'The Graveyard Book', :year => 2009
16
+ gods = Book.create! :title => 'American Gods', :publishing_year => 2001
17
+ boys = Book.create! :title => 'Anansi Boys', :publishing_year => 2005
18
+ grave = Book.create! :title => 'The Graveyard Book', :publishing_year => 2009
19
19
  index
20
20
 
21
- expect(Book.by_query_and_year('Graveyard', 2009).to_a).to eq([grave])
21
+ expect(Book.by_query_and_publishing_year('Graveyard', 2009).to_a).to eq([grave])
22
22
  end
23
23
 
24
24
  it "allows chaining of scopes" do
25
- gods = Book.create! :title => 'American Gods', :year => 2001
26
- boys = Book.create! :title => 'Anansi Boys', :year => 2005
27
- grave = Book.create! :title => 'The Graveyard Book', :year => 2009
25
+ gods = Book.create! :title => 'American Gods', :publishing_year => 2001
26
+ boys = Book.create! :title => 'Anansi Boys', :publishing_year => 2005
27
+ grave = Book.create! :title => 'The Graveyard Book', :publishing_year => 2009
28
28
  index
29
29
 
30
- expect(Book.by_year(2001..2005).ordered.to_a).to eq([boys, gods])
30
+ expect(Book.by_publishing_year(2001..2005).ordered.to_a).to eq([boys, gods])
31
31
  end
32
32
 
33
33
  it "allows chaining of scopes that include queries" do
34
- gods = Book.create! :title => 'American Gods', :year => 2001
35
- boys = Book.create! :title => 'Anansi Boys', :year => 2005
36
- grave = Book.create! :title => 'The Graveyard Book', :year => 2009
34
+ gods = Book.create! :title => 'American Gods', :publishing_year => 2001
35
+ boys = Book.create! :title => 'Anansi Boys', :publishing_year => 2005
36
+ grave = Book.create! :title => 'The Graveyard Book', :publishing_year => 2009
37
37
  index
38
38
 
39
- expect(Book.by_year(2001).by_query_and_year('Graveyard', 2009).to_a).
39
+ expect(Book.by_publishing_year(2001).by_query_and_publishing_year('Graveyard', 2009).to_a).
40
40
  to eq([grave])
41
41
  end
42
42
 
@@ -77,4 +77,11 @@ describe 'Sphinx scopes', :live => true do
77
77
  ThinkingSphinx::PopulatedResultsError
78
78
  )
79
79
  end
80
+
81
+ it "handles a chainable 'none' scope and returns nothing" do
82
+ Book.create! :title => 'Small Gods'
83
+ index
84
+
85
+ expect(Book.by_query('gods').none).to be_empty
86
+ end
80
87
  end
@@ -23,3 +23,9 @@ ThinkingSphinx::Index.define :article, :with => :active_record,
23
23
 
24
24
  set_property :morphology => 'stem_en'
25
25
  end
26
+
27
+ ThinkingSphinx::Index.define :article, :name => :published_articles, :with => :real_time do
28
+ indexes title, content
29
+
30
+ scope { Article.where :published => true }
31
+ end
@@ -6,6 +6,6 @@ ThinkingSphinx::Index.define :book, :with => :active_record, :delta => true do
6
6
  indexes [title, author], :as => :info
7
7
  indexes blurb_file, :file => true
8
8
 
9
- has year
9
+ has publishing_year
10
10
  has created_at, :type => :timestamp
11
11
  end
@@ -8,11 +8,11 @@ class Book < ActiveRecord::Base
8
8
  ThinkingSphinx::Callbacks.append(self, :behaviours => [:sql, :deltas])
9
9
 
10
10
  sphinx_scope(:by_query) { |query| query }
11
- sphinx_scope(:by_year) do |year|
12
- {:with => {:year => year}}
11
+ sphinx_scope(:by_publishing_year) do |year|
12
+ {:with => {:publishing_year => year}}
13
13
  end
14
- sphinx_scope(:by_query_and_year) do |query, year|
15
- [query, {:with => {:year =>year}}]
14
+ sphinx_scope(:by_query_and_publishing_year) do |query, year|
15
+ [query, {:with => {:publishing_year =>year}}]
16
16
  end
17
- sphinx_scope(:ordered) { {:order => 'year DESC'} }
17
+ sphinx_scope(:ordered) { {:order => 'publishing_year DESC'} }
18
18
  end
@@ -39,7 +39,7 @@ ActiveRecord::Schema.define do
39
39
  create_table(:books, :force => true) do |t|
40
40
  t.string :title
41
41
  t.string :author
42
- t.integer :year
42
+ t.integer :publishing_year
43
43
  t.string :blurb_file
44
44
  t.boolean :delta, :default => true, :null => false
45
45
  t.string :type, :default => 'Book', :null => false
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'bundler'
5
+ require 'logger'
5
6
 
6
7
  Bundler.require :default, :development
7
8
 
@@ -60,7 +60,7 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks do
60
60
 
61
61
  it "builds an update query with only updateable attributes that have changed" do
62
62
  expect(Riddle::Query).to receive(:update).
63
- with('article_core', 3, 'bar' => 7).and_return('SphinxQL')
63
+ with('article_core', 3, { 'bar' => 7 }).and_return('SphinxQL')
64
64
 
65
65
  callbacks.after_update
66
66
  end
@@ -93,7 +93,7 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
93
93
 
94
94
  it "passes through options to the attribute" do
95
95
  expect(ThinkingSphinx::ActiveRecord::Attribute).to receive(:new).
96
- with(model, column, :as => :other_name).and_return(attribute)
96
+ with(model, column, { :as => :other_name }).and_return(attribute)
97
97
 
98
98
  instance.has column, :as => :other_name
99
99
  end
@@ -141,7 +141,7 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
141
141
 
142
142
  it "passes through options to the field" do
143
143
  expect(ThinkingSphinx::ActiveRecord::Field).to receive(:new).
144
- with(model, column, :as => :other_name).and_return(field)
144
+ with(model, column, { :as => :other_name }).and_return(field)
145
145
 
146
146
  instance.indexes column, :as => :other_name
147
147
  end
@@ -230,19 +230,19 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
230
230
  end
231
231
 
232
232
  it "sends through a hash if provided" do
233
- expect(source).to receive(:set_database_settings).with(:foo => :bar)
233
+ expect(source).to receive(:set_database_settings).with({ :foo => :bar })
234
234
 
235
235
  instance.set_database :foo => :bar
236
236
  end
237
237
 
238
238
  it "finds the environment settings if given a string key" do
239
- expect(source).to receive(:set_database_settings).with(:baz => 'qux')
239
+ expect(source).to receive(:set_database_settings).with({ :baz => 'qux' })
240
240
 
241
241
  instance.set_database 'other'
242
242
  end
243
243
 
244
244
  it "finds the environment settings if given a symbol key" do
245
- expect(source).to receive(:set_database_settings).with(:baz => 'qux')
245
+ expect(source).to receive(:set_database_settings).with({ :baz => 'qux' })
246
246
 
247
247
  instance.set_database :other
248
248
  end
@@ -17,7 +17,7 @@ RSpec.describe ThinkingSphinx::Commands::ClearRealTime do
17
17
  allow(Dir).to receive(:[]).with('/path/to/my/index/parts.*').
18
18
  and_return(['parts.a', 'parts.b'])
19
19
 
20
- allow(FileUtils).to receive_messages :rm_r => true,
20
+ allow(FileUtils).to receive_messages :rm_rf => true,
21
21
  :rm => true
22
22
  allow(File).to receive_messages :exist? => true
23
23
  end
@@ -30,7 +30,7 @@ RSpec.describe ThinkingSphinx::Commands::ClearRealTime do
30
30
  end
31
31
 
32
32
  it "removes the directory for the binlog files" do
33
- expect(FileUtils).to receive(:rm_r).with('/path/to/binlog')
33
+ expect(FileUtils).to receive(:rm_rf).with('/path/to/binlog')
34
34
 
35
35
  command.call
36
36
  end
@@ -24,7 +24,7 @@ RSpec.describe ThinkingSphinx::Commands::ClearSQL do
24
24
  allow(Dir).to receive(:[]).with('/path/to/indices/ts-*.tmp').
25
25
  and_return(['/path/to/indices/ts-foo.tmp'])
26
26
 
27
- allow(FileUtils).to receive_messages :rm_r => true, :rm => true
27
+ allow(FileUtils).to receive_messages :rm_rf => true, :rm => true
28
28
  allow(File).to receive_messages :exist? => true
29
29
  end
30
30
 
@@ -45,7 +45,7 @@ RSpec.describe ThinkingSphinx::Commands::ClearSQL do
45
45
  end
46
46
 
47
47
  it "removes any indexing guard files" do
48
- expect(FileUtils).to receive(:rm_r).with(["/path/to/indices/ts-foo.tmp"])
48
+ expect(FileUtils).to receive(:rm_rf).with(["/path/to/indices/ts-foo.tmp"])
49
49
 
50
50
  command.call
51
51
  end
@@ -6,7 +6,7 @@ RSpec.describe ThinkingSphinx::Configuration::MinimumFields do
6
6
  let(:indices) { [index_a, index_b] }
7
7
  let(:index_a) { double 'Index A', :model => model_a, :type => 'plain',
8
8
  :sources => [double(:fields => [field_a1, field_a2])] }
9
- let(:index_b) { double 'Index B', :model => model_a, :type => 'rt',
9
+ let(:index_b) { double 'Index B', :model => model_b, :type => 'rt',
10
10
  :fields => [field_b1, field_b2] }
11
11
  let(:field_a1) { double :name => 'sphinx_internal_class_name' }
12
12
  let(:field_a2) { double :name => 'name' }
@@ -38,7 +38,7 @@ RSpec.describe ThinkingSphinx::Configuration::MinimumFields do
38
38
  expect(index_b.fields).to eq([field_b2])
39
39
  end
40
40
 
41
- it 'removes the class name fields only for the indices without type column' do
41
+ it 'removes the class name fields only for the rt indices without type column' do
42
42
  allow(model_a).to receive(:column_names).and_return(['id', 'name', 'type'])
43
43
  allow(model_b).to receive(:column_names).and_return(['id', 'name'])
44
44
 
@@ -47,4 +47,14 @@ RSpec.describe ThinkingSphinx::Configuration::MinimumFields do
47
47
  expect(index_a.sources.first.fields).to eq([field_a1, field_a2])
48
48
  expect(index_b.fields).to eq([field_b2])
49
49
  end
50
+
51
+ it 'removes the class name fields only for the plain indices without type column' do
52
+ allow(model_a).to receive(:column_names).and_return(['id', 'name'])
53
+ allow(model_b).to receive(:column_names).and_return(['id', 'name', 'type'])
54
+
55
+ subject.reconcile
56
+
57
+ expect(index_a.sources.first.fields).to eq([field_a2])
58
+ expect(index_b.fields).to eq([field_b1, field_b2])
59
+ end
50
60
  end
@@ -28,9 +28,10 @@ describe ThinkingSphinx::Excerpter do
28
28
  :before_match => '<b>', :chunk_separator => ' -- ')
29
29
 
30
30
  expect(Riddle::Query).to receive(:snippets).
31
- with('all of the words', 'index', 'all words',
31
+ with('all of the words', 'index', 'all words', {
32
32
  :before_match => '<b>', :after_match => '</span>',
33
- :chunk_separator => ' -- ').
33
+ :chunk_separator => ' -- '
34
+ }).
34
35
  and_return('CALL SNIPPETS')
35
36
 
36
37
  excerpter.excerpt!('all of the words')
@@ -19,7 +19,7 @@ describe ThinkingSphinx::Index do
19
19
 
20
20
  it "creates an ActiveRecord index" do
21
21
  expect(ThinkingSphinx::ActiveRecord::Index).to receive(:new).
22
- with(:user, :with => :active_record).and_return index
22
+ with(:user, { :with => :active_record }).and_return index
23
23
 
24
24
  ThinkingSphinx::Index.define(:user, :with => :active_record)
25
25
  end
@@ -100,7 +100,7 @@ describe ThinkingSphinx::Index do
100
100
 
101
101
  it "creates a real-time index" do
102
102
  expect(ThinkingSphinx::RealTime::Index).to receive(:new).
103
- with(:user, :with => :real_time).and_return index
103
+ with(:user, { :with => :real_time }).and_return index
104
104
 
105
105
  ThinkingSphinx::Index.define(:user, :with => :real_time)
106
106
  end