sunspot 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/README.rdoc +3 -0
  2. data/TODO +6 -5
  3. data/bin/sunspot-solr +4 -0
  4. data/installer/config/schema.yml +24 -0
  5. data/lib/sunspot/composite_setup.rb +14 -0
  6. data/lib/sunspot/dsl/adjustable.rb +47 -0
  7. data/lib/sunspot/dsl/fulltext.rb +23 -8
  8. data/lib/sunspot/dsl/function.rb +14 -0
  9. data/lib/sunspot/dsl/functional.rb +41 -0
  10. data/lib/sunspot/dsl/more_like_this_query.rb +56 -0
  11. data/lib/sunspot/dsl/paginatable.rb +28 -0
  12. data/lib/sunspot/dsl/search.rb +1 -1
  13. data/lib/sunspot/dsl/{query.rb → standard_query.rb} +4 -49
  14. data/lib/sunspot/dsl.rb +3 -2
  15. data/lib/sunspot/field.rb +16 -2
  16. data/lib/sunspot/indexer.rb +1 -1
  17. data/lib/sunspot/installer/schema_builder.rb +1 -1
  18. data/lib/sunspot/installer/solrconfig_updater.rb +13 -0
  19. data/lib/sunspot/installer/task_helper.rb +1 -1
  20. data/lib/sunspot/query/abstract_field_facet.rb +5 -0
  21. data/lib/sunspot/query/boost_query.rb +5 -1
  22. data/lib/sunspot/query/{query.rb → common_query.rb} +26 -20
  23. data/lib/sunspot/query/composite_fulltext.rb +31 -0
  24. data/lib/sunspot/query/dismax.rb +45 -6
  25. data/lib/sunspot/query/function_query.rb +52 -0
  26. data/lib/sunspot/query/more_like_this.rb +60 -0
  27. data/lib/sunspot/query/more_like_this_query.rb +12 -0
  28. data/lib/sunspot/query/standard_query.rb +20 -0
  29. data/lib/sunspot/query/text_field_boost.rb +2 -0
  30. data/lib/sunspot/query.rb +3 -2
  31. data/lib/sunspot/search/abstract_search.rb +302 -0
  32. data/lib/sunspot/search/date_facet.rb +1 -1
  33. data/lib/sunspot/search/facet_row.rb +1 -1
  34. data/lib/sunspot/search/field_facet.rb +1 -1
  35. data/lib/sunspot/search/highlight.rb +1 -1
  36. data/lib/sunspot/search/hit.rb +1 -1
  37. data/lib/sunspot/search/more_like_this_search.rb +31 -0
  38. data/lib/sunspot/search/query_facet.rb +1 -1
  39. data/lib/sunspot/search/standard_search.rb +21 -0
  40. data/lib/sunspot/search.rb +3 -288
  41. data/lib/sunspot/server.rb +8 -4
  42. data/lib/sunspot/session.rb +30 -2
  43. data/lib/sunspot/session_proxy/master_slave_session_proxy.rb +1 -1
  44. data/lib/sunspot/session_proxy/sharding_session_proxy.rb +9 -0
  45. data/lib/sunspot/session_proxy/thread_local_session_proxy.rb +9 -2
  46. data/lib/sunspot/setup.rb +32 -3
  47. data/lib/sunspot/type.rb +74 -0
  48. data/lib/sunspot/util.rb +3 -2
  49. data/lib/sunspot/version.rb +1 -1
  50. data/lib/sunspot.rb +9 -1
  51. data/solr/solr/conf/schema.xml +12 -0
  52. data/solr/solr/conf/solrconfig.xml +6 -0
  53. data/spec/api/indexer/attributes_spec.rb +9 -3
  54. data/spec/api/indexer/fulltext_spec.rb +2 -2
  55. data/spec/api/indexer/removal_spec.rb +1 -1
  56. data/spec/api/query/advanced_manipulation_examples.rb +35 -0
  57. data/spec/api/query/{connectives_spec.rb → connectives_examples.rb} +19 -19
  58. data/spec/api/query/{dynamic_fields_spec.rb → dynamic_fields_examples.rb} +33 -17
  59. data/spec/api/query/{faceting_spec.rb → faceting_examples.rb} +146 -43
  60. data/spec/api/query/{fulltext_spec.rb → fulltext_examples.rb} +81 -47
  61. data/spec/api/query/function_spec.rb +70 -0
  62. data/spec/api/query/{highlighting_spec.rb → highlighting_examples.rb} +27 -27
  63. data/spec/api/query/{local_spec.rb → local_examples.rb} +5 -5
  64. data/spec/api/query/more_like_this_spec.rb +140 -0
  65. data/spec/api/query/{ordering_pagination_spec.rb → ordering_pagination_examples.rb} +16 -16
  66. data/spec/api/query/{scope_spec.rb → scope_examples.rb} +44 -61
  67. data/spec/api/query/standard_spec.rb +28 -0
  68. data/spec/api/query/{text_field_scoping_spec.rb → text_field_scoping_examples.rb} +5 -5
  69. data/spec/api/search/dynamic_fields_spec.rb +6 -0
  70. data/spec/api/search/faceting_spec.rb +10 -10
  71. data/spec/api/search/hits_spec.rb +1 -1
  72. data/spec/api/search/results_spec.rb +10 -0
  73. data/spec/api/server_spec.rb +6 -0
  74. data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +2 -2
  75. data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +17 -0
  76. data/spec/api/spec_helper.rb +2 -0
  77. data/spec/helpers/query_helper.rb +25 -0
  78. data/spec/helpers/search_helper.rb +4 -0
  79. data/spec/integration/faceting_spec.rb +8 -0
  80. data/spec/integration/keyword_search_spec.rb +75 -3
  81. data/spec/integration/local_search_spec.rb +1 -1
  82. data/spec/integration/more_like_this_spec.rb +43 -0
  83. data/spec/mocks/comment.rb +1 -1
  84. data/spec/mocks/connection.rb +27 -12
  85. data/spec/mocks/post.rb +5 -4
  86. data/spec/spec_helper.rb +4 -21
  87. data/tasks/gemspec.rake +1 -1
  88. metadata +39 -27
  89. data/spec/api/query/adjust_params_spec.rb +0 -37
  90. data/spec/api/query/facet_local_params_spec.rb +0 -103
