pduey-sunspot 1.2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/.gitignore +12 -0
  2. data/Gemfile +5 -0
  3. data/History.txt +225 -0
  4. data/LICENSE +18 -0
  5. data/Rakefile +15 -0
  6. data/TODO +13 -0
  7. data/VERSION.yml +4 -0
  8. data/bin/sunspot-installer +19 -0
  9. data/installer/config/schema.yml +95 -0
  10. data/lib/light_config.rb +40 -0
  11. data/lib/sunspot.rb +568 -0
  12. data/lib/sunspot/adapters.rb +265 -0
  13. data/lib/sunspot/composite_setup.rb +202 -0
  14. data/lib/sunspot/configuration.rb +46 -0
  15. data/lib/sunspot/data_extractor.rb +50 -0
  16. data/lib/sunspot/dsl.rb +5 -0
  17. data/lib/sunspot/dsl/adjustable.rb +47 -0
  18. data/lib/sunspot/dsl/field_query.rb +279 -0
  19. data/lib/sunspot/dsl/fields.rb +103 -0
  20. data/lib/sunspot/dsl/fulltext.rb +243 -0
  21. data/lib/sunspot/dsl/function.rb +14 -0
  22. data/lib/sunspot/dsl/functional.rb +44 -0
  23. data/lib/sunspot/dsl/more_like_this_query.rb +56 -0
  24. data/lib/sunspot/dsl/paginatable.rb +28 -0
  25. data/lib/sunspot/dsl/query_facet.rb +36 -0
  26. data/lib/sunspot/dsl/restriction.rb +25 -0
  27. data/lib/sunspot/dsl/restriction_with_near.rb +121 -0
  28. data/lib/sunspot/dsl/scope.rb +217 -0
  29. data/lib/sunspot/dsl/search.rb +30 -0
  30. data/lib/sunspot/dsl/standard_query.rb +121 -0
  31. data/lib/sunspot/field.rb +193 -0
  32. data/lib/sunspot/field_factory.rb +129 -0
  33. data/lib/sunspot/indexer.rb +131 -0
  34. data/lib/sunspot/installer.rb +31 -0
  35. data/lib/sunspot/installer/library_installer.rb +45 -0
  36. data/lib/sunspot/installer/schema_builder.rb +219 -0
  37. data/lib/sunspot/installer/solrconfig_updater.rb +76 -0
  38. data/lib/sunspot/installer/task_helper.rb +18 -0
  39. data/lib/sunspot/java.rb +8 -0
  40. data/lib/sunspot/query.rb +11 -0
  41. data/lib/sunspot/query/abstract_field_facet.rb +52 -0
  42. data/lib/sunspot/query/boost_query.rb +24 -0
  43. data/lib/sunspot/query/common_query.rb +85 -0
  44. data/lib/sunspot/query/composite_fulltext.rb +36 -0
  45. data/lib/sunspot/query/connective.rb +206 -0
  46. data/lib/sunspot/query/date_field_facet.rb +14 -0
  47. data/lib/sunspot/query/dismax.rb +128 -0
  48. data/lib/sunspot/query/field_facet.rb +41 -0
  49. data/lib/sunspot/query/filter.rb +38 -0
  50. data/lib/sunspot/query/function_query.rb +52 -0
  51. data/lib/sunspot/query/geo.rb +53 -0
  52. data/lib/sunspot/query/highlighting.rb +55 -0
  53. data/lib/sunspot/query/more_like_this.rb +61 -0
  54. data/lib/sunspot/query/more_like_this_query.rb +12 -0
  55. data/lib/sunspot/query/pagination.rb +38 -0
  56. data/lib/sunspot/query/query_facet.rb +16 -0
  57. data/lib/sunspot/query/restriction.rb +262 -0
  58. data/lib/sunspot/query/scope.rb +9 -0
  59. data/lib/sunspot/query/sort.rb +95 -0
  60. data/lib/sunspot/query/sort_composite.rb +33 -0
  61. data/lib/sunspot/query/standard_query.rb +16 -0
  62. data/lib/sunspot/query/text_field_boost.rb +17 -0
  63. data/lib/sunspot/schema.rb +151 -0
  64. data/lib/sunspot/search.rb +9 -0
  65. data/lib/sunspot/search/abstract_search.rb +335 -0
  66. data/lib/sunspot/search/date_facet.rb +35 -0
  67. data/lib/sunspot/search/facet_row.rb +27 -0
  68. data/lib/sunspot/search/field_facet.rb +88 -0
  69. data/lib/sunspot/search/highlight.rb +38 -0
  70. data/lib/sunspot/search/hit.rb +150 -0
  71. data/lib/sunspot/search/more_like_this_search.rb +31 -0
  72. data/lib/sunspot/search/paginated_collection.rb +55 -0
  73. data/lib/sunspot/search/query_facet.rb +67 -0
  74. data/lib/sunspot/search/standard_search.rb +21 -0
  75. data/lib/sunspot/session.rb +260 -0
  76. data/lib/sunspot/session_proxy.rb +87 -0
  77. data/lib/sunspot/session_proxy/abstract_session_proxy.rb +29 -0
  78. data/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +66 -0
  79. data/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +89 -0
  80. data/lib/sunspot/session_proxy/master_slave_session_proxy.rb +43 -0
  81. data/lib/sunspot/session_proxy/sharding_session_proxy.rb +222 -0
  82. data/lib/sunspot/session_proxy/silent_fail_session_proxy.rb +42 -0
  83. data/lib/sunspot/session_proxy/thread_local_session_proxy.rb +37 -0
  84. data/lib/sunspot/setup.rb +350 -0
  85. data/lib/sunspot/text_field_setup.rb +29 -0
  86. data/lib/sunspot/type.rb +372 -0
  87. data/lib/sunspot/util.rb +243 -0
  88. data/lib/sunspot/version.rb +3 -0
  89. data/pduey-sunspot.gemspec +38 -0
  90. data/script/console +10 -0
  91. data/spec/api/adapters_spec.rb +33 -0
  92. data/spec/api/binding_spec.rb +50 -0
  93. data/spec/api/indexer/attributes_spec.rb +149 -0
  94. data/spec/api/indexer/batch_spec.rb +46 -0
  95. data/spec/api/indexer/dynamic_fields_spec.rb +42 -0
  96. data/spec/api/indexer/fixed_fields_spec.rb +57 -0
  97. data/spec/api/indexer/fulltext_spec.rb +43 -0
  98. data/spec/api/indexer/removal_spec.rb +53 -0
  99. data/spec/api/indexer/spec_helper.rb +1 -0
  100. data/spec/api/indexer_spec.rb +14 -0
  101. data/spec/api/query/advanced_manipulation_examples.rb +35 -0
  102. data/spec/api/query/connectives_examples.rb +189 -0
  103. data/spec/api/query/dsl_spec.rb +18 -0
  104. data/spec/api/query/dynamic_fields_examples.rb +165 -0
  105. data/spec/api/query/faceting_examples.rb +397 -0
  106. data/spec/api/query/fulltext_examples.rb +313 -0
  107. data/spec/api/query/function_spec.rb +70 -0
  108. data/spec/api/query/geo_examples.rb +68 -0
  109. data/spec/api/query/highlighting_examples.rb +223 -0
  110. data/spec/api/query/more_like_this_spec.rb +140 -0
  111. data/spec/api/query/ordering_pagination_examples.rb +95 -0
  112. data/spec/api/query/scope_examples.rb +275 -0
  113. data/spec/api/query/spec_helper.rb +1 -0
  114. data/spec/api/query/standard_spec.rb +28 -0
  115. data/spec/api/query/text_field_scoping_examples.rb +30 -0
  116. data/spec/api/query/types_spec.rb +20 -0
  117. data/spec/api/search/dynamic_fields_spec.rb +33 -0
  118. data/spec/api/search/faceting_spec.rb +360 -0
  119. data/spec/api/search/highlighting_spec.rb +69 -0
  120. data/spec/api/search/hits_spec.rb +131 -0
  121. data/spec/api/search/paginated_collection_spec.rb +26 -0
  122. data/spec/api/search/results_spec.rb +66 -0
  123. data/spec/api/search/search_spec.rb +23 -0
  124. data/spec/api/search/spec_helper.rb +1 -0
  125. data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +85 -0
  126. data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +30 -0
  127. data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +41 -0
  128. data/spec/api/session_proxy/sharding_session_proxy_spec.rb +77 -0
  129. data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +24 -0
  130. data/spec/api/session_proxy/spec_helper.rb +9 -0
  131. data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +39 -0
  132. data/spec/api/session_spec.rb +220 -0
  133. data/spec/api/spec_helper.rb +3 -0
  134. data/spec/api/sunspot_spec.rb +18 -0
  135. data/spec/ext.rb +11 -0
  136. data/spec/helpers/indexer_helper.rb +29 -0
  137. data/spec/helpers/query_helper.rb +38 -0
  138. data/spec/helpers/search_helper.rb +80 -0
  139. data/spec/integration/dynamic_fields_spec.rb +57 -0
  140. data/spec/integration/faceting_spec.rb +238 -0
  141. data/spec/integration/highlighting_spec.rb +24 -0
  142. data/spec/integration/indexing_spec.rb +33 -0
  143. data/spec/integration/keyword_search_spec.rb +317 -0
  144. data/spec/integration/local_search_spec.rb +64 -0
  145. data/spec/integration/more_like_this_spec.rb +43 -0
  146. data/spec/integration/scoped_search_spec.rb +354 -0
  147. data/spec/integration/spec_helper.rb +7 -0
  148. data/spec/integration/stored_fields_spec.rb +12 -0
  149. data/spec/integration/test_pagination.rb +32 -0
  150. data/spec/mocks/adapters.rb +32 -0
  151. data/spec/mocks/blog.rb +3 -0
  152. data/spec/mocks/comment.rb +21 -0
  153. data/spec/mocks/connection.rb +126 -0
  154. data/spec/mocks/mock_adapter.rb +30 -0
  155. data/spec/mocks/mock_class_sharding_session_proxy.rb +24 -0
  156. data/spec/mocks/mock_record.rb +52 -0
  157. data/spec/mocks/mock_sharding_session_proxy.rb +15 -0
  158. data/spec/mocks/photo.rb +11 -0
  159. data/spec/mocks/post.rb +85 -0
  160. data/spec/mocks/super_class.rb +2 -0
  161. data/spec/mocks/user.rb +13 -0
  162. data/spec/spec_helper.rb +28 -0
  163. data/tasks/rdoc.rake +27 -0
  164. data/tasks/schema.rake +19 -0
  165. data/tasks/todo.rake +4 -0
  166. metadata +369 -0
