kuahyeow-sunspot 0.9.8 → 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +38 -0
- data/README.rdoc +40 -3
- data/TODO +10 -8
- data/VERSION.yml +2 -2
- data/bin/sunspot-configure-solr +22 -28
- data/bin/sunspot-solr +50 -29
- data/lib/sunspot.rb +8 -18
- data/lib/sunspot/adapters.rb +1 -1
- data/lib/sunspot/composite_setup.rb +13 -15
- data/lib/sunspot/configuration.rb +21 -0
- data/lib/sunspot/data_extractor.rb +3 -0
- data/lib/sunspot/dsl.rb +2 -1
- data/lib/sunspot/dsl/field_query.rb +33 -6
- data/lib/sunspot/dsl/fields.rb +14 -1
- data/lib/sunspot/dsl/fulltext.rb +168 -0
- data/lib/sunspot/dsl/query.rb +82 -5
- data/lib/sunspot/dsl/query_facet.rb +3 -3
- data/lib/sunspot/dsl/restriction.rb +7 -7
- data/lib/sunspot/dsl/scope.rb +17 -10
- data/lib/sunspot/dsl/search.rb +2 -2
- data/lib/sunspot/facet.rb +12 -39
- data/lib/sunspot/facet_data.rb +169 -0
- data/lib/sunspot/facet_row.rb +5 -27
- data/lib/sunspot/field.rb +50 -26
- data/lib/sunspot/field_factory.rb +15 -0
- data/lib/sunspot/indexer.rb +6 -0
- data/lib/sunspot/instantiated_facet.rb +7 -6
- data/lib/sunspot/instantiated_facet_row.rb +16 -1
- data/lib/sunspot/query.rb +2 -187
- data/lib/sunspot/query/boost_query.rb +20 -0
- data/lib/sunspot/query/connective.rb +98 -35
- data/lib/sunspot/query/dismax.rb +73 -0
- data/lib/sunspot/query/field_facet.rb +3 -23
- data/lib/sunspot/query/fulltext_base_query.rb +47 -0
- data/lib/sunspot/query/highlighting.rb +43 -0
- data/lib/sunspot/query/local.rb +24 -0
- data/lib/sunspot/query/pagination.rb +3 -4
- data/lib/sunspot/query/query.rb +93 -0
- data/lib/sunspot/query/query_facet.rb +15 -9
- data/lib/sunspot/query/query_facet_row.rb +3 -3
- data/lib/sunspot/query/query_field_facet.rb +20 -0
- data/lib/sunspot/query/restriction.rb +36 -15
- data/lib/sunspot/query/scope.rb +3 -159
- data/lib/sunspot/query/sort.rb +84 -15
- data/lib/sunspot/query/text_field_boost.rb +15 -0
- data/lib/sunspot/schema.rb +7 -25
- data/lib/sunspot/search.rb +63 -45
- data/lib/sunspot/search/highlight.rb +38 -0
- data/lib/sunspot/search/hit.rb +50 -3
- data/lib/sunspot/session.rb +40 -11
- data/lib/sunspot/setup.rb +47 -10
- data/lib/sunspot/text_field_setup.rb +29 -0
- data/lib/sunspot/type.rb +4 -4
- data/lib/sunspot/util.rb +27 -1
- data/solr/solr/conf/schema.xml +54 -40
- data/solr/solr/conf/solrconfig.xml +30 -0
- data/solr/solr/lib/geoapi-nogenerics-2.1-M2.jar +0 -0
- data/solr/solr/lib/gt2-referencing-2.3.1.jar +0 -0
- data/solr/solr/lib/jsr108-0.01.jar +0 -0
- data/solr/solr/lib/locallucene.jar +0 -0
- data/solr/solr/lib/localsolr.jar +0 -0
- data/spec/api/indexer/attributes_spec.rb +100 -0
- data/spec/api/indexer/batch_spec.rb +46 -0
- data/spec/api/indexer/dynamic_fields_spec.rb +33 -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 +46 -0
- data/spec/api/indexer/spec_helper.rb +1 -0
- data/spec/api/indexer_spec.rb +1 -308
- data/spec/api/query/connectives_spec.rb +162 -0
- data/spec/api/query/dsl_spec.rb +12 -0
- data/spec/api/query/dynamic_fields_spec.rb +149 -0
- data/spec/api/query/faceting_spec.rb +272 -0
- data/spec/api/query/fulltext_spec.rb +193 -0
- data/spec/api/query/highlighting_spec.rb +138 -0
- data/spec/api/query/local_spec.rb +54 -0
- data/spec/api/query/ordering_pagination_spec.rb +95 -0
- data/spec/api/query/scope_spec.rb +266 -0
- data/spec/api/query/spec_helper.rb +1 -0
- data/spec/api/query/text_field_scoping_spec.rb +30 -0
- data/spec/api/query/types_spec.rb +20 -0
- data/spec/api/search/dynamic_fields_spec.rb +27 -0
- data/spec/api/search/faceting_spec.rb +206 -0
- data/spec/api/search/highlighting_spec.rb +65 -0
- data/spec/api/search/hits_spec.rb +62 -0
- data/spec/api/search/results_spec.rb +52 -0
- data/spec/api/search/search_spec.rb +23 -0
- data/spec/api/search/spec_helper.rb +1 -0
- data/spec/api/session_spec.rb +11 -5
- data/spec/api/spec_helper.rb +1 -1
- data/spec/helpers/indexer_helper.rb +29 -0
- data/spec/helpers/query_helper.rb +13 -0
- data/spec/helpers/search_helper.rb +78 -0
- data/spec/integration/faceting_spec.rb +1 -1
- data/spec/integration/highlighting_spec.rb +22 -0
- data/spec/integration/keyword_search_spec.rb +65 -0
- data/spec/integration/local_search_spec.rb +56 -0
- data/spec/integration/scoped_search_spec.rb +15 -1
- data/spec/integration/spec_helper.rb +7 -1
- data/spec/mocks/connection.rb +24 -2
- data/spec/mocks/photo.rb +1 -1
- data/spec/mocks/post.rb +5 -3
- data/spec/mocks/super_class.rb +2 -0
- data/spec/spec_helper.rb +13 -0
- data/tasks/gemspec.rake +20 -8
- data/tasks/schema.rake +1 -1
- data/tasks/spec.rake +1 -1
- data/templates/schema.xml.erb +36 -0
- metadata +118 -52
- data/lib/sunspot/date_facet.rb +0 -36
- data/lib/sunspot/date_facet_row.rb +0 -17
- data/lib/sunspot/query/base_query.rb +0 -94
- data/lib/sunspot/query/dynamic_query.rb +0 -69
- data/lib/sunspot/query/field_query.rb +0 -57
- data/lib/sunspot/query_facet.rb +0 -33
- data/lib/sunspot/query_facet_row.rb +0 -21
- data/spec/api/build_search_spec.rb +0 -1018
- data/spec/api/query_spec.rb +0 -153
- data/spec/api/search_retrieval_spec.rb +0 -335
- data/templates/schema.xml.haml +0 -24
@@ -0,0 +1,193 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'fulltext query', :type => :query do
|
4
|
+
it 'searches by keywords' do
|
5
|
+
session.search Post do
|
6
|
+
keywords 'keyword search'
|
7
|
+
end
|
8
|
+
connection.should have_last_search_with(:q => 'keyword search')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'ignores keywords if empty' do
|
12
|
+
session.search Post do
|
13
|
+
keywords ''
|
14
|
+
end
|
15
|
+
connection.should_not have_last_search_with(:defType => 'dismax')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'ignores keywords if nil' do
|
19
|
+
session.search Post do
|
20
|
+
keywords nil
|
21
|
+
end
|
22
|
+
connection.should_not have_last_search_with(:defType => 'dismax')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'ignores keywords with only whitespace' do
|
26
|
+
session.search Post do
|
27
|
+
keywords " \t"
|
28
|
+
end
|
29
|
+
connection.should_not have_last_search_with(:defType => 'dismax')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'gracefully ignores keywords block if keywords ignored' do
|
33
|
+
session.search Post do
|
34
|
+
keywords(nil) { fields(:title) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'sets default query parser to dismax when keywords used' do
|
39
|
+
session.search Post do
|
40
|
+
keywords 'keyword search'
|
41
|
+
end
|
42
|
+
connection.should have_last_search_with(:defType => 'dismax')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'searches types in filter query if keywords used' do
|
46
|
+
session.search Post do
|
47
|
+
keywords 'keyword search'
|
48
|
+
end
|
49
|
+
connection.should have_last_search_with(:fq => ['type:Post'])
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'searches all text fields for searched class' do
|
53
|
+
search = session.search Post do
|
54
|
+
keywords 'keyword search'
|
55
|
+
end
|
56
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text body_texts title_text)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'searches both stored and unstored text fields' do
|
60
|
+
session.search Post, Namespaced::Comment do
|
61
|
+
keywords 'keyword search'
|
62
|
+
end
|
63
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(author_name_text backwards_title_text body_text body_texts title_text)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'searches only specified text fields when specified' do
|
67
|
+
session.search Post do
|
68
|
+
keywords 'keyword search', :fields => [:title, :body]
|
69
|
+
end
|
70
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(body_texts title_text)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'assigns boost to fields when specified' do
|
74
|
+
session.search Post do
|
75
|
+
keywords 'keyword search' do
|
76
|
+
fields :title => 2.0, :body => 0.75
|
77
|
+
end
|
78
|
+
end
|
79
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(body_texts^0.75 title_text^2.0)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'allows assignment of boosted and unboosted fields' do
|
83
|
+
session.search Post do
|
84
|
+
keywords 'keyword search' do
|
85
|
+
fields :body, :title => 2.0
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'searches both unstored and stored text field with same name when specified' do
|
91
|
+
session.search Post, Namespaced::Comment do
|
92
|
+
keywords 'keyword search', :fields => [:body]
|
93
|
+
end
|
94
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(body_text body_texts)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'requests score when keywords used' do
|
98
|
+
session.search Post do
|
99
|
+
keywords 'keyword search'
|
100
|
+
end
|
101
|
+
connection.should have_last_search_with(:fl => '* score')
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'does not request score when keywords not used' do
|
105
|
+
session.search Post
|
106
|
+
connection.should_not have_last_search_with(:fl)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'sets phrase fields' do
|
110
|
+
session.search Post do
|
111
|
+
keywords 'great pizza' do
|
112
|
+
phrase_fields :title => 2.0
|
113
|
+
end
|
114
|
+
end
|
115
|
+
connection.should have_last_search_with(:pf => 'title_text^2.0')
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'sets phrase fields with boost' do
|
119
|
+
session.search Post do
|
120
|
+
keywords 'great pizza' do
|
121
|
+
phrase_fields :title => 1.5
|
122
|
+
end
|
123
|
+
end
|
124
|
+
connection.should have_last_search_with(:pf => 'title_text^1.5')
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'sets boost for certain fields without restricting fields' do
|
128
|
+
session.search Post do
|
129
|
+
keywords 'great pizza' do
|
130
|
+
boost_fields :title => 1.5
|
131
|
+
end
|
132
|
+
end
|
133
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text body_texts title_text^1.5)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'sets default boost with default fields' do
|
137
|
+
session.search Photo do
|
138
|
+
keywords 'great pizza'
|
139
|
+
end
|
140
|
+
connection.should have_last_search_with(:qf => 'caption_text^1.5')
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'sets default boost with fields specified in options' do
|
144
|
+
session.search Photo do
|
145
|
+
keywords 'great pizza', :fields => [:caption]
|
146
|
+
end
|
147
|
+
connection.should have_last_search_with(:qf => 'caption_text^1.5')
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'sets default boost with fields specified in DSL' do
|
151
|
+
session.search Photo do
|
152
|
+
keywords 'great pizza' do
|
153
|
+
fields :caption
|
154
|
+
end
|
155
|
+
end
|
156
|
+
connection.should have_last_search_with(:qf => 'caption_text^1.5')
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'overrides default boost when specified in DSL' do
|
160
|
+
session.search Photo do
|
161
|
+
keywords 'great pizza' do
|
162
|
+
fields :caption => 2.0
|
163
|
+
end
|
164
|
+
end
|
165
|
+
connection.should have_last_search_with(:qf => 'caption_text^2.0')
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'creates boost query' do
|
169
|
+
session.search Post do
|
170
|
+
keywords 'great pizza' do
|
171
|
+
boost 2.0 do
|
172
|
+
with(:average_rating).greater_than(2.0)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
connection.should have_last_search_with(:bq => 'average_rating_f:[2\.0 TO *]^2.0')
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'allows specification of a text field that only exists in one type' do
|
180
|
+
session.search Post, Namespaced::Comment do
|
181
|
+
keywords 'keywords', :fields => :author_name
|
182
|
+
end
|
183
|
+
connection.searches.last[:qf].should == 'author_name_text'
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'raises Sunspot::UnrecognizedFieldError for nonexistant fields in keywords' do
|
187
|
+
lambda do
|
188
|
+
session.search Post do
|
189
|
+
keywords :text, :fields => :bogus
|
190
|
+
end
|
191
|
+
end.should raise_error(Sunspot::UnrecognizedFieldError)
|
192
|
+
end
|
193
|
+
end
|
@@ -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
|