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,
:metadata_depiction,
: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
#anatomical_part_query, #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?, #only_project_or_less?, #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.
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
310
311
312
313
314
315
316
317
|
# File 'lib/queries/image/filter.rb', line 273
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]
@metadata_depiction = boolean_param(params, :metadata_depiction)
@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.
145
146
147
|
# File 'lib/queries/image/filter.rb', line 145
def biocuration_class_id
@biocuration_class_id
end
|
#collection_object_id ⇒ Array
Returns images depicting collecting_object.
68
69
70
|
# File 'lib/queries/image/filter.rb', line 68
def collection_object_id
@collection_object_id
end
|
#collection_object_scope ⇒ Object
77
78
79
|
# File 'lib/queries/image/filter.rb', line 77
def collection_object_scope
@collection_object_scope
end
|
#copyright_after_year ⇒ Number
243
244
245
|
# File 'lib/queries/image/filter.rb', line 243
def copyright_after_year
@copyright_after_year
end
|
#copyright_holder_id ⇒ Array
220
221
222
|
# File 'lib/queries/image/filter.rb', line 220
def copyright_holder_id
@copyright_holder_id
end
|
#copyright_holder_id_all ⇒ Boolean
231
232
233
|
# File 'lib/queries/image/filter.rb', line 231
def copyright_holder_id_all
@copyright_holder_id_all
end
|
#copyright_holder_organization_id ⇒ Array
225
226
227
|
# File 'lib/queries/image/filter.rb', line 225
def copyright_holder_organization_id
@copyright_holder_organization_id
end
|
#copyright_prior_to_year ⇒ Number
248
249
250
|
# File 'lib/queries/image/filter.rb', line 248
def copyright_prior_to_year
@copyright_prior_to_year
end
|
#copyright_year ⇒ Number
253
254
255
|
# File 'lib/queries/image/filter.rb', line 253
def copyright_year
@copyright_year
end
|
#creator_id ⇒ Array
177
178
179
|
# File 'lib/queries/image/filter.rb', line 177
def creator_id
@creator_id
end
|
#creator_id_all ⇒ Boolean
183
184
185
|
# File 'lib/queries/image/filter.rb', line 183
def creator_id_all
@creator_id_all
end
|
#depiction_caption ⇒ String
265
266
267
|
# File 'lib/queries/image/filter.rb', line 265
def depiction_caption
@depiction_caption
end
|
#depiction_caption_exact ⇒ Boolean
270
271
272
|
# File 'lib/queries/image/filter.rb', line 270
def depiction_caption_exact
@depiction_caption_exact
end
|
#depiction_object_type ⇒ Array
Restricts Images to those that depict these classes
108
109
110
|
# File 'lib/queries/image/filter.rb', line 108
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.
83
84
85
|
# File 'lib/queries/image/filter.rb', line 83
def depictions
@depictions
end
|
#editor_id ⇒ Array
188
189
190
|
# File 'lib/queries/image/filter.rb', line 188
def editor_id
@editor_id
end
|
#editor_id_all ⇒ Boolean
194
195
196
|
# File 'lib/queries/image/filter.rb', line 194
def editor_id_all
@editor_id_all
end
|
#field_occurrence_id ⇒ Array
Returns images depicting field_occurrence.
87
88
89
|
# File 'lib/queries/image/filter.rb', line 87
def field_occurrence_id
@field_occurrence_id
end
|
#field_occurrence_scope ⇒ Object
96
97
98
|
# File 'lib/queries/image/filter.rb', line 96
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.
102
103
104
|
# File 'lib/queries/image/filter.rb', line 102
def freeform_svg
@freeform_svg
end
|
#image_id ⇒ Array
141
142
143
|
# File 'lib/queries/image/filter.rb', line 141
def image_id
@image_id
end
|
#license ⇒ Array
199
200
201
|
# File 'lib/queries/image/filter.rb', line 199
def license
@license
end
|
Returns true - image has depiction(s) where is_metadata_depiction is true false - image has depiction(s) where is_metadata_depiction is not true nil - ignored.
259
260
261
|
# File 'lib/queries/image/filter.rb', line 259
def metadata_depiction
@metadata_depiction
end
|
#otu_id ⇒ Array
Returns images depicting otus.
112
113
114
|
# File 'lib/queries/image/filter.rb', line 112
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 !!
138
139
140
|
# File 'lib/queries/image/filter.rb', line 138
def otu_scope
@otu_scope
end
|
#owner_id ⇒ Array
204
205
206
|
# File 'lib/queries/image/filter.rb', line 204
def owner_id
@owner_id
end
|
#owner_id_all ⇒ Boolean
215
216
217
|
# File 'lib/queries/image/filter.rb', line 215
def owner_id_all
@owner_id_all
end
|
#owner_organization_id ⇒ Array
209
210
211
|
# File 'lib/queries/image/filter.rb', line 209
def owner_organization_id
@owner_organization_id
end
|
#sled_image ⇒ Boolean
Returns true - yes false - is not nil - ignored.
154
155
156
|
# File 'lib/queries/image/filter.rb', line 154
def sled_image
@sled_image
end
|
#sled_image_id ⇒ Array
148
149
150
|
# File 'lib/queries/image/filter.rb', line 148
def sled_image_id
@sled_image_id
end
|
#source_id ⇒ Array
238
239
240
|
# File 'lib/queries/image/filter.rb', line 238
def source_id
@source_id
end
|
#sqed_depiction_id ⇒ Array
157
158
159
|
# File 'lib/queries/image/filter.rb', line 157
def sqed_depiction_id
@sqed_depiction_id
end
|
#sqed_image ⇒ Boolean
Returns true - yes false - is not nil - ignored.
163
164
165
|
# File 'lib/queries/image/filter.rb', line 163
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
117
118
119
|
# File 'lib/queries/image/filter.rb', line 117
def taxon_name_id
@taxon_name_id
end
|
#taxon_name_id_target ⇒ Array
Only used when ‘taxon_name_id` provided
168
169
170
|
# File 'lib/queries/image/filter.rb', line 168
def taxon_name_id_target
@taxon_name_id_target
end
|
#type_material_depictions ⇒ Array
Returns depicts some that is a type specimen.
172
173
174
|
# File 'lib/queries/image/filter.rb', line 172
def type_material_depictions
@type_material_depictions
end
|
Instance Method Details
#biocuration_facet ⇒ Object
435
436
437
438
439
440
441
|
# File 'lib/queries/image/filter.rb', line 435
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
797
798
799
800
|
# File 'lib/queries/image/filter.rb', line 797
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
552
553
554
555
556
557
558
|
# File 'lib/queries/image/filter.rb', line 552
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
416
417
418
|
# File 'lib/queries/image/filter.rb', line 416
def collection_object_table
::CollectionObject.arel_table
end
|
#copyright_holder_facet ⇒ Object
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
|
# File 'lib/queries/image/filter.rb', line 651
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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
|
# File 'lib/queries/image/filter.rb', line 683
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
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 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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
|
# File 'lib/queries/image/filter.rb', line 706
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
452
453
454
455
|
# File 'lib/queries/image/filter.rb', line 452
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
431
432
433
|
# File 'lib/queries/image/filter.rb', line 431
def depiction_table
::Depiction.arel_table
end
|
#depictions_facet ⇒ Object
457
458
459
460
461
462
463
464
|
# File 'lib/queries/image/filter.rb', line 457
def depictions_facet
return nil if depictions.nil?
if depictions
::Image.joins(:depictions)
else
::Image.where.missing(:depictions)
end
end
|
#editor_facet ⇒ Object
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
# File 'lib/queries/image/filter.rb', line 615
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
560
561
562
563
564
565
566
|
# File 'lib/queries/image/filter.rb', line 560
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
421
422
423
|
# File 'lib/queries/image/filter.rb', line 421
def field_occurrence_table
::FieldOccurrence.arel_table
end
|
466
467
468
469
470
471
472
473
474
475
476
477
478
|
# File 'lib/queries/image/filter.rb', line 466
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
721
722
723
|
# File 'lib/queries/image/filter.rb', line 721
def images_on(t, t_id)
::Image.joins(t).where(**{t => {id: t_id}})
end
|
#images_on_collecting_events_via(t, t_id) ⇒ Object
733
734
735
736
737
|
# File 'lib/queries/image/filter.rb', line 733
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
725
726
727
728
729
730
731
|
# File 'lib/queries/image/filter.rb', line 725
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
677
678
679
680
681
|
# File 'lib/queries/image/filter.rb', line 677
def license_facet
return nil if license.empty?
::Image.joins(:attribution).where(attribution: { license: }).distinct
end
|
#merge_clauses ⇒ Object
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
|
# File 'lib/queries/image/filter.rb', line 895
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,
metadata_depiction_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
|
443
444
445
446
447
448
449
450
|
# File 'lib/queries/image/filter.rb', line 443
def metadata_depiction_facet
return nil if metadata_depiction.nil?
if metadata_depiction
::Image.joins(:depictions).where(depictions: {is_metadata_depiction: true}).distinct
else
::Image.joins(:depictions).where.not(depictions: {is_metadata_depiction: true}).distinct
end
end
|
#otu_facet_collection_object_observations(otu_ids) ⇒ Object
780
781
782
783
784
|
# File 'lib/queries/image/filter.rb', line 780
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
770
771
772
773
|
# File 'lib/queries/image/filter.rb', line 770
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
775
776
777
778
|
# File 'lib/queries/image/filter.rb', line 775
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
786
787
788
789
|
# File 'lib/queries/image/filter.rb', line 786
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
766
767
768
|
# File 'lib/queries/image/filter.rb', line 766
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
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
|
# File 'lib/queries/image/filter.rb', line 747
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
739
740
741
742
743
744
|
# File 'lib/queries/image/filter.rb', line 739
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
508
509
510
511
512
513
|
# File 'lib/queries/image/filter.rb', line 508
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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
|
# File 'lib/queries/image/filter.rb', line 515
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
411
412
413
|
# File 'lib/queries/image/filter.rb', line 411
def otu_table
::Otu.arel_table
end
|
#owner_facet ⇒ Object
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
|
# File 'lib/queries/image/filter.rb', line 632
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
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
|
# File 'lib/queries/image/filter.rb', line 877
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
|
# File 'lib/queries/image/filter.rb', line 568
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
489
490
491
492
493
494
495
496
|
# File 'lib/queries/image/filter.rb', line 489
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
498
499
500
501
|
# File 'lib/queries/image/filter.rb', line 498
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
671
672
673
674
675
|
# File 'lib/queries/image/filter.rb', line 671
def source_facet
return nil if source_id.empty?
::Image.joins(:citations).where(citations: { source_id: })
end
|
#sqed_depiction_id_facet ⇒ Object
503
504
505
506
|
# File 'lib/queries/image/filter.rb', line 503
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
480
481
482
483
484
485
486
487
|
# File 'lib/queries/image/filter.rb', line 480
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
406
407
408
|
# File 'lib/queries/image/filter.rb', line 406
def taxon_determination_table
::TaxonDetermination.arel_table
end
|
#taxon_name_id_facet ⇒ Object
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
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
|
# File 'lib/queries/image/filter.rb', line 802
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
792
793
794
795
|
# File 'lib/queries/image/filter.rb', line 792
def type_material_depictions_facet
return nil if type_material_depictions.nil?
::Image.joins(collection_objects: [:type_materials])
end
|
#type_materials_table ⇒ Arel::Table
426
427
428
|
# File 'lib/queries/image/filter.rb', line 426
def type_materials_table
::TypeMaterial.arel_table
end
|