@@ -0,0 +1,140 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'more_like_this' do
4
+ before :each do
5
+ connection.expected_handler = :mlt
6
+ end
7
+
8
+ it_should_behave_like "scoped query"
9
+ it_should_behave_like "facetable query"
10
+ it_should_behave_like "query with advanced manipulation"
11
+ it_should_behave_like "query with connective scope"
12
+ it_should_behave_like "query with dynamic field support"
13
+ it_should_behave_like "sortable query"
14
+ it_should_behave_like "query with text field scoping"
15
+
16
+ it 'should query passed in object' do
17
+ p = Post.new
18
+ session.more_like_this(p)
19
+ connection.should have_last_search_with(:q => "id:Post\\ #{p.id}")
20
+ end
21
+
22
+ it 'should use more_like_this fields if no fields specified' do
23
+ session.more_like_this(Post.new)
24
+ connection.searches.last[:"mlt.fl"].split(',').sort.should == %w(body_textsv tags_textv)
25
+ end
26
+
27
+ it 'should use more_like_this fields if specified' do
28
+ session.more_like_this(Post.new) do
29
+ fields :body
30
+ end
31
+ connection.should have_last_search_with(:"mlt.fl" => "body_textsv")
32
+ end
33
+
34
+ it 'assigns boosts to fields when specified' do
35
+ session.more_like_this(Post.new) do
36
+ fields :body, :tags => 8
37
+ end
38
+ connection.searches.last[:"mlt.fl"].split(',').sort.should == %w(body_textsv tags_textv)
39
+ connection.should have_last_search_with(:qf => "tags_textv^8")
40
+ end
41
+
42
+ it 'doesn\'t assign boosts to fields when not specified' do
43
+ session.more_like_this(Post.new) do
44
+ fields :body
45
+ end
46
+ connection.should_not have_last_search_with(:qf)
47
+ end
48
+
49
+ it 'should raise ArgumentError if a field is not setup for more_like_this' do
50
+ lambda do
51
+ session.more_like_this(Post.new) do
52
+ fields :title
53
+ end
54
+ end.should raise_error(ArgumentError)
55
+ end
56
+
57
+ it 'should accept options' do
58
+ session.more_like_this(Post.new) do
59
+ minimum_term_frequency 1
60
+ minimum_document_frequency 2
61
+ minimum_word_length 3
62
+ maximum_word_length 4
63
+ maximum_query_terms 5
64
+ boost_by_relevance false
65
+ end
66
+ connection.should have_last_search_with(:"mlt.mintf" => 1)
67
+ connection.should have_last_search_with(:"mlt.mindf" => 2)
68
+ connection.should have_last_search_with(:"mlt.minwl" => 3)
69
+ connection.should have_last_search_with(:"mlt.maxwl" => 4)
70
+ connection.should have_last_search_with(:"mlt.maxqt" => 5)
71
+ connection.should have_last_search_with(:"mlt.boost" => false)
72
+ end
73
+
74
+ it 'should accept short options' do
75
+ session.more_like_this(Post.new) do
76
+ mintf 1
77
+ mindf 2
78
+ minwl 3
79
+ maxwl 4
80
+ maxqt 5
81
+ boost true
82
+ end
83
+ connection.should have_last_search_with(:"mlt.mintf" => 1)
84
+ connection.should have_last_search_with(:"mlt.mindf" => 2)
85
+ connection.should have_last_search_with(:"mlt.minwl" => 3)
86
+ connection.should have_last_search_with(:"mlt.maxwl" => 4)
87
+ connection.should have_last_search_with(:"mlt.maxqt" => 5)
88
+ connection.should have_last_search_with(:"mlt.boost" => true)
89
+ end
90
+
91
+ it 'paginates using default per_page when page not provided' do
92
+ session.more_like_this(Post.new)
93
+ connection.should have_last_search_with(:rows => 30)
94
+ end
95
+
96
+ it 'paginates using default per_page when page provided' do
97
+ session.more_like_this(Post.new) do
98
+ paginate :page => 2
99
+ end
100
+ connection.should have_last_search_with(:rows => 30, :start => 30)
101
+ end
102
+
103
+ it 'paginates using provided per_page' do
104
+ session.more_like_this(Post.new) do
105
+ paginate :page => 4, :per_page => 15
106
+ end
107
+ connection.should have_last_search_with(:rows => 15, :start => 45)
108
+ end
109
+
110
+ it 'defaults to page 1 if no :page argument given' do
111
+ session.more_like_this(Post.new) do
112
+ paginate :per_page => 15
113
+ end
114
+ connection.should have_last_search_with(:rows => 15, :start => 0)
115
+ end
116
+
117
+ it 'paginates from string argument' do
118
+ session.more_like_this(Post.new) do
119
+ paginate :page => '3', :per_page => '15'
120
+ end
121
+ connection.should have_last_search_with(:rows => 15, :start => 30)
122
+ end
123
+
124
+ it "should send query to solr with adjusted parameters (keyword example)" do
125
+ session.more_like_this(Post.new) do
126
+ adjust_solr_params do |params|
127
+ params[:q] = 'new search'
128
+ params[:some] = 'param'
129
+ end
130
+ end
131
+ connection.should have_last_search_with(:q => 'new search')
132
+ connection.should have_last_search_with(:some => 'param')
133
+ end
134
+
135
+ private
136
+
137
+ def search(*args, &block)
138
+ session.more_like_this(Post.new, *args, &block)
139
+ end
140
+ end
@@ -1,63 +1,63 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
- describe 'ordering and pagination' do
3
+ shared_examples_for 'sortable query' do
4
4
  it 'paginates using default per_page when page not provided' do
