sunspot 0.9.8 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/History.txt +32 -0
  2. data/README.rdoc +40 -3
  3. data/TODO +10 -8
  4. data/VERSION.yml +2 -2
  5. data/bin/sunspot-configure-solr +22 -28
  6. data/bin/sunspot-solr +50 -29
  7. data/lib/sunspot/adapters.rb +1 -1
  8. data/lib/sunspot/composite_setup.rb +13 -15
  9. data/lib/sunspot/configuration.rb +14 -0
  10. data/lib/sunspot/data_extractor.rb +3 -0
  11. data/lib/sunspot/dsl/field_query.rb +33 -6
  12. data/lib/sunspot/dsl/fields.rb +14 -1
  13. data/lib/sunspot/dsl/fulltext.rb +168 -0
  14. data/lib/sunspot/dsl/query.rb +82 -5
  15. data/lib/sunspot/dsl/query_facet.rb +3 -3
  16. data/lib/sunspot/dsl/restriction.rb +7 -7
  17. data/lib/sunspot/dsl/scope.rb +17 -10
  18. data/lib/sunspot/dsl/search.rb +2 -2
  19. data/lib/sunspot/dsl.rb +2 -1
  20. data/lib/sunspot/facet.rb +9 -1
  21. data/lib/sunspot/facet_data.rb +56 -7
  22. data/lib/sunspot/facet_row.rb +2 -0
  23. data/lib/sunspot/field.rb +50 -26
  24. data/lib/sunspot/field_factory.rb +15 -0
  25. data/lib/sunspot/indexer.rb +6 -0
  26. data/lib/sunspot/instantiated_facet.rb +6 -9
  27. data/lib/sunspot/instantiated_facet_row.rb +7 -2
  28. data/lib/sunspot/query/boost_query.rb +20 -0
  29. data/lib/sunspot/query/connective.rb +98 -35
  30. data/lib/sunspot/query/dismax.rb +69 -0
  31. data/lib/sunspot/query/field_facet.rb +1 -22
  32. data/lib/sunspot/query/fulltext_base_query.rb +47 -0
  33. data/lib/sunspot/query/highlighting.rb +43 -0
  34. data/lib/sunspot/query/local.rb +24 -0
  35. data/lib/sunspot/query/pagination.rb +3 -4
  36. data/lib/sunspot/query/query.rb +93 -0
  37. data/lib/sunspot/query/query_facet.rb +14 -9
  38. data/lib/sunspot/query/query_facet_row.rb +3 -3
  39. data/lib/sunspot/query/query_field_facet.rb +10 -3
  40. data/lib/sunspot/query/restriction.rb +36 -15
  41. data/lib/sunspot/query/scope.rb +3 -159
  42. data/lib/sunspot/query/sort.rb +84 -15
  43. data/lib/sunspot/query/text_field_boost.rb +15 -0
  44. data/lib/sunspot/query.rb +2 -188
  45. data/lib/sunspot/schema.rb +7 -25
  46. data/lib/sunspot/search/highlight.rb +38 -0
  47. data/lib/sunspot/search/hit.rb +50 -3
  48. data/lib/sunspot/search.rb +51 -32
  49. data/lib/sunspot/session.rb +32 -12
  50. data/lib/sunspot/setup.rb +47 -10
  51. data/lib/sunspot/text_field_setup.rb +29 -0
  52. data/lib/sunspot/type.rb +4 -4
  53. data/lib/sunspot/util.rb +27 -1
  54. data/lib/sunspot.rb +8 -17
  55. data/solr/solr/conf/schema.xml +54 -40
  56. data/solr/solr/conf/solrconfig.xml +30 -0
  57. data/solr/solr/lib/geoapi-nogenerics-2.1-M2.jar +0 -0
  58. data/solr/solr/lib/gt2-referencing-2.3.1.jar +0 -0
  59. data/solr/solr/lib/jsr108-0.01.jar +0 -0
  60. data/solr/solr/lib/locallucene.jar +0 -0
  61. data/solr/solr/lib/localsolr.jar +0 -0
  62. data/spec/api/indexer/attributes_spec.rb +100 -0
  63. data/spec/api/indexer/batch_spec.rb +46 -0
  64. data/spec/api/indexer/dynamic_fields_spec.rb +33 -0
  65. data/spec/api/indexer/fixed_fields_spec.rb +57 -0
  66. data/spec/api/indexer/fulltext_spec.rb +43 -0
  67. data/spec/api/indexer/removal_spec.rb +46 -0
  68. data/spec/api/indexer/spec_helper.rb +1 -0
  69. data/spec/api/indexer_spec.rb +1 -308
  70. data/spec/api/query/connectives_spec.rb +162 -0
  71. data/spec/api/query/dsl_spec.rb +12 -0
  72. data/spec/api/query/dynamic_fields_spec.rb +149 -0
  73. data/spec/api/query/faceting_spec.rb +272 -0
  74. data/spec/api/query/fulltext_spec.rb +193 -0
  75. data/spec/api/query/highlighting_spec.rb +138 -0
  76. data/spec/api/query/local_spec.rb +54 -0
  77. data/spec/api/query/ordering_pagination_spec.rb +95 -0
  78. data/spec/api/query/scope_spec.rb +266 -0
  79. data/spec/api/query/spec_helper.rb +1 -0
  80. data/spec/api/query/text_field_scoping_spec.rb +30 -0
  81. data/spec/api/query/types_spec.rb +20 -0
  82. data/spec/api/search/dynamic_fields_spec.rb +27 -0
  83. data/spec/api/search/faceting_spec.rb +206 -0
  84. data/spec/api/search/highlighting_spec.rb +65 -0
  85. data/spec/api/search/hits_spec.rb +62 -0
  86. data/spec/api/search/results_spec.rb +52 -0
  87. data/spec/api/search/search_spec.rb +23 -0
  88. data/spec/api/search/spec_helper.rb +1 -0
  89. data/spec/api/spec_helper.rb +1 -1
  90. data/spec/helpers/indexer_helper.rb +29 -0
  91. data/spec/helpers/query_helper.rb +13 -0
  92. data/spec/helpers/search_helper.rb +78 -0
  93. data/spec/integration/faceting_spec.rb +1 -1
  94. data/spec/integration/highlighting_spec.rb +22 -0
  95. data/spec/integration/keyword_search_spec.rb +65 -0
  96. data/spec/integration/local_search_spec.rb +56 -0
  97. data/spec/integration/scoped_search_spec.rb +15 -1
  98. data/spec/integration/spec_helper.rb +3 -3
  99. data/spec/mocks/connection.rb +14 -1
  100. data/spec/mocks/photo.rb +1 -1
  101. data/spec/mocks/post.rb +5 -3
  102. data/spec/mocks/super_class.rb +2 -0
  103. data/spec/spec_helper.rb +13 -0
  104. data/tasks/gemspec.rake +18 -7
  105. data/tasks/schema.rake +1 -1
  106. data/tasks/spec.rake +1 -1
  107. data/templates/schema.xml.erb +36 -0
  108. metadata +117 -48
  109. data/lib/sunspot/query/base_query.rb +0 -90
  110. data/lib/sunspot/query/dynamic_query.rb +0 -69
  111. data/lib/sunspot/query/field_query.rb +0 -63
  112. data/spec/api/build_search_spec.rb +0 -1017
  113. data/spec/api/query_spec.rb +0 -153
  114. data/spec/api/search_retrieval_spec.rb +0 -362
  115. data/templates/schema.xml.haml +0 -24
