sunspot 2.2.7 → 2.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Appraisals +7 -0
- data/Gemfile +0 -8
- data/gemfiles/.gitkeep +0 -0
- data/lib/sunspot/dsl/scope.rb +6 -1
- data/lib/sunspot/field.rb +11 -0
- data/lib/sunspot/field_factory.rb +6 -2
- data/lib/sunspot/query/bbox.rb +5 -1
- data/lib/sunspot/query/restriction.rb +11 -0
- data/lib/sunspot/search/hit_enumerable.rb +4 -1
- data/lib/sunspot/search/standard_search.rb +2 -3
- data/lib/sunspot/version.rb +1 -1
- data/spec/api/adapters_spec.rb +19 -19
- data/spec/api/batcher_spec.rb +15 -15
- data/spec/api/binding_spec.rb +3 -3
- data/spec/api/class_set_spec.rb +3 -3
- data/spec/api/hit_enumerable_spec.rb +32 -9
- data/spec/api/indexer/attributes_spec.rb +31 -31
- data/spec/api/indexer/batch_spec.rb +8 -7
- data/spec/api/indexer/dynamic_fields_spec.rb +8 -8
- data/spec/api/indexer/fixed_fields_spec.rb +12 -12
- data/spec/api/indexer/fulltext_spec.rb +8 -8
- data/spec/api/indexer/removal_spec.rb +14 -14
- data/spec/api/indexer_spec.rb +2 -2
- data/spec/api/query/advanced_manipulation_examples.rb +3 -3
- data/spec/api/query/connectives_examples.rb +26 -14
- data/spec/api/query/dsl_spec.rb +17 -9
- data/spec/api/query/dynamic_fields_examples.rb +18 -18
- data/spec/api/query/faceting_examples.rb +62 -62
- data/spec/api/query/fulltext_examples.rb +56 -55
- data/spec/api/query/function_spec.rb +26 -26
- data/spec/api/query/geo_examples.rb +6 -6
- data/spec/api/query/group_spec.rb +6 -6
- data/spec/api/query/highlighting_examples.rb +26 -26
- data/spec/api/query/join_spec.rb +2 -2
- data/spec/api/query/more_like_this_spec.rb +29 -29
- data/spec/api/query/ordering_pagination_examples.rb +25 -25
- data/spec/api/query/scope_examples.rb +39 -39
- data/spec/api/query/spatial_examples.rb +3 -3
- data/spec/api/query/spellcheck_examples.rb +3 -3
- data/spec/api/query/standard_spec.rb +1 -1
- data/spec/api/query/stats_examples.rb +8 -8
- data/spec/api/query/text_field_scoping_examples.rb +5 -5
- data/spec/api/query/types_spec.rb +4 -4
- data/spec/api/search/cursor_paginated_collection_spec.rb +12 -12
- data/spec/api/search/dynamic_fields_spec.rb +4 -4
- data/spec/api/search/faceting_spec.rb +55 -52
- data/spec/api/search/highlighting_spec.rb +7 -7
- data/spec/api/search/hits_spec.rb +29 -29
- data/spec/api/search/paginated_collection_spec.rb +18 -18
- data/spec/api/search/results_spec.rb +13 -13
- data/spec/api/search/search_spec.rb +3 -3
- data/spec/api/search/stats_spec.rb +10 -10
- data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +19 -18
- data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +9 -9
- data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +10 -6
- data/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +10 -10
- data/spec/api/session_proxy/sharding_session_proxy_spec.rb +14 -13
- data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +2 -2
- data/spec/api/session_proxy/spec_helper.rb +1 -1
- data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +9 -5
- data/spec/api/session_spec.rb +42 -42
- data/spec/api/sunspot_spec.rb +4 -4
- data/spec/integration/atomic_updates_spec.rb +25 -11
- data/spec/integration/dynamic_fields_spec.rb +10 -10
- data/spec/integration/faceting_spec.rb +39 -39
- data/spec/integration/field_grouping_spec.rb +16 -16
- data/spec/integration/field_lists_spec.rb +41 -0
- data/spec/integration/geospatial_spec.rb +19 -8
- data/spec/integration/highlighting_spec.rb +5 -5
- data/spec/integration/indexing_spec.rb +5 -5
- data/spec/integration/keyword_search_spec.rb +47 -45
- data/spec/integration/local_search_spec.rb +4 -4
- data/spec/integration/more_like_this_spec.rb +7 -7
- data/spec/integration/scoped_search_spec.rb +107 -107
- data/spec/integration/spellcheck_spec.rb +52 -7
- data/spec/integration/stats_spec.rb +10 -10
- data/spec/integration/stored_fields_spec.rb +1 -1
- data/spec/integration/test_pagination.rb +4 -4
- data/spec/integration/unicode_spec.rb +1 -1
- data/spec/mocks/post.rb +5 -1
- data/spec/spec_helper.rb +11 -6
- data/sunspot.gemspec +3 -1
- metadata +40 -7
@@ -6,7 +6,7 @@ shared_examples_for "spatial query" do
|
|
6
6
|
with(:coordinates_new).in_radius(23, -46, 100)
|
7
7
|
end
|
8
8
|
|
9
|
-
connection.
|
9
|
+
expect(connection).to have_last_search_including(:fq, "{!geofilt sfield=coordinates_new_ll pt=23,-46 d=100}")
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'filters by radius via bbox (inexact)' do
|
@@ -14,7 +14,7 @@ shared_examples_for "spatial query" do
|
|
14
14
|
with(:coordinates_new).in_radius(23, -46, 100, :bbox => true)
|
15
15
|
end
|
16
16
|
|
17
|
-
connection.
|
17
|
+
expect(connection).to have_last_search_including(:fq, "{!bbox sfield=coordinates_new_ll pt=23,-46 d=100}")
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'filters by bounding box' do
|
@@ -22,6 +22,6 @@ shared_examples_for "spatial query" do
|
|
22
22
|
with(:coordinates_new).in_bounding_box([45, -94], [46, -93])
|
23
23
|
end
|
24
24
|
|
25
|
-
connection.
|
25
|
+
expect(connection).to have_last_search_including(:fq, "coordinates_new_ll:[45,-94 TO 46,-93]")
|
26
26
|
end
|
27
27
|
end
|
@@ -6,7 +6,7 @@ shared_examples_for 'spellcheck query' do
|
|
6
6
|
search do
|
7
7
|
spellcheck
|
8
8
|
end
|
9
|
-
connection.
|
9
|
+
expect(connection).to have_last_search_including(:spellcheck, true)
|
10
10
|
end
|
11
11
|
|
12
12
|
|
@@ -14,7 +14,7 @@ shared_examples_for 'spellcheck query' do
|
|
14
14
|
search do
|
15
15
|
spellcheck :only_more_popular => true, :count => 5
|
16
16
|
end
|
17
|
-
connection.
|
18
|
-
connection.
|
17
|
+
expect(connection).to have_last_search_including('spellcheck.onlyMorePopular', true)
|
18
|
+
expect(connection).to have_last_search_including('spellcheck.count', 5)
|
19
19
|
end
|
20
20
|
end
|
@@ -1,28 +1,28 @@
|
|
1
1
|
shared_examples_for 'stats query' do
|
2
2
|
it 'does not use stats unless requested' do
|
3
3
|
search
|
4
|
-
connection.
|
4
|
+
expect(connection).not_to have_last_search_with(:stats)
|
5
5
|
end
|
6
6
|
|
7
7
|
it 'uses stats when requested' do
|
8
8
|
search do
|
9
9
|
stats :average_rating
|
10
10
|
end
|
11
|
-
connection.
|
11
|
+
expect(connection).to have_last_search_with(:stats => true)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'requests single field stats' do
|
15
15
|
search do
|
16
16
|
stats :average_rating
|
17
17
|
end
|
18
|
-
connection.
|
18
|
+
expect(connection).to have_last_search_with(:"stats.field" => %w{average_rating_ft})
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'requests multiple field stats' do
|
22
22
|
search do
|
23
23
|
stats :average_rating, :published_at
|
24
24
|
end
|
25
|
-
connection.
|
25
|
+
expect(connection).to have_last_search_with(:"stats.field" => %w{average_rating_ft published_at_dt})
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'facets on a stats field' do
|
@@ -31,14 +31,14 @@ shared_examples_for 'stats query' do
|
|
31
31
|
facet :featured
|
32
32
|
end
|
33
33
|
end
|
34
|
-
connection.
|
34
|
+
expect(connection).to have_last_search_with(:"f.average_rating_ft.stats.facet" => %w{featured_bs})
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'only facets on a stats field when requested' do
|
38
38
|
search do
|
39
39
|
stats :average_rating
|
40
40
|
end
|
41
|
-
connection.
|
41
|
+
expect(connection).not_to have_last_search_with(:"f.average_rating_ft.stats.facet")
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'facets on multiple stats fields' do
|
@@ -47,7 +47,7 @@ shared_examples_for 'stats query' do
|
|
47
47
|
facet :featured
|
48
48
|
end
|
49
49
|
end
|
50
|
-
connection.
|
50
|
+
expect(connection).to have_last_search_with(
|
51
51
|
:"f.average_rating_ft.stats.facet" => %w{featured_bs},
|
52
52
|
:"f.published_at_dt.stats.facet" => %w{featured_bs}
|
53
53
|
)
|
@@ -59,7 +59,7 @@ shared_examples_for 'stats query' do
|
|
59
59
|
facet :featured, :primary_category_id
|
60
60
|
end
|
61
61
|
end
|
62
|
-
connection.
|
62
|
+
expect(connection).to have_last_search_with(
|
63
63
|
:"f.average_rating_ft.stats.facet" => %w{featured_bs primary_category_id_i}
|
64
64
|
)
|
65
65
|
end
|
@@ -5,26 +5,26 @@ shared_examples_for 'query with text field scoping' do
|
|
5
5
|
with(:body, 'test')
|
6
6
|
end
|
7
7
|
end
|
8
|
-
connection.
|
8
|
+
expect(connection).to have_last_search_including(:fq, 'body_textsv:test')
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should raise an UnrecognizedFieldError if differently configured text field is used' do
|
12
|
-
|
12
|
+
expect do
|
13
13
|
search(Post, Namespaced::Comment) do
|
14
14
|
text_fields do
|
15
15
|
with(:body, 'test')
|
16
16
|
end
|
17
17
|
end
|
18
|
-
end.
|
18
|
+
end.to raise_error(Sunspot::UnrecognizedFieldError)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should raise an UnrecognizedFieldError if no field exists' do
|
22
|
-
|
22
|
+
expect do
|
23
23
|
search do
|
24
24
|
text_fields do
|
25
25
|
with(:bogus, 'test')
|
26
26
|
end
|
27
27
|
end
|
28
|
-
end.
|
28
|
+
end.to raise_error(Sunspot::UnrecognizedFieldError)
|
29
29
|
end
|
30
30
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
describe 'typed query' do
|
2
2
|
it 'properly escapes namespaced type names' do
|
3
3
|
session.search(Namespaced::Comment)
|
4
|
-
connection.
|
4
|
+
expect(connection).to have_last_search_with(:fq => ['type:Namespaced\:\:Comment'])
|
5
5
|
end
|
6
6
|
|
7
7
|
it 'builds search for multiple types' do
|
8
8
|
session.search(Post, Namespaced::Comment)
|
9
|
-
connection.
|
9
|
+
expect(connection).to have_last_search_with(:fq => ['type:(Post OR Namespaced\:\:Comment)'])
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'searches type of subclass when superclass is configured' do
|
13
13
|
session.search PhotoPost
|
14
|
-
connection.
|
14
|
+
expect(connection).to have_last_search_with(:fq => ['type:PhotoPost'])
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'raises an ArgumentError if no types given to search' do
|
18
|
-
|
18
|
+
expect { session.search }.to raise_error(ArgumentError)
|
19
19
|
end
|
20
20
|
end
|
@@ -3,7 +3,7 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
|
|
3
3
|
describe "CursorPaginatedCollection" do
|
4
4
|
subject { Sunspot::Search::CursorPaginatedCollection.new [], 10, 20, '*', 'AoIIP4AAACxQcm9maWxlIDEwMTk=' }
|
5
5
|
|
6
|
-
it { subject.
|
6
|
+
it { expect(subject).to be_an(Array) }
|
7
7
|
|
8
8
|
describe "#send" do
|
9
9
|
it 'should allow send' do
|
@@ -13,23 +13,23 @@ describe "CursorPaginatedCollection" do
|
|
13
13
|
|
14
14
|
describe "#respond_to?" do
|
15
15
|
it 'should return true for current_cursor' do
|
16
|
-
subject.respond_to?(:current_cursor).
|
16
|
+
expect(subject.respond_to?(:current_cursor)).to be(true)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
context "behaves like a WillPaginate::Collection" do
|
21
|
-
it { subject.total_entries.
|
22
|
-
it { subject.total_pages.
|
23
|
-
it { subject.current_cursor.
|
24
|
-
it { subject.per_page.
|
25
|
-
it { subject.next_page_cursor.
|
21
|
+
it { expect(subject.total_entries).to eql(20) }
|
22
|
+
it { expect(subject.total_pages).to eql(2) }
|
23
|
+
it { expect(subject.current_cursor).to eql('*') }
|
24
|
+
it { expect(subject.per_page).to eql(10) }
|
25
|
+
it { expect(subject.next_page_cursor).to eql('AoIIP4AAACxQcm9maWxlIDEwMTk=') }
|
26
26
|
end
|
27
27
|
|
28
28
|
context "behaves like Kaminari" do
|
29
|
-
it { subject.total_count.
|
30
|
-
it { subject.num_pages.
|
31
|
-
it { subject.limit_value.
|
32
|
-
it { subject.first_page
|
33
|
-
it { subject.last_page
|
29
|
+
it { expect(subject.total_count).to eql(20) }
|
30
|
+
it { expect(subject.num_pages).to eql(2) }
|
31
|
+
it { expect(subject.limit_value).to eql(10) }
|
32
|
+
it { expect(subject.first_page?).to be(true) }
|
33
|
+
it { expect(subject.last_page?).to be(true) }
|
34
34
|
end
|
35
35
|
end
|
@@ -4,13 +4,13 @@ describe 'search with dynamic fields' do
|
|
4
4
|
it 'returns dynamic string facet' do
|
5
5
|
stub_facet(:"custom_string:test_ss", 'two' => 2, 'one' => 1)
|
6
6
|
result = session.search(Post) { dynamic(:custom_string) { facet(:test) }}
|
7
|
-
result.facet(:custom_string, :test).rows.map { |row| row.value }.
|
7
|
+
expect(result.facet(:custom_string, :test).rows.map { |row| row.value }).to eq(['two', 'one'])
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'returns dynamic field facet with custom label' do
|
11
11
|
stub_facet(:"bogus", 'two' => 2, 'one' => 1)
|
12
12
|
result = session.search(Post) { dynamic(:custom_string) { facet(:test, :name => :bogus) }}
|
13
|
-
result.facet(:bogus).rows.map { |row| row.value }.
|
13
|
+
expect(result.facet(:bogus).rows.map { |row| row.value }).to eq(['two', 'one'])
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'returns query facet specified in dynamic call' do
|
@@ -27,7 +27,7 @@ describe 'search with dynamic fields' do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
facet = search.facet(:test)
|
30
|
-
facet.rows.first.value.
|
31
|
-
facet.rows.first.count.
|
30
|
+
expect(facet.rows.first.value).to eq(:foo_bar)
|
31
|
+
expect(facet.rows.first.count).to eq(3)
|
32
32
|
end
|
33
33
|
end
|
@@ -6,7 +6,7 @@ describe 'faceting', :type => :search do
|
|
6
6
|
result = session.search Post do
|
7
7
|
facet :title
|
8
8
|
end
|
9
|
-
result.facet(:title).field_name.
|
9
|
+
expect(result.facet(:title).field_name).to eq(:title)
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'returns facet specified by string' do
|
@@ -14,7 +14,7 @@ describe 'faceting', :type => :search do
|
|
14
14
|
result = session.search Post do
|
15
15
|
facet :title
|
16
16
|
end
|
17
|
-
result.facet('title').field_name.
|
17
|
+
expect(result.facet('title').field_name).to eq(:title)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'returns all facets specified by search' do
|
@@ -24,8 +24,8 @@ describe 'faceting', :type => :search do
|
|
24
24
|
facet :title
|
25
25
|
facet :blog_id
|
26
26
|
end
|
27
|
-
result.facets.first.field_name.
|
28
|
-
result.facets.last.field_name.
|
27
|
+
expect(result.facets.first.field_name).to eq(:title)
|
28
|
+
expect(result.facets.last.field_name).to eq(:blog_id)
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'returns string facet' do
|
@@ -33,7 +33,7 @@ describe 'faceting', :type => :search do
|
|
33
33
|
result = session.search Post do
|
34
34
|
facet :title
|
35
35
|
end
|
36
|
-
facet_values(result, :title).
|
36
|
+
expect(facet_values(result, :title)).to eq(['Author 1', 'Author 2'])
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'returns counts for facet' do
|
@@ -41,7 +41,7 @@ describe 'faceting', :type => :search do
|
|
41
41
|
result = session.search Post do
|
42
42
|
facet :title
|
43
43
|
end
|
44
|
-
facet_counts(result, :title).
|
44
|
+
expect(facet_counts(result, :title)).to eq([2, 1])
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'returns integer facet' do
|
@@ -49,7 +49,7 @@ describe 'faceting', :type => :search do
|
|
49
49
|
result = session.search Post do
|
50
50
|
facet :blog_id
|
51
51
|
end
|
52
|
-
facet_values(result, :blog_id).
|
52
|
+
expect(facet_values(result, :blog_id)).to eq([3, 1])
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'returns float facet' do
|
@@ -57,7 +57,7 @@ describe 'faceting', :type => :search do
|
|
57
57
|
result = session.search Post do
|
58
58
|
facet :average_rating
|
59
59
|
end
|
60
|
-
facet_values(result, :average_rating).
|
60
|
+
expect(facet_values(result, :average_rating)).to eq([9.3, 1.1])
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'returns time facet' do
|
@@ -77,10 +77,11 @@ describe 'faceting', :type => :search do
|
|
77
77
|
rescue ArgumentError
|
78
78
|
DateTime.civil(2050, 4, 7, 20, 27, 15)
|
79
79
|
end
|
80
|
-
facet_values(result, :published_at).
|
80
|
+
expect(facet_values(result, :published_at)).to eq(
|
81
81
|
[Time.gm(2009, 4, 7, 20, 25, 23),
|
82
82
|
Time.gm(2009, 4, 7, 20, 26, 19),
|
83
83
|
future_time]
|
84
|
+
)
|
84
85
|
end
|
85
86
|
|
86
87
|
it 'returns date facet' do
|
@@ -92,9 +93,10 @@ describe 'faceting', :type => :search do
|
|
92
93
|
result = session.search(Post) do
|
93
94
|
facet :expire_date
|
94
95
|
end
|
95
|
-
facet_values(result, :expire_date).
|
96
|
+
expect(facet_values(result, :expire_date)).to eq(
|
96
97
|
[Date.new(2009, 07, 13),
|
97
98
|
Date.new(2009, 04, 01)]
|
99
|
+
)
|
98
100
|
end
|
99
101
|
|
100
102
|
it 'returns trie integer facet' do
|
@@ -102,7 +104,7 @@ describe 'faceting', :type => :search do
|
|
102
104
|
result = session.search Photo do
|
103
105
|
facet :size
|
104
106
|
end
|
105
|
-
facet_values(result, :size).
|
107
|
+
expect(facet_values(result, :size)).to eq([3, 1])
|
106
108
|
end
|
107
109
|
|
108
110
|
it 'returns float facet' do
|
@@ -110,7 +112,7 @@ describe 'faceting', :type => :search do
|
|
110
112
|
result = session.search Photo do
|
111
113
|
facet :average_rating
|
112
114
|
end
|
113
|
-
facet_values(result, :average_rating).
|
115
|
+
expect(facet_values(result, :average_rating)).to eq([9.3, 1.1])
|
114
116
|
end
|
115
117
|
|
116
118
|
it 'returns time facet' do
|
@@ -122,15 +124,16 @@ describe 'faceting', :type => :search do
|
|
122
124
|
result = session.search Photo do
|
123
125
|
facet :created_at
|
124
126
|
end
|
125
|
-
facet_values(result, :created_at).
|
127
|
+
expect(facet_values(result, :created_at)).to eq(
|
126
128
|
[Time.gm(2009, 04, 07, 20, 25, 23),
|
127
129
|
Time.gm(2009, 04, 07, 20, 26, 19)]
|
130
|
+
)
|
128
131
|
end
|
129
132
|
|
130
133
|
it 'returns boolean facet' do
|
131
134
|
stub_facet(:featured_bs, 'true' => 3, 'false' => 1)
|
132
135
|
result = session.search(Post) { facet(:featured) }
|
133
|
-
facet_values(result, :featured).
|
136
|
+
expect(facet_values(result, :featured)).to eq([true, false])
|
134
137
|
end
|
135
138
|
|
136
139
|
|
@@ -138,26 +141,26 @@ describe 'faceting', :type => :search do
|
|
138
141
|
it "returns field facet with #{type} custom name" do
|
139
142
|
stub_facet(:blog, '2' => 1, '1' => 4)
|
140
143
|
result = session.search(Post) { facet(:blog_id, :name => name) }
|
141
|
-
facet_values(result, :blog).
|
144
|
+
expect(facet_values(result, :blog)).to eq([1, 2])
|
142
145
|
end
|
143
146
|
|
144
147
|
it "assigns #{type} custom name to field facet" do
|
145
148
|
stub_facet(:blog, '2' => 1)
|
146
149
|
result = session.search(Post) { facet(:blog_id, :name => name) }
|
147
|
-
result.facet(:blog).name.
|
150
|
+
expect(result.facet(:blog).name).to eq(:blog)
|
148
151
|
end
|
149
152
|
|
150
153
|
it "retains field name for #{type} custom-named field facet" do
|
151
154
|
stub_facet(:blog, '2' => 1)
|
152
155
|
result = session.search(Post) { facet(:blog_id, :name => name) }
|
153
|
-
result.facet(:blog).field_name.
|
156
|
+
expect(result.facet(:blog).field_name).to eq(:blog_id)
|
154
157
|
end
|
155
158
|
end
|
156
159
|
|
157
160
|
it 'returns class facet' do
|
158
161
|
stub_facet(:class_name, 'Post' => 3, 'Namespaced::Comment' => 1)
|
159
162
|
result = session.search(Post) { facet(:class) }
|
160
|
-
facet_values(result, :class).
|
163
|
+
expect(facet_values(result, :class)).to eq([Post, Namespaced::Comment])
|
161
164
|
end
|
162
165
|
|
163
166
|
it 'returns special :any facet' do
|
@@ -166,8 +169,8 @@ describe 'faceting', :type => :search do
|
|
166
169
|
)
|
167
170
|
search = session.search(Post) { facet(:category_ids, :extra => :any) }
|
168
171
|
row = search.facet(:category_ids).rows.first
|
169
|
-
row.value.
|
170
|
-
row.count.
|
172
|
+
expect(row.value).to eq(:any)
|
173
|
+
expect(row.count).to eq(3)
|
171
174
|
end
|
172
175
|
|
173
176
|
it 'returns special :none facet' do
|
@@ -176,8 +179,8 @@ describe 'faceting', :type => :search do
|
|
176
179
|
)
|
177
180
|
search = session.search(Post) { facet(:category_ids, :extra => :none) }
|
178
181
|
row = search.facet(:category_ids).rows.first
|
179
|
-
row.value.
|
180
|
-
row.count.
|
182
|
+
expect(row.value).to eq(:none)
|
183
|
+
expect(row.count).to eq(3)
|
181
184
|
end
|
182
185
|
|
183
186
|
it 'returns date range facet' do
|
@@ -186,8 +189,8 @@ describe 'faceting', :type => :search do
|
|
186
189
|
end_time = start_time + 2*24*60*60
|
187
190
|
result = session.search(Post) { facet(:published_at, :time_range => start_time..end_time) }
|
188
191
|
facet = result.facet(:published_at)
|
189
|
-
facet.rows.first.value.
|
190
|
-
facet.rows.last.value.
|
192
|
+
expect(facet.rows.first.value).to eq(start_time..(start_time+24*60*60))
|
193
|
+
expect(facet.rows.last.value).to eq((start_time+24*60*60)..end_time)
|
191
194
|
end
|
192
195
|
|
193
196
|
it 'returns date range facet sorted by count' do
|
@@ -196,8 +199,8 @@ describe 'faceting', :type => :search do
|
|
196
199
|
end_time = start_time + 2*24*60*60
|
197
200
|
result = session.search(Post) { facet(:published_at, :time_range => start_time..end_time, :sort => :count) }
|
198
201
|
facet = result.facet(:published_at)
|
199
|
-
facet.rows.first.value.
|
200
|
-
facet.rows.last.value.
|
202
|
+
expect(facet.rows.first.value).to eq((start_time+24*60*60)..end_time)
|
203
|
+
expect(facet.rows.last.value).to eq(start_time..(start_time+24*60*60))
|
201
204
|
end
|
202
205
|
|
203
206
|
it 'returns query facet' do
|
@@ -216,10 +219,10 @@ describe 'faceting', :type => :search do
|
|
216
219
|
end
|
217
220
|
end
|
218
221
|
facet = search.facet(:average_rating)
|
219
|
-
facet.rows.first.value.
|
220
|
-
facet.rows.first.count.
|
221
|
-
facet.rows.last.value.
|
222
|
-
facet.rows.last.count.
|
222
|
+
expect(facet.rows.first.value).to eq(3.0..5.0)
|
223
|
+
expect(facet.rows.first.count).to eq(3)
|
224
|
+
expect(facet.rows.last.value).to eq(1.0..3.0)
|
225
|
+
expect(facet.rows.last.count).to eq(1)
|
223
226
|
end
|
224
227
|
|
225
228
|
describe 'query facet option handling' do
|
@@ -244,43 +247,43 @@ describe 'faceting', :type => :search do
|
|
244
247
|
end
|
245
248
|
|
246
249
|
it 'sorts in order of specification if no limit is given' do
|
247
|
-
facet_values_from_options.
|
250
|
+
expect(facet_values_from_options).to eq([1, 3, 2])
|
248
251
|
end
|
249
252
|
|
250
253
|
it 'sorts lexically if lexical option is specified' do
|
251
|
-
facet_values_from_options(:sort => :index).
|
254
|
+
expect(facet_values_from_options(:sort => :index)).to eq([1, 2, 3])
|
252
255
|
end
|
253
256
|
|
254
257
|
it 'sorts by count by default if limit is given' do
|
255
|
-
facet_values_from_options(:limit => 2).
|
258
|
+
expect(facet_values_from_options(:limit => 2)).to eq([2, 1])
|
256
259
|
end
|
257
260
|
|
258
261
|
it 'sorts by count if count option is specified' do
|
259
|
-
facet_values_from_options(:sort => :count).
|
262
|
+
expect(facet_values_from_options(:sort => :count)).to eq([2, 1, 3])
|
260
263
|
end
|
261
264
|
|
262
265
|
it 'sorts lexically if lexical option is specified even if limit is given' do
|
263
|
-
facet_values_from_options(:sort => :index, :limit => 2).
|
266
|
+
expect(facet_values_from_options(:sort => :index, :limit => 2)).to eq([1, 2])
|
264
267
|
end
|
265
268
|
|
266
269
|
it 'limits facets if limit option is given' do
|
267
|
-
facet_values_from_options(:limit => 1).
|
270
|
+
expect(facet_values_from_options(:limit => 1)).to eq([2])
|
268
271
|
end
|
269
272
|
|
270
273
|
it 'does not limit facets if limit option is negative' do
|
271
|
-
facet_values_from_options(:limit => -2).
|
274
|
+
expect(facet_values_from_options(:limit => -2)).to eq([1, 3, 2])
|
272
275
|
end
|
273
276
|
|
274
277
|
it 'returns all facets if limit greater than number of facets' do
|
275
|
-
facet_values_from_options(:limit => 10).
|
278
|
+
expect(facet_values_from_options(:limit => 10)).to eq([2, 1, 3])
|
276
279
|
end
|
277
280
|
|
278
281
|
it 'allows zero count if specified' do
|
279
|
-
facet_values_from_options(:zeros => true).
|
282
|
+
expect(facet_values_from_options(:zeros => true)).to eq([1, 3, 2, 4])
|
280
283
|
end
|
281
284
|
|
282
285
|
it 'sets minimum count' do
|
283
|
-
facet_values_from_options(:minimum_count => 2).
|
286
|
+
expect(facet_values_from_options(:minimum_count => 2)).to eq([1, 2])
|
284
287
|
end
|
285
288
|
end
|
286
289
|
|
@@ -293,17 +296,17 @@ describe 'faceting', :type => :search do
|
|
293
296
|
facet :category_ids, :only => [1, 3, 5]
|
294
297
|
end
|
295
298
|
facet = search.facet(:category_ids)
|
296
|
-
facet.rows.first.value.
|
297
|
-
facet.rows.first.count.
|
298
|
-
facet.rows.last.value.
|
299
|
-
facet.rows.last.count.
|
299
|
+
expect(facet.rows.first.value).to eq(1)
|
300
|
+
expect(facet.rows.first.count).to eq(3)
|
301
|
+
expect(facet.rows.last.value).to eq(3)
|
302
|
+
expect(facet.rows.last.count).to eq(1)
|
300
303
|
end
|
301
304
|
|
302
305
|
it 'returns instantiated facet values' do
|
303
306
|
blogs = Array.new(2) { Blog.new }
|
304
307
|
stub_facet(:blog_id_i, blogs[0].id.to_s => 2, blogs[1].id.to_s => 1)
|
305
308
|
search = session.search(Post) { facet(:blog_id) }
|
306
|
-
search.facet(:blog_id).rows.map { |row| row.instance }.
|
309
|
+
expect(search.facet(:blog_id).rows.map { |row| row.instance }).to eq(blogs)
|
307
310
|
end
|
308
311
|
|
309
312
|
it 'returns all instantiated facet rows, whether or not the instances exist' do
|
@@ -311,7 +314,7 @@ describe 'faceting', :type => :search do
|
|
311
314
|
blogs.last.destroy
|
312
315
|
stub_facet(:blog_id_i, blogs[0].id.to_s => 2, blogs[1].id.to_s => 1)
|
313
316
|
search = session.search(Post) { facet(:blog_id) }
|
314
|
-
search.facet(:blog_id).rows.map { |row| row.instance }.
|
317
|
+
expect(search.facet(:blog_id).rows.map { |row| row.instance }).to eq([blogs.first, nil])
|
315
318
|
end
|
316
319
|
|
317
320
|
it 'returns only rows with available instances if specified' do
|
@@ -319,7 +322,7 @@ describe 'faceting', :type => :search do
|
|
319
322
|
blogs.last.destroy
|
320
323
|
stub_facet(:blog_id_i, blogs[0].id.to_s => 2, blogs[1].id.to_s => 1)
|
321
324
|
search = session.search(Post) { facet(:blog_id) }
|
322
|
-
search.facet(:blog_id).rows(:verify => true).map { |row| row.instance }.
|
325
|
+
expect(search.facet(:blog_id).rows(:verify => true).map { |row| row.instance }).to eq(blogs[0..0])
|
323
326
|
end
|
324
327
|
|
325
328
|
it 'returns both verified and unverified rows from the same facet' do
|
@@ -327,14 +330,14 @@ describe 'faceting', :type => :search do
|
|
327
330
|
blogs.last.destroy
|
328
331
|
stub_facet(:blog_id_i, blogs[0].id.to_s => 2, blogs[1].id.to_s => 1)
|
329
332
|
search = session.search(Post) { facet(:blog_id) }
|
330
|
-
search.facet(:blog_id).rows(:verify => true).map { |row| row.instance }.
|
331
|
-
search.facet(:blog_id).rows.map { |row| row.instance }.
|
333
|
+
expect(search.facet(:blog_id).rows(:verify => true).map { |row| row.instance }).to eq(blogs[0..0])
|
334
|
+
expect(search.facet(:blog_id).rows.map { |row| row.instance }).to eq([blogs.first, nil])
|
332
335
|
end
|
333
336
|
|
334
337
|
it 'ignores :verify option if facet not a reference facet' do
|
335
338
|
stub_facet(:category_ids_im, '1' => 2, '2' => 1)
|
336
339
|
search = session.search(Post) { facet(:category_ids) }
|
337
|
-
search.facet(:category_ids).
|
340
|
+
expect(search.facet(:category_ids).rows(:verify => true).size).to eq(2)
|
338
341
|
end
|
339
342
|
|
340
343
|
it 'returns instantiated facet values for limited field facet' do
|
@@ -346,7 +349,7 @@ describe 'faceting', :type => :search do
|
|
346
349
|
search = session.search(Post) do
|
347
350
|
facet(:blog_id, :only => blogs.map { |blog| blog.id })
|
348
351
|
end
|
349
|
-
search.facet(:blog_id).rows.map { |row| row.instance }.
|
352
|
+
expect(search.facet(:blog_id).rows.map { |row| row.instance }).to eq(blogs)
|
350
353
|
end
|
351
354
|
|
352
355
|
it 'only queries the persistent store once for an instantiated facet' do
|
@@ -355,6 +358,6 @@ describe 'faceting', :type => :search do
|
|
355
358
|
stub_facet(:blog_id_i, blogs[0].id.to_s => 2, blogs[1].id.to_s => 1)
|
356
359
|
result = session.search(Post) { facet(:blog_id) }
|
357
360
|
result.facet(:blog_id).rows.each { |row| row.instance }
|
358
|
-
(Blog.query_count - query_count).
|
361
|
+
expect(Blog.query_count - query_count).to eq(1)
|
359
362
|
end
|
360
363
|
end
|