5
- session.search Post
5
+ search
6
6
  connection.should have_last_search_with(:rows => 30)
7
7
  end
8
8
 
9
9
  it 'paginates using default per_page when page provided' do
10
- session.search Post do
10
+ search do
11
11
  paginate :page => 2
12
12
  end
13
13
  connection.should have_last_search_with(:rows => 30, :start => 30)
14
14
  end
15
15
 
16
16
  it 'paginates using provided per_page' do
17
- session.search Post do
17
+ search do
18
18
  paginate :page => 4, :per_page => 15
19
19
  end
20
20
  connection.should have_last_search_with(:rows => 15, :start => 45)
21
21
  end
22
22
 
23
23
  it 'defaults to page 1 if no :page argument given' do
24
- session.search Post do
24
+ search do
25
25
  paginate :per_page => 15
26
26
  end
27
27
  connection.should have_last_search_with(:rows => 15, :start => 0)
28
28
  end
29
29
 
30
30
  it 'paginates from string argument' do
31
- session.search Post do
31
+ search do
32
32
  paginate :page => '3', :per_page => '15'
33
33
  end
34
34
  connection.should have_last_search_with(:rows => 15, :start => 30)
35
35
  end
36
36
 
37
37
  it 'orders by a single field' do
38
- session.search Post do
38
+ search do
39
39
  order_by :average_rating, :desc
