Class: Queries::FieldOccurrence::Filter
- Inherits:
-
Query::Filter
show all
- Includes:
- Concerns::Citations, Concerns::DataAttributes, Concerns::Depictions, Concerns::Notes, Concerns::Protocols, Concerns::Tags, Helpers
- Defined in:
- lib/queries/field_occurrence/filter.rb
Constant Summary
collapse
- PARAMS =
[
*::Queries::CollectingEvent::Filter::BASE_PARAMS,
*Queries::Concerns::DateRanges.params,
:field_occurrence_id,
].inject([{}]) { |ary, k| k.is_a?(Hash) ? ary.last.merge!(k) : ary.unshift(k); ary }.freeze
Query::Filter::FILTER_QUERIES, Query::Filter::SUBQUERIES
Instance Attribute Summary collapse
-
#base_collecting_event_query ⇒ Object
All params managed by CollectingEvent filter are available here as well.
-
#biocuration_class_id ⇒ Array
Of biocuration_class ids.
-
#biological_association_id ⇒ Object
Array Matching records in this BiologicalAssociation.
-
#biological_associations ⇒ True, ...
True - has collecting event that has geographic_area false - does not have collecting event that has geographic area nil - not applied.
-
#biological_relationship_id ⇒ Array
Of biological_relationship#id.
-
#collecting_event ⇒ True, ...
-
#collecting_event_id ⇒ Object
- Array
-
only return objects with these collecting event ID.
-
#collection_object_type ⇒ Object
-
#collectors ⇒ Boolean?
True - A collector role exists false - A collector role exists nil - not applied.
-
#current_determinations ⇒ Boolean?
Nil = TaxonDeterminations match regardless of current or historical true = TaxonDetermination must be .current false = TaxonDetermination must be .historical.
-
#current_repository ⇒ True, ...
True - has current_repository_id false - does not have current_repository_id nil - not applied.
-
#current_repository_id ⇒ CurrentRepository#id?
-
#dates ⇒ Object
Boolean true - any of start/end date or verbatim date are populated false - none of start/end date or verbatim date are populated nil - ignored.
-
#deaccessioned ⇒ Boolean?
Nil = Ignored true = FieldOccurrence with deaccessioned_at OR deaccessioned_reason populated or deaccession_recipient.present? false = without true.
-
#descendants ⇒ Object
Returns the value of attribute descendants.
-
#determiner_id ⇒ Array
-
#determiner_id_or ⇒ Boolean
-
#determiner_name_regex ⇒ Object
A PostgreSQL valid regular expression.
-
#determiners ⇒ Boolean?
True - A determiner role exists false - No determiner role exists nil - not applied.
-
#dwc_indexed ⇒ True, ...
True - index is built false - index is not built nil - not applied.
-
#extract_id ⇒ Object
Array match all FieldOccurrences that are the origin of these Extracts.
-
#field_occurrence_id ⇒ Object
-
#geographic_area ⇒ True, ...
True - has collecting event that has geographic_area false - does not have collecting event that has geographic area nil - not applied.
-
#georeferences ⇒ True, ...
True - has one ore more georeferences false - does not have any georeferences nil - not applied.
-
#import_dataset_id ⇒ Array
-
#is_type ⇒ Array?
One of ‘holotype`, `lectotype` etc.
-
#otu_id ⇒ Array?
Otu ids, matches on the TaxonDetermination, see also current_determinations.
-
#repository ⇒ True, ...
True - has repository_id false - does not have repository_id nil - not applied.
-
#repository_id ⇒ Repository#id?
-
#sled_image_id ⇒ SledImage#id?
-
#taxon_determinations ⇒ True, ...
True - has one ore more taxon_determinations false - does not have any taxon_determinations nil - not applied.
-
#taxon_name ⇒ True, ...
True - Otu has taxon name false - Otu without taxon name nil - not applied.
-
#taxon_name_id ⇒ Array of Protonym.id?
Return all collection objects determined as an Otu that is self or descendant linked to this TaxonName.
-
#validity ⇒ Boolean?
Nil = Match against all ancestors, valid or invalid true = Match against only valid ancestors false = Match against only invalid ancestors.
#api, #asserted_distribution_query, #biological_association_query, #biological_associations_graph_query, #collecting_event_query, #collection_object_query, #content_query, #controlled_vocabulary_term_query, #data_attribute_query, #descriptor_query, #extract_query, #field_occurrence_query, #image_query, #loan_query, #object_global_id, #observation_query, #otu_query, #page, #paginate, #params, #per, #person_query, #project_id, #recent, #taxon_name_query, #venn, #venn_mode
Attributes inherited from Query
#query_string, #terms
Instance Method Summary
collapse
Methods included from Helpers
#boolean_param
#all, #all_and_clauses, #all_merge_clauses, #annotator_and_clauses, #annotator_merge_clauses, annotator_params, api_except_params, api_excluded_params, #apply_venn, #attribute_exact_facet, base_filter, #deep_permit, included_annotator_facets, inverted_subqueries, #model_id_facet, #object_global_id_facet, params, #permitted_params, #process_url_into_params, #project_id_facet, query_name, #query_name, #set_nested_queries, #shared_and_clauses, #subquery_vector, #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
rubocop:disable Metric/MethodLength
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
# File 'lib/queries/field_occurrence/filter.rb', line 230
def initialize(query_params)
super
collecting_event_params = ::Queries::CollectingEvent::Filter.base_params + Queries::Concerns::DateRanges.params
@base_collecting_event_query = ::Queries::CollectingEvent::Filter.new(
params.select{ |a, b| collecting_event_params.include?(a) } )
@biological_association_id = params[:biological_association_id]
@biocuration_class_id = params[:biocuration_class_id]
@biological_relationship_id = params[:biological_relationship_id] @biological_associations = boolean_param(params, :biological_associations)
@collecting_event = boolean_param(params, :collecting_event)
@collectors = boolean_param(params, :collectors)
@collecting_event_id = params[:collecting_event_id]
@field_occurrence_id = params[:field_occurrence_id]
@collection_object_type = params[:collection_object_type].presence
@current_determinations = boolean_param(params, :current_determinations)
@current_repository = boolean_param(params, :current_repository)
@current_repository_id = params[:current_repository_id].presence
@dates = boolean_param(params, :dates)
@descendants = boolean_param(params, :descendants)
@deaccessioned = boolean_param(params, :deaccessioned)
@determiners = boolean_param(params, :determiners)
@determiner_id = params[:determiner_id]
@determiner_id_or = boolean_param(params, :determiner_id_or)
@determiner_name_regex = params[:determiner_name_regex]
@dwc_indexed = boolean_param(params, :dwc_indexed)
@extract_id = params[:extract_id]
@geographic_area = boolean_param(params, :geographic_area)
@georeferences = boolean_param(params, :georeferences)
@import_dataset_id = params[:import_dataset_id]
@is_type = params[:is_type] || []
@otu_descendants = boolean_param(params, :otu_descendants)
@otu_id = params[:otu_id]
@repository = boolean_param(params, :repository)
@repository_id = params[:repository_id]
@sled_image_id = (params[:sled_image_id].presence)
@taxon_determinations = boolean_param(params, :taxon_determinations)
@taxon_name_id = params[:taxon_name_id]
@validity = boolean_param(params, :validity)
set_citations_params(params)
set_data_attributes_params(params)
set_depiction_params(params)
set_notes_params(params)
set_protocols_params(params)
set_tags_params(params)
end
|
Instance Attribute Details
#base_collecting_event_query ⇒ Object
All params managed by CollectingEvent filter are available here as well
87
88
89
|
# File 'lib/queries/field_occurrence/filter.rb', line 87
def base_collecting_event_query
@base_collecting_event_query
end
|
#biocuration_class_id ⇒ Array
Returns of biocuration_class ids.
133
134
135
|
# File 'lib/queries/field_occurrence/filter.rb', line 133
def biocuration_class_id
@biocuration_class_id
end
|
#biological_association_id ⇒ Object
Returns Array Matching records in this BiologicalAssociation.
72
73
74
|
# File 'lib/queries/field_occurrence/filter.rb', line 72
def biological_association_id
@biological_association_id
end
|
#biological_associations ⇒ True, ...
Returns true - has collecting event that has geographic_area false - does not have collecting event that has geographic area nil - not applied.
68
69
70
|
# File 'lib/queries/field_occurrence/filter.rb', line 68
def biological_associations
@biological_associations
end
|
#biological_relationship_id ⇒ Array
Returns of biological_relationship#id.
137
138
139
|
# File 'lib/queries/field_occurrence/filter.rb', line 137
def biological_relationship_id
@biological_relationship_id
end
|
#collecting_event ⇒ True, ...
194
195
196
|
# File 'lib/queries/field_occurrence/filter.rb', line 194
def collecting_event
@collecting_event
end
|
#collecting_event_id ⇒ Object
- Array
-
only return objects with these collecting event ID
84
85
86
|
# File 'lib/queries/field_occurrence/filter.rb', line 84
def collecting_event_id
@collecting_event_id
end
|
#collection_object_type ⇒ Object
80
81
82
|
# File 'lib/queries/field_occurrence/filter.rb', line 80
def collection_object_type
@collection_object_type
end
|
#collectors ⇒ Boolean?
Returns true - A collector role exists false - A collector role exists nil - not applied.
129
130
131
|
# File 'lib/queries/field_occurrence/filter.rb', line 129
def collectors
@collectors
end
|
#current_determinations ⇒ Boolean?
Returns nil = TaxonDeterminations match regardless of current or historical true = TaxonDetermination must be .current false = TaxonDetermination must be .historical.
117
118
119
|
# File 'lib/queries/field_occurrence/filter.rb', line 117
def current_determinations
@current_determinations
end
|
#current_repository ⇒ True, ...
Returns true - has current_repository_id false - does not have current_repository_id nil - not applied.
187
188
189
|
# File 'lib/queries/field_occurrence/filter.rb', line 187
def current_repository
@current_repository
end
|
#current_repository_id ⇒ CurrentRepository#id?
149
150
151
|
# File 'lib/queries/field_occurrence/filter.rb', line 149
def current_repository_id
@current_repository_id
end
|
#dates ⇒ Object
Returns Boolean true - any of start/end date or verbatim date are populated false - none of start/end date or verbatim date are populated nil - ignored.
227
228
229
|
# File 'lib/queries/field_occurrence/filter.rb', line 227
def dates
@dates
end
|
#deaccessioned ⇒ Boolean?
Returns nil = Ignored true = FieldOccurrence with deaccessioned_at OR deaccessioned_reason populated or deaccession_recipient.present? false = without true.
105
106
107
|
# File 'lib/queries/field_occurrence/filter.rb', line 105
def deaccessioned
@deaccessioned
end
|
#descendants ⇒ Object
Returns the value of attribute descendants.
99
100
101
|
# File 'lib/queries/field_occurrence/filter.rb', line 99
def descendants
@descendants
end
|
#determiner_id ⇒ Array
205
206
207
|
# File 'lib/queries/field_occurrence/filter.rb', line 205
def determiner_id
@determiner_id
end
|
#determiner_id_or ⇒ Boolean
211
212
213
|
# File 'lib/queries/field_occurrence/filter.rb', line 211
def determiner_id_or
@determiner_id_or
end
|
#determiner_name_regex ⇒ Object
A PostgreSQL valid regular expression. Note that simple strings evaluate as wildcard matches. !! Probably shouldn’t expose to external API.
217
218
219
|
# File 'lib/queries/field_occurrence/filter.rb', line 217
def determiner_name_regex
@determiner_name_regex
end
|
#determiners ⇒ Boolean?
Returns true - A determiner role exists false - No determiner role exists nil - not applied.
123
124
125
|
# File 'lib/queries/field_occurrence/filter.rb', line 123
def determiners
@determiners
end
|
#dwc_indexed ⇒ True, ...
Returns true - index is built false - index is not built nil - not applied.
143
144
145
|
# File 'lib/queries/field_occurrence/filter.rb', line 143
def dwc_indexed
@dwc_indexed
end
|
Returns Array match all FieldOccurrences that are the origin of these Extracts.
221
222
223
|
# File 'lib/queries/field_occurrence/filter.rb', line 221
def
@extract_id
end
|
#field_occurrence_id ⇒ Object
76
77
78
|
# File 'lib/queries/field_occurrence/filter.rb', line 76
def field_occurrence_id
@field_occurrence_id
end
|
#geographic_area ⇒ True, ...
Returns true - has collecting event that has geographic_area false - does not have collecting event that has geographic area nil - not applied.
200
201
202
|
# File 'lib/queries/field_occurrence/filter.rb', line 200
def geographic_area
@geographic_area
end
|
#georeferences ⇒ True, ...
Returns true - has one ore more georeferences false - does not have any georeferences nil - not applied.
175
176
177
|
# File 'lib/queries/field_occurrence/filter.rb', line 175
def georeferences
@georeferences
end
|
#import_dataset_id ⇒ Array
Returns of ImportDataset ids.
62
63
64
|
# File 'lib/queries/field_occurrence/filter.rb', line 62
def import_dataset_id
@import_dataset_id
end
|
#is_type ⇒ Array?
Returns one of ‘holotype`, `lectotype` etc.
nil - not applied.
154
155
156
|
# File 'lib/queries/field_occurrence/filter.rb', line 154
def is_type
@is_type
end
|
#otu_id ⇒ Array?
Returns Otu ids, matches on the TaxonDetermination, see also current_determinations.
92
93
94
|
# File 'lib/queries/field_occurrence/filter.rb', line 92
def otu_id
@otu_id
end
|
#repository ⇒ True, ...
Returns true - has repository_id false - does not have repository_id nil - not applied.
181
182
183
|
# File 'lib/queries/field_occurrence/filter.rb', line 181
def repository
@repository
end
|
#repository_id ⇒ Repository#id?
146
147
148
|
# File 'lib/queries/field_occurrence/filter.rb', line 146
def repository_id
@repository_id
end
|
#sled_image_id ⇒ SledImage#id?
157
158
159
|
# File 'lib/queries/field_occurrence/filter.rb', line 157
def sled_image_id
@sled_image_id
end
|
#taxon_determinations ⇒ True, ...
Returns true - has one ore more taxon_determinations false - does not have any taxon_determinations nil - not applied.
163
164
165
|
# File 'lib/queries/field_occurrence/filter.rb', line 163
def taxon_determinations
@taxon_determinations
end
|
#taxon_name ⇒ True, ...
Returns true - Otu has taxon name false - Otu without taxon name nil - not applied.
169
170
171
|
# File 'lib/queries/field_occurrence/filter.rb', line 169
def taxon_name
@taxon_name
end
|
#taxon_name_id ⇒ Array of Protonym.id?
Return all collection objects determined as an Otu that is self or descendant linked to this TaxonName
97
98
99
|
# File 'lib/queries/field_occurrence/filter.rb', line 97
def taxon_name_id
@taxon_name_id
end
|
#validity ⇒ Boolean?
Returns nil = Match against all ancestors, valid or invalid true = Match against only valid ancestors false = Match against only invalid ancestors.
111
112
113
|
# File 'lib/queries/field_occurrence/filter.rb', line 111
def validity
@validity
end
|
Instance Method Details
#and_clauses ⇒ Object
::FieldOccurrence.from(‘(’ + s + ‘) as collection_objects’).distinct
end
731
732
733
734
735
736
|
# File 'lib/queries/field_occurrence/filter.rb', line 731
def and_clauses
[
field_occurrence_id_facet,
]
end
|
#base_collecting_event_query_facet ⇒ Object
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
|
# File 'lib/queries/field_occurrence/filter.rb', line 622
def base_collecting_event_query_facet
base_collecting_event_query.project_id = nil
return nil if base_collecting_event_query.all(true).nil?
base_collecting_event_query.project_id = project_id
s = 'WITH query_ce_base_co AS (' + base_collecting_event_query.all.to_sql + ') ' +
::FieldOccurrence
.joins('JOIN query_ce_base_co as query_ce_base_co1 on query_ce_base_co1.id = collection_objects.collecting_event_id')
.to_sql
::FieldOccurrence.from('(' + s + ') as collection_objects').distinct
end
|
#biocuration_facet ⇒ Object
477
478
479
480
481
|
# File 'lib/queries/field_occurrence/filter.rb', line 477
def biocuration_facet
return nil if biocuration_class_id.empty?
::FieldOccurrence::BiologicalFieldOccurrence.joins(:biocuration_classifications)
.where(biocuration_classifications: { biocuration_class_id: })
end
|
#biological_relationship_id_facet ⇒ Object
488
489
490
491
|
# File 'lib/queries/field_occurrence/filter.rb', line 488
def biological_relationship_id_facet
return nil if biological_relationship_id.empty?
::FieldOccurrence.with_biological_relationship_id(biological_relationship_id)
end
|
#collecting_event_facet ⇒ Object
455
456
457
458
459
460
461
462
|
# File 'lib/queries/field_occurrence/filter.rb', line 455
def collecting_event_facet
return nil if collecting_event.nil?
if collecting_event
::FieldOccurrence.where.not(collecting_event_id: nil)
else
::FieldOccurrence.where(collecting_event_id: nil)
end
end
|
#collecting_event_id_facet ⇒ Object
500
501
502
503
|
# File 'lib/queries/field_occurrence/filter.rb', line 500
def collecting_event_id_facet
return nil if collecting_event_id.empty?
table[:collecting_event_id].in(collecting_event_id)
end
|
#collecting_event_table ⇒ Arel::Table
284
285
286
|
# File 'lib/queries/field_occurrence/filter.rb', line 284
def collecting_event_table
::CollectingEvent.arel_table
end
|
#collectors_facet ⇒ Object
412
413
414
415
416
417
418
419
|
# File 'lib/queries/field_occurrence/filter.rb', line 412
def collectors_facet
return nil if collectors.nil?
if collectors
::FieldOccurrence.joins(:collectors)
else
::FieldOccurrence.where.missing(:collectors)
end
end
|
#current_repository_facet ⇒ Object
446
447
448
449
450
451
452
453
|
# File 'lib/queries/field_occurrence/filter.rb', line 446
def current_repository_facet
return nil if current_repository.nil?
if current_repository
::FieldOccurrence.where.not(current_repository_id: nil)
else
::FieldOccurrence.where(current_repository_id: nil)
end
end
|
#current_repository_id_facet ⇒ Object
510
511
512
513
|
# File 'lib/queries/field_occurrence/filter.rb', line 510
def current_repository_id_facet
return nil if current_repository_id.blank?
table[:current_repository_id].eq(current_repository_id)
end
|
#dates_facet ⇒ Object
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
|
# File 'lib/queries/field_occurrence/filter.rb', line 578
def dates_facet
return nil if dates.nil?
if dates
::FieldOccurrence.left_joins(:collecting_event).where(
'start_date_year IS NOT NULL OR ' \
'start_date_month IS NOT NULL OR ' \
'start_date_day IS NOT NULL OR ' \
'end_date_year IS NOT NULL OR ' \
'end_date_month IS NOT NULL OR ' \
'end_date_day IS NOT NULL OR ' \
'verbatim_date IS NOT NULL'
)
else
::FieldOccurrence.left_joins(:collecting_event).where(
collecting_event: {
start_date_year: nil,
start_date_month: nil,
start_date_day: nil,
end_date_year: nil,
end_date_month: nil,
end_date_day: nil,
verbatim_date: nil,
},
)
end
end
|
#deaccessioned_facet ⇒ Object
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
# File 'lib/queries/field_occurrence/filter.rb', line 605
def deaccessioned_facet
return nil if deaccessioned.nil?
a = ::FieldOccurrence.where('(deaccession_reason IS NOT NULL) OR (deaccessioned_at IS NOT NULL)')
b = ::FieldOccurrence.joins(:deaccession_recipient)
c = referenced_klass_union([a, b])
if deaccessioned
c
else
s = 'WITH query_deac AS (' + c.all.to_sql + ') ' +
::FieldOccurrence
.joins('LEFT JOIN query_deac as query_deac1 on query_deac1.id = collection_objects.id')
.where('query_deac1.id IS NULL').to_sql
::FieldOccurrence.from('(' + s + ') as collection_objects').distinct
end
end
|
#determiner_facet ⇒ Object
TODO: DRY with Source (author), TaxonName, etc. See Queries::ColletingEvent::Filter for other use
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
# File 'lib/queries/field_occurrence/filter.rb', line 372
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].in(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_')
::FieldOccurrence.joins(Arel::Nodes::InnerJoin.new(b, Arel::Nodes::On.new(b['biological_field_occurrence_id'].eq(tt['id']))))
end
|
#determiner_name_regex_facet ⇒ Object
421
422
423
424
|
# File 'lib/queries/field_occurrence/filter.rb', line 421
def determiner_name_regex_facet
return nil if determiner_name_regex.nil?
::FieldOccurrence.joins(:determiners).where('people.cached ~* ?', determiner_name_regex)
end
|
#determiners_facet ⇒ Object
403
404
405
406
407
408
409
410
|
# File 'lib/queries/field_occurrence/filter.rb', line 403
def determiners_facet
return nil if determiners.nil?
if determiners
::FieldOccurrence.joins(:determiners)
else
::FieldOccurrence.where.missing(:determiners)
end
end
|
#dwc_indexed_facet ⇒ Object
493
494
495
496
497
498
|
# File 'lib/queries/field_occurrence/filter.rb', line 493
def dwc_indexed_facet
return nil if dwc_indexed.nil?
dwc_indexed ?
::FieldOccurrence.dwc_indexed :
::FieldOccurrence.dwc_not_indexed
end
|
353
354
355
356
357
358
|
# File 'lib/queries/field_occurrence/filter.rb', line 353
def
return nil if .empty?
::FieldOccurrence
.joins(:origin_relationships)
.where(origin_relationships: { new_object_id: , new_object_type: 'Extract' })
end
|
#field_occurrence_id_facet ⇒ Object
342
343
344
345
|
# File 'lib/queries/field_occurrence/filter.rb', line 342
def field_occurrence_id_facet
return nil if field_occurrence_id.empty?
table[:id].in(field_occurrence_id)
end
|
#geographic_area_facet ⇒ Object
465
466
467
468
469
470
471
472
473
474
475
|
# File 'lib/queries/field_occurrence/filter.rb', line 465
def geographic_area_facet
return nil if geographic_area.nil?
if geographic_area
::FieldOccurrence.joins(:collecting_event).where.not(collecting_events: { geographic_area_id: nil }).distinct
else
::FieldOccurrence.left_outer_joins(:collecting_event)
.where(collecting_events: { geographic_area_id: nil })
.distinct
end
end
|
#georeferences_facet ⇒ Object
426
427
428
429
430
431
432
433
434
435
|
# File 'lib/queries/field_occurrence/filter.rb', line 426
def georeferences_facet
return nil if georeferences.nil?
if georeferences
::FieldOccurrence.joins(:georeferences).distinct
else
::FieldOccurrence.left_outer_joins(:georeferences)
.where(georeferences: { id: nil })
.distinct
end
end
|
#import_dataset_id_facet ⇒ Object
347
348
349
350
351
|
# File 'lib/queries/field_occurrence/filter.rb', line 347
def import_dataset_id_facet
return nil if import_dataset_id.blank?
::FieldOccurrence.joins(:related_origin_relationships)
.where(origin_relationships: {old_object_id: import_dataset_id, old_object_type: 'ImportDataset'})
end
|
#merge_clauses ⇒ Object
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
|
# File 'lib/queries/field_occurrence/filter.rb', line 738
def merge_clauses
[
]
end
|
#otu_id_facet ⇒ Object
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
# File 'lib/queries/field_occurrence/filter.rb', line 515
def otu_id_facet
return nil if otu_id.empty?
w = taxon_determination_table[:biological_field_occurrence_id].eq(table[:id])
.and(taxon_determination_table[:otu_id].in(otu_id))
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
::FieldOccurrence.where(
::TaxonDetermination.where(w).arel.exists
)
end
|
#otu_table ⇒ Arel::Table
289
290
291
|
# File 'lib/queries/field_occurrence/filter.rb', line 289
def otu_table
::Otu.arel_table
end
|
#repository_facet ⇒ Object
437
438
439
440
441
442
443
444
|
# File 'lib/queries/field_occurrence/filter.rb', line 437
def repository_facet
return nil if repository.nil?
if repository
::FieldOccurrence.where.not(repository_id: nil)
else
::FieldOccurrence.where(repository_id: nil)
end
end
|
#repository_id_facet ⇒ Object
505
506
507
508
|
# File 'lib/queries/field_occurrence/filter.rb', line 505
def repository_id_facet
return nil if repository_id.blank?
table[:repository_id].in(repository_id)
end
|
#sled_image_facet ⇒ Object
483
484
485
486
|
# File 'lib/queries/field_occurrence/filter.rb', line 483
def sled_image_facet
return nil if sled_image_id.nil?
::FieldOccurrence::BiologicalFieldOccurrence.joins(:depictions).where('depictions.sled_image_id = ?', sled_image_id)
end
|
#taxon_determination_table ⇒ Arel::Table
294
295
296
|
# File 'lib/queries/field_occurrence/filter.rb', line 294
def taxon_determination_table
::TaxonDetermination.arel_table
end
|
#taxon_determinations_facet ⇒ Object
360
361
362
363
364
365
366
367
368
|
# File 'lib/queries/field_occurrence/filter.rb', line 360
def taxon_determinations_facet
return nil if taxon_determinations.nil?
if taxon_determinations
::FieldOccurrence.joins(:taxon_determinations).distinct
else
::FieldOccurrence.where.missing(:taxon_determinations)
end
end
|
#taxon_name_id_facet ⇒ Object
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
568
569
570
571
572
573
574
575
576
|
# File 'lib/queries/field_occurrence/filter.rb', line 532
def taxon_name_id_facet
return nil if taxon_name_id.empty?
q = nil
z = nil
if descendants
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_field_occurrence_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].in(taxon_name_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
else
q = ::FieldOccurrence.joins(taxon_determinations: [:otu])
.where(otus: { taxon_name_id: })
if current_determinations
q = q.where(taxon_determinations: { position: 1 })
end
return q
end
::FieldOccurrence.joins(q.join_sources).where(z).distinct
end
|