benjaminkrause-sunspot 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +107 -0
- data/LICENSE +18 -0
- data/README.rdoc +159 -0
- data/Rakefile +9 -0
- data/TODO +11 -0
- data/VERSION.yml +4 -0
- data/bin/sunspot-configure-solr +46 -0
- data/bin/sunspot-solr +86 -0
- data/lib/light_config.rb +40 -0
- data/lib/sunspot/adapters.rb +265 -0
- data/lib/sunspot/composite_setup.rb +184 -0
- data/lib/sunspot/configuration.rb +49 -0
- data/lib/sunspot/data_extractor.rb +50 -0
- data/lib/sunspot/dsl/field_query.rb +77 -0
- data/lib/sunspot/dsl/fields.rb +95 -0
- data/lib/sunspot/dsl/fulltext.rb +106 -0
- data/lib/sunspot/dsl/query.rb +107 -0
- data/lib/sunspot/dsl/query_facet.rb +31 -0
- data/lib/sunspot/dsl/restriction.rb +25 -0
- data/lib/sunspot/dsl/scope.rb +193 -0
- data/lib/sunspot/dsl/search.rb +30 -0
- data/lib/sunspot/dsl.rb +4 -0
- data/lib/sunspot/facet.rb +24 -0
- data/lib/sunspot/facet_data.rb +152 -0
- data/lib/sunspot/facet_row.rb +12 -0
- data/lib/sunspot/field.rb +148 -0
- data/lib/sunspot/field_factory.rb +141 -0
- data/lib/sunspot/indexer.rb +129 -0
- data/lib/sunspot/instantiated_facet.rb +45 -0
- data/lib/sunspot/instantiated_facet_row.rb +27 -0
- data/lib/sunspot/query/base_query.rb +55 -0
- data/lib/sunspot/query/boost_query.rb +20 -0
- data/lib/sunspot/query/connective.rb +148 -0
- data/lib/sunspot/query/dynamic_query.rb +61 -0
- data/lib/sunspot/query/field_facet.rb +129 -0
- data/lib/sunspot/query/field_query.rb +69 -0
- data/lib/sunspot/query/fulltext_base_query.rb +86 -0
- data/lib/sunspot/query/highlighting.rb +36 -0
- data/lib/sunspot/query/local.rb +24 -0
- data/lib/sunspot/query/pagination.rb +39 -0
- data/lib/sunspot/query/query_facet.rb +78 -0
- data/lib/sunspot/query/query_facet_row.rb +19 -0
- data/lib/sunspot/query/query_field_facet.rb +20 -0
- data/lib/sunspot/query/restriction.rb +272 -0
- data/lib/sunspot/query/scope.rb +185 -0
- data/lib/sunspot/query/sort.rb +105 -0
- data/lib/sunspot/query/sort_composite.rb +33 -0
- data/lib/sunspot/query/text_field_boost.rb +15 -0
- data/lib/sunspot/query.rb +108 -0
- data/lib/sunspot/schema.rb +147 -0
- data/lib/sunspot/search/highlight.rb +38 -0
- data/lib/sunspot/search/hit.rb +113 -0
- data/lib/sunspot/search.rb +240 -0
- data/lib/sunspot/session.rb +206 -0
- data/lib/sunspot/setup.rb +312 -0
- data/lib/sunspot/text_field_setup.rb +29 -0
- data/lib/sunspot/type.rb +200 -0
- data/lib/sunspot/util.rb +190 -0
- data/lib/sunspot.rb +459 -0
- data/solr/etc/jetty.xml +212 -0
- data/solr/etc/webdefault.xml +379 -0
- data/solr/lib/jetty-6.1.3.jar +0 -0
- data/solr/lib/jetty-util-6.1.3.jar +0 -0
- data/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
- data/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
- data/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
- data/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
- data/solr/lib/servlet-api-2.5-6.1.3.jar +0 -0
- data/solr/solr/conf/elevate.xml +36 -0
- data/solr/solr/conf/protwords.txt +21 -0
- data/solr/solr/conf/schema.xml +64 -0
- data/solr/solr/conf/solrconfig.xml +726 -0
- data/solr/solr/conf/stopwords.txt +57 -0
- data/solr/solr/conf/synonyms.txt +31 -0
- data/solr/start.jar +0 -0
- data/solr/webapps/solr.war +0 -0
- data/spec/api/adapters_spec.rb +33 -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 +4 -0
- data/spec/api/query/connectives_spec.rb +161 -0
- data/spec/api/query/dsl_spec.rb +12 -0
- data/spec/api/query/dynamic_fields_spec.rb +148 -0
- data/spec/api/query/faceting_spec.rb +272 -0
- data/spec/api/query/fulltext_spec.rb +152 -0
- data/spec/api/query/highlighting_spec.rb +82 -0
- data/spec/api/query/local_spec.rb +37 -0
- data/spec/api/query/ordering_pagination_spec.rb +95 -0
- data/spec/api/query/scope_spec.rb +253 -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 +11 -0
- data/spec/api/search/spec_helper.rb +1 -0
- data/spec/api/session_spec.rb +157 -0
- data/spec/api/spec_helper.rb +1 -0
- data/spec/api/sunspot_spec.rb +18 -0
- 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/dynamic_fields_spec.rb +55 -0
- data/spec/integration/faceting_spec.rb +169 -0
- data/spec/integration/highlighting_spec.rb +22 -0
- data/spec/integration/keyword_search_spec.rb +148 -0
- data/spec/integration/local_search_spec.rb +47 -0
- data/spec/integration/scoped_search_spec.rb +303 -0
- data/spec/integration/spec_helper.rb +1 -0
- data/spec/integration/stored_fields_spec.rb +10 -0
- data/spec/integration/test_pagination.rb +32 -0
- data/spec/mocks/adapters.rb +32 -0
- data/spec/mocks/blog.rb +3 -0
- data/spec/mocks/comment.rb +19 -0
- data/spec/mocks/connection.rb +84 -0
- data/spec/mocks/mock_adapter.rb +30 -0
- data/spec/mocks/mock_record.rb +48 -0
- data/spec/mocks/photo.rb +8 -0
- data/spec/mocks/post.rb +75 -0
- data/spec/mocks/super_class.rb +2 -0
- data/spec/mocks/user.rb +8 -0
- data/spec/spec_helper.rb +60 -0
- data/tasks/gemspec.rake +35 -0
- data/tasks/rcov.rake +28 -0
- data/tasks/rdoc.rake +22 -0
- data/tasks/schema.rake +19 -0
- data/tasks/spec.rake +24 -0
- data/tasks/todo.rake +4 -0
- data/templates/schema.xml.erb +36 -0
- metadata +312 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'dynamic field query', :type => :query do
|
4
|
+
it 'restricts by dynamic string field with equality restriction' do
|
5
|
+
session.search Post do
|
6
|
+
dynamic :custom_string do
|
7
|
+
with :test, 'string'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
connection.should have_last_search_with(:fq => ['custom_string\:test_s:string'])
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'restricts by dynamic integer field with less than restriction' do
|
14
|
+
session.search Post do
|
15
|
+
dynamic :custom_integer do
|
16
|
+
with(:test).less_than(1)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
connection.should have_last_search_with(:fq => ['custom_integer\:test_i:[* TO 1]'])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'restricts by dynamic float field with between restriction' do
|
23
|
+
session.search Post do
|
24
|
+
dynamic :custom_float do
|
25
|
+
with(:test).between(2.2..3.3)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
connection.should have_last_search_with(:fq => ['custom_float\:test_fm:[2\.2 TO 3\.3]'])
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'restricts by dynamic time field with any of restriction' do
|
32
|
+
session.search Post do
|
33
|
+
dynamic :custom_time do
|
34
|
+
with(:test).any_of([Time.parse('2009-02-10 14:00:00 UTC'),
|
35
|
+
Time.parse('2009-02-13 18:00:00 UTC')])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
connection.should have_last_search_with(:fq => ['custom_time\:test_d:(2009\-02\-10T14\:00\:00Z OR 2009\-02\-13T18\:00\:00Z)'])
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'restricts by dynamic boolean field with equality restriction' do
|
42
|
+
session.search Post do
|
43
|
+
dynamic :custom_boolean do
|
44
|
+
with :test, false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
connection.should have_last_search_with(:fq => ['custom_boolean\:test_b:false'])
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'negates a dynamic field restriction' do
|
51
|
+
session.search Post do
|
52
|
+
dynamic :custom_string do
|
53
|
+
without :test, 'foo'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
connection.should have_last_search_with(:fq => ['-custom_string\:test_s:foo'])
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'scopes by a dynamic field inside a disjunction' do
|
60
|
+
session.search Post do
|
61
|
+
any_of do
|
62
|
+
dynamic :custom_string do
|
63
|
+
with :test, 'foo'
|
64
|
+
end
|
65
|
+
with :title, 'bar'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
connection.should have_last_search_with(
|
69
|
+
:fq => '(custom_string\:test_s:foo OR title_ss:bar)'
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'orders by a dynamic field' do
|
74
|
+
session.search Post do
|
75
|
+
dynamic :custom_integer do
|
76
|
+
order_by :test, :desc
|
77
|
+
end
|
78
|
+
end
|
79
|
+
connection.should have_last_search_with(:sort => 'custom_integer:test_i desc')
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'orders by a dynamic field and static field, with given precedence' do
|
83
|
+
session.search Post do
|
84
|
+
dynamic :custom_integer do
|
85
|
+
order_by :test, :desc
|
86
|
+
end
|
87
|
+
order_by :sort_title, :asc
|
88
|
+
end
|
89
|
+
connection.should have_last_search_with(:sort => 'custom_integer:test_i desc, sort_title_s asc')
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'raises an UnrecognizedFieldError if an unknown dynamic field is searched by' do
|
93
|
+
lambda do
|
94
|
+
session.search Post do
|
95
|
+
dynamic(:bogus) { with :some, 'value' }
|
96
|
+
end
|
97
|
+
end.should raise_error(Sunspot::UnrecognizedFieldError)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'raises a NoMethodError if pagination is attempted in a dynamic query' do
|
101
|
+
lambda do
|
102
|
+
session.search Post do
|
103
|
+
dynamic :custom_string do
|
104
|
+
paginate 3, 10
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end.should raise_error(NoMethodError)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'requests query facet with internal dynamic field' do
|
111
|
+
session.search Post do
|
112
|
+
facet :test do
|
113
|
+
row 'foo' do
|
114
|
+
dynamic :custom_string do
|
115
|
+
with :test, 'foo'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
connection.should have_last_search_with(
|
121
|
+
:"facet.query" => 'custom_string\:test_s:foo'
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'requests query facet with external dynamic field' do
|
126
|
+
session.search Post do
|
127
|
+
dynamic :custom_string do
|
128
|
+
facet :test do
|
129
|
+
row 'foo' do
|
130
|
+
with :test, 'foo'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
connection.should have_last_search_with(
|
136
|
+
:"facet.query" => 'custom_string\:test_s:foo'
|
137
|
+
)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'allows scoping on dynamic fields common to all types' do
|
141
|
+
session.search Post, Namespaced::Comment do
|
142
|
+
dynamic :custom_string do
|
143
|
+
with(:test, 'test')
|
144
|
+
end
|
145
|
+
end
|
146
|
+
connection.should have_last_search_with(:fq => ['custom_string\\:test_s:test'])
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,272 @@
|
|
1
|
+
describe 'faceting' do
|
2
|
+
describe 'on fields' do
|
3
|
+
it 'does not turn faceting on if no facet requested' do
|
4
|
+
session.search(Post)
|
5
|
+
connection.should_not have_last_search_with('facet')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'turns faceting on if facet is requested' do
|
9
|
+
session.search Post do
|
10
|
+
facet :category_ids
|
11
|
+
end
|
12
|
+
connection.should have_last_search_with(:facet => 'true')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'requests single field facet' do
|
16
|
+
session.search Post do
|
17
|
+
facet :category_ids
|
18
|
+
end
|
19
|
+
connection.should have_last_search_with(:"facet.field" => %w(category_ids_im))
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'requests multiple field facets' do
|
23
|
+
session.search Post do
|
24
|
+
facet :category_ids, :blog_id
|
25
|
+
end
|
26
|
+
connection.should have_last_search_with(:"facet.field" => %w(category_ids_im blog_id_i))
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'sets facet sort by count' do
|
30
|
+
session.search Post do
|
31
|
+
facet :category_ids, :sort => :count
|
32
|
+
end
|
33
|
+
connection.should have_last_search_with(:"f.category_ids_im.facet.sort" => 'true')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'sets facet sort by index' do
|
37
|
+
session.search Post do
|
38
|
+
facet :category_ids, :sort => :index
|
39
|
+
end
|
40
|
+
connection.should have_last_search_with(:"f.category_ids_im.facet.sort" => 'false')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'raises ArgumentError if bogus facet sort provided' do
|
44
|
+
lambda do
|
45
|
+
session.search Post do
|
46
|
+
facet :category_ids, :sort => :sideways
|
47
|
+
end
|
48
|
+
end.should raise_error(ArgumentError)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'sets the facet limit' do
|
52
|
+
session.search Post do
|
53
|
+
facet :category_ids, :limit => 10
|
54
|
+
end
|
55
|
+
connection.should have_last_search_with(:"f.category_ids_im.facet.limit" => 10)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'sets the facet minimum count' do
|
59
|
+
session.search Post do
|
60
|
+
facet :category_ids, :minimum_count => 5
|
61
|
+
end
|
62
|
+
connection.should have_last_search_with(:"f.category_ids_im.facet.mincount" => 5)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'sets the facet minimum count to zero if zeros are allowed' do
|
66
|
+
session.search Post do
|
67
|
+
facet :category_ids, :zeros => true
|
68
|
+
end
|
69
|
+
connection.should have_last_search_with(:"f.category_ids_im.facet.mincount" => 0)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'sets the facet minimum count to one by default' do
|
73
|
+
session.search Post do
|
74
|
+
facet :category_ids
|
75
|
+
end
|
76
|
+
connection.should have_last_search_with(:"f.category_ids_im.facet.mincount" => 1)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'on time ranges' do
|
81
|
+
before :each do
|
82
|
+
@time_range = (Time.parse('2009-06-01 00:00:00 -0400')..
|
83
|
+
Time.parse('2009-07-01 00:00:00 -0400'))
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'does not send date facet parameters if time range is not specified' do
|
87
|
+
session.search Post do |query|
|
88
|
+
query.facet :published_at
|
89
|
+
end
|
90
|
+
connection.should_not have_last_search_with(:"facet.date")
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'sets the facet to a date facet if time range is specified' do
|
94
|
+
session.search Post do |query|
|
95
|
+
query.facet :published_at, :time_range => @time_range
|
96
|
+
end
|
97
|
+
connection.should have_last_search_with(:"facet.date" => ['published_at_d'])
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'sets the facet start and end' do
|
101
|
+
session.search Post do |query|
|
102
|
+
query.facet :published_at, :time_range => @time_range
|
103
|
+
end
|
104
|
+
connection.should have_last_search_with(
|
105
|
+
:"f.published_at_d.facet.date.start" => '2009-06-01T04:00:00Z',
|
106
|
+
:"f.published_at_d.facet.date.end" => '2009-07-01T04:00:00Z'
|
107
|
+
)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'defaults the time interval to 1 day' do
|
111
|
+
session.search Post do |query|
|
112
|
+
query.facet :published_at, :time_range => @time_range
|
113
|
+
end
|
114
|
+
connection.should have_last_search_with(:"f.published_at_d.facet.date.gap" => "+86400SECONDS")
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'uses custom time interval' do
|
118
|
+
session.search Post do |query|
|
119
|
+
query.facet :published_at, :time_range => @time_range, :time_interval => 3600
|
120
|
+
end
|
121
|
+
connection.should have_last_search_with(:"f.published_at_d.facet.date.gap" => "+3600SECONDS")
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'does not allow date faceting on a non-date field' do
|
125
|
+
lambda do
|
126
|
+
session.search Post do |query|
|
127
|
+
query.facet :blog_id, :time_range => @time_range
|
128
|
+
end
|
129
|
+
end.should raise_error(ArgumentError)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'using queries' do
|
134
|
+
it 'turns faceting on' do
|
135
|
+
session.search Post do
|
136
|
+
facet :foo do
|
137
|
+
row :bar do
|
138
|
+
with(:average_rating).between(4.0..5.0)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
connection.should have_last_search_with(:facet => 'true')
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'facets by query' do
|
146
|
+
session.search Post do
|
147
|
+
facet :foo do
|
148
|
+
row :bar do
|
149
|
+
with(:average_rating).between(4.0..5.0)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
connection.should have_last_search_with(:"facet.query" => 'average_rating_f:[4\.0 TO 5\.0]')
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'requests multiple query facets' do
|
157
|
+
session.search Post do
|
158
|
+
facet :foo do
|
159
|
+
row :bar do
|
160
|
+
with(:average_rating).between(3.0..4.0)
|
161
|
+
end
|
162
|
+
row :baz do
|
163
|
+
with(:average_rating).between(4.0..5.0)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
connection.should have_last_search_with(
|
168
|
+
:"facet.query" => [
|
169
|
+
'average_rating_f:[3\.0 TO 4\.0]',
|
170
|
+
'average_rating_f:[4\.0 TO 5\.0]'
|
171
|
+
]
|
172
|
+
)
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'requests query facet with multiple conditions' do
|
176
|
+
session.search Post do
|
177
|
+
facet :foo do
|
178
|
+
row :bar do
|
179
|
+
with(:category_ids, 1)
|
180
|
+
with(:blog_id, 2)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
connection.should have_last_search_with(
|
185
|
+
:"facet.query" => '(category_ids_im:1 AND blog_id_i:2)'
|
186
|
+
)
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'requests query facet with disjunction' do
|
190
|
+
session.search Post do
|
191
|
+
facet :foo do
|
192
|
+
row :bar do
|
193
|
+
any_of do
|
194
|
+
with(:category_ids, 1)
|
195
|
+
with(:blog_id, 2)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
connection.should have_last_search_with(
|
201
|
+
:"facet.query" => '(category_ids_im:1 OR blog_id_i:2)'
|
202
|
+
)
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'builds query facets when passed :only argument to field facet declaration' do
|
206
|
+
session.search Post do
|
207
|
+
facet :category_ids, :only => [1, 3]
|
208
|
+
end
|
209
|
+
connection.should have_last_search_with(
|
210
|
+
:"facet.query" => ['category_ids_im:1', 'category_ids_im:3']
|
211
|
+
)
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'converts limited query facet values to the correct type' do
|
215
|
+
session.search Post do
|
216
|
+
facet :published_at, :only => [Time.utc(2009, 8, 28, 15, 33), Time.utc(2008,8, 28, 15, 33)]
|
217
|
+
end
|
218
|
+
connection.should have_last_search_with(
|
219
|
+
:"facet.query" => [
|
220
|
+
'published_at_d:2009\-08\-28T15\:33\:00Z',
|
221
|
+
'published_at_d:2008\-08\-28T15\:33\:00Z'
|
222
|
+
]
|
223
|
+
)
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'ignores facet query with no rows' do
|
227
|
+
session.search Post do
|
228
|
+
facet(:foo) {}
|
229
|
+
end
|
230
|
+
connection.should_not have_last_search_with(:"facet.query")
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'ignores facet query row with no restrictions' do
|
234
|
+
session.search Post do
|
235
|
+
facet :foo do
|
236
|
+
row(:bar) do
|
237
|
+
with(:blog_id, 1)
|
238
|
+
end
|
239
|
+
row(:baz) {}
|
240
|
+
end
|
241
|
+
end
|
242
|
+
connection.searches.last[:"facet.query"].should be_a(String)
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'ignores facet query with only empty rows' do
|
246
|
+
session.search Post do
|
247
|
+
facet :foo do
|
248
|
+
row(:bar) {}
|
249
|
+
end
|
250
|
+
end
|
251
|
+
connection.should_not have_last_search_with(:"facet.query")
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'does not allow 0 arguments to facet method with block' do
|
255
|
+
lambda do
|
256
|
+
session.search Post do
|
257
|
+
facet do
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end.should raise_error(ArgumentError)
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'does not allow more than 1 argument to facet method with block' do
|
264
|
+
lambda do
|
265
|
+
session.search Post do
|
266
|
+
facet :foo, :bar do
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end.should raise_error(ArgumentError)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
@@ -0,0 +1,152 @@
|
|
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
|
113
|
+
end
|
114
|
+
end
|
115
|
+
connection.should have_last_search_with(:pf => 'title_text')
|
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 'creates boost query' do
|
128
|
+
session.search Post do
|
129
|
+
keywords 'great pizza' do
|
130
|
+
boost 2.0 do
|
131
|
+
with(:average_rating).greater_than(2.0)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
connection.should have_last_search_with(:bq => 'average_rating_f:[2\.0 TO *]^2.0')
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'allows specification of a text field that only exists in one type' do
|
139
|
+
session.search Post, Namespaced::Comment do
|
140
|
+
keywords 'keywords', :fields => :author_name
|
141
|
+
end
|
142
|
+
connection.searches.last[:qf].should == 'author_name_text'
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'raises Sunspot::UnrecognizedFieldError for nonexistant fields in keywords' do
|
146
|
+
lambda do
|
147
|
+
session.search Post do
|
148
|
+
keywords :text, :fields => :bogus
|
149
|
+
end
|
150
|
+
end.should raise_error(Sunspot::UnrecognizedFieldError)
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,82 @@
|
|
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 set internal formatting' do
|
19
|
+
session.search(Post) do
|
20
|
+
keywords 'test', :highlight => true
|
21
|
+
end
|
22
|
+
connection.should have_last_search_with(
|
23
|
+
:"hl.simple.pre" => '@@@hl@@@',
|
24
|
+
:"hl.simple.post" => '@@@endhl@@@'
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should set maximum highlights per field' do
|
29
|
+
session.search(Post) do
|
30
|
+
keywords 'test' do
|
31
|
+
highlight :max_snippets => 3
|
32
|
+
end
|
33
|
+
end
|
34
|
+
connection.should have_last_search_with(
|
35
|
+
:"hl.snippets" => 3
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should set the maximum size' do
|
40
|
+
session.search(Post) do
|
41
|
+
keywords 'text' do
|
42
|
+
highlight :fragment_size => 200
|
43
|
+
end
|
44
|
+
end
|
45
|
+
connection.should have_last_search_with(
|
46
|
+
:"hl.fragsize" => 200
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'enables merging of continuous fragments' do
|
51
|
+
session.search(Post) do
|
52
|
+
keywords 'test' do
|
53
|
+
highlight :merge_continuous_fragments => true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
connection.should have_last_search_with(
|
57
|
+
:"hl.mergeContinuous" => 'true'
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'enables use of phrase highlighter' do #TODO figure out what the hell this means
|
62
|
+
session.search(Post) do
|
63
|
+
keywords 'test' do
|
64
|
+
highlight :phrase_highlighter => true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
connection.should have_last_search_with(
|
68
|
+
:"hl.usePhraseHighlighter" => 'true'
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'requires field match if requested' do
|
73
|
+
session.search(Post) do
|
74
|
+
keywords 'test' do
|
75
|
+
highlight :phrase_highlighter => true, :require_field_match => true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
connection.should have_last_search_with(
|
79
|
+
:"hl.requireFieldMatch" => 'true'
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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
|
+
[
|
26
|
+
[:lat, :lng],
|
27
|
+
[:lat, :lon],
|
28
|
+
[:lat, :long]
|
29
|
+
].each do |lat_attr, lng_attr|
|
30
|
+
it "sets coordinates using #{lat_attr.inspect}, #{lng_attr.inspect}" do
|
31
|
+
session.search Post do
|
32
|
+
near OpenStruct.new(lat_attr => 40.7, lng_attr => -73.5), 5
|
33
|
+
end
|
34
|
+
connection.should have_last_search_with(:lat => 40.7, :long => -73.5)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|