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



182
183
184
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
# File 'lib/queries/collection_object/filter.rb', line 182

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)
  @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 = params[:recent].blank? ? false : true
  @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



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

def ancestor_id
  @ancestor_id
end

#biocuration_class_idsArray

Returns of biocuration_class ids.

Returns:

  • (Array)

    of biocuration_class ids



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

def biocuration_class_ids
  @biocuration_class_ids
end

#biological_relationship_idsArray

Returns of biological_relationship_ids.

Returns:

  • (Array)

    of biological_relationship_ids



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

def biological_relationship_ids
  @biological_relationship_ids
end

#buffered_collecting_eventString?

Returns:

  • (String, nil)


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

def buffered_collecting_event
  @buffered_collecting_event
end

#buffered_determinationsString?

Returns:

  • (String, nil)


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

def buffered_determinations
  @buffered_determinations
end

#buffered_other_labelsString?

Returns:

  • (String, nil)


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

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)


122
123
124
# File 'lib/queries/collection_object/filter.rb', line 122

def collecting_event
  @collecting_event
end

#collecting_event_idsObject

Array

only return objects with this collecting event ID



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

def collecting_event_ids
  @collecting_event_ids
end

#collecting_event_queryObject

All params managed by CollectingEvent filter are available here as well



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

def collecting_event_query
  @collecting_event_query
end

#collection_object_typeObject

Parameters:

  • one (String, nil)

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



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

def collection_object_type
  @collection_object_type
end

#collector_idsObject

See Queries::CollectingEvent::Filter



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

def collector_ids
  @collector_ids
end

#collector_ids_orObject

Returns the value of attribute collector_ids_or.



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

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



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

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



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

def depictions
  @depictions
end

#determiner_idArray

Parameters:

  • determiner (Array or Person#id)

    one ore more people id

Returns:

  • (Array)


133
134
135
# File 'lib/queries/collection_object/filter.rb', line 133

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)


139
140
141
# File 'lib/queries/collection_object/filter.rb', line 139

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



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

def dwc_indexed
  @dwc_indexed
end

#exact_buffered_collecting_eventBoolean?

Returns:

  • (Boolean, nil)


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

def exact_buffered_collecting_event
  @exact_buffered_collecting_event
end

#exact_buffered_determinationsBoolean?

Returns:

  • (Boolean, nil)


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

def exact_buffered_determinations
  @exact_buffered_determinations
end

#exact_buffered_other_labelsBoolean?

Returns:

  • (Boolean, nil)


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

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



128
129
130
# File 'lib/queries/collection_object/filter.rb', line 128

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



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

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
    


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

def is_type
  @is_type
end

#loanedTrue?

Returns:

  • (True, nil)


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

def loaned
  @loaned
end

#never_loanedTrue?

Returns:

  • (True, nil)


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

def never_loaned
  @never_loaned
end

#on_loanTrue?

Returns:

  • (True, nil)


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

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



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

def otu_ids
  @otu_ids
end

#recentBoolen?

Parameters:

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

    'false', nil - do not apply ordering

Returns:

  • (Boolen, nil)


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

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



115
116
117
# File 'lib/queries/collection_object/filter.rb', line 115

def repository
  @repository
end

#repository_idRepository#id?

Returns:



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

def repository_id
  @repository_id
end

#sled_image_idSledImage#id?

Returns:



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

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



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

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



167
168
169
# File 'lib/queries/collection_object/filter.rb', line 167

def type_material
  @type_material
end

#type_specimen_taxon_name_idProtonym#id?

Returns:



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

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



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

def validity
  @validity
end

#with_buffered_collecting_eventObject

See with_buffered_determinations



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

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



173
174
175
# File 'lib/queries/collection_object/filter.rb', line 173

def with_buffered_determinations
  @with_buffered_determinations
end

#with_buffered_other_labelsObject

See with_buffered_determinations



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

def with_buffered_other_labels
  @with_buffered_other_labels
end

Instance Method Details

#allActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'lib/queries/collection_object/filter.rb', line 560

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

  q = q.order(updated_at: :desc) if recent
  q
end

#ancestors_facetObject



631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/queries/collection_object/filter.rb', line 631

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)


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

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)


493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# File 'lib/queries/collection_object/filter.rb', line 493

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
  ]
  clauses.compact!
  clauses
end

#base_merge_clausesObject



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
534
535
536
537
538
539
540
541
542
543
544
545
546
# File 'lib/queries/collection_object/filter.rb', line 509

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



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

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

#biocuration_facetObject



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

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



416
417
418
419
# File 'lib/queries/collection_object/filter.rb', line 416

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



469
470
471
472
473
474
475
476
477
# File 'lib/queries/collection_object/filter.rb', line 469

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



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

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



444
445
446
447
# File 'lib/queries/collection_object/filter.rb', line 444

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



459
460
461
462
463
464
465
466
467
# File 'lib/queries/collection_object/filter.rb', line 459

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)


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

def collecting_event_table
  ::CollectingEvent.arel_table
end

#depiction_tableArel::Table

Returns:

  • (Arel::Table)


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

def depiction_table
  ::Depiction.arel_table
end

#depictions_facetObject



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

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



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
318
# File 'lib/queries/collection_object/filter.rb', line 292

def determiner_facet
  return nil if determiner_id.empty?
  o = ::TaxonDetermination.arel_table
  r = ::Role.arel_table

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

  c = r.alias('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(:taxon_determinations).joins(Arel::Nodes::InnerJoin.new(b, Arel::Nodes::On.new(b['id'].eq(o['id']))))
end

#dwc_indexed_facetObject



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

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

#geographic_area_facetObject



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

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



320
321
322
323
324
325
326
327
328
329
# File 'lib/queries/collection_object/filter.rb', line 320

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



421
422
423
424
# File 'lib/queries/collection_object/filter.rb', line 421

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

#merge_clausesActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


549
550
551
552
553
554
555
556
557
# File 'lib/queries/collection_object/filter.rb', line 549

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



426
427
428
429
# File 'lib/queries/collection_object/filter.rb', line 426

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

#on_loan_facetObject



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

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

#otu_tableArel::Table

Returns:

  • (Arel::Table)


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

def otu_table
  ::Otu.arel_table
end

#otus_facetScope

Returns:

  • (Scope)


614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
# File 'lib/queries/collection_object/filter.rb', line 614

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



274
275
276
# File 'lib/queries/collection_object/filter.rb', line 274

def preparation_type_id
  [@preparation_type_id].flatten.compact
end

#preparation_type_id_facetObject



449
450
451
452
# File 'lib/queries/collection_object/filter.rb', line 449

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

#repository_facetObject



331
332
333
334
335
336
337
338
# File 'lib/queries/collection_object/filter.rb', line 331

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



454
455
456
457
# File 'lib/queries/collection_object/filter.rb', line 454

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

#sled_image_facetObject



411
412
413
414
# File 'lib/queries/collection_object/filter.rb', line 411

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)


237
238
239
# File 'lib/queries/collection_object/filter.rb', line 237

def table
  ::CollectionObject.arel_table
end

#taxon_determination_tableArel::Table

Returns:

  • (Arel::Table)


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

def taxon_determination_table
  ::TaxonDetermination.arel_table
end

#taxon_determinations_facetObject



278
279
280
281
282
283
284
285
286
287
288
# File 'lib/queries/collection_object/filter.rb', line 278

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)


579
580
581
582
583
584
585
586
587
588
# File 'lib/queries/collection_object/filter.rb', line 579

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



394
395
396
397
# File 'lib/queries/collection_object/filter.rb', line 394

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

#type_material_facetObject



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

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

#type_material_type_facetScope

Returns:

  • (Scope)


591
592
593
594
595
596
597
598
599
600
# File 'lib/queries/collection_object/filter.rb', line 591

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)


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

def type_materials_table
  ::TypeMaterial.arel_table
end

#with_buffered_collecting_event_facetObject



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

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



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

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



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

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