sunspot 2.2.5 → 2.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddf4e1e101c7789cbba01b5d4a46d69ac295f0e3
4
- data.tar.gz: ef751e6cb93dbdd4bda40b18b661e044cee927fe
3
+ metadata.gz: db2b5999f51846958ab592d6e9b7d1481d707693
4
+ data.tar.gz: d036d9d479cb4ff7a9780cf32891084c0ede9a20
5
5
  SHA512:
6
- metadata.gz: 2dd0adb2ce792ce3fa11ebbf9c05d7043e3402ba946e06a8b2ac78d84e885dc6cdda942528804f674e219d08ac1555e44fd392f8d993dd7feb4b24725e2368a6
7
- data.tar.gz: feaeaa4d3d41676e5d063dad39cccbf1bca1ebe6968e9f952037e9b362886f76f1f8b2e7118078ee4335435da39c5b6f4e1e3323faab0d1eb636836863c5d123
6
+ metadata.gz: 49393ba5303b4742838fcca8cbfdd4b7dc023c8fd812d6cabcbbf8501868b29f0adfe8d163064a7ed30cf412716bd945556da296d0880af1aa53316fb211d582
7
+ data.tar.gz: 3e93cb4d25d43634ed84c48984ab235d66cd39e080b916f5ef6bad24a7049c146caf35f2cc154c3615084a26d11232cdc924c27744722dae3b515a6dd420077b
@@ -26,9 +26,9 @@ module Sunspot
26
26
  # params["mlt.match.include"] = true
27
27
  # end
28
28
  # end
29
- #
29
+ #
30
30
  def adjust_solr_params( &block )
31
- @query.solr_parameter_adjustment = block
31
+ @query.add_parameter_adjustment(block)
32
32
  end
33
33
 
34
34
  #
@@ -1,6 +1,6 @@
1
1
  module Sunspot
2
2
  module DSL #:nodoc:
3
- #
3
+ #
4
4
  # This DSL presents methods for constructing restrictions and other query
5
5
  # elements that are specific to fields. As well as being a superclass of
6
6
  # Sunspot::DSL::StandardQuery, which presents the main query block, this
@@ -12,7 +12,12 @@ module Sunspot
12
12
  @scope, @setup = scope, setup
13
13
  end
14
14
 
15
- #
15
+ # Build a restriction to return only fields of the type in the results.
16
+ def field_list(*args)
17
+ @query.add_field_list(Sunspot::Query::FieldList.new(args.flatten))
18
+ end
19
+
20
+ #
16
21
  # Build a positive restriction. This method can take three forms: equality
17
22
  # restriction, restriction by another restriction, or identity
18
23
  # restriction.
@@ -62,7 +67,7 @@ module Sunspot
62
67
  # Sunspot.search do
63
68
  # with(:category_ids, [1, 5, 9])
64
69
  # end
65
- #
70
+ #
66
71
  # Other restriction types:
67
72
  #
68
73
  # Sunspot.search(Post) do
@@ -87,7 +92,7 @@ module Sunspot
87
92
  add_restriction(true, *args)
88
93
  end
89
94
 
90
- #
95
+ #
91
96
  # Create a disjunction, scoping the results to documents that match any
92
97
  # of the enclosed restrictions.
93
98
  #
@@ -109,7 +114,7 @@ module Sunspot
109
114
  disjunction
110
115
  end
111
116
 
112
- #
117
+ #
113
118
  # Create a conjunction, scoping the results to documents that match all of
114
119
  # the enclosed restrictions. When called from the top level of a search
115
120
  # block, this has no effect, but can be useful for grouping a conjunction
@@ -138,9 +143,9 @@ module Sunspot
138
143
  # The block API is implemented by Sunspot::DSL::FieldQuery, which is a
139
144
  # superclass of the Query DSL (thus providing a subset of the API, in
140
145
  # particular only methods that refer to particular fields).
141
- #
146
+ #
142
147
  # ==== Parameters
143
- #
148
+ #
144
149
  # base_name<Symbol>:: The base name for the dynamic field definition
145
150
  #
146
151
  # ==== Example
@@ -160,14 +165,14 @@ module Sunspot
160
165
  )
161
166
  end
162
167
 
163
- #
168
+ #
164
169
  # Apply scope-type restrictions on fulltext fields. In certain situations,
165
170
  # it may be desirable to place logical restrictions on text fields.
166
171
  # Remember that text fields are tokenized; your mileage may very.
167
172
  #
168
173
  # The block works exactly like a normal scope, except that the field names
169
174
  # refer to text fields instead of attribute fields.
