Class: Queries::CollectionObject::Filter

Inherits:
Query
  • Object
show all
Includes:
Queries::Concerns::Identifiers, Queries::Concerns::Tags, Queries::Concerns::Users, Helpers
Defined in:
lib/queries/collection_object/filter.rb

Overview

TODO

  • use date processing? / DateConcern

  • syncronize with GIS/GEO

Instance Attribute Summary collapse

Attributes inherited from Query

#dynamic_limit, #options, #project_id, #query_string, #terms

Instance Method Summary collapse

Methods included from Helpers

#boolean_param

Methods inherited from Query

#alphabetic_strings, #attribute_exact_facet, #autocomplete, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_common_name_exact, #autocomplete_common_name_like, #autocomplete_exact_id, #autocomplete_exactly_named, #autocomplete_named, #autocomplete_ordered_wildcard_pieces_in_cached, #build_terms, #cached, #combine_or_clauses, #common_name_name, #common_name_table, #common_name_wild_pieces, #end_wildcard, #exactly_named, #fragments, #integers, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #no_terms?, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #start_and_end_wildcard, #start_wildcard, #wildcard_pieces, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #year_letter, #years

Constructor Details

#initialize(params) ⇒ Filter

Returns a new instance of Filter.

Parameters:

  • args (Hash)

    are permitted params



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/queries/collection_object/filter.rb', line 185

def initialize(params)
  params.reject!{ |_k, v| v.blank? } # dump all entries with empty values

  # Only CollectingEvent fields are permitted now.
  # (Perhaps) TODO: allow concern attributes nested inside as well, e.g. show me all COs with this Tag on CE.
  collecting_event_params = ::Queries::CollectingEvent::Filter::ATTRIBUTES + ::Queries::CollectingEvent::Filter::PARAMS

  @collecting_event_query = ::Queries::CollectingEvent::Filter.new(
    params.select{|a,b| collecting_event_params.include?(a.to_s) }
  )

  @ancestor_id = params[:ancestor_id].blank? ? nil : params[:ancestor_id]
  @biocuration_class_ids = params[:biocuration_class_ids] || []
  @biological_relationship_ids = params[:biological_relationship_ids] || []
  @buffered_collecting_event = params[:buffered_collecting_event]
  @buffered_determinations = params[:buffered_determinations]
  @buffered_other_labels = params[:buffered_other_labels]
  @collecting_event = boolean_param(params, :collecting_event)
  @collecting_event_ids = params[:collecting_event_ids] || []
  @collection_object_type = params[:collection_object_type].blank? ? nil : params[:collection_object_type]
  @current_determinations = boolean_param(params, :current_determinations)
  @depictions = boolean_param(params, :depictions)
  @determiner_id = params[:determiner_id]
  @determiner_id_or = boolean_param(params, :determiner_id_or)
  @dwc_indexed = boolean_param(params, :dwc_indexed)
  @exact_buffered_collecting_event = boolean_param(params, :exact_buffered_collecting_event)
  @exact_buffered_determinations = boolean_param(params, :exact_buffered_determinations)
  @exact_buffered_other_labels = boolean_param(params, :exact_buffered_other_labels)
  @geographic_area = boolean_param(params, :geographic_area)
  @georeferences = boolean_param(params, :georeferences)
  @is_type = params[:is_type] || []
  @loaned = boolean_param(params, :loaned)
  @never_loaned = boolean_param(params, :never_loaned)
  @object_global_id = params[:object_global_id]
  @on_loan =  boolean_param(params, :on_loan)
  @otu_descendants = boolean_param(params, :otu_descendants)
  @otu_ids = params[:otu_ids] || []
  @preparation_type_id = params[:preparation_type_id]
  @recent = boolean_param(params, :recent)
  @repository = boolean_param(params, :repository)
  @repository_id = params[:repository_id].blank? ? nil : params[:repository_id]
  @sled_image_id = params[:sled_image_id].blank? ? nil : params[:sled_image_id]
  @taxon_determinations = boolean_param(params, :taxon_determinations)
  @type_material = boolean_param(params, :type_material)
  @type_specimen_taxon_name_id = params[:type_specimen_taxon_name_id].blank? ? nil : params[:type_specimen_taxon_name_id]
  @validity = boolean_param(params, :validity)
  @with_buffered_collecting_event = boolean_param(params, :with_buffered_collecting_event)
  @with_buffered_determinations =  boolean_param(params, :with_buffered_determinations)
  @with_buffered_other_labels = boolean_param(params, :with_buffered_other_labels)

  set_identifier(params)
  set_tags_params(params)
  set_user_dates(params)
