gojee-sunspot 2.0.3 → 2.0.4
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.
- data/.gitignore +12 -0
- data/Gemfile +5 -0
- data/History.txt +252 -0
- data/LICENSE +18 -0
- data/Rakefile +13 -0
- data/TODO +13 -0
- data/lib/light_config.rb +40 -0
- data/lib/sunspot/adapters.rb +265 -0
- data/lib/sunspot/batcher.rb +62 -0
- data/lib/sunspot/class_set.rb +23 -0
- data/lib/sunspot/composite_setup.rb +202 -0
- data/lib/sunspot/configuration.rb +53 -0
- data/lib/sunspot/data_extractor.rb +50 -0
- data/lib/sunspot/dsl/adjustable.rb +47 -0
- data/lib/sunspot/dsl/field_group.rb +57 -0
- data/lib/sunspot/dsl/field_query.rb +327 -0
- data/lib/sunspot/dsl/fields.rb +103 -0
- data/lib/sunspot/dsl/fulltext.rb +243 -0
- data/lib/sunspot/dsl/function.rb +27 -0
- data/lib/sunspot/dsl/functional.rb +44 -0
- data/lib/sunspot/dsl/more_like_this_query.rb +56 -0
- data/lib/sunspot/dsl/paginatable.rb +32 -0
- data/lib/sunspot/dsl/query_facet.rb +36 -0
- data/lib/sunspot/dsl/restriction.rb +25 -0
- data/lib/sunspot/dsl/restriction_with_near.rb +160 -0
- data/lib/sunspot/dsl/scope.rb +217 -0
- data/lib/sunspot/dsl/search.rb +30 -0
- data/lib/sunspot/dsl/standard_query.rb +123 -0
- data/lib/sunspot/dsl.rb +5 -0
- data/lib/sunspot/field.rb +193 -0
- data/lib/sunspot/field_factory.rb +129 -0
- data/lib/sunspot/indexer.rb +136 -0
- data/lib/sunspot/query/abstract_field_facet.rb +52 -0
- data/lib/sunspot/query/bbox.rb +15 -0
- data/lib/sunspot/query/boost_query.rb +24 -0
- data/lib/sunspot/query/common_query.rb +96 -0
- data/lib/sunspot/query/composite_fulltext.rb +36 -0
- data/lib/sunspot/query/connective.rb +206 -0
- data/lib/sunspot/query/date_field_facet.rb +14 -0
- data/lib/sunspot/query/dismax.rb +132 -0
- data/lib/sunspot/query/field_facet.rb +41 -0
- data/lib/sunspot/query/field_group.rb +36 -0
- data/lib/sunspot/query/filter.rb +38 -0
- data/lib/sunspot/query/function_query.rb +52 -0
- data/lib/sunspot/query/geo.rb +53 -0
- data/lib/sunspot/query/geofilt.rb +16 -0
- data/lib/sunspot/query/highlighting.rb +62 -0
- data/lib/sunspot/query/more_like_this.rb +61 -0
- data/lib/sunspot/query/more_like_this_query.rb +12 -0
- data/lib/sunspot/query/pagination.rb +42 -0
- data/lib/sunspot/query/query_facet.rb +16 -0
- data/lib/sunspot/query/restriction.rb +262 -0
- data/lib/sunspot/query/scope.rb +9 -0
- data/lib/sunspot/query/sort.rb +109 -0
- data/lib/sunspot/query/sort_composite.rb +34 -0
- data/lib/sunspot/query/standard_query.rb +16 -0
- data/lib/sunspot/query/text_field_boost.rb +17 -0
- data/lib/sunspot/query.rb +11 -0
- data/lib/sunspot/schema.rb +151 -0
- data/lib/sunspot/search/abstract_search.rb +281 -0
- data/lib/sunspot/search/date_facet.rb +35 -0
- data/lib/sunspot/search/facet_row.rb +27 -0
- data/lib/sunspot/search/field_facet.rb +88 -0
- data/lib/sunspot/search/field_group.rb +32 -0
- data/lib/sunspot/search/group.rb +50 -0
- data/lib/sunspot/search/highlight.rb +38 -0
- data/lib/sunspot/search/hit.rb +150 -0
- data/lib/sunspot/search/hit_enumerable.rb +72 -0
- data/lib/sunspot/search/more_like_this_search.rb +31 -0
- data/lib/sunspot/search/paginated_collection.rb +57 -0
- data/lib/sunspot/search/query_facet.rb +67 -0
- data/lib/sunspot/search/standard_search.rb +21 -0
- data/lib/sunspot/search.rb +9 -0
- data/lib/sunspot/session.rb +262 -0
- data/lib/sunspot/session_proxy/abstract_session_proxy.rb +29 -0
- data/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +66 -0
- data/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +89 -0
- data/lib/sunspot/session_proxy/master_slave_session_proxy.rb +43 -0
- data/lib/sunspot/session_proxy/multicore_session_proxy.rb +67 -0
- data/lib/sunspot/session_proxy/sharding_session_proxy.rb +222 -0
- data/lib/sunspot/session_proxy/silent_fail_session_proxy.rb +42 -0
- data/lib/sunspot/session_proxy/thread_local_session_proxy.rb +37 -0
- data/lib/sunspot/session_proxy.rb +95 -0
- data/lib/sunspot/setup.rb +350 -0
- data/lib/sunspot/text_field_setup.rb +29 -0
- data/lib/sunspot/type.rb +393 -0
- data/lib/sunspot/util.rb +252 -0
- data/lib/sunspot/version.rb +3 -0
- data/lib/sunspot.rb +579 -0
- data/log/.gitignore +1 -0
- data/pkg/.gitignore +1 -0
- data/script/console +10 -0
- data/spec/api/adapters_spec.rb +33 -0
- data/spec/api/batcher_spec.rb +112 -0
- data/spec/api/binding_spec.rb +50 -0
- data/spec/api/class_set_spec.rb +24 -0
- data/spec/api/hit_enumerable_spec.rb +47 -0
- data/spec/api/indexer/attributes_spec.rb +149 -0
- data/spec/api/indexer/batch_spec.rb +72 -0
- data/spec/api/indexer/dynamic_fields_spec.rb +42 -0
- data/spec/api/indexer/fixed_fields_spec.rb +57 -0
- data/spec/api/indexer/fulltext_spec.rb +43 -0
- data/spec/api/indexer/removal_spec.rb +53 -0
- data/spec/api/indexer/spec_helper.rb +1 -0
- data/spec/api/indexer_spec.rb +14 -0
- data/spec/api/query/advanced_manipulation_examples.rb +35 -0
- data/spec/api/query/connectives_examples.rb +189 -0
- data/spec/api/query/dsl_spec.rb +18 -0
- data/spec/api/query/dynamic_fields_examples.rb +165 -0
- data/spec/api/query/faceting_examples.rb +397 -0
- data/spec/api/query/fulltext_examples.rb +313 -0
- data/spec/api/query/function_spec.rb +79 -0
- data/spec/api/query/geo_examples.rb +68 -0
- data/spec/api/query/group_spec.rb +32 -0
- data/spec/api/query/highlighting_examples.rb +245 -0
- data/spec/api/query/more_like_this_spec.rb +140 -0
- data/spec/api/query/ordering_pagination_examples.rb +116 -0
- data/spec/api/query/scope_examples.rb +275 -0
- data/spec/api/query/spatial_examples.rb +27 -0
- data/spec/api/query/spec_helper.rb +1 -0
- data/spec/api/query/standard_spec.rb +29 -0
- data/spec/api/query/text_field_scoping_examples.rb +30 -0
- data/spec/api/query/types_spec.rb +20 -0
- data/spec/api/search/dynamic_fields_spec.rb +33 -0
- data/spec/api/search/faceting_spec.rb +360 -0
- data/spec/api/search/highlighting_spec.rb +69 -0
- data/spec/api/search/hits_spec.rb +131 -0
- data/spec/api/search/paginated_collection_spec.rb +36 -0
- data/spec/api/search/results_spec.rb +72 -0
- data/spec/api/search/search_spec.rb +23 -0
- data/spec/api/search/spec_helper.rb +1 -0
- data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +85 -0
- data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +30 -0
- data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +41 -0
- data/spec/api/session_proxy/sharding_session_proxy_spec.rb +77 -0
- data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +24 -0
- data/spec/api/session_proxy/spec_helper.rb +9 -0
- data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +39 -0
- data/spec/api/session_spec.rb +232 -0
- data/spec/api/spec_helper.rb +3 -0
- data/spec/api/sunspot_spec.rb +29 -0
- data/spec/ext.rb +11 -0
- data/spec/helpers/indexer_helper.rb +17 -0
- data/spec/helpers/integration_helper.rb +8 -0
- data/spec/helpers/mock_session_helper.rb +13 -0
- data/spec/helpers/query_helper.rb +26 -0
- data/spec/helpers/search_helper.rb +68 -0
- data/spec/integration/dynamic_fields_spec.rb +57 -0
- data/spec/integration/faceting_spec.rb +251 -0
- data/spec/integration/field_grouping_spec.rb +66 -0
- data/spec/integration/geospatial_spec.rb +85 -0
- data/spec/integration/highlighting_spec.rb +44 -0
- data/spec/integration/indexing_spec.rb +55 -0
- data/spec/integration/keyword_search_spec.rb +317 -0
- data/spec/integration/local_search_spec.rb +64 -0
- data/spec/integration/more_like_this_spec.rb +43 -0
- data/spec/integration/scoped_search_spec.rb +354 -0
- data/spec/integration/stored_fields_spec.rb +12 -0
- data/spec/integration/test_pagination.rb +43 -0
- data/spec/integration/unicode_spec.rb +15 -0
- data/spec/mocks/adapters.rb +32 -0
- data/spec/mocks/blog.rb +3 -0
- data/spec/mocks/comment.rb +21 -0
- data/spec/mocks/connection.rb +126 -0
- data/spec/mocks/mock_adapter.rb +30 -0
- data/spec/mocks/mock_class_sharding_session_proxy.rb +24 -0
- data/spec/mocks/mock_record.rb +52 -0
- data/spec/mocks/mock_sharding_session_proxy.rb +15 -0
- data/spec/mocks/photo.rb +11 -0
- data/spec/mocks/post.rb +86 -0
- data/spec/mocks/super_class.rb +2 -0
- data/spec/mocks/user.rb +13 -0
- data/spec/spec_helper.rb +40 -0
- data/sunspot.gemspec +42 -0
- data/tasks/rdoc.rake +27 -0
- data/tasks/schema.rake +19 -0
- data/tasks/todo.rake +4 -0
- metadata +261 -3
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
shared_examples_for "query with advanced manipulation" do
|
4
|
+
describe 'adjust_solr_params' do
|
5
|
+
before :each do
|
6
|
+
search do
|
7
|
+
adjust_solr_params do |params|
|
8
|
+
params[:rows] = 40
|
9
|
+
params[:qt] = 'complicated'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "modifies existing param" do
|
15
|
+
connection.should have_last_search_with(:rows => 40)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "adds new param" do
|
19
|
+
connection.should have_last_search_with(:qt => 'complicated')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'request_handler' do
|
24
|
+
before :each do
|
25
|
+
connection.expected_handler = :myRequestHandler
|
26
|
+
search do
|
27
|
+
request_handler :myRequestHandler
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should use specified request handler' do
|
32
|
+
connection.should have_last_search_with({})
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
shared_examples_for "query with connective scope" do
|
2
|
+
it 'creates a disjunction between two restrictions' do
|
3
|
+
search do
|
4
|
+
any_of do
|
5
|
+
with :category_ids, 1
|
6
|
+
with :blog_id, 2
|
7
|
+
end
|
8
|
+
end
|
9
|
+
connection.should have_last_search_including(
|
10
|
+
:fq, '(category_ids_im:1 OR blog_id_i:2)'
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'creates a conjunction inside of a disjunction' do
|
15
|
+
search do
|
16
|
+
any_of do
|
17
|
+
with :blog_id, 2
|
18
|
+
all_of do
|
19
|
+
with :category_ids, 1
|
20
|
+
with(:average_rating).greater_than(3.0)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
connection.should have_last_search_including(
|
25
|
+
:fq,
|
26
|
+
'(blog_id_i:2 OR (category_ids_im:1 AND average_rating_ft:[3\.0 TO *]))'
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'creates a disjunction with nested conjunction with negated restrictions' do
|
31
|
+
search do
|
32
|
+
any_of do
|
33
|
+
with :category_ids, 1
|
34
|
+
all_of do
|
35
|
+
without(:average_rating).greater_than(3.0)
|
36
|
+
with(:blog_id, 1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
connection.should have_last_search_including(
|
41
|
+
:fq, '(category_ids_im:1 OR (-average_rating_ft:[3\.0 TO *] AND blog_id_i:1))'
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'does nothing special if #all_of called from the top level' do
|
46
|
+
search do
|
47
|
+
all_of do
|
48
|
+
with :blog_id, 2
|
49
|
+
with :category_ids, 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
connection.should have_last_search_including(
|
53
|
+
:fq, 'blog_id_i:2', 'category_ids_im:1'
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'creates a disjunction with negated restrictions' do
|
58
|
+
search do
|
59
|
+
any_of do
|
60
|
+
with :category_ids, 1
|
61
|
+
without(:average_rating).greater_than(3.0)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
connection.should have_last_search_including(
|
65
|
+
:fq, '-(-category_ids_im:1 AND average_rating_ft:[3\.0 TO *])'
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'creates a disjunction with a negated restriction and a nested disjunction in a conjunction with a negated restriction' do
|
70
|
+
search do
|
71
|
+
any_of do
|
72
|
+
without(:title, 'Yes')
|
73
|
+
all_of do
|
74
|
+
with(:blog_id, 1)
|
75
|
+
any_of do
|
76
|
+
with(:category_ids, 4)
|
77
|
+
without(:average_rating, 2.0)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
connection.should have_last_search_including(
|
83
|
+
:fq, '-(title_ss:Yes AND -(blog_id_i:1 AND -(-category_ids_im:4 AND average_rating_ft:2\.0)))'
|
84
|
+
)
|
85
|
+
end
|
86
|
+
it 'creates a disjunction with nested conjunction with nested disjunction with negated restriction' do
|
87
|
+
search do
|
88
|
+
any_of do
|
89
|
+
with(:title, 'Yes')
|
90
|
+
all_of do
|
91
|
+
with(:blog_id, 1)
|
92
|
+
any_of do
|
93
|
+
with(:category_ids, 4)
|
94
|
+
without(:average_rating, 2.0)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
connection.should have_last_search_including(
|
100
|
+
:fq, '(title_ss:Yes OR (blog_id_i:1 AND -(-category_ids_im:4 AND average_rating_ft:2\.0)))'
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# This is important because if a disjunction could be nested in another
|
106
|
+
# disjunction, then the inner disjunction could denormalize (and thus
|
107
|
+
# become negated) after the outer disjunction denormalized (checking to
|
108
|
+
# see if the inner one is negated). Since conjunctions never need to
|
109
|
+
# denormalize, if a disjunction can only contain conjunctions or restrictions,
|
110
|
+
# we can guarantee that the negation state of a disjunction's components will
|
111
|
+
# not change when #to_params is called on them.
|
112
|
+
#
|
113
|
+
# Since disjunction is associative, this behavior has no effect on the actual
|
114
|
+
# logical semantics of the disjunction.
|
115
|
+
#
|
116
|
+
it 'creates a single disjunction when disjunctions nested' do
|
117
|
+
search do
|
118
|
+
any_of do
|
119
|
+
with(:title, 'Yes')
|
120
|
+
any_of do
|
121
|
+
with(:blog_id, 1)
|
122
|
+
with(:category_ids, 4)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
connection.should have_last_search_including(
|
127
|
+
:fq, '(title_ss:Yes OR blog_id_i:1 OR category_ids_im:4)'
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'creates a disjunction with instance exclusion' do
|
132
|
+
post = Post.new
|
133
|
+
search do
|
134
|
+
any_of do
|
135
|
+
without(post)
|
136
|
+
with(:category_ids, 1)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
connection.should have_last_search_including(
|
140
|
+
:fq, "-(id:(Post\\ #{post.id}) AND -category_ids_im:1)"
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'creates a disjunction with empty restriction' do
|
145
|
+
search do
|
146
|
+
any_of do
|
147
|
+
with(:average_rating, nil)
|
148
|
+
with(:average_rating).greater_than(3.0)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
connection.should have_last_search_including(
|
152
|
+
:fq, '-(average_rating_ft:[* TO *] AND -average_rating_ft:[3\.0 TO *])'
|
153
|
+
)
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'creates a disjunction with instance inclusion' do
|
157
|
+
post = Post.new
|
158
|
+
search do
|
159
|
+
any_of do
|
160
|
+
with(post)
|
161
|
+
with(:average_rating).greater_than(3.0)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
connection.should have_last_search_including(
|
165
|
+
:fq, "(id:(Post\\ #{post.id}) OR average_rating_ft:[3\\.0 TO *])"
|
166
|
+
)
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'creates a disjunction with some text field components' do
|
170
|
+
search do
|
171
|
+
any_of do
|
172
|
+
text_fields do
|
173
|
+
with(:title).starting_with('test')
|
174
|
+
end
|
175
|
+
with(:blog_id, 1)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
connection.should have_last_search_including(
|
179
|
+
:fq, '(title_text:test* OR blog_id_i:1)'
|
180
|
+
)
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should ignore empty connectives' do
|
184
|
+
search do
|
185
|
+
any_of {}
|
186
|
+
end
|
187
|
+
connection.should_not have_last_search_including(:fq, '')
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe 'query DSL', :type => :query do
|
4
|
+
it 'should allow building search using block argument rather than instance_eval' do
|
5
|
+
@blog_id = 1
|
6
|
+
session.search Post do |query|
|
7
|
+
query.with(:blog_id, @blog_id)
|
8
|
+
end
|
9
|
+
connection.should have_last_search_including(:fq, 'blog_id_i:1')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should accept a block in the #new_search method' do
|
13
|
+
search = session.new_search(Post) { with(:blog_id, 1) }
|
14
|
+
search.execute
|
15
|
+
connection.should have_last_search_including(:fq, 'blog_id_i:1')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,165 @@
|
|
1
|
+
shared_examples_for "query with dynamic field support" do
|
2
|
+
it 'restricts by dynamic string field with equality restriction' do
|
3
|
+
search do
|
4
|
+
dynamic :custom_string do
|
5
|
+
with :test, 'string'
|
6
|
+
end
|
7
|
+
end
|
8
|
+
connection.should have_last_search_including(:fq, 'custom_string\:test_ss:string')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'restricts by dynamic integer field with less than restriction' do
|
12
|
+
search do
|
13
|
+
dynamic :custom_integer do
|
14
|
+
with(:test).less_than(1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
connection.should have_last_search_including(:fq, 'custom_integer\:test_i:[* TO 1]')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'restricts by dynamic float field with between restriction' do
|
21
|
+
search do
|
22
|
+
dynamic :custom_float do
|
23
|
+
with(:test).between(2.2..3.3)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
connection.should have_last_search_including(:fq, 'custom_float\:test_fm:[2\.2 TO 3\.3]')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'restricts by dynamic time field with any of restriction' do
|
30
|
+
search do
|
31
|
+
dynamic :custom_time do
|
32
|
+
with(:test).any_of([Time.parse('2009-02-10 14:00:00 UTC'),
|
33
|
+
Time.parse('2009-02-13 18:00:00 UTC')])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
connection.should have_last_search_including(:fq, 'custom_time\:test_d:(2009\-02\-10T14\:00\:00Z OR 2009\-02\-13T18\:00\:00Z)')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'restricts by dynamic boolean field with equality restriction' do
|
40
|
+
search do
|
41
|
+
dynamic :custom_boolean do
|
42
|
+
with :test, false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
connection.should have_last_search_including(:fq, 'custom_boolean\:test_b:false')
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'negates a dynamic field restriction' do
|
49
|
+
search do
|
50
|
+
dynamic :custom_string do
|
51
|
+
without :test, 'foo'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
connection.should have_last_search_including(:fq, '-custom_string\:test_ss:foo')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'scopes by a dynamic field inside a disjunction' do
|
58
|
+
search do
|
59
|
+
any_of do
|
60
|
+
dynamic :custom_string do
|
61
|
+
with :test, 'foo'
|
62
|
+
end
|
63
|
+
with :title, 'bar'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
connection.should have_last_search_including(
|
67
|
+
:fq, '(custom_string\:test_ss:foo OR title_ss:bar)'
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'orders by a dynamic field' do
|
72
|
+
search do
|
73
|
+
dynamic :custom_integer do
|
74
|
+
order_by :test, :desc
|
75
|
+
end
|
76
|
+
end
|
77
|
+
connection.should have_last_search_with(:sort => 'custom_integer:test_i desc')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'orders by a dynamic field and static field, with given precedence' do
|
81
|
+
search do
|
82
|
+
dynamic :custom_integer do
|
83
|
+
order_by :test, :desc
|
84
|
+
end
|
85
|
+
order_by :sort_title, :asc
|
86
|
+
end
|
87
|
+
connection.should have_last_search_with(:sort => 'custom_integer:test_i desc, sort_title_s asc')
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'raises an UnrecognizedFieldError if an unknown dynamic field is searched by' do
|
91
|
+
lambda do
|
92
|
+
search do
|
93
|
+
dynamic(:bogus) { with :some, 'value' }
|
94
|
+
end
|
95
|
+
end.should raise_error(Sunspot::UnrecognizedFieldError)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'raises a NoMethodError if pagination is attempted in a dynamic query' do
|
99
|
+
lambda do
|
100
|
+
search do
|
101
|
+
dynamic :custom_string do
|
102
|
+
paginate :page => 3, :per_page => 10
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end.should raise_error(NoMethodError)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'requests field facet on dynamic field' do
|
109
|
+
search do
|
110
|
+
dynamic :custom_string do
|
111
|
+
facet(:test)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
connection.should have_last_search_including(:"facet.field", 'custom_string:test_ss')
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'requests named field facet on dynamic field' do
|
118
|
+
search do
|
119
|
+
dynamic :custom_string do
|
120
|
+
facet(:test, :name => :bogus)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
connection.should have_last_search_including(:"facet.field", '{!key=bogus}custom_string:test_ss')
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'requests query facet with internal dynamic field' do
|
127
|
+
search do
|
128
|
+
facet :test do
|
129
|
+
row 'foo' do
|
130
|
+
dynamic :custom_string do
|
131
|
+
with :test, 'foo'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
connection.should have_last_search_with(
|
137
|
+
:"facet.query" => 'custom_string\:test_ss:foo'
|
138
|
+
)
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'requests query facet with external dynamic field' do
|
142
|
+
search do
|
143
|
+
dynamic :custom_string do
|
144
|
+
facet :test do
|
145
|
+
row 'foo' do
|
146
|
+
with :test, 'foo'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
connection.should have_last_search_including(
|
152
|
+
:"facet.query",
|
153
|
+
'custom_string\:test_ss:foo'
|
154
|
+
)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'allows scoping on dynamic fields common to all types' do
|
158
|
+
search Post, Namespaced::Comment do
|
159
|
+
dynamic :custom_float do
|
160
|
+
with(:test, 1.23)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
connection.should have_last_search_including(:fq, 'custom_float\\:test_fm:1\\.23')
|
164
|
+
end
|
165
|
+
end
|