Class: Queries::Image::Filter
- Inherits:
-
Query::Filter
show all
- Includes:
- Concerns::Citations, Concerns::Notes, Concerns::Tags
- Defined in:
- lib/queries/image/filter.rb
Constant Summary
collapse
- PARAMS =
[
:biocuration_class_id,
:collection_object_id,
:collection_object_scope,
:copyright_after_year,
:copyright_holder_id,
:copyright_holder_id_all,
:copyright_holder_organization_id,
:copyright_prior_to_year,
:copyright_year,
:creator_id,
:creator_id_all,
:depiction_caption,
:depiction_caption_exact,
:depiction_object_type,
:depictions,
:editor_id,
:editor_id_all,
:field_occurrence_id,
:field_occurrence_scope,
:freeform_svg,
:image_id,
:license,
:owner_id,
:owner_id_all,
:owner_organization_id,
:otu_id,
:otu_scope,
:sled_image,
:sled_image_id,
:source_id,
:sqed_image,
:taxon_name_id,
:taxon_name_id_target,
:type_material_depictions,
biocuration_class_id: [],
collection_object_id: [],
collection_object_scope: [],
copyright_holder_id: [],
copyright_holder_organization_id: [],
creator_id: [],
depiction_object_type: [],
editor_id: [],
field_occurrence_id: [],
field_occurrence_scope: [],
image_id: [],
license: [],
otu_id: [],
otu_scope: [],
owner_id: [],
owner_organization_id: [],
sled_image_id: [],
source_id: [],
taxon_name_id: [],
].freeze
Query::Filter::FILTER_QUERIES, Query::Filter::SUBQUERIES
Instance Attribute Summary collapse
#api, #asserted_distribution_query, #biological_association_query, #biological_associations_graph_query, #collecting_event_query, #collection_object_query, #content_query, #controlled_vocabulary_term_query, #conveyance_query, #data_attribute_query, #depiction_query, #descriptor_query, #document_query, #dwc_occurrence_query, #extract_query, #field_occurrence_query, #image_query, #loan_query, #object_global_id, #observation_query, #order_by, #otu_query, #page, #paginate, #params, #per, #person_query, #project_id, #recent, #recent_target, #roll_call, #sound_query, #taxon_name_query, #taxon_name_relationship_query, #venn, #venn_ignore_pagination, #venn_mode
Attributes inherited from Query
#query_string, #terms
Instance Method Summary
collapse
#all, #all_and_clauses, #all_merge_clauses, #and_clauses, #annotator_and_clauses, #annotator_merge_clauses, annotator_params, api_except_params, api_excluded_params, #apply_venn, #attribute_exact_facet, base_filter, base_query_name, base_query_to_h, #deep_permit, #disable_paging, included_annotator_facets, instantiated_base_filter, inverted_subqueries, #model_id_facet, #object_global_id_facet, #only_project?, #paging_state, params, #permitted_params, #process_url_into_params, #project_id_facet, query_name, #set_nested_queries, #set_paging, set_paging, #shared_and_clauses, #subquery_vector, #target_and_clauses, #venn_query
Methods inherited from Query
#alphabetic_strings, #alphanumeric_strings, base_name, #base_name, #base_query, #build_terms, #cached_facet, #end_wildcard, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #no_terms?, referenced_klass, #referenced_klass, #referenced_klass_except, #referenced_klass_intersection, #referenced_klass_union, #start_and_end_wildcard, #start_wildcard, #table, #wildcard_pieces
Constructor Details
#initialize(query_params) ⇒ Filter
Returns a new instance of Filter.
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
# File 'lib/queries/image/filter.rb', line 266
def initialize(query_params)
super
@biocuration_class_id = params[:biocuration_class_id]
@collection_object_id = params[:collection_object_id]
@collection_object_scope = params[:collection_object_scope]
@copyright_after_year = params[:copyright_after_year]
@copyright_holder_id = params[:copyright_holder_id]
@copyright_holder_id_all = boolean_param(params, :copyright_holder_id_all)
@copyright_holder_organization_id =
params[:copyright_holder_organization_id]
@copyright_prior_to_year = params[:copyright_prior_to_year]
@copyright_year = params[:copyright_year]
@creator_id = params[:creator_id]
@creator_id_all = boolean_param(params, :creator_id_all)
@depiction_caption = params[:depiction_caption]
@depiction_caption_exact = boolean_param(params, :depiction_caption_exact)
@depiction_object_type = params[:depiction_object_type]
@depictions = boolean_param(params, :depictions)
@editor_id = params[:editor_id]
@editor_id_all = boolean_param(params, :editor_id_all)
@field_occurrence_id = params[:field_occurrence_id]
@field_occurrence_scope = params[:field_occurrence_scope]
@freeform_svg = boolean_param(params, :freeform_svg)
@image_id = params[:image_id]
@license = params[:license]
@otu_id = params[:otu_id]
@otu_scope = params[:otu_scope]
@owner_id = params[:owner_id]
@owner_id_all = boolean_param(params, :owner_id_all)
@owner_organization_id = params[:owner_organization_id]
@sled_image = boolean_param(params, :sled_image)
@sled_image_id = params[:sled_image_id]
@source_id = params[:source_id]
@sqed_depiction_id = params[:sqed_depiction_id]
@sqed_image = boolean_param(params, :sqed_image)
@taxon_name_id = params[:taxon_name_id]
@taxon_name_id_target = params[:taxon_name_id_target]
@type_material_depictions = boolean_param(params, :type_material_depictions)
set_citations_params(params)
set_notes_params(params)
set_tags_params(params)
end
|
Instance Attribute Details
#biocuration_class_id ⇒ Array
Returns of biocuration_class ids.
144
145
146
|
# File 'lib/queries/image/filter.rb', line 144
def biocuration_class_id
@biocuration_class_id
end
|
#collection_object_id ⇒ Array
Returns images depicting collecting_object.
67
68
69
|
# File 'lib/queries/image/filter.rb', line 67
def collection_object_id
@collection_object_id
end
|
#collection_object_scope ⇒ Object
76
77
78
|
# File 'lib/queries/image/filter.rb', line 76
def collection_object_scope
@collection_object_scope
end
|
#copyright_after_year ⇒ Number
242
243
244
|
# File 'lib/queries/image/filter.rb', line 242
def copyright_after_year
@copyright_after_year
end
|
#copyright_holder_id ⇒ Array
219
220
221
|
# File 'lib/queries/image/filter.rb', line 219
def copyright_holder_id
@copyright_holder_id
end
|
#copyright_holder_id_all ⇒ Boolean
230
231
232
|
# File 'lib/queries/image/filter.rb', line 230
def copyright_holder_id_all
@copyright_holder_id_all
end
|
#copyright_holder_organization_id ⇒ Array
224
225
226
|
# File 'lib/queries/image/filter.rb', line 224
def copyright_holder_organization_id
@copyright_holder_organization_id
end
|
#copyright_prior_to_year ⇒ Number
247
248
249
|
# File 'lib/queries/image/filter.rb', line 247
def copyright_prior_to_year
@copyright_prior_to_year
end
|
#copyright_year ⇒ Number
252
253
254
|
# File 'lib/queries/image/filter.rb', line 252
def copyright_year
@copyright_year
end
|
#creator_id ⇒ Array
176
177
178
|
# File 'lib/queries/image/filter.rb', line 176
def creator_id
@creator_id
end
|
#creator_id_all ⇒ Boolean
182
183
184
|
# File 'lib/queries/image/filter.rb', line 182
def creator_id_all
@creator_id_all
end
|
#depiction_caption ⇒ String
258
259
260
|
# File 'lib/queries/image/filter.rb', line 258
def depiction_caption
@depiction_caption
end
|
#depiction_caption_exact ⇒ Boolean
263
264
265
|
# File 'lib/queries/image/filter.rb', line 263
def depiction_caption_exact
@depiction_caption_exact
end
|
#depiction_object_type ⇒ Array
Restricts Images to those that depict these classes
107
108
109
|
# File 'lib/queries/image/filter.rb', line 107
def depiction_object_type
@depiction_object_type
end
|
#depictions ⇒ Boolean?
Returns true - image is used (in a depiction) false - image is not used nil - either.
82
83
84
|
# File 'lib/queries/image/filter.rb', line 82
def depictions
@depictions
end
|
#editor_id ⇒ Array
187
188
189
|
# File 'lib/queries/image/filter.rb', line 187
def editor_id
@editor_id
end
|
#editor_id_all ⇒ Boolean
193
194
195
|
# File 'lib/queries/image/filter.rb', line 193
def editor_id_all
@editor_id_all
end
|
#field_occurrence_id ⇒ Array
Returns images depicting field_occurrence.
86
87
88
|
# File 'lib/queries/image/filter.rb', line 86
def field_occurrence_id
@field_occurrence_id
end
|
#field_occurrence_scope ⇒ Object
95
96
97
|
# File 'lib/queries/image/filter.rb', line 95
def field_occurrence_scope
@field_occurrence_scope
end
|
Returns true - image is used (in a depiction) that has svg false - is not a true image nil - ignored.
101
102
103
|
# File 'lib/queries/image/filter.rb', line 101
def freeform_svg
@freeform_svg
end
|
#image_id ⇒ Array
140
141
142
|
# File 'lib/queries/image/filter.rb', line 140
def image_id
@image_id
end
|
#license ⇒ Array
198
199
200
|
# File 'lib/queries/image/filter.rb', line 198
def license
@license
end
|
#otu_id ⇒ Array
Returns images depicting otus.
111
112
113
|
# File 'lib/queries/image/filter.rb', line 111
def otu_id
@otu_id
end
|
#otu_scope ⇒ Array
A sub scope of sorts. Purpose is to gather all images possible under an OTU that are of an OTU, CollectionObject or Observation.
!! Must be used with an otu_id !!
137
138
139
|
# File 'lib/queries/image/filter.rb', line 137
def otu_scope
@otu_scope
end
|
#owner_id ⇒ Array
203
204
205
|
# File 'lib/queries/image/filter.rb', line 203
def owner_id
@owner_id
end
|
#owner_id_all ⇒ Boolean
214
215
216
|
# File 'lib/queries/image/filter.rb', line 214
def owner_id_all
@owner_id_all
end
|
#owner_organization_id ⇒ Array
208
209
210
|
# File 'lib/queries/image/filter.rb', line 208
def owner_organization_id
@owner_organization_id
end
|
#sled_image ⇒ Boolean
Returns true - yes false - is not nil - ignored.
153
154
155
|
# File 'lib/queries/image/filter.rb', line 153
def sled_image
@sled_image
end
|
#sled_image_id ⇒ Array
147
148
149
|
# File 'lib/queries/image/filter.rb', line 147
def sled_image_id
@sled_image_id
end
|
#source_id ⇒ Array
237
238
239
|
# File 'lib/queries/image/filter.rb', line 237
def source_id
@source_id
end
|
#sqed_depiction_id ⇒ Array
156
157
158
|
# File 'lib/queries/image/filter.rb', line 156
def sqed_depiction_id
@sqed_depiction_id
end
|
#sqed_image ⇒ Boolean
Returns true - yes false - is not nil - ignored.
162
163
164
|
# File 'lib/queries/image/filter.rb', line 162
def sqed_image
@sqed_image
end
|
#taxon_name_id ⇒ Protonym.id?
Return all images depicting an Otu that is self or descendant linked to this TaxonName
116
117
118
|
# File 'lib/queries/image/filter.rb', line 116
def taxon_name_id
@taxon_name_id
end
|
#taxon_name_id_target ⇒ Array
Only used when ‘taxon_name_id` provided
167
168
169
|
# File 'lib/queries/image/filter.rb', line 167
def taxon_name_id_target
@taxon_name_id_target
end
|
#type_material_depictions ⇒ Array
Returns depicts some that is a type specimen.
171
172
173
|
# File 'lib/queries/image/filter.rb', line 171
def type_material_depictions
@type_material_depictions
end
|
Instance Method Details
#biocuration_facet ⇒ Object
427
428
429
430
431
432
433
|
# File 'lib/queries/image/filter.rb', line 427
def biocuration_facet
return nil if biocuration_class_id.empty?
::Image.joins(collection_objects: [:depictions]).merge(
::CollectionObject::BiologicalCollectionObject.joins(:biocuration_classifications)
.where(biocuration_classifications: {biocuration_class_id:})
)
end
|
#build_depiction_facet(kind, ids) ⇒ Object
780
781
782
783
|
# File 'lib/queries/image/filter.rb', line 780
def build_depiction_facet(kind, ids)
return nil if ids.empty?
::Image.joins(:depictions).where(depictions: {depiction_object_id: ids, depiction_object_type: kind})
end
|
#collection_object_scope_facet ⇒ Object
535
536
537
538
539
540
541
|
# File 'lib/queries/image/filter.rb', line 535
def collection_object_scope_facet
return nil if collection_object_id.empty?
scope_facet_for(
:collection_objects, collection_object_id, collection_object_scope
)
end
|
#collection_object_table ⇒ Arel::Table
408
409
410
|
# File 'lib/queries/image/filter.rb', line 408
def collection_object_table
::CollectionObject.arel_table
end
|
#copyright_holder_facet ⇒ Object
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
|
# File 'lib/queries/image/filter.rb', line 634
def copyright_holder_facet
return nil if copyright_holder_id.empty? &&
copyright_holder_organization_id.empty?
q = ::Image
.joins(attribution: :roles)
.where(roles: {type: 'AttributionCopyrightHolder'})
.where('roles.person_id IN (?) OR roles.organization_id IN (?)',
copyright_holder_id, copyright_holder_organization_id
)
if copyright_holder_id_all
q
.group(:id)
.having("count(images.id) = #{copyright_holder_id.length + copyright_holder_organization_id.length}")
else
q.distinct
end
end
|
#copyright_year_facet ⇒ Object
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
|
# File 'lib/queries/image/filter.rb', line 666
def copyright_year_facet
return nil if copyright_year.nil? && copyright_after_year.nil? &&
copyright_prior_to_year.nil?
if copyright_year
a = ::Image.joins(:attribution).where(attribution: { copyright_year: })
return a
end
t = ::Attribution.arel_table
if copyright_after_year && copyright_prior_to_year.nil?
y = t[:copyright_year].gt(copyright_after_year)
elsif copyright_after_year.nil? && copyright_prior_to_year
y = t[:copyright_year].lt(copyright_prior_to_year)
else
y = t[:copyright_year].gt(copyright_after_year).and(
t[:copyright_year].lt(copyright_prior_to_year)
)
end
::Image.joins(:attribution).where(y)
end
|
#creator_facet ⇒ Object
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
|
# File 'lib/queries/image/filter.rb', line 581
def creator_facet
return nil if creator_id.empty?
q = ::Image
.joins(attribution: :roles)
.where(roles: {type: 'AttributionCreator'})
.where(roles: {person_id: creator_id})
if creator_id_all
q
.group(:id)
.having("count(images.id) = #{creator_id.length}")
else
q.distinct
end
end
|
#depiction_caption_facet ⇒ Object
689
690
691
692
693
694
695
696
697
698
699
700
701
702
|
# File 'lib/queries/image/filter.rb', line 689
def depiction_caption_facet
return nil if depiction_caption.nil?
if depiction_caption_exact
::Image
.joins(:depictions)
.where('depictions.caption = ?', depiction_caption)
else
caption = "%#{depiction_caption.strip.gsub(/\s+/, '%')}%"
::Image
.joins(:depictions)
.where('depictions.caption ILIKE ?', caption)
end
end
|
#depiction_object_type_facet ⇒ Object
435
436
437
438
|
# File 'lib/queries/image/filter.rb', line 435
def depiction_object_type_facet
return nil if depiction_object_type.empty?
::Image.joins(:depictions).where(depictions: {depiction_object_type:})
end
|
#depiction_table ⇒ Arel::Table
423
424
425
|
# File 'lib/queries/image/filter.rb', line 423
def depiction_table
::Depiction.arel_table
end
|
#depictions_facet ⇒ Object
440
441
442
443
444
445
446
447
|
# File 'lib/queries/image/filter.rb', line 440
def depictions_facet
return nil if depictions.nil?
if depictions
::Image.joins(:depictions)
else
::Image.where.missing(:depictions)
end
end
|
#editor_facet ⇒ Object
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
|
# File 'lib/queries/image/filter.rb', line 598
def editor_facet
return nil if editor_id.empty?
q = ::Image
.joins(attribution: :roles)
.where(roles: {type: 'AttributionEditor'})
.where(roles: {person_id: editor_id})
if editor_id_all
q
.group(:id)
.having("count(images.id) = #{editor_id.length}")
else
q.distinct
end
end
|
#field_occurrence_scope_facet ⇒ Object
543
544
545
546
547
548
549
|
# File 'lib/queries/image/filter.rb', line 543
def field_occurrence_scope_facet
return nil if field_occurrence_id.empty?
scope_facet_for(
:field_occurrences, field_occurrence_id, field_occurrence_scope
)
end
|
#field_occurrence_table ⇒ Arel::Table
413
414
415
|
# File 'lib/queries/image/filter.rb', line 413
def field_occurrence_table
::FieldOccurrence.arel_table
end
|
449
450
451
452
453
454
455
456
457
458
459
460
461
|
# File 'lib/queries/image/filter.rb', line 449
def freeform_svg_facet
return nil if freeform_svg.nil?
q = ::Image.left_joins(depictions: [:sled_image, :sqed_depiction])
.where.missing(:sled_image)
.where.not(depictions: {svg_clip: nil}).distinct
if freeform_svg
q
else
::Queries.except(::Image.where(project_id:), q)
end
end
|
#images_on(t, t_id) ⇒ Object
704
705
706
|
# File 'lib/queries/image/filter.rb', line 704
def images_on(t, t_id)
::Image.joins(t).where(**{t => {id: t_id}})
end
|
#images_on_collecting_events_via(t, t_id) ⇒ Object
716
717
718
719
720
|
# File 'lib/queries/image/filter.rb', line 716
def images_on_collecting_events_via(t, t_id)
::Image
.joins(collecting_events: t)
.where("#{t}.id IN (?)", t_id)
end
|
#images_on_observations_linked_to(t, t_id) ⇒ Object
708
709
710
711
712
713
714
|
# File 'lib/queries/image/filter.rb', line 708
def images_on_observations_linked_to(t, t_id)
::Image.joins(:observations)
.where(observations: {
observation_object_type: t.to_s.classify,
observation_object_id: t_id
})
end
|
#license_facet ⇒ Object
660
661
662
663
664
|
# File 'lib/queries/image/filter.rb', line 660
def license_facet
return nil if license.empty?
::Image.joins(:attribution).where(attribution: { license: }).distinct
end
|
#merge_clauses ⇒ Object
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
|
# File 'lib/queries/image/filter.rb', line 878
def merge_clauses
s = ::Queries::Query::Filter::SUBQUERIES.select{|k,v| v.include?(:image)}.keys.map(&:to_s) - ['source']
[
*s.collect{|m| query_facets_facet(m)}, biocuration_facet,
collection_object_scope_facet,
copyright_holder_facet,
copyright_year_facet,
creator_facet,
editor_facet,
depiction_caption_facet,
depiction_object_type_facet,
depictions_facet,
field_occurrence_scope_facet,
freeform_svg_facet,
license_facet,
otu_id_facet,
otu_scope_facet,
owner_facet,
sled_image_facet,
sled_image_id_facet,
source_facet,
sqed_image_facet,
sqed_depiction_id_facet,
sqed_image_facet,
taxon_name_id_facet,
type_material_depictions_facet,
]
end
|
#otu_facet_collection_object_observations(otu_ids) ⇒ Object
763
764
765
766
767
|
# File 'lib/queries/image/filter.rb', line 763
def otu_facet_collection_object_observations(otu_ids)
::Image.joins(:observations)
.joins("INNER JOIN taxon_determinations on taxon_determinations.taxon_determination_object_id = observations.observation_object_id AND taxon_determinations.taxon_determination_object_type = 'CollectionObject'")
.where(taxon_determinations: {otu_id: otu_ids}, observations: {observation_object_type: 'CollectionObject'})
end
|
#otu_facet_collection_objects(otu_ids) ⇒ Object
753
754
755
756
|
# File 'lib/queries/image/filter.rb', line 753
def otu_facet_collection_objects(otu_ids)
::Image.joins(collection_objects: [:taxon_determinations])
.where(taxon_determinations: {otu_id: otu_ids})
end
|
#otu_facet_field_occurrences(otu_ids) ⇒ Object
758
759
760
761
|
# File 'lib/queries/image/filter.rb', line 758
def otu_facet_field_occurrences(otu_ids)
::Image.joins(field_occurrences: [:taxon_determinations])
.where(taxon_determinations: {otu_id: otu_ids})
end
|
#otu_facet_otu_observations(otu_ids) ⇒ Object
769
770
771
772
|
# File 'lib/queries/image/filter.rb', line 769
def otu_facet_otu_observations(otu_ids)
::Image.joins(:observations)
.where(observations: {observation_object_id: otu_ids, observation_object_type: 'Otu'})
end
|
#otu_facet_otus(otu_ids) ⇒ Object
749
750
751
|
# File 'lib/queries/image/filter.rb', line 749
def otu_facet_otus(otu_ids)
::Image.joins(:depictions).where(depictions: {depiction_object_type: 'Otu', depiction_object_id: otu_ids})
end
|
#otu_facet_type_material(otu_ids) ⇒ Object
Find all TaxonNames, and their synonyms
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
|
# File 'lib/queries/image/filter.rb', line 730
def otu_facet_type_material(otu_ids)
protonyms = if otu_ids.any?
::Queries::TaxonName::Filter.new(
otu_query: { otu_id: otu_ids},
synonymify: true,
project_id:
).all.where(type: 'Protonym')
else
TaxonName.none
end
::Image.joins(collection_objects: [type_materials: [:protonym]]).where(collection_objects: {type_materials: {protonym: protonyms}})
end
|
#otu_facet_type_material_observations(otu_ids) ⇒ Object
722
723
724
725
726
727
|
# File 'lib/queries/image/filter.rb', line 722
def otu_facet_type_material_observations(otu_ids)
::Image.joins(:observations)
.joins("INNER JOIN type_materials on type_materials.collection_object_id = observations.observation_object_id AND observations.observation_object_type = 'CollectionObject'")
.joins('INNER JOIN otus on otus.taxon_name_id = type_materials.protonym_id')
.where(otus: {id: otu_ids})
end
|
#otu_id_facet ⇒ Object
491
492
493
494
495
496
|
# File 'lib/queries/image/filter.rb', line 491
def otu_id_facet
return nil if otu_id.empty? || !otu_scope.empty?
::Image.joins(:otus).where(otus: {id: otu_id})
end
|
#otu_scope_facet ⇒ Object
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
|
# File 'lib/queries/image/filter.rb', line 498
def otu_scope_facet
return nil if otu_id.empty? || otu_scope.empty?
otu_ids = otu_id
otu_ids += ::Otu.coordinate_otu_ids(otu_id) if otu_scope.include?(:coordinate_otus)
otu_ids.uniq!
selected = []
if otu_scope.include?(:all) selected = [
:otu_facet_otus,
:otu_facet_collection_objects,
:otu_facet_field_occurrences,
:otu_facet_otu_observations,
:otu_facet_collection_object_observations,
:otu_facet_type_material,
:otu_facet_type_material_observations
]
elsif otu_scope.empty?
selected = [:otu_facet_otus]
else
selected.push :otu_facet_otus if otu_scope.include?(:otus)
selected.push :otu_facet_collection_objects if otu_scope.include?(:collection_objects)
selected.push :otu_facet_collection_object_observations if otu_scope.include?(:collection_object_observations)
selected.push :otu_facet_field_occurrences if otu_scope.include?(:field_occurrences)
selected.push :otu_facet_otu_observations if otu_scope.include?(:otu_observations)
selected.push :otu_facet_type_material if otu_scope.include?(:type_material)
selected.push :otu_facet_type_material_observations if otu_scope.include?(:type_material_observations)
end
q = selected.collect{|a| '(' + send(a, otu_ids).to_sql + ')'}.join(' UNION ')
d = ::Image.from('(' + q + ')' + ' as images')
d
end
|
#otu_table ⇒ Arel::Table
403
404
405
|
# File 'lib/queries/image/filter.rb', line 403
def otu_table
::Otu.arel_table
end
|
#owner_facet ⇒ Object
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
|
# File 'lib/queries/image/filter.rb', line 615
def owner_facet
return nil if owner_id.empty? && owner_organization_id.empty?
q = ::Image
.joins(attribution: :roles)
.where(roles: {type: 'AttributionOwner'})
.where('roles.person_id IN (?) OR roles.organization_id IN (?)',
owner_id, owner_organization_id
)
if owner_id_all
q
.group(:id)
.having("count(images.id) = #{owner_id.length + owner_organization_id.length}")
else
q.distinct
end
end
|
#query_facets_facet(name = nil) ⇒ Object
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
|
# File 'lib/queries/image/filter.rb', line 860
def query_facets_facet(name = nil)
return nil if name.nil?
q = send((name + '_query').to_sym)
return nil if q.nil?
n = "query_#{name}_img"
s = "WITH #{n} AS (" + q.all.to_sql + ') ' +
::Image
.joins(:depictions)
.joins("JOIN #{n} as #{n}1 on depictions.depiction_object_id = #{n}1.id AND depictions.depiction_object_type = '#{name.treetop_camelize}'")
.to_sql
::Image.from('(' + s + ') as images').distinct
end
|
#scope_facet_for(t, t_id, t_scope) ⇒ Object
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
|
# File 'lib/queries/image/filter.rb', line 551
def scope_facet_for(t, t_id, t_scope)
selected = []
if t_scope.include?(:all) selected = [
images_on(t, t_id).to_sql,
images_on_observations_linked_to(t, t_id).to_sql,
images_on_collecting_events_via_observed(t, t_id).to_sql
]
elsif t_scope.empty?
selected =
[images_on(t, t_id).to_sql]
else
selected.push(
images_on(t, t_id).to_sql
) if t_scope.include?(t)
selected.push(
images_on_observations_linked_to(t, t_id).to_sql
) if t_scope.include?(:observations)
selected.push(
images_on_collecting_events_via(t, t_id).to_sql
) if t_scope.include?(:collecting_events)
end
q = selected.map{ |q| '(' + q + ')' }.join(' UNION ')
::Image.from('(' + q + ')' + ' as images')
end
|
#sled_image_facet ⇒ Object
472
473
474
475
476
477
478
479
|
# File 'lib/queries/image/filter.rb', line 472
def sled_image_facet
return nil if sled_image.nil?
if sled_image
::Image.joins(:sled_image).distinct
else
::Image.where.missing(:sled_image).distinct
end
end
|
#sled_image_id_facet ⇒ Object
481
482
483
484
|
# File 'lib/queries/image/filter.rb', line 481
def sled_image_id_facet
return nil if sled_image_id.empty?
::Image.joins(:sled_image).where(sled_images: {id: sled_image_id})
end
|
#source_facet ⇒ Object
654
655
656
657
658
|
# File 'lib/queries/image/filter.rb', line 654
def source_facet
return nil if source_id.empty?
::Image.joins(:citations).where(citations: { source_id: })
end
|
#sqed_depiction_id_facet ⇒ Object
486
487
488
489
|
# File 'lib/queries/image/filter.rb', line 486
def sqed_depiction_id_facet
return nil if sqed_depiction_id.empty?
::Image.joins(depictions: [:sqed_depiction]).where(sqed_depictions: {id: sqed_depiction_id})
end
|
#sqed_image_facet ⇒ Object
463
464
465
466
467
468
469
470
|
# File 'lib/queries/image/filter.rb', line 463
def sqed_image_facet
return nil if sqed_image.nil?
if sqed_image
::Image.joins(depictions: [:sqed_depiction]).distinct
else
::Image.left_joins(depictions: [:sqed_depiction]).where(sqed_depiction: {id: nil}).distinct
end
end
|
#taxon_determination_table ⇒ Arel::Table
398
399
400
|
# File 'lib/queries/image/filter.rb', line 398
def taxon_determination_table
::TaxonDetermination.arel_table
end
|
#taxon_name_id_facet ⇒ Object
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
|
# File 'lib/queries/image/filter.rb', line 785
def taxon_name_id_facet
return nil if taxon_name_id.empty?
h = Arel::Table.new(:taxon_name_hierarchies)
t = ::TaxonName.arel_table
j1, j2, j3, q1, q2, q3 = nil, nil, nil, nil, nil, nil
if taxon_name_id_target.include?('Otu')
a = otu_table.alias('oj1')
b = t.alias('tj1')
h_alias = h.alias('th1')
j1 = table
.join(depiction_table, Arel::Nodes::InnerJoin).on(table[:id].eq(depiction_table[:image_id]))
.join(a, Arel::Nodes::InnerJoin).on( depiction_table[:depiction_object_id].eq(a[:id]).and( depiction_table[:depiction_object_type].eq('Otu') ))
.join(b, Arel::Nodes::InnerJoin).on( a[:taxon_name_id].eq(b[:id]))
.join(h_alias, Arel::Nodes::InnerJoin).on(b[:id].eq(h_alias[:descendant_id]))
z = h_alias[:ancestor_id].in(taxon_name_id)
q1 = ::Image.joins(j1.join_sources).where(z)
end
if taxon_name_id_target.include?('CollectionObject')
a = otu_table.alias('oj2')
b = t.alias('tj2')
h_alias = h.alias('th2')
j2 = table
.join(depiction_table, Arel::Nodes::InnerJoin).on(table[:id].eq(depiction_table[:image_id]))
.join(collection_object_table, Arel::Nodes::InnerJoin).on( depiction_table[:depiction_object_id].eq(collection_object_table[:id]).and( depiction_table[:depiction_object_type].eq('CollectionObject') ))
.join(taxon_determination_table, Arel::Nodes::InnerJoin).on(
collection_object_table[:id].eq(taxon_determination_table[:taxon_determination_object_id])
.and(taxon_determination_table[:taxon_determination_object_type].eq('CollectionObject'))
)
.join(a, Arel::Nodes::InnerJoin).on( taxon_determination_table[:otu_id].eq(a[:id]) )
.join(b, Arel::Nodes::InnerJoin).on( a[:taxon_name_id].eq(b[:id]))
.join(h_alias, Arel::Nodes::InnerJoin).on(b[:id].eq(h_alias[:descendant_id]))
z = h_alias[:ancestor_id].in(taxon_name_id)
q2 = ::Image.joins(j2.join_sources).where(z)
end
if taxon_name_id_target.include?('FieldOccurrence')
a = otu_table.alias('oj3')
b = t.alias('tj3')
h_alias = h.alias('th3')
j3 = table
.join(depiction_table, Arel::Nodes::InnerJoin).on(table[:id].eq(depiction_table[:image_id]))
.join(field_occurrence_table, Arel::Nodes::InnerJoin).on( depiction_table[:depiction_object_id].eq(field_occurrence_table[:id]).and( depiction_table[:depiction_object_type].eq('FieldOccurrence') ))
.join(taxon_determination_table, Arel::Nodes::InnerJoin).on(
field_occurrence_table[:id].eq(taxon_determination_table[:taxon_determination_object_id])
.and(taxon_determination_table[:taxon_determination_object_type].eq('FieldOccurrence'))
)
.join(a, Arel::Nodes::InnerJoin).on( taxon_determination_table[:otu_id].eq(a[:id]) )
.join(b, Arel::Nodes::InnerJoin).on( a[:taxon_name_id].eq(b[:id]))
.join(h_alias, Arel::Nodes::InnerJoin).on(b[:id].eq(h_alias[:descendant_id]))
z = h_alias[:ancestor_id].in(taxon_name_id)
q3 = ::Image.joins(j3.join_sources).where(z)
end
if q1 && q2 && q3
::Image.from("((#{q1.to_sql}) UNION (#{q2.to_sql}) UNION (#{q3.to_sql})) AS images")
elsif q1
q1.distinct
elsif q2
q2.distinct
else
q3.distinct
end
end
|
#type_material_depictions_facet ⇒ Scope
775
776
777
778
|
# File 'lib/queries/image/filter.rb', line 775
def type_material_depictions_facet
return nil if type_material_depictions.nil?
::Image.joins(collection_objects: [:type_materials])
end
|
#type_materials_table ⇒ Arel::Table
418
419
420
|
# File 'lib/queries/image/filter.rb', line 418
def type_materials_table
::TypeMaterial.arel_table
end
|