end

Instance Attribute Details

#ancestor_idProtonym.id?

Return all collection objects determined as an Otu that is self or descendant linked to this TaxonName

Returns:

  • (Protonym.id, nil)

    return all collection objects determined as an Otu that is self or descendant linked to this TaxonName



37
38
39
# File 'lib/queries/collection_object/filter.rb', line 37

def ancestor_id
  @ancestor_id
end

#biocuration_class_idsArray

Returns of biocuration_class ids.

Returns:

  • (Array)

    of biocuration_class ids



62
63
64
# File 'lib/queries/collection_object/filter.rb', line 62

def biocuration_class_ids
  @biocuration_class_ids
end

#biological_relationship_idsArray

Returns of biological_relationship_ids.

Returns:

  • (Array)

    of biological_relationship_ids



66
67
68
# File 'lib/queries/collection_object/filter.rb', line 66

def biological_relationship_ids
  @biological_relationship_ids
end

#buffered_collecting_eventString?

Returns:

  • (String, nil)


151
152
153
# File 'lib/queries/collection_object/filter.rb', line 151

def buffered_collecting_event
  @buffered_collecting_event
end

#buffered_determinationsString?

Returns:

  • (String, nil)


145
146
147
# File 'lib/queries/collection_object/filter.rb', line 145

def buffered_determinations
  @buffered_determinations
end

#buffered_other_labelsString?

Returns:

  • (String, nil)


160
161
162
# File 'lib/queries/collection_object/filter.rb', line 160

def buffered_other_labels
  @buffered_other_labels
end

#collecting_eventTrue, ...

Parameters:

  • collecting_event ('true', 'false')

    true - has collecting_event_id false - does not have collecting_event_id nil - not applied

Returns:

  • (True, False, nil)


125
126
127
# File 'lib/queries/collection_object/filter.rb', line 125

def collecting_event
  @collecting_event
end

#collecting_event_idsObject

Array

only return objects with this collecting event ID



25
26
27
# File 'lib/queries/collection_object/filter.rb', line 25

def collecting_event_ids
  @collecting_event_ids
end

#collecting_event_queryObject

All params managed by CollectingEvent filter are available here as well



28
29
30
# File 'lib/queries/collection_object/filter.rb', line 28

def collecting_event_query
  @collecting_event_query
end

#collection_object_typeObject

Parameters:

  • one (String, nil)

    of 'Specimen', 'Lot', or 'RangedLot'



21
22
23
# File 'lib/queries/collection_object/filter.rb', line 21

def collection_object_type
  @collection_object_type
end

#collector_idsObject

See Queries::CollectingEvent::Filter



163
164
165
# File 'lib/queries/collection_object/filter.rb', line 163

def collector_ids
  @collector_ids
end

#collector_ids_orObject

Returns the value of attribute collector_ids_or.



164
165
166
# File 'lib/queries/collection_object/filter.rb', line 164

def collector_ids_or
  @collector_ids_or
end

#current_determinationsBoolean?

Returns nil = TaxonDeterminations match regardless of current or historical true = TaxonDetermination must be .current false = TaxonDetermination must be .historical.

Returns:

  • (Boolean, nil)

    nil = TaxonDeterminations match regardless of current or historical true = TaxonDetermination must be .current false = TaxonDetermination must be .historical



49
50
51
# File 'lib/queries/collection_object/filter.rb', line 49