40
40
  end
41
- connection.should have_last_search_with(:sort => 'average_rating_f desc')
41
+ connection.should have_last_search_with(:sort => 'average_rating_ft desc')
42
42
  end
43
43
 
44
44
  it 'orders by multiple fields' do
45
- session.search Post do
45
+ search do
46
46
  order_by :average_rating, :desc
47
47
  order_by :sort_title, :asc
48
48
  end
49
- connection.should have_last_search_with(:sort => 'average_rating_f desc, sort_title_s asc')
49
+ connection.should have_last_search_with(:sort => 'average_rating_ft desc, sort_title_s asc')
50
50
  end
51
51
 
52
52
  it 'orders by random' do
53
- session.search Post do
53
+ search do
54
54
  order_by :random
55
55
  end
56
56
  connection.searches.last[:sort].should =~ /^random_\d+ asc$/
57
57
  end
58
58
 
59
59
  it 'orders by score' do
60
- session.search Post do
60
+ search do
61
61
  order_by :score, :desc
62
62
  end
63
63
  connection.should have_last_search_with(:sort => 'score desc')
@@ -65,7 +65,7 @@ describe 'ordering and pagination' do
65
65
 
66
66
  it 'throws an ArgumentError if a bogus order direction is given' do
67
67
  lambda do
68
- session.search Post do
68
+ search do
69
69
  order_by :sort_title, :sideways
70
70
  end
71
71
  end.should raise_error(ArgumentError)
@@ -73,7 +73,7 @@ describe 'ordering and pagination' do
73
73
 
74
74
  it 'throws an UnrecognizedFieldError if :distance is given for sort' do
75
75
  lambda do
76
- session.search Post do
76
+ search do
77
77
  order_by :distance, :asc
78
78
  end
79
79
  end.should raise_error(Sunspot::UnrecognizedFieldError)
@@ -81,7 +81,7 @@ describe 'ordering and pagination' do
81
81
 
82
82
  it 'does not allow ordering by multiple-value fields' do
83
83
  lambda do
84
- session.search Post do
84
+ search do
85
85
  order_by :category_ids
86
86
  end
87
87
  end.should raise_error(ArgumentError)