170
- #
175
+ #
171
176
  # === Example
172
177
  #
173
178
  # Sunspot.search(Post) do
@@ -189,26 +194,25 @@ module Sunspot
189
194
 
190
195
  def add_restriction(negated, *args)
191
196
  case args.first
192
- when String, Symbol
193
- raise ArgumentError if args.length > 2
194
- field = @setup.field(args[0].to_sym)
195
- if args.length > 1
196
- value = args[1]
197
- @scope.add_shorthand_restriction(negated, field, value)
198
- else # NONE
199
- DSL::Restriction.new(field, @scope, negated)
197
+ when String, Symbol
198
+ raise ArgumentError if args.length > 2
199
+ field = @setup.field(args[0].to_sym)
200
+ if args.length > 1
201
+ value = args[1]
202
+ @scope.add_shorthand_restriction(negated, field, value)
203
+ else # NONE
204
+ DSL::Restriction.new(field, @scope, negated)
205
+ end
206
+ else # args are instances
207
+ @scope.add_restriction(
208
+ negated,
209
+ IdField.instance,
210
+ Sunspot::Query::Restriction::AnyOf,
211
+ args.flatten.map { |instance|
212
+ Sunspot::Adapters::InstanceAdapter.adapt(instance).index_id }
213
+ )
200
214
  end
201
- else # args are instances
202
- @scope.add_restriction(
203
- negated,
204
- IdField.instance,
205
- Sunspot::Query::Restriction::AnyOf,
206
- args.flatten.map { |instance|
207
- Sunspot::Adapters::InstanceAdapter.adapt(instance).index_id }
208
- )
209
215
  end
210
- end
211
-
212
216
  end
213
217
  end
214
218
  end
@@ -102,7 +102,7 @@ module Sunspot
102
102
  # Convert documents into hash of indexed properties
103
103
  #
104
104
  def prepare_full_update(model)
105
- document = document_for(model.class, model.id)
105
+ document = document_for_full_update(model)
106
106
  setup = setup_for_object(model)
107
107
  if boost = setup.document_boost_for(model)
108
108
  document.attrs[:boost] = boost
@@ -114,7 +114,7 @@ module Sunspot
114
114
  end
115
115
 
116
116
  def prepare_atomic_update(clazz, id, updates = {})
117
- document = document_for(clazz, id)
117
+ document = document_for_atomic_update(clazz, id)
118
118
  setup_for_class(clazz).all_field_factories.each do |field_factory|
119
119
  if updates.has_key?(field_factory.name)
120
120
  field_factory.populate_document(document, nil, value: updates[field_factory.name], update: :set)
@@ -137,10 +137,17 @@ module Sunspot
137
137
 
138
138
  #
139
139
  # All indexed documents index and store the +id+ and +type+ fields.
140
- # This method constructs the document hash containing those key-value
140
+ # These methods construct the document hash containing those key-value
141
141
  # pairs.
142
142
  #
143
- def document_for(clazz, id)
143
+ def document_for_full_update(model)
144
+ RSolr::Xml::Document.new(
145
+ id: Adapters::InstanceAdapter.adapt(model).index_id,
146
+ type: Util.superclasses_for(model.class).map(&:name)
147
+ )
148
+ end
149
+
150
+ def document_for_atomic_update(clazz, id)
144
151
  if Adapters::InstanceAdapter.for(clazz)
145
152
  RSolr::Xml::Document.new(
146
153
  id: Adapters::InstanceAdapter.index_id_for(clazz.name, id),
@@ -148,7 +155,6 @@ module Sunspot
148
155
  )
149
156
  end
150
157
  end
151
-
152
158
  #
153
159
  # Get the Setup object for the given object's class.
154
160
  #