def current_determinations
  @current_determinations
end

#depictionsTrue, ...

Returns true - index is built false - index is not built nil - not applied.

Returns:

  • (True, False, nil)

    true - index is built false - index is not built nil - not applied



92
93
94
# File 'lib/queries/collection_object/filter.rb', line 92

def depictions
  @depictions
end

#determiner_idArray

Parameters:

  • determiner (Array or Person#id)

    one ore more people id

Returns:

  • (Array)


136
137
138
# File 'lib/queries/collection_object/filter.rb', line 136

def determiner_id
  @determiner_id
end

#determiner_id_orBoolean

Parameters:

  • determiner_id_or (String, nil)

    `false`, nil - treat ids as “or” 'true' - treat ids as “and” (only collection objects with all and only all will match)

Returns:

  • (Boolean)


142
143
144
# File 'lib/queries/collection_object/filter.rb', line 142

def determiner_id_or
  @determiner_id_or
end

#dwc_indexedTrue, ...

Returns true - index is built false - index is not built nil - not applied.

Returns:

  • (True, False, nil)

    true - index is built false - index is not built nil - not applied



72
73
74
# File 'lib/queries/collection_object/filter.rb', line 72

def dwc_indexed
  @dwc_indexed
end

#exact_buffered_collecting_eventBoolean?

Returns:

  • (Boolean, nil)


154
155
156
# File 'lib/queries/collection_object/filter.rb', line 154

def exact_buffered_collecting_event
  @exact_buffered_collecting_event
end

#exact_buffered_determinationsBoolean?

Returns:

  • (Boolean, nil)


148
149
150
# File 'lib/queries/collection_object/filter.rb', line 148

def exact_buffered_determinations
  @exact_buffered_determinations
end

#exact_buffered_other_labelsBoolean?

Returns:

  • (Boolean, nil)


157
158
159
# File 'lib/queries/collection_object/filter.rb', line 157

def exact_buffered_other_labels
  @exact_buffered_other_labels
end

#geographic_areaTrue, ...

Returns true - has collecting event that has geographic_area false - does not have collecting event that has geographic area nil - not applied.

Returns:

  • (True, False, nil)

    true - has collecting event that has geographic_area false - does not have collecting event that has geographic area nil - not applied



131
132
133
# File 'lib/queries/collection_object/filter.rb', line 131

def geographic_area
  @geographic_area
end

#georeferencesTrue, ...

Returns true - has one ore more georeferences false - does not have any georeferences nil - not applied.

Returns:

  • (True, False, nil)

    true - has one ore more georeferences false - does not have any georeferences nil - not applied



104
105
106
# File 'lib/queries/collection_object/filter.rb', line 104

def georeferences
  @georeferences
end

#is_typeArray?

Returns one of `holotype`, `lectotype` etc.

nil - not applied.

Returns:

  • (Array, nil)

    one of `holotype`, `lectotype` etc.

    nil - not applied
    


83
84
85
# File 'lib/queries/collection_object/filter.rb', line 83

def is_type
  @is_type
end

#loanedTrue?

Returns:

  • (True, nil)


55
56
57
# File 'lib/queries/collection_object/filter.rb', line 55

def loaned
  @loaned
end

#never_loanedTrue?

Returns:

  • (True, nil)


58
59
60
# File 'lib/queries/collection_object/filter.rb', line 58

def never_loaned
  @never_loaned
end

#object_global_idObject

Returns the value of attribute object_global_id.



112
113
114
# File 'lib/queries/collection_object/filter.rb', line 112

def object_global_id
  @object_global_id
end

#on_loanTrue?

Returns:

  • (True, nil)


52
53
54
# File 'lib/queries/collection_object/filter.rb', line 52

def on_loan
  @on_loan
end

#otu_idsArray?

Returns a list of Otu ids, matches one ot one only.

Returns:

  • (Array, nil)

    a list of Otu ids, matches one ot one only



32
33
34
# File 'lib/queries/collection_object/filter.rb', line 32

def otu_ids
  @otu_ids
end

#recentBoolen?

Parameters:

  • 'true' (String, nil)
    • order by updated_at

    'false', nil - do not apply ordering

Returns:

  • (Boolen, nil)


110
111
112
# File 'lib/queries/collection_object/filter.rb', line 110

def recent
  @recent
end

#repositoryTrue, ...

Returns true - has repository_id false - does not have repository_id nil - not applied.

Returns:

  • (True, False, nil)

    true - has repository_id false - does not have repository_id nil - not applied



118
119
120
# File 'lib/queries/collection_object/filter.rb', line 118

def repository
  @repository
end

#repository_idRepository#id?

Returns:



78
79
80
# File 'lib/queries/collection_object/filter.rb', line 78

def repository_id
  @repository_id
end

#sled_image_idSledImage#id?

Returns:



86
87
88
# File 'lib/queries/collection_object/filter.rb', line 86

def sled_image_id
  @sled_image_id
end

#taxon_determinationsTrue, ...

Returns true - has one ore more taxon_determinations false - does not have any taxon_determinations nil - not applied.

Returns:

  • (True, False, nil)

    true - has one ore more taxon_determinations false - does not have any taxon_determinations nil - not applied



98
99
100
# File 'lib/queries/collection_object/filter.rb', line 98

def taxon_determinations
  @taxon_determinations
end

#type_materialTrue, ...

Returns true - has collecting event that has geographic_area false - does not have collecting event that has geographic area nil - not applied.

Returns:

  • (True, False, nil)

    true - has collecting event that has geographic_area false - does not have collecting event that has geographic area nil - not applied



170
171
172
# File 'lib/queries/collection_object/filter.rb', line 170

def type_material
  @type_material
end

#type_specimen_taxon_name_idProtonym#id?

Returns:



75
76
77
# File 'lib/queries/collection_object/filter.rb', line 75

def type_specimen_taxon_name_id
  @type_specimen_taxon_name_id
end

#validityBoolean?

Returns nil = Match against all ancestors, valid or invalid true = Match against only valid ancestors false = Match against only invalid ancestors.

Returns:

  • (Boolean, nil)

    nil = Match against all ancestors, valid or invalid true = Match against only valid ancestors false = Match against only invalid ancestors



43
44
45
# File 'lib/queries/collection_object/filter.rb', line 43

def validity
  @validity
end

#with_buffered_collecting_eventObject

See with_buffered_determinations



179
180
181
# File 'lib/queries/collection_object/filter.rb', line 179

def with_buffered_collecting_event
  @with_buffered_collecting_event
end

#with_buffered_determinationsBoolean?

Returns Boolean, nil.

Parameters:

  • with_buffered_determinations (String, nil)

    `false`, nil - without buffered determination field value 'true' - with buffered_determinations field value

Returns:

  • (Boolean, nil)

    Boolean, nil



176
177
178
# File 'lib/queries/collection_object/filter.rb', line 176

def with_buffered_determinations
  @with_buffered_determinations
end

#with_buffered_other_labelsObject

See with_buffered_determinations



182
183
184
# File 'lib/queries/collection_object/filter.rb', line 182

def with_buffered_other_labels
  @with_buffered_other_labels
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
# File 'lib/queries/collection_object/filter.rb', line 581

def all
  a = and_clauses
  b = merge_clauses
  # q = nil
  if a && b
    q = b.where(a).distinct
  elsif a
    q = ::CollectionObject.where(a).distinct
  elsif b
    q = b.distinct
  else
    q = ::CollectionObject.all
  end

  # TODO: needs to go, orders mess with chaining.
  q = q.order(updated_at: :desc) if recent
  q
end

#ancestors_facetObject



653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
# File 'lib/queries/collection_object/filter.rb', line 653

def ancestors_facet
  return nil if ancestor_id.nil?
  h = Arel::Table.new(:taxon_name_hierarchies)
  t = ::TaxonName.arel_table

  q = table.join(taxon_determination_table, Arel::Nodes::InnerJoin).on(
    table[:id].eq(taxon_determination_table[:biological_collection_object_id])
  ).join(otu_table, Arel::Nodes::InnerJoin).on(
    taxon_determination_table[:otu_id].eq(otu_table[:id])
  ).join(t, Arel::Nodes::InnerJoin).on(
    otu_table[:taxon_name_id].eq(t[:id])
  ).join(h, Arel::Nodes::InnerJoin).on(
    t[:id].eq(h[:descendant_id])
  )

  z = h[:ancestor_id].eq(ancestor_id)

  if validity == true
    z = z.and(t[:cached_valid_taxon_name_id].eq(t[:id]))
  elsif validity == false
    z = z.and(t[:cached_valid_taxon_name_id].not_eq(t[:id]))
  end

  if current_determinations == true
    z = z.and(taxon_determination_table[:position].eq(1))
  elsif current_determinations == false
    z = z.and(taxon_determination_table[:position].gt(1))
  end

  ::CollectionObject.joins(q.join_sources).where(z)
end

#and_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


500
501
502
503
504
505
506
507
508
509
510
# File 'lib/queries/collection_object/filter.rb', line 500

def and_clauses
  clauses = base_and_clauses

  return nil if clauses.empty?

  a = clauses.shift
  clauses.each do |b|
    a = a.and(b)
  end
  a
end

#base_and_clausesArray

Returns:

  • (Array)


513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# File 'lib/queries/collection_object/filter.rb', line 513

def base_and_clauses
  clauses = []

  clauses += [
    attribute_exact_facet(:buffered_determinations),
    attribute_exact_facet(:buffered_collecting_event),
    attribute_exact_facet(:buffered_other_labels),
    collecting_event_ids_facet,
    preparation_type_id_facet,
    type_facet,
    repository_id_facet,
    object_global_id_facet
  ]
  clauses.compact!
  clauses
end

#base_merge_clausesObject



530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'lib/queries/collection_object/filter.rb', line 530

def base_merge_clauses
  clauses = []
  clauses += collecting_event_merge_clauses + collecting_event_and_clauses

  clauses += [
    with_buffered_collecting_event_facet,
    with_buffered_other_labels_facet,
    with_buffered_determinations_facet,
    determiner_facet,
    geographic_area_facet,
    collecting_event_facet,
    repository_facet,
    type_material_facet,
    georeferences_facet,
    taxon_determinations_facet,
    otus_facet,
    type_by_taxon_name_facet,
    type_material_type_facet,
    ancestors_facet,
    keyword_id_facet,       # See Queries::Concerns::Tags
    created_updated_facet,  # See Queries::Concerns::Users
    identifiers_facet,      # See Queries::Concerns::Identifiers
    identifier_between_facet,
    identifier_facet, # See Queries::Concerns::Identifiers
    identifier_namespace_facet,
    loaned_facet,
    on_loan_facet,
    dwc_indexed_facet,
    never_loaned_facet,
    biocuration_facet,
    biological_relationship_ids_facet,
    sled_image_facet,
    depictions_facet,
  ]

  clauses.compact!
  clauses
end

#base_queryObject



245
246
247
# File 'lib/queries/collection_object/filter.rb', line 245

def base_query
  ::CollectionObject.select('collection_objects.*')
end

#biocuration_facetObject



409
410
411
412
# File 'lib/queries/collection_object/filter.rb', line 409

def biocuration_facet
  return nil if biocuration_class_ids.empty?
  ::CollectionObject::BiologicalCollectionObject.joins(:biocuration_classifications).where(biocuration_classifications: {biocuration_class_id: biocuration_class_ids})
end

#biological_relationship_ids_facetObject



436
437
438
439
# File 'lib/queries/collection_object/filter.rb', line 436

def biological_relationship_ids_facet
  return nil if biological_relationship_ids.empty?
  ::CollectionObject.with_biological_relationship_ids(biological_relationship_ids)
end

#collecting_event_and_clausesObject



489
490
491
492
493
494
495
496
497
# File 'lib/queries/collection_object/filter.rb', line 489

def collecting_event_and_clauses
  c = []

  # Convert base and clauses to merge clauses
  collecting_event_query.base_and_clauses.each do |i|
    c.push ::CollectionObject.joins(:collecting_event).where( i )
  end
  c
end

#collecting_event_facetObject



360
361
362
363
364
365
366
367
# File 'lib/queries/collection_object/filter.rb', line 360

def collecting_event_facet
  return nil if collecting_event.nil?
  if collecting_event
    ::CollectionObject.where.not(collecting_event_id: nil)
  else
    ::CollectionObject.where(collecting_event_id: nil)
  end
end

#collecting_event_ids_facetObject

Returns Scope.

Returns:

  • Scope



464
465
466
467
# File 'lib/queries/collection_object/filter.rb', line 464

def collecting_event_ids_facet
  return nil if collecting_event_ids.empty?
  table[:collecting_event_id].eq_any(collecting_event_ids)
end

#collecting_event_merge_clausesObject



479
480
481
482
483
484
485
486
487
# File 'lib/queries/collection_object/filter.rb', line 479

def collecting_event_merge_clauses
  c = []

  # Convert base and clauses to merge clauses
  collecting_event_query.base_merge_clauses.each do |i|
    c.push ::CollectionObject.joins(:collecting_event).merge( i )
  end
  c
end

#collecting_event_tableArel::Table

Returns:

  • (Arel::Table)


250
251
252
# File 'lib/queries/collection_object/filter.rb', line 250

def collecting_event_table
  ::CollectingEvent.arel_table
end

#depiction_tableArel::Table

Returns:

  • (Arel::Table)


265
266
267
# File 'lib/queries/collection_object/filter.rb', line 265

def depiction_table
  ::Depiction.arel_table
end

#depictions_facetObject



419
420
421
422
423
424
425
426
427
428
429
# File 'lib/queries/collection_object/filter.rb', line 419

def depictions_facet
  return nil if depictions.nil?

  if depictions
    ::CollectionObject.joins(:depictions).distinct
  else
    ::CollectionObject.left_outer_joins(:depictions)
      .where(depictions: {id: nil})
      .distinct
  end
end

#determiner_facetObject

TODO: DRY with Source (author), TaxonName, etc. See Queries::ColletingEvent::Filter for other use



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/queries/collection_object/filter.rb', line 296

def determiner_facet
  return nil if determiner_id.empty?
  tt = table

  o = ::TaxonDetermination.arel_table
  r = ::Role.arel_table

  a = o.alias("a_det__")
  b = o.project(a[Arel.star]).from(a)

  c = r.alias('det_r1')

  b = b.join(c, Arel::Nodes::OuterJoin)
    .on(
      a[:id].eq(c[:role_object_id])
    .and(c[:role_object_type].eq('TaxonDetermination'))
    .and(c[:type].eq('Determiner'))
    )

  e = c[:id].not_eq(nil)
  f = c[:person_id].eq_any(determiner_id)

  b = b.where(e.and(f))
  b = b.group(a['id'])
  b = b.having(a['id'].count.eq(determiner_id.length)) unless determiner_id_or

  b = b.as('det_z1_')

  ::CollectionObject.joins(Arel::Nodes::InnerJoin.new(b, Arel::Nodes::On.new(b['biological_collection_object_id'].eq(tt['id']))))
end

#dwc_indexed_facetObject



456
457
458
459
460
461
# File 'lib/queries/collection_object/filter.rb', line 456

def dwc_indexed_facet
  return nil if dwc_indexed.nil?
  dwc_indexed ?
    ::CollectionObject.dwc_indexed :
    ::CollectionObject.dwc_not_indexed
end

#geographic_area_facetObject



397
398
399
400
401
402
403
404
405
406
407
# File 'lib/queries/collection_object/filter.rb', line 397

def geographic_area_facet
  return nil if geographic_area.nil?

  if geographic_area
    ::CollectionObject.joins(:collecting_event).where.not(collecting_events: {geographic_area_id: nil}).distinct
  else
    ::CollectionObject.left_outer_joins(:collecting_event)
      .where(collecting_events: {geographic_area_id: nil})
      .distinct
  end
end

#georeferences_facetObject



327
328
329
330
331
332
333
334
335
336
# File 'lib/queries/collection_object/filter.rb', line 327

def georeferences_facet
  return nil if georeferences.nil?
  if georeferences
    ::CollectionObject.joins(:georeferences).distinct
  else
    ::CollectionObject.left_outer_joins(:georeferences)
      .where(georeferences: {id: nil})
      .distinct
  end
end

#loaned_facetObject



441
442
443
444
# File 'lib/queries/collection_object/filter.rb', line 441

def loaned_facet
  return nil unless loaned
  ::CollectionObject.loaned
end

#merge_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


570
571
572
573
574
575
576
577
578
# File 'lib/queries/collection_object/filter.rb', line 570

def merge_clauses
  clauses = base_merge_clauses
  return nil if clauses.empty?
  a = clauses.shift
  clauses.each do |b|
    a = a.merge(b)
  end
  a
end

#never_loaned_facetObject



446
447
448
449
# File 'lib/queries/collection_object/filter.rb', line 446

def never_loaned_facet
  return nil unless never_loaned
  ::CollectionObject.never_loaned
end

#object_global_id_facetObject



338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/queries/collection_object/filter.rb', line 338

def object_global_id_facet
  return nil if object_global_id.nil?

  if o = GlobalID::Locator.locate(object_global_id)
    k = o.class.name
    id = o.id

    table[:id].eq(id).and(table[:type].eq(k))
  else
    nil
  end
end

#on_loan_facetObject



451
452
453
454
# File 'lib/queries/collection_object/filter.rb', line 451

def on_loan_facet
  return nil unless on_loan
  ::CollectionObject.on_loan
end

#otu_tableArel::Table

Returns:

  • (Arel::Table)


255
256
257
# File 'lib/queries/collection_object/filter.rb', line 255

def otu_table
  ::Otu.arel_table
end

#otus_facetScope

Returns:

  • (Scope)


636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
# File 'lib/queries/collection_object/filter.rb', line 636

def otus_facet
  return nil if otu_ids.empty?

  w = taxon_determination_table[:biological_collection_object_id].eq(table[:id])
    .and( taxon_determination_table[:otu_id].eq_any(otu_ids) )

  if current_determinations
    w = w.and(taxon_determination_table[:position].eq(1))
  elsif current_determinations == false
    w = w.and(taxon_determination_table[:position].gt(1))
  end

  ::CollectionObject.where(
    ::TaxonDetermination.where(w).arel.exists
  )
end

#preparation_type_idObject



278
279
280
# File 'lib/queries/collection_object/filter.rb', line 278

def preparation_type_id
  [@preparation_type_id].flatten.compact
end

#preparation_type_id_facetObject



469
470
471
472
# File 'lib/queries/collection_object/filter.rb', line 469

def preparation_type_id_facet
  return nil if preparation_type_id.empty?
  table[:preparation_type_id].eq_any(preparation_type_id)
end

#repository_facetObject



351
352
353
354
355
356
357
358
# File 'lib/queries/collection_object/filter.rb', line 351

def repository_facet
  return nil if repository.nil?
  if repository
    ::CollectionObject.where.not(repository_id: nil)
  else
    ::CollectionObject.where(repository_id: nil)
  end
end

#repository_id_facetObject



474
475
476
477
# File 'lib/queries/collection_object/filter.rb', line 474

def repository_id_facet
  return nil if repository_id.blank?
  table[:repository_id].eq(repository_id)
end

#sled_image_facetObject



431
432
433
434
# File 'lib/queries/collection_object/filter.rb', line 431

def sled_image_facet
  return nil if sled_image_id.nil?
  ::CollectionObject::BiologicalCollectionObject.joins(:depictions).where("depictions.sled_image_id = ?", sled_image_id)
end

#tableArel::Table

Returns:

  • (Arel::Table)


241
242
243
# File 'lib/queries/collection_object/filter.rb', line 241

def table
  ::CollectionObject.arel_table
end

#taxon_determination_tableArel::Table

Returns:

  • (Arel::Table)


270
271
272
# File 'lib/queries/collection_object/filter.rb', line 270

def taxon_determination_table
  ::TaxonDetermination.arel_table
end

#taxon_determinations_facetObject



282
283
284
285
286
287
288
289
290
291
292
# File 'lib/queries/collection_object/filter.rb', line 282

def taxon_determinations_facet
  return nil if taxon_determinations.nil?

  if taxon_determinations
    ::CollectionObject.joins(:taxon_determinations).distinct
  else
    ::CollectionObject.left_outer_joins(:taxon_determinations)
      .where(taxon_determinations: {id: nil})
      .distinct
  end
end

#type_by_taxon_name_facetScope

Returns:

  • (Scope)


601
602
603
604
605
606
607
608
609
610
# File 'lib/queries/collection_object/filter.rb', line 601

def type_by_taxon_name_facet
  return nil if type_specimen_taxon_name_id.nil?

  w = type_materials_table[:collection_object_id].eq(table[:id])
    .and( type_materials_table[:protonym_id].eq(type_specimen_taxon_name_id) )

  ::CollectionObject.where(
    ::TypeMaterial.where(w).arel.exists
  )
end

#type_facetObject



414
415
416
417
# File 'lib/queries/collection_object/filter.rb', line 414

def type_facet
  return nil if collection_object_type.nil?
  table[:type].eq(collection_object_type)
end

#type_material_facetObject



624
625
626
627
628
629
630
631
632
633
# File 'lib/queries/collection_object/filter.rb', line 624

def type_material_facet
  return nil if type_material.nil?
  if type_material
    ::CollectionObject.joins(:type_materials).distinct
  else
    ::CollectionObject.left_outer_joins(:type_materials)
      .where(type_materials: {id: nil})
      .distinct
  end
end

#type_material_type_facetScope

Returns:

  • (Scope)


613
614
615
616
617
618
619
620
621
622
# File 'lib/queries/collection_object/filter.rb', line 613

def type_material_type_facet
  return nil if is_type.empty?

  w = type_materials_table[:collection_object_id].eq(table[:id])
    .and( type_materials_table[:type_type].eq_any(is_type) )

  ::CollectionObject.where(
    ::TypeMaterial.where(w).arel.exists
  )
end

#type_materials_tableArel::Table

Returns:

  • (Arel::Table)


260
261
262
# File 'lib/queries/collection_object/filter.rb', line 260

def type_materials_table
  ::TypeMaterial.arel_table
end

#with_buffered_collecting_event_facetObject



370
371
372
373
374
375
376
377
# File 'lib/queries/collection_object/filter.rb', line 370

def with_buffered_collecting_event_facet
  return nil if with_buffered_collecting_event.nil?
  if with_buffered_collecting_event
    ::CollectionObject.where.not(buffered_collecting_event: nil)
  else
    ::CollectionObject.where(buffered_collecting_event: nil)
  end
end

#with_buffered_determinations_facetObject



388
389
390
391
392
393
394
395
# File 'lib/queries/collection_object/filter.rb', line 388

def with_buffered_determinations_facet
  return nil if with_buffered_determinations.nil?
  if with_buffered_determinations
    ::CollectionObject.where.not(buffered_determinations: nil)
  else
    ::CollectionObject.where(buffered_determinations: nil)
  end
end

#with_buffered_other_labels_facetObject



379
380
381
382
383
384
385
386
# File 'lib/queries/collection_object/filter.rb', line 379

def with_buffered_other_labels_facet
  return nil if with_buffered_other_labels.nil?
  if with_buffered_other_labels
    ::CollectionObject.where.not(buffered_other_labels: nil)
  else
    ::CollectionObject.where(buffered_other_labels: nil)
  end
end