sunspot 2.0.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Appraisals +7 -0
- data/Gemfile +0 -2
- data/History.txt +10 -0
- data/lib/sunspot.rb +55 -17
- data/lib/sunspot/adapters.rb +68 -18
- data/lib/sunspot/batcher.rb +1 -1
- data/lib/sunspot/configuration.rb +4 -2
- data/lib/sunspot/data_extractor.rb +36 -6
- data/lib/sunspot/dsl.rb +4 -3
- data/lib/sunspot/dsl/adjustable.rb +2 -2
- data/lib/sunspot/dsl/field_query.rb +69 -16
- data/lib/sunspot/dsl/field_stats.rb +25 -0
- data/lib/sunspot/dsl/fields.rb +28 -8
- data/lib/sunspot/dsl/fulltext.rb +9 -1
- data/lib/sunspot/dsl/group.rb +118 -0
- data/lib/sunspot/dsl/paginatable.rb +4 -1
- data/lib/sunspot/dsl/scope.rb +19 -10
- data/lib/sunspot/dsl/search.rb +1 -1
- data/lib/sunspot/dsl/spellcheckable.rb +14 -0
- data/lib/sunspot/dsl/standard_query.rb +63 -35
- data/lib/sunspot/field.rb +76 -4
- data/lib/sunspot/field_factory.rb +60 -11
- data/lib/sunspot/indexer.rb +70 -18
- data/lib/sunspot/query.rb +5 -4
- data/lib/sunspot/query/abstract_field_facet.rb +0 -2
- data/lib/sunspot/query/abstract_fulltext.rb +76 -0
- data/lib/sunspot/query/abstract_json_field_facet.rb +70 -0
- data/lib/sunspot/query/bbox.rb +5 -1
- data/lib/sunspot/query/common_query.rb +31 -6
- data/lib/sunspot/query/composite_fulltext.rb +58 -8
- data/lib/sunspot/query/date_field_json_facet.rb +25 -0
- data/lib/sunspot/query/dismax.rb +25 -71
- data/lib/sunspot/query/field_json_facet.rb +19 -0
- data/lib/sunspot/query/field_list.rb +15 -0
- data/lib/sunspot/query/field_stats.rb +61 -0
- data/lib/sunspot/query/function_query.rb +1 -2
- data/lib/sunspot/query/geo.rb +1 -1
- data/lib/sunspot/query/geofilt.rb +8 -3
- data/lib/sunspot/query/group.rb +46 -0
- data/lib/sunspot/query/group_query.rb +17 -0
- data/lib/sunspot/query/join.rb +88 -0
- data/lib/sunspot/query/more_like_this.rb +1 -1
- data/lib/sunspot/query/pagination.rb +12 -4
- data/lib/sunspot/query/range_json_facet.rb +28 -0
- data/lib/sunspot/query/restriction.rb +99 -13
- data/lib/sunspot/query/sort.rb +41 -0
- data/lib/sunspot/query/sort_composite.rb +7 -0
- data/lib/sunspot/query/spellcheck.rb +19 -0
- data/lib/sunspot/query/standard_query.rb +24 -2
- data/lib/sunspot/query/text_field_boost.rb +1 -3
- data/lib/sunspot/schema.rb +12 -3
- data/lib/sunspot/search.rb +4 -2
- data/lib/sunspot/search/abstract_search.rb +93 -43
- data/lib/sunspot/search/cursor_paginated_collection.rb +32 -0
- data/lib/sunspot/search/field_facet.rb +4 -4
- data/lib/sunspot/search/field_json_facet.rb +33 -0
- data/lib/sunspot/search/field_stats.rb +21 -0
- data/lib/sunspot/search/hit.rb +6 -1
- data/lib/sunspot/search/hit_enumerable.rb +4 -1
- data/lib/sunspot/search/json_facet_row.rb +40 -0
- data/lib/sunspot/search/json_facet_stats.rb +23 -0
- data/lib/sunspot/search/paginated_collection.rb +1 -0
- data/lib/sunspot/search/query_group.rb +74 -0
- data/lib/sunspot/search/standard_search.rb +70 -3
- data/lib/sunspot/search/stats_facet.rb +25 -0
- data/lib/sunspot/search/stats_json_row.rb +82 -0
- data/lib/sunspot/search/stats_row.rb +68 -0
- data/lib/sunspot/session.rb +62 -37
- data/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +6 -4
- data/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +16 -8
- data/lib/sunspot/session_proxy/master_slave_session_proxy.rb +2 -2
- data/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb +1 -1
- data/lib/sunspot/session_proxy/sharding_session_proxy.rb +4 -2
- data/lib/sunspot/session_proxy/silent_fail_session_proxy.rb +1 -1
- data/lib/sunspot/session_proxy/thread_local_session_proxy.rb +6 -4
- data/lib/sunspot/setup.rb +42 -0
- data/lib/sunspot/type.rb +20 -0
- data/lib/sunspot/util.rb +78 -14
- data/lib/sunspot/version.rb +1 -1
- data/spec/api/adapters_spec.rb +40 -15
- data/spec/api/batcher_spec.rb +15 -15
- data/spec/api/binding_spec.rb +3 -3
- data/spec/api/class_set_spec.rb +6 -6
- data/spec/api/data_extractor_spec.rb +39 -0
- data/spec/api/hit_enumerable_spec.rb +32 -9
- data/spec/api/indexer/attributes_spec.rb +35 -30
- 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 +16 -11
- data/spec/api/indexer/fulltext_spec.rb +8 -8
- data/spec/api/indexer/removal_spec.rb +24 -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 +24 -6
- data/spec/api/query/dynamic_fields_examples.rb +18 -18
- data/spec/api/query/faceting_examples.rb +80 -61
- data/spec/api/query/fulltext_examples.rb +194 -40
- data/spec/api/query/function_spec.rb +116 -13
- data/spec/api/query/geo_examples.rb +8 -12
- data/spec/api/query/group_spec.rb +27 -5
- data/spec/api/query/highlighting_examples.rb +26 -26
- data/spec/api/query/join_spec.rb +19 -0
- data/spec/api/query/more_like_this_spec.rb +40 -27
- data/spec/api/query/ordering_pagination_examples.rb +37 -23
- 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 +20 -0
- data/spec/api/query/standard_spec.rb +3 -1
- data/spec/api/query/stats_examples.rb +66 -0
- 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 +35 -0
- 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 +43 -29
- data/spec/api/search/paginated_collection_spec.rb +19 -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 +94 -0
- data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +23 -16
- data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +16 -4
- data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +10 -6
- data/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +11 -11
- data/spec/api/session_proxy/sharding_session_proxy_spec.rb +15 -14
- data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +3 -3
- data/spec/api/session_proxy/spec_helper.rb +1 -1
- data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +40 -26
- data/spec/api/session_spec.rb +78 -38
- data/spec/api/sunspot_spec.rb +7 -4
- data/spec/helpers/integration_helper.rb +11 -1
- data/spec/helpers/query_helper.rb +1 -1
- data/spec/helpers/search_helper.rb +30 -0
- data/spec/integration/atomic_updates_spec.rb +58 -0
- data/spec/integration/dynamic_fields_spec.rb +31 -20
- data/spec/integration/faceting_spec.rb +252 -39
- data/spec/integration/field_grouping_spec.rb +47 -15
- data/spec/integration/field_lists_spec.rb +57 -0
- data/spec/integration/geospatial_spec.rb +34 -8
- data/spec/integration/highlighting_spec.rb +8 -8
- data/spec/integration/indexing_spec.rb +7 -6
- data/spec/integration/join_spec.rb +45 -0
- data/spec/integration/keyword_search_spec.rb +68 -38
- 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 +193 -74
- data/spec/integration/spellcheck_spec.rb +119 -0
- data/spec/integration/stats_spec.rb +88 -0
- 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/adapters.rb +36 -0
- data/spec/mocks/connection.rb +5 -3
- data/spec/mocks/photo.rb +32 -1
- data/spec/mocks/post.rb +18 -3
- data/spec/spec_helper.rb +13 -8
- data/sunspot.gemspec +6 -4
- data/tasks/rdoc.rake +22 -14
- metadata +101 -44
- data/lib/sunspot/dsl/field_group.rb +0 -57
- data/lib/sunspot/query/field_group.rb +0 -37
@@ -0,0 +1,119 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
include SearchHelper
|
3
|
+
|
4
|
+
describe 'spellcheck' do
|
5
|
+
before :each do
|
6
|
+
Sunspot.remove_all
|
7
|
+
|
8
|
+
@posts = [
|
9
|
+
Post.new(:title => 'Clojure Developer'),
|
10
|
+
Post.new(:title => 'Conjure Flow'),
|
11
|
+
Post.new(:title => 'Clojure Analyst'),
|
12
|
+
Post.new(:title => 'C++ Developer'),
|
13
|
+
Post.new(:title => 'C++ Developing')
|
14
|
+
]
|
15
|
+
|
16
|
+
Sunspot.index!(*@posts)
|
17
|
+
Sunspot.commit
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'has no spellchecking by default' do
|
21
|
+
search = Sunspot.search(Post) do
|
22
|
+
keywords 'Closure'
|
23
|
+
end
|
24
|
+
expect(search.spellcheck_suggestions).to eq({})
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns the list of suggestions' do
|
28
|
+
search = Sunspot.search(Post) do
|
29
|
+
keywords 'Closure'
|
30
|
+
spellcheck :count => 3
|
31
|
+
end
|
32
|
+
expect(search.spellcheck_suggestions['closure']['suggestion']).to eq([
|
33
|
+
{'word'=>'clojure', 'freq'=>2}, {'word'=>'conjure', 'freq'=>1}
|
34
|
+
])
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns suggestion with highest frequency' do
|
38
|
+
search = Sunspot.search(Post) do
|
39
|
+
keywords 'Closure'
|
40
|
+
spellcheck :count => 3
|
41
|
+
end
|
42
|
+
expect(search.spellcheck_suggestion_for('closure')).to eq('clojure')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns suggestion without collation when only more popular is true' do
|
46
|
+
search = Sunspot.search(Post) do
|
47
|
+
keywords 'Closure'
|
48
|
+
spellcheck :count => 3, :only_more_popular => true, :collate => false
|
49
|
+
end
|
50
|
+
|
51
|
+
expect(search.spellcheck_suggestion_for('closure')).to eq('clojure')
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'spellcheck collation' do
|
55
|
+
it 'replaces terms that are not in the index if terms are provided' do
|
56
|
+
|
57
|
+
search = Sunspot.search(Post) do
|
58
|
+
keywords 'lojure developing'
|
59
|
+
spellcheck :count => 3, :only_more_popular => true
|
60
|
+
end
|
61
|
+
expect(search.spellcheck_collation('lojure', 'developing')).to eq('clojure developing')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns Solr collation if terms are not provided' do
|
65
|
+
|
66
|
+
search = Sunspot.search(Post) do
|
67
|
+
keywords 'lojure developing'
|
68
|
+
spellcheck :count => 3, :only_more_popular => true
|
69
|
+
end
|
70
|
+
expect(search.spellcheck_collation).to eq('clojure developer')
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns Solr collation if terms are not provided even for single word' do
|
74
|
+
|
75
|
+
search = Sunspot.search(Post) do
|
76
|
+
keywords 'lojure'
|
77
|
+
spellcheck :count => 3, :only_more_popular => true
|
78
|
+
end
|
79
|
+
expect(search.spellcheck_collation).to eq('clojure')
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'returns Solr collation if terms are provided even for single word' do
|
83
|
+
|
84
|
+
search = Sunspot.search(Post) do
|
85
|
+
keywords 'lojure'
|
86
|
+
spellcheck :count => 3
|
87
|
+
end
|
88
|
+
expect(search.spellcheck_collation).to eq('clojure')
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'returns Solr collation if terms are provided even for single word' do
|
92
|
+
|
93
|
+
search = Sunspot.search(Post) do
|
94
|
+
keywords 'lojure'
|
95
|
+
spellcheck :count => 3
|
96
|
+
end
|
97
|
+
expect(search.spellcheck_collation('lojure')).to eq('clojure')
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'returns Solr collation if terms are provided even if single keyword is word' do
|
101
|
+
|
102
|
+
search = Sunspot.search(Post) do
|
103
|
+
keywords 'C++, lojure Developer'
|
104
|
+
spellcheck :count => 3
|
105
|
+
end
|
106
|
+
expect(search.spellcheck_collation).to eq('C++, clojure Developer')
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'returns nil if terms are provided which varies from actual keywords' do
|
110
|
+
|
111
|
+
search = Sunspot.search(Post) do
|
112
|
+
keywords 'clojure'
|
113
|
+
spellcheck :count => 3
|
114
|
+
end
|
115
|
+
expect(search.spellcheck_collation('lojure')).to eq(nil)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe 'search stats' do
|
4
|
+
before :each do
|
5
|
+
Sunspot.remove_all
|
6
|
+
@posts = Post.new(:ratings_average => 4.0, :author_name => 'plinio', :blog_id => 2),
|
7
|
+
Post.new(:ratings_average => 4.0, :author_name => 'caio', :blog_id => 1),
|
8
|
+
Post.new(:ratings_average => 3.0, :author_name => 'sempronio', :blog_id => 2)
|
9
|
+
Sunspot.index!(@posts)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns minimum stats' do
|
13
|
+
expect(Sunspot.search(Post) do
|
14
|
+
stats :average_rating
|
15
|
+
end.stats(:average_rating).min).to eq(3.0)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns maximum stats' do
|
19
|
+
expect(Sunspot.search(Post) do
|
20
|
+
stats :average_rating
|
21
|
+
end.stats(:average_rating).max).to eq(4.0)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns count stats' do
|
25
|
+
expect(Sunspot.search(Post) do
|
26
|
+
stats :average_rating
|
27
|
+
end.stats(:average_rating).count).to eq(3)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'facets' do
|
31
|
+
it 'returns minimum on facet row with two blog ids' do
|
32
|
+
expect(Sunspot.search(Post) do
|
33
|
+
stats :average_rating do
|
34
|
+
facet :blog_id
|
35
|
+
end
|
36
|
+
end.stats(:average_rating).facet(:blog_id).rows[1].min).to eq(3.0)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns maximum on facet row with two blog ids' do
|
40
|
+
expect(Sunspot.search(Post) do
|
41
|
+
stats :average_rating do
|
42
|
+
facet :blog_id
|
43
|
+
end
|
44
|
+
end.stats(:average_rating).facet(:blog_id).rows[1].max).to eq(4.0)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'json facets' do
|
49
|
+
it 'returns minimum on facet row with two blog ids' do
|
50
|
+
expect(Sunspot.search(Post) do
|
51
|
+
stats :average_rating, sort: :min do
|
52
|
+
json_facet :blog_id
|
53
|
+
end
|
54
|
+
end.json_facet_stats(:blog_id).rows[1].min).to eq(3.0)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns maximum on facet row with two blog ids' do
|
58
|
+
expect(Sunspot.search(Post) do
|
59
|
+
stats :average_rating, sort: :max do
|
60
|
+
json_facet :blog_id
|
61
|
+
end
|
62
|
+
end.json_facet_stats(:blog_id).rows[1].max).to eq(4.0)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns only sum' do
|
66
|
+
search = Sunspot.search(Post) do
|
67
|
+
stats :average_rating, stats: [:sum] do
|
68
|
+
json_facet :blog_id
|
69
|
+
end
|
70
|
+
end
|
71
|
+
expect(search.json_facet_stats(:blog_id).rows[1].max).to eq(nil)
|
72
|
+
expect(search.json_facet_stats(:blog_id).rows[1].min).to eq(nil)
|
73
|
+
expect(search.json_facet_stats(:blog_id).rows[1].avg).to eq(nil)
|
74
|
+
expect(search.json_facet_stats(:blog_id).rows[1].sumsq).to eq(nil)
|
75
|
+
expect(search.json_facet_stats(:blog_id).rows[1].sum).to eq(4.0)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'works with nested facets' do
|
79
|
+
search = Sunspot.search(Post) do
|
80
|
+
stats :average_rating, sort: :min do
|
81
|
+
json_facet(:blog_id, nested: { field: :author_name, limit: 3, nested: { field: :average_rating } } )
|
82
|
+
end
|
83
|
+
end
|
84
|
+
expect(search.json_facet_stats(:blog_id).rows[1].nested.first.nested.first.min).to eq(4.0)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
@@ -11,7 +11,7 @@ describe 'pagination' do
|
|
11
11
|
|
12
12
|
it 'should return all by default' do
|
13
13
|
results = Sunspot.search(Post) { order_by :blog_id }.results
|
14
|
-
results.
|
14
|
+
expect(results).to eq(@posts)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should return first page of 10' do
|
@@ -19,7 +19,7 @@ describe 'pagination' do
|
|
19
19
|
order_by :blog_id
|
20
20
|
paginate :page => 1, :per_page => 10
|
21
21
|
end.results
|
22
|
-
results.
|
22
|
+
expect(results).to eq(@posts[0,10])
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should return second page of 10' do
|
@@ -27,7 +27,7 @@ describe 'pagination' do
|
|
27
27
|
order_by :blog_id
|
28
28
|
paginate :page => 2, :per_page => 10
|
29
29
|
end.results
|
30
|
-
results.
|
30
|
+
expect(results).to eq(@posts[10,10])
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should return pages with offsets' do
|
@@ -38,6 +38,6 @@ describe 'pagination' do
|
|
38
38
|
|
39
39
|
# page 1 is 3, 4, 5, 6, 7
|
40
40
|
# page 2 is 8, 9, 10, 11, 12
|
41
|
-
results.
|
41
|
+
expect(results).to eq(@posts[8,5])
|
42
42
|
end
|
43
43
|
end
|
data/spec/mocks/adapters.rb
CHANGED
@@ -4,7 +4,43 @@ end
|
|
4
4
|
class Model < AbstractModel
|
5
5
|
end
|
6
6
|
|
7
|
+
class UnseenModel < AbstractModel
|
8
|
+
end
|
9
|
+
|
10
|
+
class ModelWithPrefixId < AbstractModel
|
11
|
+
def id
|
12
|
+
1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Sunspot.setup(ModelWithPrefixId) do
|
17
|
+
id_prefix { "USERDATA!" }
|
18
|
+
end
|
19
|
+
|
20
|
+
class ModelWithNestedPrefixId < AbstractModel
|
21
|
+
def id
|
22
|
+
1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Sunspot.setup(ModelWithNestedPrefixId) do
|
27
|
+
id_prefix { "USER!USERDATA!" }
|
28
|
+
end
|
29
|
+
|
30
|
+
class ModelWithoutPrefixId < AbstractModel
|
31
|
+
def id
|
32
|
+
1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Sunspot.setup(ModelWithoutPrefixId) do
|
37
|
+
end
|
38
|
+
|
39
|
+
|
7
40
|
class AbstractModelInstanceAdapter < Sunspot::Adapters::InstanceAdapter
|
41
|
+
def id
|
42
|
+
@instance.id
|
43
|
+
end
|
8
44
|
end
|
9
45
|
|
10
46
|
class AbstractModelDataAccessor < Sunspot::Adapters::DataAccessor
|
data/spec/mocks/connection.rb
CHANGED
@@ -22,7 +22,7 @@ module Mock
|
|
22
22
|
end
|
23
23
|
|
24
24
|
class Connection
|
25
|
-
attr_reader :adds, :commits, :optims, :searches, :message, :opts, :deletes_by_query
|
25
|
+
attr_reader :adds, :commits, :soft_commits, :optims, :searches, :message, :opts, :deletes_by_query
|
26
26
|
attr_accessor :response
|
27
27
|
attr_writer :expected_handler
|
28
28
|
undef_method :select # annoyingly defined on Object
|
@@ -30,7 +30,7 @@ module Mock
|
|
30
30
|
def initialize(opts = {})
|
31
31
|
@opts = opts
|
32
32
|
@message = OpenStruct.new
|
33
|
-
@adds, @deletes, @deletes_by_query, @commits, @optims, @searches = Array.new(
|
33
|
+
@adds, @deletes, @deletes_by_query, @commits, @soft_commits, @optims, @searches = Array.new(7) { [] }
|
34
34
|
@expected_handler = :select
|
35
35
|
end
|
36
36
|
|
@@ -46,8 +46,10 @@ module Mock
|
|
46
46
|
@deletes_by_query << query
|
47
47
|
end
|
48
48
|
|
49
|
-
def commit
|
49
|
+
def commit(opts = {})
|
50
|
+
commit_attrs = opts.delete(:commit_attributes) || {}
|
50
51
|
@commits << Time.now
|
52
|
+
@soft_commits << Time.now if commit_attrs[:softCommit]
|
51
53
|
end
|
52
54
|
|
53
55
|
def optimize
|
data/spec/mocks/photo.rb
CHANGED
@@ -1,11 +1,42 @@
|
|
1
1
|
class Photo < MockRecord
|
2
|
-
attr_accessor :caption, :lat, :lng, :size, :average_rating, :created_at
|
2
|
+
attr_accessor :caption, :description, :lat, :lng, :size, :average_rating, :created_at, :post_id, :photo_container_id
|
3
3
|
end
|
4
4
|
|
5
5
|
Sunspot.setup(Photo) do
|
6
6
|
text :caption, :default_boost => 1.5
|
7
|
+
text :description
|
8
|
+
string :caption
|
9
|
+
integer :photo_container_id
|
7
10
|
boost 0.75
|
8
11
|
integer :size, :trie => true
|
9
12
|
float :average_rating, :trie => true
|
10
13
|
time :created_at, :trie => true
|
11
14
|
end
|
15
|
+
|
16
|
+
class Picture < MockRecord
|
17
|
+
attr_accessor :description, :photo_container_id
|
18
|
+
end
|
19
|
+
|
20
|
+
Sunspot.setup(Picture) do
|
21
|
+
text :description
|
22
|
+
integer :photo_container_id
|
23
|
+
end
|
24
|
+
|
25
|
+
class PhotoContainer < MockRecord
|
26
|
+
attr_accessor :description
|
27
|
+
|
28
|
+
def id
|
29
|
+
1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Sunspot.setup(PhotoContainer) do
|
34
|
+
integer :id
|
35
|
+
text :description, :default_boost => 1.2
|
36
|
+
|
37
|
+
join(:caption, :target => Photo, :type => :string, :join => { :from => :photo_container_id, :to => :id })
|
38
|
+
join(:photo_rating, :target => Photo, :type => :trie_float, :join => { :from => :photo_container_id, :to => :id }, :as => 'average_rating_ft')
|
39
|
+
join(:caption, :target => Photo, :type => :text, :join => { :from => :photo_container_id, :to => :id })
|
40
|
+
join(:description, :target => Photo, :type => :text, :join => { :from => :photo_container_id, :to => :id }, :prefix => "photo")
|
41
|
+
join(:description, :target => Picture, :type => :text, :join => { :from => :photo_container_id, :to => :id }, :prefix => "picture")
|
42
|
+
end
|
data/spec/mocks/post.rb
CHANGED
@@ -3,7 +3,8 @@ require File.join(File.dirname(__FILE__), 'super_class')
|
|
3
3
|
|
4
4
|
class Post < SuperClass
|
5
5
|
attr_accessor :title, :body, :blog_id, :published_at, :ratings_average,
|
6
|
-
:author_name, :featured, :expire_date, :coordinates, :tags
|
6
|
+
:author_name, :featured, :expire_date, :coordinates, :tags,
|
7
|
+
:featured_for
|
7
8
|
alias_method :featured?, :featured
|
8
9
|
|
9
10
|
def category_ids
|
@@ -14,6 +15,10 @@ class Post < SuperClass
|
|
14
15
|
@custom_string ||= {}
|
15
16
|
end
|
16
17
|
|
18
|
+
def custom_underscored_string
|
19
|
+
@custom_underscored_string ||= {}
|
20
|
+
end
|
21
|
+
|
17
22
|
def custom_fl
|
18
23
|
@custom_fl ||= {}
|
19
24
|
end
|
@@ -27,22 +32,27 @@ class Post < SuperClass
|
|
27
32
|
end
|
28
33
|
|
29
34
|
private
|
30
|
-
attr_writer :category_ids, :custom_string, :custom_fl, :custom_time, :custom_boolean
|
35
|
+
attr_writer :category_ids, :custom_string, :custom_underscored_string, :custom_fl, :custom_time, :custom_boolean
|
31
36
|
end
|
32
37
|
|
33
38
|
Sunspot.setup(Post) do
|
34
39
|
text :title, :boost => 2
|
40
|
+
text :text_array, :boost => 3 do
|
41
|
+
[title, title]
|
42
|
+
end
|
35
43
|
text :body, :stored => true, :more_like_this => true
|
36
44
|
text :backwards_title do
|
37
45
|
title.reverse if title
|
38
46
|
end
|
39
47
|
text :tags, :more_like_this => true
|
40
48
|
string :title, :stored => true
|
49
|
+
string :author_name
|
41
50
|
integer :blog_id, :references => Blog
|
42
51
|
integer :category_ids, :multiple => true
|
43
52
|
float :average_rating, :using => :ratings_average, :trie => true
|
44
53
|
time :published_at, :trie => true
|
45
54
|
date :expire_date
|
55
|
+
date_range :featured_for
|
46
56
|
boolean :featured, :using => :featured?, :stored => true
|
47
57
|
string :sort_title do
|
48
58
|
title.downcase.sub(/^(a|an|the)\W+/, '') if title
|
@@ -57,6 +67,7 @@ Sunspot.setup(Post) do
|
|
57
67
|
latlon(:coordinates_new) { coordinates }
|
58
68
|
|
59
69
|
dynamic_string :custom_string, :stored => true
|
70
|
+
dynamic_string :custom_underscored_string, separator: '__'
|
60
71
|
dynamic_float :custom_float, :multiple => true, :using => :custom_fl
|
61
72
|
dynamic_integer :custom_integer do
|
62
73
|
category_ids.inject({}) do |hash, category_id|
|
@@ -78,7 +89,11 @@ Sunspot.setup(Post) do
|
|
78
89
|
|
79
90
|
string :legacy_array, :as => :legacy_array_field_sm, :multiple => true do
|
80
91
|
['first string', 'second string']
|
81
|
-
|
92
|
+
end
|
93
|
+
|
94
|
+
string :tag_list, :multiple => true, :stored => true do
|
95
|
+
tags
|
96
|
+
end
|
82
97
|
end
|
83
98
|
|
84
99
|
class PhotoPost < Post
|