@@ -89,7 +89,7 @@ describe 'ordering and pagination' do
89
89
 
90
90
  it 'raises ArgumentError if bogus argument given to paginate' do
91
91
  lambda do
92
- session.search Post do
92
+ search do
93
93
  paginate :page => 4, :ugly => :puppy
94
94
  end
95
95
  end.should raise_error(ArgumentError)
@@ -1,22 +1,13 @@
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
-
1
+ shared_examples_for "scoped query" do
11
2
  it 'scopes by exact match with a string' do
12
- session.search Post do
3
+ search do
13
4
  with :title, 'My Pet Post'
14
5
  end
15
6
  connection.should have_last_search_including(:fq, 'title_ss:My\ Pet\ Post')
16
7
  end
17
8
 
18
9
  it 'scopes by exact match with a special string' do
19
- session.search Post do
10
+ search do
20
11
  with :title, 'OR'
21
12
  end
22
13
  connection.should have_last_search_including(:fq, 'title_ss:"OR"')
@@ -24,18 +15,18 @@ describe 'scoped query', :type => :query do
24
15
 
25
16
  it 'scopes by exact match with time' do
26
17
  time = Time.parse('1983-07-08 05:00:00 -0400')
27
- session.search Post do
18
+ search do
28
19
  with :published_at, time
29
20
  end
30
21
  connection.should have_last_search_including(
31
22
  :fq,
32
- 'published_at_d:1983\-07\-08T09\:00\:00Z'
23
+ 'published_at_dt:1983\-07\-08T09\:00\:00Z'
33
24
  )
34
25
  end
35
26
 
36
27
  it 'scopes by exact match with date' do
37
28
  date = Date.new(1983, 7, 8)
38
- session.search Post do
29
+ search do
39
30
  with :expire_date, date
40
31
  end
