Class: Sunspot::JoinField

Inherits:
Field
  • Object
show all
Defined in:
lib/sunspot/field.rb

Overview

JoinField encapsulates attributes from referenced models. Could be of any type

Instance Attribute Summary collapse

Attributes inherited from Field

#boost, #indexed_name, #name, #reference, #type

Instance Method Summary collapse

Methods inherited from Field

#cast, #hash, #joined?, #more_like_this?, #multiple?, #stored?, #to_indexed

Constructor Details

#initialize(name, type, options = {}) ⇒ JoinField

Returns a new instance of JoinField.



200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/sunspot/field.rb', line 200

def initialize(name, type, options = {})
  @multiple = !!options.delete(:multiple)

  super(name, type, options)

  @prefix = options.delete(:prefix)
  @join = options.delete(:join)
  @clazz = options.delete(:clazz)
  @target = options.delete(:target)
  @default_boost = options.delete(:default_boost)
  @joined = true

  check_options(options)
end

Instance Attribute Details

#default_boostObject (readonly)

:nodoc:



198
199
200
# File 'lib/sunspot/field.rb', line 198

def default_boost
  @default_boost
end

Instance Method Details

#eql?(field) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


233
234
235
# File 'lib/sunspot/field.rb', line 233

def eql?(field)
  super && target == field.target && from == field.from && to == field.to
end

#fromObject



215
216
217
# File 'lib/sunspot/field.rb', line 215

def from
  Sunspot::Setup.for(target).field(@join[:from]).indexed_name
end

#local_params(value) ⇒ Object



223
224
225
226
227
# File 'lib/sunspot/field.rb', line 223

def local_params(value)
  query = ["type:\"#{target.name}\""] | Util.Array(value)

  "{!join from=#{from} to=#{to} v='#{query.join(' AND ')}'}"
end

#targetObject



239
240
241
242
# File 'lib/sunspot/field.rb', line 239

def target
  @target = Util.full_const_get(@target) if @target.is_a?(String)
  @target
end

#toObject



219
220
221
# File 'lib/sunspot/field.rb', line 219

def to
  Sunspot::Setup.for(@clazz).field(@join[:to]).indexed_name
end

#to_solr_conditional(value) ⇒ Object



229
230
231
# File 'lib/sunspot/field.rb', line 229

def to_solr_conditional(value)
  "\"#{value}\""
end