@@ -1,4 +1,5 @@
1
- %w(filter abstract_field_facet connective boost_query date_field_facet range_facet abstract_fulltext dismax join
1
+ %w(filter abstract_field_facet connective boost_query date_field_facet
2
+ range_facet abstract_fulltext dismax join field_list
2
3
  field_facet highlighting pagination restriction common_query spellcheck
3
4
  standard_query more_like_this more_like_this_query geo geofilt bbox query_facet
4
5
  scope sort sort_composite text_field_boost function_query field_stats
@@ -12,17 +12,22 @@ module Sunspot
12
12
  end
13
13
 
14
14
  @pagination = nil
15
- @parameter_adjustment = nil
15
+ @parameter_adjustments = []
16
16
  end
17
17
 
18
- def solr_parameter_adjustment=(block)
19
- @parameter_adjustment = block
18
+ def add_parameter_adjustment(block)
19
+ @parameter_adjustments << block
20
20
  end
21
21
 
22
22
  def add_sort(sort)
23
23
  @sort << sort
24
24
  end
25
25
 
26
+ def add_field_list(field_list)
27
+ @components << field_list
28
+ field_list
29
+ end
30
+
26
31
  def add_group(group)
27
32
  @components << group
28
33
  group
@@ -76,7 +81,11 @@ module Sunspot
76
81
  @components.each do |component|
77
82
  Sunspot::Util.deep_merge!(params, component.to_params)
78
83
  end
79
- @parameter_adjustment.call(params) if @parameter_adjustment
84
+
85
+ @parameter_adjustments.each do |_block|
86
+ _block.call(params)
87
+ end
88
+
80
89
  params[:q] ||= '*:*'
81
90
  params
82
91
  end
@@ -0,0 +1,15 @@
1
+ module Sunspot
2
+ module Query #:nodoc:
3
+
4
+ # This DSL represents only fields that would come out of the results of the search type.
5
+ class FieldList
6
+ def initialize(list)
7
+ @list = list
8
+ end
9
+
10
+ def to_params
11
+ { :fl => @list }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -257,7 +257,15 @@ module Sunspot
257
257
  end
258
258
 
259
259
  def id
260
- @__calling_context__.__send__(:id)
260
+ begin
261
+ @__calling_context__.__send__(:id)
262
+ rescue ::NoMethodError => e
263
+ begin
264
+ @__receiver__.__send__(:id)
265
+ rescue ::NoMethodError
266
+ raise(e)
267
+ end
268
+ end
261
269
  end
262
270
 
263
271
  # Special case due to `Kernel#sub`'s existence
@@ -1,3 +1,3 @@
1
1
  module Sunspot
2
- VERSION = '2.2.5'
2
+ VERSION = '2.2.6'
3
3
  end
@@ -4,9 +4,20 @@ describe 'query DSL', :type => :query do
4
4
  it 'should allow building search using block argument rather than instance_eval' do
5
5
  @blog_id = 1
6
6
  session.search Post do |query|
7
+ query.field_list [:blog_id, :title]
7
8
  query.with(:blog_id, @blog_id)
8
9
  end
9
10
  connection.should have_last_search_including(:fq, 'blog_id_i:1')
11
+ connection.should have_last_search_with(fl: [:blog_id, :title])
12
+ end
13
+
14
+ it 'should allow field_list specified as arguments' do
15
+ @blog_id = 1
16
+ session.search Post do |query|
17
+ query.field_list :blog_id, :title
18
+ query.with(:blog_id, @blog_id)
19
+ end
20
+ connection.should have_last_search_with(fl: [:blog_id, :title])
10
21
  end
11
22
 
12
23
  it 'should accept a block in the #new_search method' do
@@ -15,4 +26,3 @@ describe 'query DSL', :type => :query do
15
26
  connection.should have_last_search_including(:fq, 'blog_id_i:1')
16
27
  end
17
28
  end
18
-
@@ -132,6 +132,19 @@ describe 'more_like_this' do
132
132
  connection.should have_last_search_with(:some => 'param')
133
133
  end
134
134
 
135
+ it "should send query to solr with adjusted parameters in multiple blocks" do
136
+ session.more_like_this(Post.new) do
137
+ adjust_solr_params do |params|
138
+ params[:q] = 'new search'
139
+ end
140
+ adjust_solr_params do |params|
141
+ params[:some] = 'param'
142
+ end
143
+ end
144
+ connection.should have_last_search_with(:q => 'new search')
145
+ connection.should have_last_search_with(:some => 'param')
146
+ end
147
+
135
148
  private
136
149
 
137
150
  def search(*args, &block)
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.2.5
4
+ version: 2.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Brown
@@ -29,7 +29,7 @@ authors:
29
29
  autorequire:
30
30
  bindir: bin
31
31
  cert_chain: []
32
- date: 2016-03-05 00:00:00.000000000 Z
32
+ date: 2016-09-01 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rsolr
@@ -129,6 +129,7 @@ files:
129
129
  - lib/sunspot/query/date_field_facet.rb
130
130
  - lib/sunspot/query/dismax.rb
131
131
  - lib/sunspot/query/field_facet.rb
132
+ - lib/sunspot/query/field_list.rb
132
133
  - lib/sunspot/query/field_stats.rb
133
134
  - lib/sunspot/query/filter.rb
134
135
  - lib/sunspot/query/function_query.rb