Module: SupplejackApi::Support::Concept::Searchable::ClassMethods

Defined in:
app/models/supplejack_api/support/concept/searchable.rb

Overview

included

Instance Method Summary collapse

Instance Method Details

#build_sunspot_schema(builder) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/supplejack_api/support/concept/searchable.rb', line 47

def build_sunspot_schema(builder)
  ConceptSchema.model_fields.each do |_name, field|
    options = {}
    search_as = field.search_as || []

    value_block = nil
    if field.search_value.present?
      value_block = proc do
        field.search_value.call(self)
      end
    end

    options[:as] = field.solr_name if field.solr_name.present?

    if search_as.include? :filter
      filter_options = {}
      filter_options[:multiple] = true if field.multi_value.present?
      type = SUNSPOT_TYPE_NAMES[field.type]

      builder.public_send(type, field.name, options.merge(filter_options), &value_block)
    end

    if search_as.include? :fulltext
      options[:boost] = field.search_boost if field.search_boost.present?
      builder.text field.name, options, &value_block
    end
  end
end

#custom_find(id, _scope = nil, options = {}) ⇒ Object

Raises:

  • (Mongoid::Errors::DocumentNotFound)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/supplejack_api/support/concept/searchable.rb', line 32

def custom_find(id, _scope = nil, options = {})
  options ||= {}
  class_scope = unscoped

  if id.to_s =~ /^\d+$/
    data = class_scope.where(concept_id: id).first
  elsif id.to_s =~ /^[0-9a-f]{24}$/i
    data = class_scope.find(id)
  end

  raise Mongoid::Errors::DocumentNotFound.new(self, [id], [id]) unless data

  data
end