sunspot 2.3.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +4 -4
- data/lib/sunspot/adapters.rb +15 -1
- data/lib/sunspot/data_extractor.rb +36 -6
- data/lib/sunspot/dsl/fields.rb +16 -0
- data/lib/sunspot/dsl/fulltext.rb +1 -1
- data/lib/sunspot/dsl/group.rb +10 -0
- data/lib/sunspot/dsl/scope.rb +17 -17
- data/lib/sunspot/dsl/standard_query.rb +29 -1
- data/lib/sunspot/dsl.rb +2 -2
- data/lib/sunspot/field.rb +15 -4
- data/lib/sunspot/indexer.rb +37 -8
- data/lib/sunspot/query/abstract_fulltext.rb +7 -3
- data/lib/sunspot/query/abstract_json_field_facet.rb +3 -0
- data/lib/sunspot/query/composite_fulltext.rb +21 -2
- data/lib/sunspot/query/date_field_json_facet.rb +2 -16
- data/lib/sunspot/query/dismax.rb +10 -4
- data/lib/sunspot/query/function_query.rb +25 -1
- data/lib/sunspot/query/group.rb +4 -5
- data/lib/sunspot/query/join.rb +3 -5
- data/lib/sunspot/query/range_json_facet.rb +5 -2
- data/lib/sunspot/query/restriction.rb +18 -13
- data/lib/sunspot/query/standard_query.rb +12 -0
- data/lib/sunspot/search/abstract_search.rb +1 -1
- data/lib/sunspot/search/field_json_facet.rb +14 -3
- data/lib/sunspot/search/hit.rb +6 -1
- data/lib/sunspot/session.rb +9 -1
- data/lib/sunspot/setup.rb +69 -0
- data/lib/sunspot/util.rb +4 -11
- data/lib/sunspot/version.rb +1 -1
- data/lib/sunspot.rb +9 -1
- data/spec/api/adapters_spec.rb +13 -0
- data/spec/api/data_extractor_spec.rb +39 -0
- data/spec/api/indexer/removal_spec.rb +87 -0
- data/spec/api/query/connective_boost_examples.rb +85 -0
- data/spec/api/query/fulltext_examples.rb +6 -12
- data/spec/api/query/join_spec.rb +2 -2
- data/spec/api/query/standard_spec.rb +10 -0
- data/spec/api/search/hits_spec.rb +14 -0
- data/spec/api/setup_spec.rb +99 -0
- data/spec/api/sunspot_spec.rb +3 -0
- data/spec/helpers/indexer_helper.rb +22 -0
- data/spec/integration/atomic_updates_spec.rb +169 -5
- data/spec/integration/faceting_spec.rb +68 -34
- data/spec/integration/field_grouping_spec.rb +19 -0
- data/spec/integration/field_lists_spec.rb +16 -0
- data/spec/integration/geospatial_spec.rb +15 -0
- data/spec/integration/join_spec.rb +64 -0
- data/spec/integration/scoped_search_spec.rb +78 -0
- data/spec/mocks/adapters.rb +33 -0
- data/spec/mocks/connection.rb +6 -0
- data/spec/mocks/photo.rb +19 -5
- data/spec/mocks/post.rb +35 -1
- data/sunspot.gemspec +0 -2
- metadata +14 -8
- data/gemfiles/.gitkeep +0 -0
@@ -538,4 +538,82 @@ describe 'scoped_search' do
|
|
538
538
|
expect(search.results.first).to eq(@p1)
|
539
539
|
end
|
540
540
|
end
|
541
|
+
|
542
|
+
describe 'boosting' do
|
543
|
+
before :all do
|
544
|
+
Sunspot.remove_all
|
545
|
+
@p1 = Post.new(:title => 'Post', :body => 'Lorem', :blog_id => 1, :category_ids => [3], :ratings_average => 30)
|
546
|
+
@p2 = Post.new(:title => 'Post', :body => 'Ipsum', :blog_id => 2, :category_ids => [2], :ratings_average => 60)
|
547
|
+
@p3 = Post.new(:title => 'Post', :body => 'Dolor', :blog_id => 3, :category_ids => [1], :ratings_average => 90)
|
548
|
+
Sunspot.index([@p1, @p2, @p3])
|
549
|
+
Sunspot.commit
|
550
|
+
end
|
551
|
+
|
552
|
+
it 'without boost should returns post in default order' do
|
553
|
+
search = Sunspot.search(Post) {}
|
554
|
+
|
555
|
+
expect(search.results[0]).to eq(@p1)
|
556
|
+
expect(search.results[1]).to eq(@p2)
|
557
|
+
expect(search.results[2]).to eq(@p3)
|
558
|
+
end
|
559
|
+
|
560
|
+
it 'should apply boost function' do
|
561
|
+
search = Sunspot.search(Post) do
|
562
|
+
boost(function() { field(:average_rating) })
|
563
|
+
end
|
564
|
+
|
565
|
+
expect(search.results[0]).to eq(@p3)
|
566
|
+
expect(search.results[1]).to eq(@p2)
|
567
|
+
expect(search.results[2]).to eq(@p1)
|
568
|
+
end
|
569
|
+
|
570
|
+
it 'should apply multilicative boost function' do
|
571
|
+
search = Sunspot.search(Post) do
|
572
|
+
boost_multiplicative(function() { field(:average_rating) })
|
573
|
+
end
|
574
|
+
|
575
|
+
expect(search.results[0]).to eq(@p3)
|
576
|
+
expect(search.results[1]).to eq(@p2)
|
577
|
+
expect(search.results[2]).to eq(@p1)
|
578
|
+
end
|
579
|
+
|
580
|
+
it 'should apply boost query' do
|
581
|
+
search = Sunspot.search(Post) do
|
582
|
+
boost(5) do
|
583
|
+
with(:blog_id, 1)
|
584
|
+
end
|
585
|
+
|
586
|
+
boost(10) do
|
587
|
+
with(:blog_id, 3)
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
591
|
+
expect(search.results[0]).to eq(@p3)
|
592
|
+
expect(search.results[1]).to eq(@p1)
|
593
|
+
expect(search.results[2]).to eq(@p2)
|
594
|
+
end
|
595
|
+
|
596
|
+
it 'should work properly when combined with fulltext' do
|
597
|
+
search = Sunspot.search(Post) do
|
598
|
+
fulltext('Post Ipsum') do
|
599
|
+
boost_fields :body => 0.2
|
600
|
+
minimum_match 1
|
601
|
+
end
|
602
|
+
|
603
|
+
boost(0.9) do
|
604
|
+
with(:blog_id, 1)
|
605
|
+
end
|
606
|
+
|
607
|
+
boost(function() { div(field(:average_rating), 100) })
|
608
|
+
|
609
|
+
fulltext('Post') do
|
610
|
+
minimum_match 1
|
611
|
+
end
|
612
|
+
end
|
613
|
+
|
614
|
+
expect(search.results[0]).to eq(@p2)
|
615
|
+
expect(search.results[1]).to eq(@p3)
|
616
|
+
expect(search.results[2]).to eq(@p1)
|
617
|
+
end
|
618
|
+
end
|
541
619
|
end
|
data/spec/mocks/adapters.rb
CHANGED
@@ -7,7 +7,40 @@ end
|
|
7
7
|
class UnseenModel < AbstractModel
|
8
8
|
end
|
9
9
|
|
10
|
+
class ModelWithPrefixId < AbstractModel
|
11
|
+
def id
|
12
|
+
1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Sunspot.setup(ModelWithPrefixId) do
|
17
|
+
id_prefix { "USERDATA!" }
|
18
|
+
end
|
19
|
+
|
20
|
+
class ModelWithNestedPrefixId < AbstractModel
|
21
|
+
def id
|
22
|
+
1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Sunspot.setup(ModelWithNestedPrefixId) do
|
27
|
+
id_prefix { "USER!USERDATA!" }
|
28
|
+
end
|
29
|
+
|
30
|
+
class ModelWithoutPrefixId < AbstractModel
|
31
|
+
def id
|
32
|
+
1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Sunspot.setup(ModelWithoutPrefixId) do
|
37
|
+
end
|
38
|
+
|
39
|
+
|
10
40
|
class AbstractModelInstanceAdapter < Sunspot::Adapters::InstanceAdapter
|
41
|
+
def id
|
42
|
+
@instance.id
|
43
|
+
end
|
11
44
|
end
|
12
45
|
|
13
46
|
class AbstractModelDataAccessor < Sunspot::Adapters::DataAccessor
|
data/spec/mocks/connection.rb
CHANGED
data/spec/mocks/photo.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Photo < MockRecord
|
2
|
-
attr_accessor :caption, :description, :lat, :lng, :size, :average_rating, :created_at, :post_id, :photo_container_id
|
2
|
+
attr_accessor :caption, :description, :lat, :lng, :size, :average_rating, :created_at, :post_id, :photo_container_id, :published
|
3
3
|
end
|
4
4
|
|
5
5
|
Sunspot.setup(Photo) do
|
@@ -7,12 +7,23 @@ Sunspot.setup(Photo) do
|
|
7
7
|
text :description
|
8
8
|
string :caption
|
9
9
|
integer :photo_container_id
|
10
|
+
boolean :published
|
10
11
|
boost 0.75
|
11
12
|
integer :size, :trie => true
|
12
13
|
float :average_rating, :trie => true
|
13
14
|
time :created_at, :trie => true
|
14
15
|
end
|
15
16
|
|
17
|
+
class Picture < MockRecord
|
18
|
+
attr_accessor :description, :photo_container_id, :published
|
19
|
+
end
|
20
|
+
|
21
|
+
Sunspot.setup(Picture) do
|
22
|
+
text :description
|
23
|
+
integer :photo_container_id
|
24
|
+
boolean :published
|
25
|
+
end
|
26
|
+
|
16
27
|
class PhotoContainer < MockRecord
|
17
28
|
attr_accessor :description
|
18
29
|
|
@@ -25,8 +36,11 @@ Sunspot.setup(PhotoContainer) do
|
|
25
36
|
integer :id
|
26
37
|
text :description, :default_boost => 1.2
|
27
38
|
|
28
|
-
join(:caption,
|
29
|
-
join(:photo_rating, :target => Photo,
|
30
|
-
join(:caption,
|
31
|
-
join(:description,
|
39
|
+
join(:caption, :target => 'Photo', :type => :string, :join => { :from => :photo_container_id, :to => :id })
|
40
|
+
join(:photo_rating, :target => 'Photo', :type => :trie_float, :join => { :from => :photo_container_id, :to => :id }, :as => 'average_rating_ft')
|
41
|
+
join(:caption, :target => 'Photo', :type => :text, :join => { :from => :photo_container_id, :to => :id })
|
42
|
+
join(:description, :target => 'Photo', :type => :text, :join => { :from => :photo_container_id, :to => :id }, :prefix => "photo")
|
43
|
+
join(:published, :target => 'Photo', :type => :boolean, :join => { :from => :photo_container_id, :to => :id }, :prefix => "photo")
|
44
|
+
join(:description, :target => 'Picture', :type => :text, :join => { :from => :photo_container_id, :to => :id }, :prefix => "picture")
|
45
|
+
join(:published, :target => 'Picture', :type => :boolean, :join => { :from => :photo_container_id, :to => :id }, :prefix => "picture")
|
32
46
|
end
|
data/spec/mocks/post.rb
CHANGED
@@ -37,7 +37,7 @@ end
|
|
37
37
|
|
38
38
|
Sunspot.setup(Post) do
|
39
39
|
text :title, :boost => 2
|
40
|
-
text :text_array
|
40
|
+
text :text_array do
|
41
41
|
[title, title]
|
42
42
|
end
|
43
43
|
text :body, :stored => true, :more_like_this => true
|
@@ -99,3 +99,37 @@ end
|
|
99
99
|
class PhotoPost < Post
|
100
100
|
end
|
101
101
|
|
102
|
+
class PostWithProcPrefixId < Post
|
103
|
+
end
|
104
|
+
|
105
|
+
Sunspot.setup(PostWithProcPrefixId) do
|
106
|
+
id_prefix { "USERDATA-#{id}!" }
|
107
|
+
string :title, :stored => true
|
108
|
+
boolean :featured, :using => :featured?, :stored => true
|
109
|
+
end
|
110
|
+
|
111
|
+
class PostWithSymbolPrefixId < Post
|
112
|
+
end
|
113
|
+
|
114
|
+
Sunspot.setup(PostWithSymbolPrefixId) do
|
115
|
+
id_prefix :title
|
116
|
+
string :title, :stored => true
|
117
|
+
boolean :featured, :using => :featured?, :stored => true
|
118
|
+
end
|
119
|
+
|
120
|
+
class PostWithStringPrefixId < Post
|
121
|
+
end
|
122
|
+
|
123
|
+
Sunspot.setup(PostWithStringPrefixId) do
|
124
|
+
id_prefix 'USERDATA!'
|
125
|
+
string :title, :stored => true
|
126
|
+
boolean :featured, :using => :featured?, :stored => true
|
127
|
+
end
|
128
|
+
|
129
|
+
class PostWithoutPrefixId < Post
|
130
|
+
end
|
131
|
+
|
132
|
+
Sunspot.setup(PostWithoutPrefixId) do
|
133
|
+
string :title, :stored => true
|
134
|
+
boolean :featured, :using => :featured?, :stored => true
|
135
|
+
end
|
data/sunspot.gemspec
CHANGED
@@ -20,8 +20,6 @@ Gem::Specification.new do |s|
|
|
20
20
|
can be performed without hand-writing any boolean queries or building Solr parameters by hand.
|
21
21
|
TEXT
|
22
22
|
|
23
|
-
s.rubyforge_project = "sunspot"
|
24
|
-
|
25
23
|
s.files = `git ls-files`.split("\n")
|
26
24
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
25
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunspot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat Brown
|
@@ -27,10 +27,10 @@ authors:
|
|
27
27
|
- Nicholas Jakobsen
|
28
28
|
- Bragadeesh J
|
29
29
|
- Ethiraj Srinivasan
|
30
|
-
autorequire:
|
30
|
+
autorequire:
|
31
31
|
bindir: bin
|
32
32
|
cert_chain: []
|
33
|
-
date:
|
33
|
+
date: 2022-05-30 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: rsolr
|
@@ -126,7 +126,6 @@ files:
|
|
126
126
|
- LICENSE
|
127
127
|
- Rakefile
|
128
128
|
- TODO
|
129
|
-
- gemfiles/.gitkeep
|
130
129
|
- lib/light_config.rb
|
131
130
|
- lib/sunspot.rb
|
132
131
|
- lib/sunspot/adapters.rb
|
@@ -240,6 +239,7 @@ files:
|
|
240
239
|
- spec/api/batcher_spec.rb
|
241
240
|
- spec/api/binding_spec.rb
|
242
241
|
- spec/api/class_set_spec.rb
|
242
|
+
- spec/api/data_extractor_spec.rb
|
243
243
|
- spec/api/hit_enumerable_spec.rb
|
244
244
|
- spec/api/indexer/attributes_spec.rb
|
245
245
|
- spec/api/indexer/batch_spec.rb
|
@@ -250,6 +250,7 @@ files:
|
|
250
250
|
- spec/api/indexer/spec_helper.rb
|
251
251
|
- spec/api/indexer_spec.rb
|
252
252
|
- spec/api/query/advanced_manipulation_examples.rb
|
253
|
+
- spec/api/query/connective_boost_examples.rb
|
253
254
|
- spec/api/query/connectives_examples.rb
|
254
255
|
- spec/api/query/dsl_spec.rb
|
255
256
|
- spec/api/query/dynamic_fields_examples.rb
|
@@ -289,6 +290,7 @@ files:
|
|
289
290
|
- spec/api/session_proxy/spec_helper.rb
|
290
291
|
- spec/api/session_proxy/thread_local_session_proxy_spec.rb
|
291
292
|
- spec/api/session_spec.rb
|
293
|
+
- spec/api/setup_spec.rb
|
292
294
|
- spec/api/spec_helper.rb
|
293
295
|
- spec/api/sunspot_spec.rb
|
294
296
|
- spec/ext.rb
|
@@ -305,6 +307,7 @@ files:
|
|
305
307
|
- spec/integration/geospatial_spec.rb
|
306
308
|
- spec/integration/highlighting_spec.rb
|
307
309
|
- spec/integration/indexing_spec.rb
|
310
|
+
- spec/integration/join_spec.rb
|
308
311
|
- spec/integration/keyword_search_spec.rb
|
309
312
|
- spec/integration/local_search_spec.rb
|
310
313
|
- spec/integration/more_like_this_spec.rb
|
@@ -335,7 +338,7 @@ homepage: http://outoftime.github.com/sunspot
|
|
335
338
|
licenses:
|
336
339
|
- MIT
|
337
340
|
metadata: {}
|
338
|
-
post_install_message:
|
341
|
+
post_install_message:
|
339
342
|
rdoc_options:
|
340
343
|
- "--webcvs=http://github.com/outoftime/sunspot/tree/master/%s"
|
341
344
|
- "--title"
|
@@ -355,9 +358,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
355
358
|
- !ruby/object:Gem::Version
|
356
359
|
version: '0'
|
357
360
|
requirements: []
|
358
|
-
|
359
|
-
|
360
|
-
signing_key:
|
361
|
+
rubygems_version: 3.1.4
|
362
|
+
signing_key:
|
361
363
|
specification_version: 4
|
362
364
|
summary: Library for expressive, powerful interaction with the Solr search engine
|
363
365
|
test_files:
|
@@ -365,6 +367,7 @@ test_files:
|
|
365
367
|
- spec/api/batcher_spec.rb
|
366
368
|
- spec/api/binding_spec.rb
|
367
369
|
- spec/api/class_set_spec.rb
|
370
|
+
- spec/api/data_extractor_spec.rb
|
368
371
|
- spec/api/hit_enumerable_spec.rb
|
369
372
|
- spec/api/indexer/attributes_spec.rb
|
370
373
|
- spec/api/indexer/batch_spec.rb
|
@@ -375,6 +378,7 @@ test_files:
|
|
375
378
|
- spec/api/indexer/spec_helper.rb
|
376
379
|
- spec/api/indexer_spec.rb
|
377
380
|
- spec/api/query/advanced_manipulation_examples.rb
|
381
|
+
- spec/api/query/connective_boost_examples.rb
|
378
382
|
- spec/api/query/connectives_examples.rb
|
379
383
|
- spec/api/query/dsl_spec.rb
|
380
384
|
- spec/api/query/dynamic_fields_examples.rb
|
@@ -414,6 +418,7 @@ test_files:
|
|
414
418
|
- spec/api/session_proxy/spec_helper.rb
|
415
419
|
- spec/api/session_proxy/thread_local_session_proxy_spec.rb
|
416
420
|
- spec/api/session_spec.rb
|
421
|
+
- spec/api/setup_spec.rb
|
417
422
|
- spec/api/spec_helper.rb
|
418
423
|
- spec/api/sunspot_spec.rb
|
419
424
|
- spec/ext.rb
|
@@ -430,6 +435,7 @@ test_files:
|
|
430
435
|
- spec/integration/geospatial_spec.rb
|
431
436
|
- spec/integration/highlighting_spec.rb
|
432
437
|
- spec/integration/indexing_spec.rb
|
438
|
+
- spec/integration/join_spec.rb
|
433
439
|
- spec/integration/keyword_search_spec.rb
|
434
440
|
- spec/integration/local_search_spec.rb
|
435
441
|
- spec/integration/more_like_this_spec.rb
|
data/gemfiles/.gitkeep
DELETED
File without changes
|