Module: Queries::Concerns::Depictions

Overview

Helpers and facets for queries that reference Depictions/Images

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.merge_clausesObject



99
100
101
102
103
104
105
106
107
# File 'lib/queries/concerns/depictions.rb', line 99

def self.merge_clauses
  [
    :data_depiction_facet,
    :depictions_facet,
    :image_id_facet,
    :image_query_facet,
    :images_facet
  ]
end

.paramsObject



6
7
8
9
10
11
12
13
14
# File 'lib/queries/concerns/depictions.rb', line 6

def self.params
  [
    :image_id,
    :images,
    :depictions,
    :data_depictions,
    image_id: []
  ]
end

Instance Method Details

#data_depiction_facetObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/queries/concerns/depictions.rb', line 66

def data_depiction_facet
  return nil if data_depictions.nil?
  if data_depictions
    referenced_klass.joins(:depictions).where(depictions: {is_metadata_depiction: true}).distinct
  else
    a = referenced_klass.where.missing(:depictions)
    b = referenced_klass.joins(:depictions).where.not(depictions: {is_metadata_depiction: true})

    referenced_klass_union([a,b]).distinct
  end
end

#depictions_facetObject

!! Duplicate with images



57
58
59
60
61
62
63
64
# File 'lib/queries/concerns/depictions.rb', line 57

def depictions_facet
  return nil if depictions.nil?
  if depictions
    referenced_klass.joins(:depictions).distinct
  else
    referenced_klass.where.missing(:depictions)
  end
end

#image_id_facetObject



51
52
53
54
# File 'lib/queries/concerns/depictions.rb', line 51

def image_id_facet
  return nil if image_id.empty?
  referenced_klass.joins(:depictions).where(depictions: {image_id:})
end

#image_query_facetObject



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/queries/concerns/depictions.rb', line 87

def image_query_facet
  return nil if image_query.nil?
  s = 'WITH query_images AS (' + image_query.all.to_sql + ')'

  s << ' ' + referenced_klass
  .joins(:depictions)
  .joins('JOIN query_images as query_images1 on depictions.image_id = query_images1.id')
  .to_sql

  referenced_klass.from('(' + s + ') as ' + referenced_klass.name.tableize).distinct
end

#images_facetObject



78
79
80
81
82
83
84
85
# File 'lib/queries/concerns/depictions.rb', line 78

def images_facet
  return nil if images.nil?
  if images
    referenced_klass.joins(:depictions).distinct
  else
    referenced_klass.where.missing(:depictions)
  end
end

#set_depiction_params(params) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/queries/concerns/depictions.rb', line 43

def set_depiction_params(params)
  @image_id = params[:image_id]

  @images = boolean_param(params, :images)
  @depictions = boolean_param(params, :depictions)
  @data_depictions = boolean_param(params, :data_depictions)
end