Class: Queries::FieldOccurrence::Filter
- Inherits:
-
Query::Filter
- Object
- Query
- Query::Filter
- Queries::FieldOccurrence::Filter
- 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, # Fead to CE query. Revisit possibly. :biocuration_class_id, :biological_association_id, :biological_associations, # :biological_relationship_id, :collecting_event_id, :determiner_id, :field_occurrence_id, # :collectors, # :current_determinations, :dates, :descendants, # :determiner_id_all, # :determiner_name_regex, # :determiners, # :dwc_indexed, :georeferences, # :import_dataset_id, :otu_id, # :sled_image_id, :spatial_geographic_areas, # :taxon_determination_id, :taxon_name_id, # :validity, biocuration_class_id: [], biological_association_id: [], # biological_relationship_id: [], collecting_event_id: [], field_occurrence_id: [], determiner_id: [], # import_dataset_id: [], # is_type: [], otu_id: [], taxon_name_id: [], ].inject([{}]) { |ary, k| k.is_a?(Hash) ? ary.last.merge!(k) : ary.unshift(k); ary }.freeze
Constants inherited from Query::Filter
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 - is used in a bilogical association false - is not used in a biological association nil - not applied.
-
#biological_relationship_id ⇒ Array
Of biological_relationship#id.
-
#collecting_event_id ⇒ Object
- Array
-
only return objects with these collecting event ID.
-
#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.
-
#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.
-
#descendants ⇒ Object
Returns the value of attribute descendants.
- #determiner_id ⇒ Array
- #determiner_id_all ⇒ 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.
- #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.
-
#import_dataset_id ⇒ Array
Of ImportDataset ids.
-
#is_type ⇒ Array?
One of ‘holotype`, `lectotype` etc.
-
#otu_id ⇒ Array?
Otu ids, matches on the TaxonDetermination, see also current_determinations.
- #sled_image_id ⇒ SledImage#id?
-
#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.
Attributes inherited from Query::Filter
#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
Instance Method Summary collapse
- #and_clauses ⇒ Object
- #base_collecting_event_query_facet ⇒ Object
- #biocuration_facet ⇒ Object
-
#biological_association_id_facet ⇒ Object
TODO: turn into UNION!.
-
#biological_association_query_facet ⇒ Object
TODO: turn into UNION!.
- #biological_associations_facet ⇒ Object
- #biological_relationship_id_facet ⇒ Object
- #collecting_event_id_facet ⇒ Object
- #collecting_event_query_facet ⇒ Object
- #collecting_event_table ⇒ Arel::Table
-
#dates_facet ⇒ Object
TODO: Probably just move to CE.
-
#determiner_facet ⇒ Object
TODO: DRY with Source (author), TaxonName, etc.
- #determiner_name_regex_facet ⇒ Object
- #determiners_facet ⇒ Object
- #dwc_indexed_facet ⇒ Object
- #dwc_occurrence_query_facet ⇒ Object
- #field_occurrence_id_facet ⇒ Object
- #image_query_facet ⇒ Object
- #import_dataset_id_facet ⇒ Object
-
#initialize(query_params) ⇒ Filter
constructor
rubocop:disable Metric/MethodLength.
- #merge_clauses ⇒ Object
- #observation_query_facet ⇒ Object
- #otu_id_facet ⇒ Object
- #otu_query_facet ⇒ Object
- #otu_table ⇒ Arel::Table
- #sled_image_facet ⇒ Object
- #taxon_determination_table ⇒ Arel::Table
-
#taxon_name_id_facet ⇒ Object
TODO: use filter proxy.
- #taxon_name_query_facet ⇒ Object
Methods included from Helpers
#boolean_param, #integer_param
Methods inherited from Query::Filter
#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, base_query_name, base_query_to_h, #deep_permit, #disable_paging, included_annotator_facets, instantiated_base_filter, inverted_subqueries, #model_id_facet, #object_global_id_facet, #only_project?, #paging_state, params, #permitted_params, #process_url_into_params, #project_id_facet, query_name, #set_nested_queries, #set_paging, set_paging, #shared_and_clauses, #subquery_vector, #target_and_clauses, #venn_query
Methods inherited from Query
#alphabetic_strings, #alphanumeric_strings, base_name, #base_name, #base_query, #build_terms, #cached_facet, #end_wildcard, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #no_terms?, referenced_klass, #referenced_klass, #referenced_klass_except, #referenced_klass_intersection, #referenced_klass_union, #start_and_end_wildcard, #start_wildcard, #table, #wildcard_pieces
Constructor Details
#initialize(query_params) ⇒ Filter
rubocop:disable Metric/MethodLength
171 172 173 174 175 176 177 178 179 180 181 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 |
# File 'lib/queries/field_occurrence/filter.rb', line 171 def initialize(query_params) super # Only CollectingEvent fields are permitted, for advanced nesting (e.g. tags on CEs), use collecting_event_query collecting_event_params = ::Queries::CollectingEvent::Filter.base_params + Queries::Concerns::DateRanges.params # project_id is handled during use @base_collecting_event_query = ::Queries::CollectingEvent::Filter.new( params.select{ |a, b| collecting_event_params.include?(a) } # maintain this to avoid sub query initialization for now ) @biological_association_id = params[:biological_association_id] @biocuration_class_id = params[:biocuration_class_id] @biological_relationship_id = params[:biological_relationship_id] # TODO: no reference? @biological_associations = boolean_param(params, :biological_associations) @collectors = boolean_param(params, :collectors) @collecting_event_id = params[:collecting_event_id] @field_occurrence_id = params[:field_occurrence_id] @current_determinations = boolean_param(params, :current_determinations) @dates = boolean_param(params, :dates) @descendants = boolean_param(params, :descendants) @determiners = boolean_param(params, :determiners) @determiner_id = params[:determiner_id] @determiner_id_all = boolean_param(params, :determiner_id_all) @determiner_name_regex = params[:determiner_name_regex] @dwc_indexed = boolean_param(params, :dwc_indexed) @import_dataset_id = params[:import_dataset_id] @is_type = params[:is_type] || [] @otu_descendants = boolean_param(params, :otu_descendants) @otu_id = params[:otu_id] @sled_image_id = (params[:sled_image_id].presence) @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) (params) end |
Instance Attribute Details
#base_collecting_event_query ⇒ Object
All params managed by CollectingEvent filter are available here as well
75 76 77 |
# File 'lib/queries/field_occurrence/filter.rb', line 75 def base_collecting_event_query @base_collecting_event_query end |
#biocuration_class_id ⇒ Array
Returns of biocuration_class ids.
115 116 117 |
# File 'lib/queries/field_occurrence/filter.rb', line 115 def biocuration_class_id @biocuration_class_id end |
#biological_association_id ⇒ Object
Returns Array Matching records in this BiologicalAssociation.
64 65 66 |
# File 'lib/queries/field_occurrence/filter.rb', line 64 def biological_association_id @biological_association_id end |
#biological_associations ⇒ True, ...
Returns true - is used in a bilogical association false - is not used in a biological association nil - not applied.
60 61 62 |
# File 'lib/queries/field_occurrence/filter.rb', line 60 def biological_associations @biological_associations end |
#biological_relationship_id ⇒ Array
Returns of biological_relationship#id.
119 120 121 |
# File 'lib/queries/field_occurrence/filter.rb', line 119 def biological_relationship_id @biological_relationship_id end |
#collecting_event_id ⇒ Object
- Array
-
only return objects with these collecting event ID
72 73 74 |
# File 'lib/queries/field_occurrence/filter.rb', line 72 def collecting_event_id @collecting_event_id end |
#collectors ⇒ Boolean?
Returns true - A collector role exists false - A collector role exists nil - not applied.
111 112 113 |
# File 'lib/queries/field_occurrence/filter.rb', line 111 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.
99 100 101 |
# File 'lib/queries/field_occurrence/filter.rb', line 99 def current_determinations @current_determinations 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.
168 169 170 |
# File 'lib/queries/field_occurrence/filter.rb', line 168 def dates @dates end |
#descendants ⇒ Object
Returns the value of attribute descendants.
87 88 89 |
# File 'lib/queries/field_occurrence/filter.rb', line 87 def descendants @descendants end |
#determiner_id ⇒ Array
150 151 152 |
# File 'lib/queries/field_occurrence/filter.rb', line 150 def determiner_id @determiner_id end |
#determiner_id_all ⇒ Boolean
156 157 158 |
# File 'lib/queries/field_occurrence/filter.rb', line 156 def determiner_id_all @determiner_id_all 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.
162 163 164 |
# File 'lib/queries/field_occurrence/filter.rb', line 162 def determiner_name_regex @determiner_name_regex end |
#determiners ⇒ Boolean?
Returns true - A determiner role exists false - No determiner role exists nil - not applied.
105 106 107 |
# File 'lib/queries/field_occurrence/filter.rb', line 105 def determiners @determiners end |
#dwc_indexed ⇒ True, ...
Returns true - index is built false - index is not built nil - not applied.
125 126 127 |
# File 'lib/queries/field_occurrence/filter.rb', line 125 def dwc_indexed @dwc_indexed end |
#field_occurrence_id ⇒ Object
68 69 70 |
# File 'lib/queries/field_occurrence/filter.rb', line 68 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.
145 146 147 |
# File 'lib/queries/field_occurrence/filter.rb', line 145 def geographic_area @geographic_area end |
#import_dataset_id ⇒ Array
Returns of ImportDataset ids.
54 55 56 |
# File 'lib/queries/field_occurrence/filter.rb', line 54 def import_dataset_id @import_dataset_id end |
#is_type ⇒ Array?
Returns one of ‘holotype`, `lectotype` etc.
nil - not applied.
130 131 132 |
# File 'lib/queries/field_occurrence/filter.rb', line 130 def is_type @is_type end |
#otu_id ⇒ Array?
Returns Otu ids, matches on the TaxonDetermination, see also current_determinations.
80 81 82 |
# File 'lib/queries/field_occurrence/filter.rb', line 80 def otu_id @otu_id end |
#sled_image_id ⇒ SledImage#id?
133 134 135 |
# File 'lib/queries/field_occurrence/filter.rb', line 133 def sled_image_id @sled_image_id end |
#taxon_name ⇒ True, ...
Returns true - Otu has taxon name false - Otu without taxon name nil - not applied.
139 140 141 |
# File 'lib/queries/field_occurrence/filter.rb', line 139 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
85 86 87 |
# File 'lib/queries/field_occurrence/filter.rb', line 85 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.
93 94 95 |
# File 'lib/queries/field_occurrence/filter.rb', line 93 def validity @validity end |
Instance Method Details
#and_clauses ⇒ Object
558 559 560 561 562 563 |
# File 'lib/queries/field_occurrence/filter.rb', line 558 def and_clauses [ collecting_event_id_facet, field_occurrence_id_facet, ] end |
#base_collecting_event_query_facet ⇒ Object
442 443 444 445 446 447 448 449 450 451 |
# File 'lib/queries/field_occurrence/filter.rb', line 442 def base_collecting_event_query_facet return nil if base_collecting_event_query.only_project? 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 = field_occurrences.collecting_event_id') .to_sql ::FieldOccurrence.from('(' + s + ') as field_occurrences').distinct end |
#biocuration_facet ⇒ Object
322 323 324 325 326 |
# File 'lib/queries/field_occurrence/filter.rb', line 322 def biocuration_facet return nil if biocuration_class_id.empty? ::FieldOccurrence::BiologicalFieldOccurrence.joins(:biocuration_classifications) .where(biocuration_classifications: { biocuration_class_id: }) end |
#biological_association_id_facet ⇒ Object
TODO: turn into UNION!
486 487 488 489 490 491 492 493 494 495 496 497 |
# File 'lib/queries/field_occurrence/filter.rb', line 486 def biological_association_id_facet return nil if biological_association_id.empty? b = ::BiologicalAssociation.where(id: biological_association_id) s = 'WITH query_ba_id_co AS (' + b.all.to_sql + ') ' + ::FieldOccurrence .joins("LEFT JOIN query_ba_id_co as query_ba_id_co1 on field_occurrences.id = query_ba_id_co1.biological_association_subject_id AND query_ba_id_co1.biological_association_subject_type = 'FieldOccurrence'") .joins("LEFT JOIN query_ba_id_co as query_ba_id_co2 on field_occurrences.id = query_ba_id_co2.biological_association_object_id AND query_ba_id_co2.biological_association_object_type = 'FieldOccurrence'") .where('(query_ba_id_co1.id) IS NOT NULL OR (query_ba_id_co2.id IS NOT NULL)') .to_sql ::FieldOccurrence.from('(' + s + ') as field_occurrences').distinct end |
#biological_association_query_facet ⇒ Object
TODO: turn into UNION!
500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/queries/field_occurrence/filter.rb', line 500 def biological_association_query_facet return nil if biological_association_query.nil? s = 'WITH query_ba_co AS (' + biological_association_query.all.to_sql + ') ' + ::FieldOccurrence .joins("LEFT JOIN query_ba_co as query_ba_co1 on field_occurrences.id = query_ba_co1.biological_association_subject_id AND query_ba_co1.biological_association_subject_type = 'FieldOccurrence'") .joins("LEFT JOIN query_ba_co as query_ba_co2 on field_occurrences.id = query_ba_co2.biological_association_object_id AND query_ba_co2.biological_association_object_type = 'FieldOccurrence'") .where('(query_ba_co1.id) IS NOT NULL OR (query_ba_co2.id IS NOT NULL)') .to_sql ::FieldOccurrence.from('(' + s + ') as field_occurrences').distinct end |
#biological_associations_facet ⇒ Object
477 478 479 480 481 482 483 |
# File 'lib/queries/field_occurrence/filter.rb', line 477 def biological_associations_facet return nil if biological_associations.nil? a = ::FieldOccurrence.joins(:biological_associations) b = ::FieldOccurrence.joins(:related_biological_associations) referenced_klass_union([a, b]) end |
#biological_relationship_id_facet ⇒ Object
333 334 335 336 |
# File 'lib/queries/field_occurrence/filter.rb', line 333 def biological_relationship_id_facet return nil if biological_relationship_id.empty? ::FieldOccurrence.with_biological_relationship_id(biological_relationship_id) end |
#collecting_event_id_facet ⇒ Object
345 346 347 348 |
# File 'lib/queries/field_occurrence/filter.rb', line 345 def collecting_event_id_facet return nil if collecting_event_id.empty? table[:collecting_event_id].in(collecting_event_id) end |
#collecting_event_query_facet ⇒ Object
512 513 514 515 516 517 518 519 520 |
# File 'lib/queries/field_occurrence/filter.rb', line 512 def collecting_event_query_facet return nil if collecting_event_query.nil? s = 'WITH query_ce_co AS (' + collecting_event_query.all.select(:id).to_sql + ') ' + ::FieldOccurrence .joins('JOIN query_ce_co as query_ce_co1 on query_ce_co1.id = field_occurrences.collecting_event_id') .to_sql ::FieldOccurrence.from('(' + s + ') as field_occurrences').distinct end |
#collecting_event_table ⇒ Arel::Table
214 215 216 |
# File 'lib/queries/field_occurrence/filter.rb', line 214 def collecting_event_table ::CollectingEvent.arel_table end |
#dates_facet ⇒ Object
TODO: Probably just move to CE
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/queries/field_occurrence/filter.rb', line 415 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 |
#determiner_facet ⇒ Object
TODO: DRY with Source (author), TaxonName, etc. See Queries::ColletingEvent::Filter for other use
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 |
# File 'lib/queries/field_occurrence/filter.rb', line 277 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)) if determiner_id_all b = b.as('det_z1_') ::FieldOccurrence.joins(Arel::Nodes::InnerJoin.new(b, Arel::Nodes::On.new(b['taxon_determination_object_id'].eq(tt['id'])))) end |
#determiner_name_regex_facet ⇒ Object
317 318 319 320 |
# File 'lib/queries/field_occurrence/filter.rb', line 317 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
308 309 310 311 312 313 314 315 |
# File 'lib/queries/field_occurrence/filter.rb', line 308 def determiners_facet return nil if determiners.nil? if determiners ::FieldOccurrence.joins(:determiners) else ::FieldOccurrence.where.missing(:determiners) end end |
#dwc_indexed_facet ⇒ Object
338 339 340 341 342 343 |
# File 'lib/queries/field_occurrence/filter.rb', line 338 def dwc_indexed_facet return nil if dwc_indexed.nil? dwc_indexed ? ::FieldOccurrence.dwc_indexed : ::FieldOccurrence.dwc_not_indexed end |
#dwc_occurrence_query_facet ⇒ Object
522 523 524 525 526 527 528 529 530 531 532 |
# File 'lib/queries/field_occurrence/filter.rb', line 522 def dwc_occurrence_query_facet return nil if dwc_occurrence_query.nil? s = ::FieldOccurrence .with(query_dwc_fo: dwc_occurrence_query.all.select(:dwc_occurrence_object_id, :dwc_occurrence_object_type, :id)) .joins(:dwc_occurrence) .joins('JOIN query_dwc_fo as query_dwc_fo1 on query_dwc_fo1.id = dwc_occurrences.id') .to_sql ::FieldOccurrence.from('(' + s + ') as field_occurrences').distinct end |
#field_occurrence_id_facet ⇒ Object
264 265 266 267 |
# File 'lib/queries/field_occurrence/filter.rb', line 264 def field_occurrence_id_facet return nil if field_occurrence_id.empty? table[:id].in(field_occurrence_id) end |
#image_query_facet ⇒ Object
534 535 536 537 538 539 540 541 542 543 544 |
# File 'lib/queries/field_occurrence/filter.rb', line 534 def image_query_facet return nil if image_query.nil? s = ::FieldOccurrence .with(query_image: image_query.all) .joins(:depictions) .joins('JOIN query_image ON query_image.id = depictions.image_id') .to_sql ::FieldOccurrence.from('(' + s + ') as field_occurrences').distinct end |
#import_dataset_id_facet ⇒ Object
269 270 271 272 273 |
# File 'lib/queries/field_occurrence/filter.rb', line 269 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
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 |
# File 'lib/queries/field_occurrence/filter.rb', line 565 def merge_clauses [ # import_dataset_id_facet, biological_association_id_facet, base_collecting_event_query_facet, biological_association_query_facet, collecting_event_query_facet, dwc_occurrence_query_facet, image_query_facet, observation_query_facet, otu_query_facet, taxon_name_query_facet, biocuration_facet, biological_associations_facet, # biological_relationship_id_facet, dates_facet, determiner_facet, # determiner_name_regex_facet, determiners_facet, # dwc_indexed_facet, otu_id_facet, # sled_image_facet, taxon_name_id_facet, ] end |
#observation_query_facet ⇒ Object
546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/queries/field_occurrence/filter.rb', line 546 def observation_query_facet return nil if observation_query.nil? s = ::FieldOccurrence .with(obs_query_fo: observation_query.all) .joins(:observations) .joins('JOIN obs_query_fo on observations.id = obs_query_fo.id') .to_sql ::FieldOccurrence.from('(' + s + ') as field_occurrences').distinct end |
#otu_id_facet ⇒ Object
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/queries/field_occurrence/filter.rb', line 350 def otu_id_facet return nil if otu_id.empty? w = taxon_determination_table[:taxon_determination_object_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_query_facet ⇒ Object
465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/queries/field_occurrence/filter.rb', line 465 def otu_query_facet return nil if otu_query.nil? s = 'WITH query_otu_co AS (' + otu_query.all.to_sql + ') ' + ::FieldOccurrence .joins(:taxon_determinations) .joins('JOIN query_otu_co as query_otu_co1 on query_otu_co1.id = taxon_determinations.otu_id') .where(taxon_determinations: { position: 1 }) .to_sql ::FieldOccurrence.from('(' + s + ') as field_occurrences').distinct end |
#otu_table ⇒ Arel::Table
219 220 221 |
# File 'lib/queries/field_occurrence/filter.rb', line 219 def otu_table ::Otu.arel_table end |
#sled_image_facet ⇒ Object
328 329 330 331 |
# File 'lib/queries/field_occurrence/filter.rb', line 328 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
224 225 226 |
# File 'lib/queries/field_occurrence/filter.rb', line 224 def taxon_determination_table ::TaxonDetermination.arel_table end |
#taxon_name_id_facet ⇒ Object
TODO: use filter proxy
368 369 370 371 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 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/queries/field_occurrence/filter.rb', line 368 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[:taxon_determination_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].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 |
#taxon_name_query_facet ⇒ Object
453 454 455 456 457 458 459 460 461 462 463 |
# File 'lib/queries/field_occurrence/filter.rb', line 453 def taxon_name_query_facet return nil if taxon_name_query.nil? s = ::FieldOccurrence .with(query_tn_fo: taxon_name_query.all.select(:id)) .joins(:taxon_names) .joins('JOIN query_tn_fo on query_tn_fo.id = taxon_names.id') .to_sql ::FieldOccurrence.from('(' + s + ') as field_occurrences').distinct end |