thinking-sphinx 3.2.0 → 3.3.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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -2
- data/Appraisals +13 -0
- data/Gemfile +2 -1
- data/HISTORY +19 -0
- data/README.textile +3 -2
- data/gemfiles/rails_3_2.gemfile +2 -1
- data/gemfiles/rails_4_0.gemfile +2 -1
- data/gemfiles/rails_4_1.gemfile +2 -1
- data/gemfiles/rails_4_2.gemfile +2 -1
- data/gemfiles/rails_5_0.gemfile +12 -0
- data/lib/thinking_sphinx.rb +2 -0
- data/lib/thinking_sphinx/active_record/attribute/type.rb +17 -3
- data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +12 -4
- data/lib/thinking_sphinx/active_record/database_adapters.rb +1 -1
- data/lib/thinking_sphinx/active_record/sql_builder/query.rb +4 -0
- data/lib/thinking_sphinx/active_record/sql_source.rb +1 -1
- data/lib/thinking_sphinx/configuration.rb +3 -2
- data/lib/thinking_sphinx/connection.rb +23 -10
- data/lib/thinking_sphinx/deltas/index_job.rb +6 -2
- data/lib/thinking_sphinx/errors.rb +25 -0
- data/lib/thinking_sphinx/middlewares/active_record_translator.rb +14 -2
- data/lib/thinking_sphinx/railtie.rb +1 -1
- data/lib/thinking_sphinx/rake_interface.rb +71 -23
- data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +15 -7
- data/lib/thinking_sphinx/real_time/populator.rb +3 -3
- data/lib/thinking_sphinx/tasks.rb +7 -8
- data/lib/thinking_sphinx/wildcard.rb +1 -1
- data/spec/acceptance/association_scoping_spec.rb +5 -5
- data/spec/acceptance/attribute_access_spec.rb +4 -4
- data/spec/acceptance/attribute_updates_spec.rb +3 -3
- data/spec/acceptance/batch_searching_spec.rb +4 -4
- data/spec/acceptance/big_integers_spec.rb +6 -6
- data/spec/acceptance/connection_spec.rb +23 -0
- data/spec/acceptance/excerpts_spec.rb +8 -8
- data/spec/acceptance/facets_spec.rb +13 -13
- data/spec/acceptance/geosearching_spec.rb +8 -8
- data/spec/acceptance/grouping_by_attributes_spec.rb +10 -10
- data/spec/acceptance/index_options_spec.rb +16 -16
- data/spec/acceptance/indexing_spec.rb +3 -3
- data/spec/acceptance/paginating_search_results_spec.rb +3 -3
- data/spec/acceptance/real_time_updates_spec.rb +4 -4
- data/spec/acceptance/remove_deleted_records_spec.rb +12 -12
- data/spec/acceptance/search_counts_spec.rb +2 -2
- data/spec/acceptance/search_for_just_ids_spec.rb +2 -2
- data/spec/acceptance/searching_across_models_spec.rb +6 -6
- data/spec/acceptance/searching_across_schemas_spec.rb +10 -10
- data/spec/acceptance/searching_on_fields_spec.rb +9 -9
- data/spec/acceptance/searching_with_filters_spec.rb +16 -16
- data/spec/acceptance/searching_with_sti_spec.rb +9 -9
- data/spec/acceptance/searching_within_a_model_spec.rb +17 -17
- data/spec/acceptance/sorting_search_results_spec.rb +6 -6
- data/spec/acceptance/specifying_sql_spec.rb +62 -62
- data/spec/acceptance/sphinx_scopes_spec.rb +9 -9
- data/spec/acceptance/sql_deltas_spec.rb +7 -7
- data/spec/acceptance/support/database_cleaner.rb +1 -1
- data/spec/acceptance/support/sphinx_controller.rb +4 -1
- data/spec/acceptance/support/sphinx_helpers.rb +4 -0
- data/spec/acceptance/suspended_deltas_spec.rb +9 -9
- data/spec/internal/app/indices/article_index.rb +2 -2
- data/spec/internal/app/indices/book_index.rb +2 -1
- data/spec/internal/app/indices/product_index.rb +0 -2
- data/spec/internal/app/models/categorisation.rb +8 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/support/json_column.rb +5 -1
- data/spec/support/multi_schema.rb +3 -1
- data/spec/support/sphinx_yaml_helpers.rb +1 -1
- data/spec/thinking_sphinx/active_record/association_spec.rb +1 -1
- data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +41 -38
- data/spec/thinking_sphinx/active_record/base_spec.rb +29 -29
- data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +10 -10
- data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +48 -25
- data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +8 -8
- data/spec/thinking_sphinx/active_record/column_spec.rb +13 -13
- data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +5 -5
- data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +5 -5
- data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +11 -11
- data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +13 -13
- data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +48 -48
- data/spec/thinking_sphinx/active_record/field_spec.rb +7 -7
- data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +32 -32
- data/spec/thinking_sphinx/active_record/index_spec.rb +35 -36
- data/spec/thinking_sphinx/active_record/interpreter_spec.rb +51 -51
- data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +14 -14
- data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +67 -67
- data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +140 -140
- data/spec/thinking_sphinx/active_record/sql_source_spec.rb +97 -95
- data/spec/thinking_sphinx/configuration_spec.rb +81 -81
- data/spec/thinking_sphinx/connection_spec.rb +13 -13
- data/spec/thinking_sphinx/deletion_spec.rb +11 -11
- data/spec/thinking_sphinx/deltas/default_delta_spec.rb +20 -20
- data/spec/thinking_sphinx/deltas_spec.rb +12 -12
- data/spec/thinking_sphinx/errors_spec.rb +30 -30
- data/spec/thinking_sphinx/excerpter_spec.rb +7 -7
- data/spec/thinking_sphinx/facet_search_spec.rb +16 -16
- data/spec/thinking_sphinx/index_set_spec.rb +7 -7
- data/spec/thinking_sphinx/index_spec.rb +24 -24
- data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +20 -20
- data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +18 -18
- data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +22 -22
- data/spec/thinking_sphinx/middlewares/geographer_spec.rb +9 -9
- data/spec/thinking_sphinx/middlewares/glazier_spec.rb +4 -4
- data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +7 -7
- data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +53 -53
- data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +5 -5
- data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +15 -15
- data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +1 -1
- data/spec/thinking_sphinx/panes/distance_pane_spec.rb +4 -4
- data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +5 -5
- data/spec/thinking_sphinx/panes/weight_pane_spec.rb +1 -1
- data/spec/thinking_sphinx/rake_interface_spec.rb +66 -53
- data/spec/thinking_sphinx/real_time/attribute_spec.rb +13 -13
- data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +107 -23
- data/spec/thinking_sphinx/real_time/field_spec.rb +14 -14
- data/spec/thinking_sphinx/real_time/index_spec.rb +29 -30
- data/spec/thinking_sphinx/real_time/interpreter_spec.rb +30 -30
- data/spec/thinking_sphinx/scopes_spec.rb +5 -5
- data/spec/thinking_sphinx/search/glaze_spec.rb +15 -15
- data/spec/thinking_sphinx/search/query_spec.rb +10 -10
- data/spec/thinking_sphinx/search_spec.rb +28 -28
- data/spec/thinking_sphinx/wildcard_spec.rb +16 -11
- data/spec/thinking_sphinx_spec.rb +6 -6
- data/thinking-sphinx.gemspec +4 -4
- metadata +12 -9
|
@@ -5,7 +5,7 @@ describe 'Get search result counts', :live => true do
|
|
|
5
5
|
4.times { |i| Article.create :title => "Article #{i}" }
|
|
6
6
|
index
|
|
7
7
|
|
|
8
|
-
Article.search_count.
|
|
8
|
+
expect(Article.search_count).to eq(4)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
it "returns counts across all models" do
|
|
@@ -13,6 +13,6 @@ describe 'Get search result counts', :live => true do
|
|
|
13
13
|
2.times { |i| Book.create :title => "Book #{i}" }
|
|
14
14
|
index
|
|
15
15
|
|
|
16
|
-
ThinkingSphinx.count.
|
|
16
|
+
expect(ThinkingSphinx.count).to eq(5)
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -6,7 +6,7 @@ describe 'Searching for just instance Ids', :live => true do
|
|
|
6
6
|
waffles = Article.create! :title => 'Waffles'
|
|
7
7
|
index
|
|
8
8
|
|
|
9
|
-
Article.search_for_ids('pancakes').to_a.
|
|
9
|
+
expect(Article.search_for_ids('pancakes').to_a).to eq([pancakes.id])
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "works across the global context" do
|
|
@@ -14,6 +14,6 @@ describe 'Searching for just instance Ids', :live => true do
|
|
|
14
14
|
book = Book.create! :title => 'American Gods'
|
|
15
15
|
index
|
|
16
16
|
|
|
17
|
-
ThinkingSphinx.search_for_ids.to_a.
|
|
17
|
+
expect(ThinkingSphinx.search_for_ids.to_a).to match_array([article.id, book.id])
|
|
18
18
|
end
|
|
19
19
|
end
|
|
@@ -5,7 +5,7 @@ describe 'Searching across models', :live => true do
|
|
|
5
5
|
article = Article.create! :title => 'Pancakes'
|
|
6
6
|
index
|
|
7
7
|
|
|
8
|
-
ThinkingSphinx.search.first.
|
|
8
|
+
expect(ThinkingSphinx.search.first).to eq(article)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
it "returns results matching the given query" do
|
|
@@ -14,8 +14,8 @@ describe 'Searching across models', :live => true do
|
|
|
14
14
|
index
|
|
15
15
|
|
|
16
16
|
articles = ThinkingSphinx.search 'pancakes'
|
|
17
|
-
articles.
|
|
18
|
-
articles.
|
|
17
|
+
expect(articles).to include(pancakes)
|
|
18
|
+
expect(articles).not_to include(waffles)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "handles results from different models" do
|
|
@@ -23,7 +23,7 @@ describe 'Searching across models', :live => true do
|
|
|
23
23
|
book = Book.create! :title => 'American Gods'
|
|
24
24
|
index
|
|
25
25
|
|
|
26
|
-
ThinkingSphinx.search.to_a.
|
|
26
|
+
expect(ThinkingSphinx.search.to_a).to match_array([article, book])
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
it "filters by multiple classes" do
|
|
@@ -32,7 +32,7 @@ describe 'Searching across models', :live => true do
|
|
|
32
32
|
user = User.create! :name => 'Pat'
|
|
33
33
|
index
|
|
34
34
|
|
|
35
|
-
ThinkingSphinx.search(:classes => [User, Article]).to_a.
|
|
36
|
-
|
|
35
|
+
expect(ThinkingSphinx.search(:classes => [User, Article]).to_a).
|
|
36
|
+
to match_array([article, user])
|
|
37
37
|
end
|
|
38
38
|
end
|
|
@@ -16,23 +16,23 @@ describe 'Searching across PostgreSQL schemas', :live => true do
|
|
|
16
16
|
it 'can distinguish between objects with the same primary key' do
|
|
17
17
|
multi_schema.switch :public
|
|
18
18
|
jekyll = Product.create name: 'Doctor Jekyll'
|
|
19
|
-
Product.search('Jekyll', :retry_stale => false).to_a.
|
|
20
|
-
Product.search(:retry_stale => false).to_a.
|
|
19
|
+
expect(Product.search('Jekyll', :retry_stale => false).to_a).to eq([jekyll])
|
|
20
|
+
expect(Product.search(:retry_stale => false).to_a).to eq([jekyll])
|
|
21
21
|
|
|
22
22
|
multi_schema.switch :thinking_sphinx
|
|
23
23
|
hyde = Product.create name: 'Mister Hyde'
|
|
24
|
-
Product.search('Jekyll', :retry_stale => false).to_a.
|
|
25
|
-
Product.search('Hyde', :retry_stale => false).to_a.
|
|
26
|
-
Product.search(:retry_stale => false).to_a.
|
|
24
|
+
expect(Product.search('Jekyll', :retry_stale => false).to_a).to eq([])
|
|
25
|
+
expect(Product.search('Hyde', :retry_stale => false).to_a).to eq([hyde])
|
|
26
|
+
expect(Product.search(:retry_stale => false).to_a).to eq([hyde])
|
|
27
27
|
|
|
28
28
|
multi_schema.switch :public
|
|
29
|
-
Product.search('Jekyll', :retry_stale => false).to_a.
|
|
30
|
-
Product.search(:retry_stale => false).to_a.
|
|
31
|
-
Product.search('Hyde', :retry_stale => false).to_a.
|
|
29
|
+
expect(Product.search('Jekyll', :retry_stale => false).to_a).to eq([jekyll])
|
|
30
|
+
expect(Product.search(:retry_stale => false).to_a).to eq([jekyll])
|
|
31
|
+
expect(Product.search('Hyde', :retry_stale => false).to_a).to eq([])
|
|
32
32
|
|
|
33
|
-
Product.search(
|
|
33
|
+
expect(Product.search(
|
|
34
34
|
:middleware => ThinkingSphinx::Middlewares::RAW_ONLY,
|
|
35
35
|
:indices => ['product_core', 'product_two_core']
|
|
36
|
-
).to_a.length.
|
|
36
|
+
).to_a.length).to eq(2)
|
|
37
37
|
end
|
|
38
38
|
end if multi_schema.active?
|
|
@@ -8,8 +8,8 @@ describe 'Searching on fields', :live => true do
|
|
|
8
8
|
index
|
|
9
9
|
|
|
10
10
|
articles = Article.search :conditions => {:title => 'pancakes'}
|
|
11
|
-
articles.
|
|
12
|
-
articles.
|
|
11
|
+
expect(articles).to include(pancakes)
|
|
12
|
+
expect(articles).not_to include(waffles)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it "limits results for a field from an association" do
|
|
@@ -17,7 +17,7 @@ describe 'Searching on fields', :live => true do
|
|
|
17
17
|
pancakes = Article.create! :title => 'Pancakes', :user => user
|
|
18
18
|
index
|
|
19
19
|
|
|
20
|
-
Article.search(:conditions => {:user => 'pat'}).first.
|
|
20
|
+
expect(Article.search(:conditions => {:user => 'pat'}).first).to eq(pancakes)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
it "returns results with matches from grouped fields" do
|
|
@@ -26,23 +26,23 @@ describe 'Searching on fields', :live => true do
|
|
|
26
26
|
waffles = Article.create! :title => 'Waffles', :user => user
|
|
27
27
|
index
|
|
28
28
|
|
|
29
|
-
Article.search('waffles', :conditions => {:title => 'pancakes'}).to_a.
|
|
30
|
-
|
|
29
|
+
expect(Article.search('waffles', :conditions => {:title => 'pancakes'}).to_a).
|
|
30
|
+
to eq([pancakes])
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
it "returns results with matches from concatenated columns in a field" do
|
|
34
34
|
book = Book.create! :title => 'Night Watch', :author => 'Terry Pratchett'
|
|
35
35
|
index
|
|
36
36
|
|
|
37
|
-
Book.search(:conditions => {:info => 'Night Pratchett'}).to_a.
|
|
38
|
-
|
|
37
|
+
expect(Book.search(:conditions => {:info => 'Night Pratchett'}).to_a).
|
|
38
|
+
to eq([book])
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "handles NULLs in concatenated fields" do
|
|
42
42
|
book = Book.create! :title => 'Night Watch'
|
|
43
43
|
index
|
|
44
44
|
|
|
45
|
-
Book.search(:conditions => {:info => 'Night Watch'}).to_a.
|
|
45
|
+
expect(Book.search(:conditions => {:info => 'Night Watch'}).to_a).to eq([book])
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it "returns results with matches from file fields" do
|
|
@@ -52,6 +52,6 @@ describe 'Searching on fields', :live => true do
|
|
|
52
52
|
book = Book.create! :title => 'Accelerando', :blurb_file => file_path.to_s
|
|
53
53
|
index
|
|
54
54
|
|
|
55
|
-
Book.search('cyberpunk').to_a.
|
|
55
|
+
expect(Book.search('cyberpunk').to_a).to eq([book])
|
|
56
56
|
end
|
|
57
57
|
end
|
|
@@ -6,7 +6,7 @@ describe 'Searching with filters', :live => true do
|
|
|
6
6
|
waffles = Article.create! :title => 'Waffles', :published => false
|
|
7
7
|
index
|
|
8
8
|
|
|
9
|
-
Article.search(:with => {:published => true}).to_a.
|
|
9
|
+
expect(Article.search(:with => {:published => true}).to_a).to eq([pancakes])
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "limits results by an array of values" do
|
|
@@ -15,7 +15,7 @@ describe 'Searching with filters', :live => true do
|
|
|
15
15
|
grave = Book.create! :title => 'The Graveyard Book', :year => 2009
|
|
16
16
|
index
|
|
17
17
|
|
|
18
|
-
Book.search(:with => {:year => [2001, 2005]}).to_a.
|
|
18
|
+
expect(Book.search(:with => {:year => [2001, 2005]}).to_a).to eq([gods, boys])
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "limits results by a ranged filter" do
|
|
@@ -28,8 +28,8 @@ describe 'Searching with filters', :live => true do
|
|
|
28
28
|
grave.update_column :created_at, 1.day.ago
|
|
29
29
|
index
|
|
30
30
|
|
|
31
|
-
Book.search(:with => {:created_at => 6.days.ago..2.days.ago}).to_a.
|
|
32
|
-
|
|
31
|
+
expect(Book.search(:with => {:created_at => 6.days.ago..2.days.ago}).to_a).
|
|
32
|
+
to eq([gods, boys])
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "limits results by exclusive filters on single values" do
|
|
@@ -37,7 +37,7 @@ describe 'Searching with filters', :live => true do
|
|
|
37
37
|
waffles = Article.create! :title => 'Waffles', :published => false
|
|
38
38
|
index
|
|
39
39
|
|
|
40
|
-
Article.search(:without => {:published => true}).to_a.
|
|
40
|
+
expect(Article.search(:without => {:published => true}).to_a).to eq([waffles])
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
it "limits results by exclusive filters on arrays of values" do
|
|
@@ -46,7 +46,7 @@ describe 'Searching with filters', :live => true do
|
|
|
46
46
|
grave = Book.create! :title => 'The Graveyard Book', :year => 2009
|
|
47
47
|
index
|
|
48
48
|
|
|
49
|
-
Book.search(:without => {:year => [2001, 2005]}).to_a.
|
|
49
|
+
expect(Book.search(:without => {:year => [2001, 2005]}).to_a).to eq([grave])
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
it "limits results by ranged filters on timestamp MVAs" do
|
|
@@ -64,9 +64,9 @@ describe 'Searching with filters', :live => true do
|
|
|
64
64
|
|
|
65
65
|
index
|
|
66
66
|
|
|
67
|
-
Article.search(
|
|
67
|
+
expect(Article.search(
|
|
68
68
|
:with => {:taggings_at => 1.days.ago..1.day.from_now}
|
|
69
|
-
).to_a.
|
|
69
|
+
).to_a).to eq([pancakes])
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
it "takes into account local timezones for timestamps" do
|
|
@@ -84,9 +84,9 @@ describe 'Searching with filters', :live => true do
|
|
|
84
84
|
|
|
85
85
|
index
|
|
86
86
|
|
|
87
|
-
Article.search(
|
|
87
|
+
expect(Article.search(
|
|
88
88
|
:with => {:taggings_at => 2.minutes.ago..Time.zone.now}
|
|
89
|
-
).to_a.
|
|
89
|
+
).to_a).to eq([pancakes])
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
it "limits results with MVAs having all of the given values" do
|
|
@@ -103,13 +103,13 @@ describe 'Searching with filters', :live => true do
|
|
|
103
103
|
index
|
|
104
104
|
|
|
105
105
|
articles = Article.search :with_all => {:tag_ids => [food.id, flat.id]}
|
|
106
|
-
articles.to_a.
|
|
106
|
+
expect(articles.to_a).to eq([pancakes])
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
it "limits results with MVAs that don't contain all the given values" do
|
|
110
110
|
# Matching results may have some of the given values, but cannot have all
|
|
111
111
|
# of them. Certainly an edge case.
|
|
112
|
-
|
|
112
|
+
skip "SphinxQL doesn't yet support OR in its WHERE clause"
|
|
113
113
|
|
|
114
114
|
pancakes = Article.create :title => 'Pancakes'
|
|
115
115
|
waffles = Article.create :title => 'Waffles'
|
|
@@ -124,7 +124,7 @@ describe 'Searching with filters', :live => true do
|
|
|
124
124
|
index
|
|
125
125
|
|
|
126
126
|
articles = Article.search :without_all => {:tag_ids => [food.id, flat.id]}
|
|
127
|
-
articles.to_a.
|
|
127
|
+
expect(articles.to_a).to eq([waffles])
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
it "limits results on real-time indices with multi-value integer attributes" do
|
|
@@ -139,7 +139,7 @@ describe 'Searching with filters', :live => true do
|
|
|
139
139
|
waffles.categories << food
|
|
140
140
|
|
|
141
141
|
products = Product.search :with => {:category_ids => [flat.id]}
|
|
142
|
-
products.to_a.
|
|
142
|
+
expect(products.to_a).to eq([pancakes])
|
|
143
143
|
end
|
|
144
144
|
|
|
145
145
|
it 'searches with real-time JSON attributes' do
|
|
@@ -149,9 +149,9 @@ describe 'Searching with filters', :live => true do
|
|
|
149
149
|
:options => {'chocolate' => 1, 'sugar' => 1, :number => 1}
|
|
150
150
|
|
|
151
151
|
products = Product.search :with => {"options.lemon" => 1}
|
|
152
|
-
products.to_a.
|
|
152
|
+
expect(products.to_a).to eq([pancakes])
|
|
153
153
|
|
|
154
154
|
products = Product.search :with => {"options.sugar" => 1}
|
|
155
|
-
products.to_a.
|
|
155
|
+
expect(products.to_a).to eq([pancakes, waffles])
|
|
156
156
|
end if JSONColumn.call
|
|
157
157
|
end
|
|
@@ -6,7 +6,7 @@ describe 'Searching across STI models', :live => true do
|
|
|
6
6
|
duck = Bird.create :name => 'Duck'
|
|
7
7
|
index
|
|
8
8
|
|
|
9
|
-
Animal.search(:indices => ['animal_core']).to_a.
|
|
9
|
+
expect(Animal.search(:indices => ['animal_core']).to_a).to eq([platypus, duck])
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "limits results based on subclasses" do
|
|
@@ -14,7 +14,7 @@ describe 'Searching across STI models', :live => true do
|
|
|
14
14
|
duck = Bird.create :name => 'Duck'
|
|
15
15
|
index
|
|
16
16
|
|
|
17
|
-
Bird.search(:indices => ['animal_core']).to_a.
|
|
17
|
+
expect(Bird.search(:indices => ['animal_core']).to_a).to eq([duck])
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it "returns results for deeper subclasses when searching on their parents" do
|
|
@@ -23,7 +23,7 @@ describe 'Searching across STI models', :live => true do
|
|
|
23
23
|
emu = FlightlessBird.create :name => 'Emu'
|
|
24
24
|
index
|
|
25
25
|
|
|
26
|
-
Bird.search(:indices => ['animal_core']).to_a.
|
|
26
|
+
expect(Bird.search(:indices => ['animal_core']).to_a).to eq([duck, emu])
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
it "returns results for deeper subclasses" do
|
|
@@ -32,7 +32,7 @@ describe 'Searching across STI models', :live => true do
|
|
|
32
32
|
emu = FlightlessBird.create :name => 'Emu'
|
|
33
33
|
index
|
|
34
34
|
|
|
35
|
-
FlightlessBird.search(:indices => ['animal_core']).to_a.
|
|
35
|
+
expect(FlightlessBird.search(:indices => ['animal_core']).to_a).to eq([emu])
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it "filters out sibling subclasses" do
|
|
@@ -41,7 +41,7 @@ describe 'Searching across STI models', :live => true do
|
|
|
41
41
|
otter = Mammal.create :name => 'Otter'
|
|
42
42
|
index
|
|
43
43
|
|
|
44
|
-
Bird.search(:indices => ['animal_core']).to_a.
|
|
44
|
+
expect(Bird.search(:indices => ['animal_core']).to_a).to eq([duck])
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
it "obeys :classes if supplied" do
|
|
@@ -50,18 +50,18 @@ describe 'Searching across STI models', :live => true do
|
|
|
50
50
|
emu = FlightlessBird.create :name => 'Emu'
|
|
51
51
|
index
|
|
52
52
|
|
|
53
|
-
Bird.search(
|
|
53
|
+
expect(Bird.search(
|
|
54
54
|
:indices => ['animal_core'],
|
|
55
55
|
:skip_sti => true,
|
|
56
56
|
:classes => [Bird, FlightlessBird]
|
|
57
|
-
).to_a.
|
|
57
|
+
).to_a).to eq([duck, emu])
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
it 'finds root objects when type is blank' do
|
|
61
61
|
animal = Animal.create :name => 'Animal', type: ''
|
|
62
62
|
index
|
|
63
63
|
|
|
64
|
-
Animal.search(:indices => ['animal_core']).to_a.
|
|
64
|
+
expect(Animal.search(:indices => ['animal_core']).to_a).to eq([animal])
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it 'allows for indices on mid-hierarchy classes' do
|
|
@@ -69,6 +69,6 @@ describe 'Searching across STI models', :live => true do
|
|
|
69
69
|
emu = FlightlessBird.create :name => 'Emu'
|
|
70
70
|
index
|
|
71
71
|
|
|
72
|
-
Bird.search(:indices => ['bird_core']).to_a.
|
|
72
|
+
expect(Bird.search(:indices => ['bird_core']).to_a).to eq([duck, emu])
|
|
73
73
|
end
|
|
74
74
|
end
|
|
@@ -6,7 +6,7 @@ describe 'Searching within a model', :live => true do
|
|
|
6
6
|
article = Article.create! :title => 'Pancakes'
|
|
7
7
|
index
|
|
8
8
|
|
|
9
|
-
Article.search.first.
|
|
9
|
+
expect(Article.search.first).to eq(article)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "returns results matching the given query" do
|
|
@@ -15,22 +15,22 @@ describe 'Searching within a model', :live => true do
|
|
|
15
15
|
index
|
|
16
16
|
|
|
17
17
|
articles = Article.search 'pancakes'
|
|
18
|
-
articles.
|
|
19
|
-
articles.
|
|
18
|
+
expect(articles).to include(pancakes)
|
|
19
|
+
expect(articles).not_to include(waffles)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "handles unicode characters" do
|
|
23
23
|
istanbul = City.create! :name => 'İstanbul'
|
|
24
24
|
index
|
|
25
25
|
|
|
26
|
-
City.search('İstanbul').to_a.
|
|
26
|
+
expect(City.search('İstanbul').to_a).to eq([istanbul])
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
it "will star provided queries on request" do
|
|
30
30
|
article = Article.create! :title => 'Pancakes'
|
|
31
31
|
index
|
|
32
32
|
|
|
33
|
-
Article.search('cake', :star => true).first.
|
|
33
|
+
expect(Article.search('cake', :star => true).first).to eq(article)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "allows for searching on specific indices" do
|
|
@@ -38,7 +38,7 @@ describe 'Searching within a model', :live => true do
|
|
|
38
38
|
index
|
|
39
39
|
|
|
40
40
|
articles = Article.search('pancake', :indices => ['stemmed_article_core'])
|
|
41
|
-
articles.to_a.
|
|
41
|
+
expect(articles.to_a).to eq([article])
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it "allows for searching on distributed indices" do
|
|
@@ -46,38 +46,38 @@ describe 'Searching within a model', :live => true do
|
|
|
46
46
|
index
|
|
47
47
|
|
|
48
48
|
articles = Article.search('pancake', :indices => ['article'])
|
|
49
|
-
articles.to_a.
|
|
49
|
+
expect(articles.to_a).to eq([article])
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
it "can search on namespaced models" do
|
|
53
53
|
person = Admin::Person.create :name => 'James Bond'
|
|
54
54
|
index
|
|
55
55
|
|
|
56
|
-
Admin::Person.search('Bond').to_a.
|
|
56
|
+
expect(Admin::Person.search('Bond').to_a).to eq([person])
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
it "raises an error if searching through an ActiveRecord scope" do
|
|
60
|
-
|
|
60
|
+
expect {
|
|
61
61
|
City.ordered.search
|
|
62
|
-
}.
|
|
62
|
+
}.to raise_error(ThinkingSphinx::MixedScopesError)
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
it "does not raise an error when searching with a default ActiveRecord scope" do
|
|
66
|
-
|
|
66
|
+
expect {
|
|
67
67
|
User.search
|
|
68
|
-
}.
|
|
68
|
+
}.not_to raise_error
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
it "raises an error when searching with default and applied AR scopes" do
|
|
72
|
-
|
|
72
|
+
expect {
|
|
73
73
|
User.recent.search
|
|
74
|
-
}.
|
|
74
|
+
}.to raise_error(ThinkingSphinx::MixedScopesError)
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
it "raises an error if the model has no indices defined" do
|
|
78
|
-
|
|
78
|
+
expect {
|
|
79
79
|
Category.search.to_a
|
|
80
|
-
}.
|
|
80
|
+
}.to raise_error(ThinkingSphinx::NoIndicesError)
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
83
|
|
|
@@ -85,6 +85,6 @@ describe 'Searching within a model with a realtime index', :live => true do
|
|
|
85
85
|
it "returns results" do
|
|
86
86
|
product = Product.create! :name => 'Widget'
|
|
87
87
|
|
|
88
|
-
Product.search.first.
|
|
88
|
+
expect(Product.search.first).to eq(product)
|
|
89
89
|
end
|
|
90
90
|
end
|