@@ -0,0 +1,53 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ describe 'document removal', :type => :indexer do
4
+ it 'removes an object from the index' do
5
+ session.remove(post)
6
+ connection.should have_delete("Post #{post.id}")
7
+ end
8
+
9
+ it 'removes an object by type and id' do
10
+ session.remove_by_id(Post, 1)
11
+ connection.should have_delete('Post 1')
12
+ end
13
+
14
+ it 'removes an object by type and id and immediately commits' do
15
+ connection.should_receive(:delete_by_id).with(['Post 1']).ordered
16
+ connection.should_receive(:commit).ordered
17
+ session.remove_by_id!(Post, 1)
18
+ end
19
+
20
+ it 'removes an object from the index and immediately commits' do
21
+ connection.should_receive(:delete_by_id).ordered
22
+ connection.should_receive(:commit).ordered
23
+ session.remove!(post)
24
+ end
25
+
26
+ it 'removes everything from the index' do
27
+ session.remove_all
28
+ connection.should have_delete_by_query("*:*")
29
+ end
30
+
31
+ it 'removes everything from the index and immediately commits' do
32
+ connection.should_receive(:delete_by_query).ordered
33
+ connection.should_receive(:commit).ordered
34
+ session.remove_all!
35
+ end
36
+
37
+ it 'removes everything of a given class from the index' do
38
+ session.remove_all(Post)
39
+ connection.should have_delete_by_query("type:Post")
40
+ end
41
+
42
+ it 'correctly escapes namespaced classes when removing everything from the index' do
43
+ connection.should_receive(:delete_by_query).with('type:Namespaced\:\:Comment')
44
+ session.remove_all(Namespaced::Comment)
45
+ end
46
+
47
+ it 'should remove by query' do
48
+ session.remove(Post) do
49
+ with(:title, 'monkeys')
50
+ end
51
+ connection.should have_delete_by_query("(type:Post AND title_ss:monkeys)")
52
+ end
53
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path('spec_helper', File.join(File.dirname(__FILE__), '..'))
@@ -0,0 +1,14 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ describe 'indexer', :type => :indexer do
4
+ it 'should completely wipe setup if class redefined (reloaded)' do
5
+ Object::ReloadableClass = Class.new(MockRecord)
6
+ Sunspot.setup(ReloadableClass) { string(:title) }
7
+ Object.class_eval { remove_const(:ReloadableClass) }
8
+ Object::ReloadableClass = Class.new(MockRecord)
9
+ Sunspot.setup(ReloadableClass) {}
10
+ lambda do
11
+ Sunspot.search(ReloadableClass) { with(:title, 'title') }
12
+ end.should raise_error(Sunspot::UnrecognizedFieldError)
13
+ end
14
+ end
@@ -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