41
32
  connection.should have_last_search_including(
@@ -45,148 +36,148 @@ describe 'scoped query', :type => :query do
45
36
  end
46
37
 
47
38
  it 'scopes by exact match with boolean' do
48
- session.search Post do
39
+ search do
49
40
  with :featured, false
50
41
  end
51
42
  connection.should have_last_search_including(:fq, 'featured_b:false')
52
43
  end
53
44
 
54
45
  it 'scopes by less than match with float' do
55
- session.search Post do
46
+ search do
56
47
  with(:average_rating).less_than 3.0
57
48
  end
58
- connection.should have_last_search_including(:fq, 'average_rating_f:[* TO 3\.0]')
49
+ connection.should have_last_search_including(:fq, 'average_rating_ft:[* TO 3\.0]')
59
50
  end
60
51
 
61
52
  it 'should quote string with space in a less than match' do
62
- session.search Post do
53
+ search do
63
54
  with(:title).less_than('test value')
64
55
  end
65
56
  connection.should have_last_search_including(:fq, 'title_ss:[* TO "test\ value"]')
66
57
  end
67
58
 
68
59
  it 'scopes by greater than match with float' do
69
- session.search Post do
60
+ search do
70
61
  with(:average_rating).greater_than 3.0
71
62
  end
72
- connection.should have_last_search_including(:fq, 'average_rating_f:[3\.0 TO *]')
63
+ connection.should have_last_search_including(:fq, 'average_rating_ft:[3\.0 TO *]')
73
64
  end
74
65
 
75
66
  it 'scopes by short-form between match with integers' do
76
- session.search Post do
67
+ search do
77
68
  with :blog_id, 2..4
78
69
  end
79
70
  connection.should have_last_search_including(:fq, 'blog_id_i:[2 TO 4]')
80
71
  end
81
72
 
82
73
  it 'scopes by between match with float' do
83
- session.search Post do
74
+ search do
84
75
  with(:average_rating).between 2.0..4.0
85
76
  end
86
- connection.should have_last_search_including(:fq, 'average_rating_f:[2\.0 TO 4\.0]')
77
+ connection.should have_last_search_including(:fq, 'average_rating_ft:[2\.0 TO 4\.0]')
87
78
  end
88
79
 
89
80
  it 'automatically sorts ranges in between matches' do
90
- session.search Post do
81
+ search do
91
82
  with(:blog_id).between(4..2)
92
83
  end
93
84
  connection.should have_last_search_including(:fq, 'blog_id_i:[2 TO 4]')
94
85
  end
95
86
 
96
87
  it 'scopes by any match with integer' do
97
- session.search Post do
88
+ search do
98
89
  with(:category_ids).any_of [2, 7, 12]
99
90
  end
100
91
  connection.should have_last_search_including(:fq, 'category_ids_im:(2 OR 7 OR 12)')
101
92
  end
102
93
 
103
94
  it 'scopes by short-form any-of match with integers' do
104
- session.search Post do
95
+ search do
105
96
  with :category_ids, [2, 7, 12]
106
97
  end
107
98
  connection.should have_last_search_including(:fq, 'category_ids_im:(2 OR 7 OR 12)')
108
99
  end
109
100
 
110
101
  it 'scopes by all match with integer' do
111
- session.search Post do
102
+ search do
112
103
  with(:category_ids).all_of [2, 7, 12]
113
104
  end
114
105
  connection.should have_last_search_including(:fq, 'category_ids_im:(2 AND 7 AND 12)')
115
106
  end
116
107
 
117
108
  it 'scopes by prefix match with string' do
118
- session.search Post do
109
+ search do
119
110
  with(:title).starting_with('tes')
120
111
  end
121
112
  connection.should have_last_search_including(:fq, 'title_ss:tes*')
122
113
  end
123
114
 
124
115
  it 'scopes by not equal match with string' do
125
- session.search Post do
116
+ search do
126
117
  without :title, 'Bad Post'
127
118
  end
128
119
  connection.should have_last_search_including(:fq, '-title_ss:Bad\ Post')
129
120
  end
130
121
 
131
122
  it 'scopes by not less than match with float' do
132
- session.search Post do
123
+ search do
133
124
  without(:average_rating).less_than 3.0
134
125
  end
135
- connection.should have_last_search_including(:fq, '-average_rating_f:[* TO 3\.0]')
126
+ connection.should have_last_search_including(:fq, '-average_rating_ft:[* TO 3\.0]')
136
127
  end
137
128
 
138
129
  it 'scopes by not greater than match with float' do
139
- session.search Post do
130
+ search do
140
131
  without(:average_rating).greater_than 3.0
141
132
  end
142
- connection.should have_last_search_including(:fq, '-average_rating_f:[3\.0 TO *]')
133
+ connection.should have_last_search_including(:fq, '-average_rating_ft:[3\.0 TO *]')
143
134
  end
144
135
 
145
136
  it 'scopes by not between match with shorthand' do
146
- session.search Post do
137
+ search do
147
138
  without(:blog_id, 2..4)
148
139
  end
149
140
  connection.should have_last_search_including(:fq, '-blog_id_i:[2 TO 4]')
150
141
  end
151
142
 
152
143
  it 'scopes by not between match with float' do
153
- session.search Post do
144
+ search do
154
145
  without(:average_rating).between 2.0..4.0
155
146
  end
156
- connection.should have_last_search_including(:fq, '-average_rating_f:[2\.0 TO 4\.0]')
147
+ connection.should have_last_search_including(:fq, '-average_rating_ft:[2\.0 TO 4\.0]')
157
148
  end
158
149
 
159
150
  it 'scopes by not any match with integer' do
160
- session.search Post do
151
+ search do
161
152
  without(:category_ids).any_of [2, 7, 12]
162
153
  end
163
154
  connection.should have_last_search_including(:fq, '-category_ids_im:(2 OR 7 OR 12)')
164
155
  end
165
156
 
166
157
  it 'scopes by not all match with integer' do
167
- session.search Post do
158
+ search do
168
159
  without(:category_ids).all_of [2, 7, 12]
169
160
  end
170
161
  connection.should have_last_search_including(:fq, '-category_ids_im:(2 AND 7 AND 12)')
171
162
  end
172
163
 
173
164
  it 'scopes by empty field' do
174
- session.search Post do
165
+ search do
175
166
  with :average_rating, nil
176
167
  end
177
- connection.should have_last_search_including(:fq, '-average_rating_f:[* TO *]')
168
+ connection.should have_last_search_including(:fq, '-average_rating_ft:[* TO *]')
178
169
  end
179
170
 
180
171
  it 'scopes by non-empty field' do
181
- session.search Post do
172
+ search do
182
173
  without :average_rating, nil
183
174
  end
184
- connection.should have_last_search_including(:fq, 'average_rating_f:[* TO *]')
175
+ connection.should have_last_search_including(:fq, 'average_rating_ft:[* TO *]')
185
176
  end
186
177
 
187
178
  it 'excludes by object identity' do
188
179
  post = Post.new
189
- session.search Post do
180
+ search do
190
181
  without post
191
182
  end
192
183
  connection.should have_last_search_including(:fq, "-id:Post\\ #{post.id}")
@@ -194,7 +185,7 @@ describe 'scoped query', :type => :query do
194
185
 
195
186
  it 'excludes multiple objects passed as varargs by object identity' do
196
187
  post1, post2 = Post.new, Post.new
197
- session.search Post do
188
+ search do
198
189
  without post1, post2
199
190
  end
200
191
  connection.should have_last_search_including(
@@ -206,7 +197,7 @@ describe 'scoped query', :type => :query do
206
197
 
207
198
  it 'excludes multiple objects passed as array by object identity' do
208
199
  posts = [Post.new, Post.new]
209
- session.search Post do
200
+ search do
210
201
  without posts
211
202
  end
212
203
  connection.should have_last_search_including(
@@ -218,14 +209,14 @@ describe 'scoped query', :type => :query do
218
209
 
219
210
  it 'allows scoping on fields common to all types' do
220
211
  time = Time.parse('1983-07-08 05:00:00 -0400')
221
- session.search Post, Namespaced::Comment do
212
+ search Post, Namespaced::Comment do
222
213
  with :published_at, time
223
214
  end
224
- connection.should have_last_search_including(:fq, 'published_at_d:1983\-07\-08T09\:00\:00Z')
215
+ connection.should have_last_search_including(:fq, 'published_at_dt:1983\-07\-08T09\:00\:00Z')
225
216
  end
226
217
 
227
218
  it 'allows scoping on field not common to all types' do
228
- session.search Post, Namespaced::Comment do
219
+ search Post, Namespaced::Comment do
229
220
  with :blog_id, 1
230
221
  end
231
222
  connection.should have_last_search_including(:fq, 'blog_id_i:1')
@@ -233,23 +224,15 @@ describe 'scoped query', :type => :query do
233
224
 
234
225
  it 'raises Sunspot::UnrecognizedFieldError if search scoped to field configured differently between types' do
235
226
  lambda do
236
- session.search Post, Namespaced::Comment do
227
+ search Post, Namespaced::Comment do
237
228
  with :average_rating, 2.2 # this is a float in Post but an integer in Comment
238
229
  end
239
230
  end.should raise_error(Sunspot::UnrecognizedFieldError)
240
231
  end
241
232
 
242
- it 'raises Sunspot::UnrecognizedFieldError if a text field that does not exist for any type is specified' do
243
- lambda do
244
- session.search Post, Namespaced::Comment do
245
- keywords 'fulltext', :fields => :bogus
246
- end
247
- end.should raise_error(Sunspot::UnrecognizedFieldError)
248
- end
249
-
250
233
  it 'raises Sunspot::UnrecognizedFieldError for nonexistant fields in block scope' do
251
234
  lambda do
252
- session.search Post do
235
+ search do
253
236
  with :bogus, 'Field'
254
237
  end
255
238
  end.should raise_error(Sunspot::UnrecognizedFieldError)
@@ -257,7 +240,7 @@ describe 'scoped query', :type => :query do
257
240
 
258
241
  it 'raises NoMethodError if bogus operator referenced' do
259
242
  lambda do
260
- session.search Post do
243
+ search do
261
244
  with(:category_ids).resembling :bogus_condition
262
245
  end
263
246
  end.should raise_error(NoMethodError)
@@ -265,7 +248,7 @@ describe 'scoped query', :type => :query do
265
248
 
266
249
  it 'should raise ArgumentError if more than two arguments passed to scope method' do
267
250
  lambda do
268
- session.search Post do
251
+ search do
269
252
  with(:category_ids, 4, 5)
270
253
  end
271
254
  end.should raise_error(ArgumentError)
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'standard query', :type => :query do
4
+ it_should_behave_like "scoped query"
5
+ it_should_behave_like "query with advanced manipulation"
6
+ it_should_behave_like "query with connective scope"
7
+ it_should_behave_like "query with dynamic field support"
8
+ it_should_behave_like "facetable query"
9
+ it_should_behave_like "fulltext query"
10
+ it_should_behave_like "query with highlighting support"
11
+ it_should_behave_like "sortable query"
12
+ it_should_behave_like "spatial query"
13
+ it_should_behave_like "query with text field scoping"
14
+
15
+ it 'adds a no-op query to :q parameter when no :q provided' do
16
+ session.search Post do
17
+ with :title, 'My Pet Post'
18
+ end
19
+ connection.should have_last_search_with(:q => '*:*')
20
+ end
21
+
22
+ private
23
+
24
+ def search(*classes, &block)
25
+ classes[0] ||= Post
26
+ session.search(*classes, &block)
27
+ end
28
+ end
@@ -1,16 +1,16 @@
1
- describe 'scoping with text fields', :type => :query do
1
+ shared_examples_for 'query with text field scoping' do
2
2
  it 'should scope with a text field' do
3
- session.search(Post) do
3
+ search do
4
4
  text_fields do
5
5
  with(:body, 'test')
6
6
  end
7
7
  end
8
- connection.should have_last_search_including(:fq, 'body_texts:test')
8
+ connection.should have_last_search_including(:fq, 'body_textsv:test')
9
9
  end
10
10
 
11
11
  it 'should raise an UnrecognizedFieldError if differently configured text field is used' do
12
12
  lambda do
13
- session.search(Post, Namespaced::Comment) do
13
+ search(Post, Namespaced::Comment) do
14
14
  text_fields do
15
15
  with(:body, 'test')
16
16
  end
@@ -20,7 +20,7 @@ describe 'scoping with text fields', :type => :query do
20
20
 
21
21
  it 'should raise an UnrecognizedFieldError if no field exists' do
22
22
  lambda do
23
- session.search(Post) do
23
+ search do
24
24
  text_fields do
25
25
  with(:bogus, 'test')
26
26
  end
@@ -7,6 +7,12 @@ describe 'search with dynamic fields' do
7
7
  result.facet(:custom_string, :test).rows.map { |row| row.value }.should == ['two', 'one']
8
8
  end
9
9
 
10
+ it 'returns dynamic field facet with custom label' do
11
+ stub_facet(:"bogus", 'two' => 2, 'one' => 1)
12
+ result = session.search(Post) { dynamic(:custom_string) { facet(:test, :name => :bogus) }}
13
+ result.facet(:bogus).rows.map { |row| row.value }.should == ['two', 'one']
14
+ end
15
+
10
16
  it 'returns query facet specified in dynamic call' do
11
17
  stub_query_facet(
12
18
  'custom_string\:test_ss:(foo OR bar)' => 3