@@ -0,0 +1,138 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'highlighted fulltext queries', :type => :query do
4
+ it 'should not send highlight parameter when highlight not requested' do
5
+ session.search(Post) do
6
+ keywords 'test'
7
+ end
8
+ connection.should_not have_last_search_with(:hl)
9
+ end
10
+
11
+ it 'should enable highlighting when highlighting requested as keywords argument' do
12
+ session.search(Post) do
13
+ keywords 'test', :highlight => true
14
+ end
15
+ connection.should have_last_search_with(:hl => 'on')
16
+ end
17
+
18
+ it 'should not set highlight fields parameter if highlight fields are not passed' do
19
+ session.search(Post) do
20
+ keywords 'test', :highlight => true, :fields => [:title]
21
+ end
22
+ connection.should_not have_last_search_with(:'hl.fl')
23
+ end
24
+
25
+ it 'should enable highlighting on multiple fields when highlighting requested as array of fields via keywords argument' do
26
+ session.search(Post) do
27
+ keywords 'test', :highlight => [:title, :body]
28
+ end
29
+
30
+ connection.should have_last_search_with(:hl => 'on', :'hl.fl' => %w(title_text body_texts))
31
+ end
32
+
33
+ it 'should raise UnrecognizedFieldError if try to highlight unexisting field via keywords argument' do
34
+ lambda {
35
+ session.search(Post) do
36
+ keywords 'test', :highlight => [:unknown_field]
37
+ end
38
+ }.should raise_error(Sunspot::UnrecognizedFieldError)
39
+ end
40
+
41
+ it 'should enable highlighting on multiple fields when highlighting requested as list of fields via block call' do
42
+ session.search(Post) do
43
+ keywords 'test' do
44
+ highlight :title, :body
45
+ end
46
+ end
47
+
48
+ connection.should have_last_search_with(:hl => 'on', :'hl.fl' => %w(title_text body_texts))
49
+ end
50
+
51
+ it 'should raise UnrecognizedFieldError if try to highlight unexisting field via block call' do
52
+ lambda {
53
+ session.search(Post) do
54
+ keywords 'test' do
55
+ highlight :unknown_field
56
+ end
57
+ end
58
+ }.should raise_error(Sunspot::UnrecognizedFieldError)
59
+ end
60
+
61
+ it 'should set internal formatting' do
62
+ session.search(Post) do
63
+ keywords 'test', :highlight => true
64
+ end
65
+ connection.should have_last_search_with(
66
+ :"hl.simple.pre" => '@@@hl@@@',
67
+ :"hl.simple.post" => '@@@endhl@@@'
68
+ )
69
+ end
70
+
71
+ it 'should set options and hihglight fields' do
72
+ session.search(Post) do
73
+ keywords 'test' do
74
+ highlight :title, :max_snippets => 3
75
+ end
76
+ end
77
+ connection.should have_last_search_with(
78
+ :"hl.fl" => %w(title_text),
79
+ :"hl.snippets" => 3
80
+ )
81
+ end
82
+
83
+ it 'should set maximum highlights per field' do
84
+ session.search(Post) do
85
+ keywords 'test' do
86
+ highlight :max_snippets => 3
87
+ end
88
+ end
89
+ connection.should have_last_search_with(
90
+ :"hl.snippets" => 3
91
+ )
92
+ end
93
+
94
+ it 'should set the maximum size' do
95
+ session.search(Post) do
96
+ keywords 'text' do
97
+ highlight :fragment_size => 200
98
+ end
99
+ end
100
+ connection.should have_last_search_with(
101
+ :"hl.fragsize" => 200
102
+ )
103
+ end
104
+
105
+ it 'enables merging of continuous fragments' do
106
+ session.search(Post) do
107
+ keywords 'test' do
108
+ highlight :merge_continuous_fragments => true
109
+ end
110
+ end
111
+ connection.should have_last_search_with(
112
+ :"hl.mergeContinuous" => 'true'
113
+ )
114
+ end
115
+
116
+ it 'enables use of phrase highlighter' do #TODO figure out what the hell this means
117
+ session.search(Post) do
118
+ keywords 'test' do
119
+ highlight :phrase_highlighter => true
120
+ end
121
+ end
122
+ connection.should have_last_search_with(
123
+ :"hl.usePhraseHighlighter" => 'true'
124
+ )
125
+ end
126
+
127
+ it 'requires field match if requested' do
128
+ session.search(Post) do
129
+ keywords 'test' do
130
+ highlight :phrase_highlighter => true, :require_field_match => true
131
+ end
132
+ end
133
+ connection.should have_last_search_with(
134
+ :"hl.requireFieldMatch" => 'true'
135
+ )
136
+ end
137
+
138
+ end
@@ -0,0 +1,54 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'local query' do
4
+ it 'sets query type to geo when geo search performed' do
5
+ session.search Post do
6
+ near [40.7, -73.5], 5
7
+ end
8
+ connection.should have_last_search_with(:qt => 'geo')
9
+ end
10
+
11
+ it 'sets lat and lng when geo search is performed' do
12
+ session.search Post do
13
+ near [40.7, -73.5], 5
14
+ end
15
+ connection.should have_last_search_with(:lat => 40.7, :long => -73.5)
16
+ end
17
+
18
+ it 'sets radius when geo search is performed' do
19
+ session.search Post do
20
+ near [40.7, -73.5], 5
21
+ end
22
+ connection.should have_last_search_with(:radius => 5)
23
+ end
24
+
25
+ it 'puts all scope parameters into :q parameter when geo search is performed' do
26
+ session.search Post do
27
+ with :blog_id, 1
28
+ near [40.7, -73.5], 5
29
+ end
30
+ connection.should have_last_search_with(:q => '(type:Post AND blog_id_i:1)')
31
+ end
32
+
33
+ it 'raises error if keywords specified in local search' do
34
+ lambda do
35
+ session.search Post do
36
+ keywords 'fail'
37
+ near [40.7, -73.5], 5
38
+ end
39
+ end.should raise_error(Sunspot::IllegalSearchError)
40
+ end
41
+
42
+ [
43
+ [:lat, :lng],
44
+ [:lat, :lon],
45
+ [:lat, :long]
46
+ ].each do |lat_attr, lng_attr|
47
+ it "sets coordinates using #{lat_attr.inspect}, #{lng_attr.inspect}" do
48
+ session.search Post do
49
+ near OpenStruct.new(lat_attr => 40.7, lng_attr => -73.5), 5
50
+ end
51
+ connection.should have_last_search_with(:lat => 40.7, :long => -73.5)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,95 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'ordering and pagination' do
4
+ it 'paginates using default per_page when page not provided' do
5
+ session.search Post
6
+ connection.should have_last_search_with(:rows => 30)
7
+ end
8
+
9
+ it 'paginates using default per_page when page provided' do
10
+ session.search Post do
11
+ paginate :page => 2
12
+ end
13
+ connection.should have_last_search_with(:rows => 30, :start => 30)
14
+ end
15
+
16
+ it 'paginates using provided per_page' do
17
+ session.search Post do
18
+ paginate :page => 4, :per_page => 15
19
+ end
20
+ connection.should have_last_search_with(:rows => 15, :start => 45)
21
+ end
22
+
23
+ it 'defaults to page 1 if no :page argument given' do
24
+ session.search Post do
25
+ paginate :per_page => 15
26
+ end
27
+ connection.should have_last_search_with(:rows => 15, :start => 0)
28
+ end
29
+
30
+ it 'paginates from string argument' do
31
+ session.search Post do
32
+ paginate :page => '3', :per_page => '15'
33
+ end
34
+ connection.should have_last_search_with(:rows => 15, :start => 30)
35
+ end
36
+
37
+ it 'orders by a single field' do
38
+ session.search Post do
39
+ order_by :average_rating, :desc
40
+ end
41
+ connection.should have_last_search_with(:sort => 'average_rating_f desc')
42
+ end
43
+
44
+ it 'orders by multiple fields' do
45
+ session.search Post do
46
+ order_by :average_rating, :desc
47
+ order_by :sort_title, :asc
48
+ end
49
+ connection.should have_last_search_with(:sort => 'average_rating_f desc, sort_title_s asc')
50
+ end
51
+
52
+ it 'orders by random' do
53
+ session.search Post do
54
+ order_by :random
55
+ end
56
+ connection.searches.last[:sort].should =~ /^random_\d+ asc$/
57
+ end
58
+
59
+ it 'orders by score' do
60
+ session.search Post do
61
+ order_by :score, :desc
62
+ end
63
+ connection.should have_last_search_with(:sort => 'score desc')
64
+ end
65
+
66
+ it 'orders by geo distance' do
67
+ session.search Post do
68
+ order_by :distance, :asc
69
+ end
70
+ end
71
+
72
+ it 'throws an ArgumentError if a bogus order direction is given' do
73
+ lambda do
74
+ session.search Post do
75
+ order_by :sort_title, :sideways
76
+ end
77
+ end.should raise_error(ArgumentError)
78
+ end
79
+
80
+ it 'does not allow ordering by multiple-value fields' do
81
+ lambda do
82
+ session.search Post do
83
+ order_by :category_ids
84
+ end
85
+ end.should raise_error(ArgumentError)
86
+ end
87
+
88
+ it 'raises ArgumentError if bogus argument given to paginate' do
89
+ lambda do
90
+ session.search Post do
91
+ paginate :page => 4, :ugly => :puppy
92
+ end
93
+ end.should raise_error(ArgumentError)
94
+ end
95
+ end
@@ -0,0 +1,266 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'scoped query', :type => :query do
4
+ it 'adds a no-op query to :q parameter when no :q provided' do
5
+ session.search Post do
6
+ with :title, 'My Pet Post'
7
+ end
8
+ connection.should have_last_search_with(:q => '*:*')
9
+ end
10
+
11
+ it 'scopes by exact match with a string' do
12
+ session.search Post do
13
+ with :title, 'My Pet Post'
14
+ end
15
+ connection.should have_last_search_including(:fq, 'title_ss:My\ Pet\ Post')
16
+ end
17
+
18
+ it 'scopes by exact match with time' do
19
+ time = Time.parse('1983-07-08 05:00:00 -0400')
20
+ session.search Post do
21
+ with :published_at, time
22
+ end
23
+ connection.should have_last_search_including(
24
+ :fq,
25
+ 'published_at_d:1983\-07\-08T09\:00\:00Z'
26
+ )
27
+ end
28
+
29
+ it 'scopes by exact match with date' do
30
+ date = Date.new(1983, 7, 8)
31
+ session.search Post do
32
+ with :expire_date, date
33
+ end
34
+ connection.should have_last_search_including(
35
+ :fq,
36
+ 'expire_date_d:1983\-07\-08T00\:00\:00Z'
37
+ )
38
+ end
39
+
40
+ it 'scopes by exact match with boolean' do
41
+ session.search Post do
42
+ with :featured, false
43
+ end
44
+ connection.should have_last_search_including(:fq, 'featured_b:false')
45
+ end
46
+
47
+ it 'scopes by less than match with float' do
48
+ session.search Post do
49
+ with(:average_rating).less_than 3.0
50
+ end
51
+ connection.should have_last_search_including(:fq, 'average_rating_f:[* TO 3\.0]')
52
+ end
53
+
54
+ it 'should quote string with space in a less than match' do
55
+ session.search Post do
56
+ with(:title).less_than('test value')
57
+ end
58
+ connection.should have_last_search_including(:fq, 'title_ss:[* TO "test\ value"]')
59
+ end
60
+
61
+ it 'scopes by greater than match with float' do
62
+ session.search Post do
63
+ with(:average_rating).greater_than 3.0
64
+ end
65
+ connection.should have_last_search_including(:fq, 'average_rating_f:[3\.0 TO *]')
66
+ end
67
+
68
+ it 'scopes by short-form between match with integers' do
69
+ session.search Post do
70
+ with :blog_id, 2..4
71
+ end
72
+ connection.should have_last_search_including(:fq, 'blog_id_i:[2 TO 4]')
73
+ end
74
+
75
+ it 'scopes by between match with float' do
76
+ session.search Post do
77
+ with(:average_rating).between 2.0..4.0
78
+ end
79
+ connection.should have_last_search_including(:fq, 'average_rating_f:[2\.0 TO 4\.0]')
80
+ end
81
+
82
+ it 'automatically sorts ranges in between matches' do
83
+ session.search Post do
84
+ with(:blog_id).between(4..2)
85
+ end
86
+ connection.should have_last_search_including(:fq, 'blog_id_i:[2 TO 4]')
87
+ end
88
+
89
+ it 'scopes by any match with integer' do
90
+ session.search Post do
91
+ with(:category_ids).any_of [2, 7, 12]
92
+ end
93
+ connection.should have_last_search_including(:fq, 'category_ids_im:(2 OR 7 OR 12)')
94
+ end
95
+
96
+ it 'scopes by short-form any-of match with integers' do
97
+ session.search Post do
98
+ with :category_ids, [2, 7, 12]
99
+ end
100
+ connection.should have_last_search_including(:fq, 'category_ids_im:(2 OR 7 OR 12)')
101
+ end
102
+
103
+ it 'scopes by all match with integer' do
104
+ session.search Post do
105
+ with(:category_ids).all_of [2, 7, 12]
106
+ end
107
+ connection.should have_last_search_including(:fq, 'category_ids_im:(2 AND 7 AND 12)')
108
+ end
109
+
110
+ it 'scopes by prefix match with string' do
111
+ session.search Post do
112
+ with(:title).starting_with('tes')
113
+ end
114
+ connection.should have_last_search_including(:fq, 'title_ss:tes*')
115
+ end
116
+
117
+ it 'scopes by not equal match with string' do
118
+ session.search Post do
119
+ without :title, 'Bad Post'
120
+ end
121
+ connection.should have_last_search_including(:fq, '-title_ss:Bad\ Post')
122
+ end
123
+
124
+ it 'scopes by not less than match with float' do
125
+ session.search Post do
126
+ without(:average_rating).less_than 3.0
127
+ end
128
+ connection.should have_last_search_including(:fq, '-average_rating_f:[* TO 3\.0]')
129
+ end
130
+
131
+ it 'scopes by not greater than match with float' do
132
+ session.search Post do
133
+ without(:average_rating).greater_than 3.0
134
+ end
135
+ connection.should have_last_search_including(:fq, '-average_rating_f:[3\.0 TO *]')
136
+ end
137
+
138
+ it 'scopes by not between match with shorthand' do
139
+ session.search Post do
140
+ without(:blog_id, 2..4)
141
+ end
142
+ connection.should have_last_search_including(:fq, '-blog_id_i:[2 TO 4]')
143
+ end
144
+
145
+ it 'scopes by not between match with float' do
146
+ session.search Post do
147
+ without(:average_rating).between 2.0..4.0
148
+ end
149
+ connection.should have_last_search_including(:fq, '-average_rating_f:[2\.0 TO 4\.0]')
150
+ end
151
+
152
+ it 'scopes by not any match with integer' do
153
+ session.search Post do
154
+ without(:category_ids).any_of [2, 7, 12]
155
+ end
156
+ connection.should have_last_search_including(:fq, '-category_ids_im:(2 OR 7 OR 12)')
157
+ end
158
+
159
+ it 'scopes by not all match with integer' do
160
+ session.search Post do
161
+ without(:category_ids).all_of [2, 7, 12]
162
+ end
163
+ connection.should have_last_search_including(:fq, '-category_ids_im:(2 AND 7 AND 12)')
164
+ end
165
+
166
+ it 'scopes by empty field' do
167
+ session.search Post do
168
+ with :average_rating, nil
169
+ end
170
+ connection.should have_last_search_including(:fq, '-average_rating_f:[* TO *]')
171
+ end
172
+
173
+ it 'scopes by non-empty field' do
174
+ session.search Post do
175
+ without :average_rating, nil
176
+ end
177
+ connection.should have_last_search_including(:fq, 'average_rating_f:[* TO *]')
178
+ end
179
+
180
+ it 'excludes by object identity' do
181
+ post = Post.new
182
+ session.search Post do
183
+ without post
184
+ end
185
+ connection.should have_last_search_including(:fq, "-id:Post\\ #{post.id}")
186
+ end
187
+
188
+ it 'excludes multiple objects passed as varargs by object identity' do
189
+ post1, post2 = Post.new, Post.new
190
+ session.search Post do
191
+ without post1, post2
192
+ end
193
+ connection.should have_last_search_including(
194
+ :fq,
195
+ "-id:Post\\ #{post1.id}",
196
+ "-id:Post\\ #{post2.id}"
197
+ )
198
+ end
199
+
200
+ it 'excludes multiple objects passed as array by object identity' do
201
+ posts = [Post.new, Post.new]
202
+ session.search Post do
203
+ without posts
204
+ end
205
+ connection.should have_last_search_including(
206
+ :fq,
207
+ "-id:Post\\ #{posts.first.id}",
208
+ "-id:Post\\ #{posts.last.id}"
209
+ )
210
+ end
211
+
212
+ it 'allows scoping on fields common to all types' do
213
+ time = Time.parse('1983-07-08 05:00:00 -0400')
214
+ session.search Post, Namespaced::Comment do
215
+ with :published_at, time
216
+ end
217
+ connection.should have_last_search_including(:fq, 'published_at_d:1983\-07\-08T09\:00\:00Z')
218
+ end
219
+
220
+ it 'allows scoping on field not common to all types' do
221
+ session.search Post, Namespaced::Comment do
222
+ with :blog_id, 1
223
+ end
224
+ connection.should have_last_search_including(:fq, 'blog_id_i:1')
225
+ end
226
+
227
+ it 'raises Sunspot::UnrecognizedFieldError if search scoped to field configured differently between types' do
228
+ lambda do
229
+ session.search Post, Namespaced::Comment do
230
+ with :average_rating, 2.2 # this is a float in Post but an integer in Comment
231
+ end
232
+ end.should raise_error(Sunspot::UnrecognizedFieldError)
233
+ end
234
+
235
+ it 'raises Sunspot::UnrecognizedFieldError if a text field that does not exist for any type is specified' do
236
+ lambda do
237
+ session.search Post, Namespaced::Comment do
238
+ keywords 'fulltext', :fields => :bogus
239
+ end
240
+ end.should raise_error(Sunspot::UnrecognizedFieldError)
241
+ end
242
+
243
+ it 'raises Sunspot::UnrecognizedFieldError for nonexistant fields in block scope' do
244
+ lambda do
245
+ session.search Post do
246
+ with :bogus, 'Field'
247
+ end
248
+ end.should raise_error(Sunspot::UnrecognizedFieldError)
249
+ end
250
+
251
+ it 'raises NoMethodError if bogus operator referenced' do
252
+ lambda do
253
+ session.search Post do
254
+ with(:category_ids).resembling :bogus_condition
255
+ end
256
+ end.should raise_error(NoMethodError)
257
+ end
258
+
259
+ it 'should raise ArgumentError if more than two arguments passed to scope method' do
260
+ lambda do
261
+ session.search Post do
262
+ with(:category_ids, 4, 5)
263
+ end
264
+ end.should raise_error(ArgumentError)
265
+ end
266
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
@@ -0,0 +1,30 @@
1
+ describe 'scoping with text fields', :type => :query do
2
+ it 'should scope with a text field' do
3
+ session.search(Post) do
4
+ text_fields do
5
+ with(:body, 'test')
6
+ end
7
+ end
8
+ connection.should have_last_search_including(:fq, 'body_texts:test')
9
+ end
10
+
11
+ it 'should raise an UnrecognizedFieldError if differently configured text field is used' do
12
+ lambda do
13
+ session.search(Post, Namespaced::Comment) do
14
+ text_fields do
15
+ with(:body, 'test')
16
+ end
17
+ end
18
+ end.should raise_error(Sunspot::UnrecognizedFieldError)
19
+ end
20
+
21
+ it 'should raise an UnrecognizedFieldError if no field exists' do
22
+ lambda do
23
+ session.search(Post) do
24
+ text_fields do
25
+ with(:bogus, 'test')
26
+ end
27
+ end
28
+ end.should raise_error(Sunspot::UnrecognizedFieldError)
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ describe 'typed query' do
2
+ it 'properly escapes namespaced type names' do
3
+ session.search(Namespaced::Comment)
4
+ connection.should have_last_search_with(:fq => ['type:Namespaced\:\:Comment'])
5
+ end
6
+
7
+ it 'builds search for multiple types' do
8
+ session.search(Post, Namespaced::Comment)
9
+ connection.should have_last_search_with(:fq => ['type:(Post OR Namespaced\:\:Comment)'])
10
+ end
11
+
12
+ it 'searches type of subclass when superclass is configured' do
13
+ session.search PhotoPost
14
+ connection.should have_last_search_with(:fq => ['type:PhotoPost'])
15
+ end
16
+
17
+ it 'raises an ArgumentError if no types given to search' do
18
+ lambda { session.search }.should raise_error(ArgumentError)
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'search with dynamic fields' do
4
+ it 'returns dynamic string facet' do
5
+ stub_facet(:"custom_string:test_s", 'two' => 2, 'one' => 1)
6
+ result = session.search(Post) { dynamic(:custom_string) { facet(:test) }}
7
+ result.dynamic_facet(:custom_string, :test).rows.map { |row| row.value }.should == ['two', 'one']
8
+ end
9
+
10
+ it 'returns query facet specified in dynamic call' do
11
+ stub_query_facet(
12
+ 'custom_string\:test_s:(foo OR bar)' => 3
13
+ )
14
+ search = session.search(Post) do
15
+ dynamic :custom_string do
16
+ facet :test do
17
+ row :foo_bar do
18
+ with :test, %w(foo bar)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ facet = search.facet(:test)
24
+ facet.rows.first.value.should == :foo_bar
25
+ facet.rows.first.count.should == 3
26
+ end
27
+ end