Class: Queries::TaxonName::Filter
- Inherits:
-
Query::Filter
show all
- Includes:
- Concerns::Citations, Concerns::Confidences, Concerns::DataAttributes, Concerns::Depictions, Concerns::Notes, Concerns::Sounds, Concerns::Tags, Helpers
- Defined in:
- lib/queries/taxon_name/filter.rb
Constant Summary
collapse
- PARAMS =
[
:ancestors,
:ancestrify,
:author,
:author_exact,
:authors,
:availability,
:cached,
:collecting_event_id,
:collection_object_id,
:combinations,
:combinationify,
:descendants,
:descendants_max_depth,
:epithet_only,
:etymology,
:latinized,
:leaves,
:name,
:name_exact,
:nomenclature_code,
:nomenclature_date,
:nomenclature_group, :not_specified,
:original_combination,
:otu_id,
:otus,
:rank,
:relation_to_relationship,
:sort,
:taxon_name_relationship_target,
:synonymify,
:taxon_name_author_id_or,
:taxon_name_id,
:taxon_name_type,
:type_metadata,
:validify,
:validity,
:verbatim_author,
:verbatim_name,
:year,
:year_end,
:year_start,
cached: [],
collection_object_id: [],
collecting_event_id: [],
combination_taxon_name_id: [],
name: [],
otu_id: [],
parent_id: [],
rank: [],
taxon_name_author_id: [],
taxon_name_classification: [],
taxon_name_id: [],
taxon_name_relationship: [
:subject_taxon_name_id,
:object_taxon_name_id,
:type,
],
taxon_name_relationship_type_subject: [],
taxon_name_relationship_type_object: [],
taxon_name_relationship_type_either: [],
type: [],
].freeze
Query::Filter::FILTER_QUERIES, Query::Filter::SUBQUERIES
Instance Attribute Summary collapse
-
#ancestors ⇒ Boolean
Ignored when taxon_name_id.empty? Works as AND clause with descendants :(.
-
#ancestrify ⇒ Object
!! This parameter is not like the others, it is applied POST result, see also synonymify and validify, etc.
-
#author ⇒ Object
-
#author_exact ⇒ Boolean
-
#authors ⇒ Object
['true' or 'false'] on initialize whether the name has an author string, from any source, provided.
-
#availability ⇒ Object
['true' or 'false'] on initialize true if only available, false if only unavailable, nil if both.
-
#cached ⇒ Array
Of TaxonNames matching cached exactly.
-
#collecting_event_id ⇒ Array
-
#collection_object_id ⇒ Array
-
#combination_taxon_name_id ⇒ Array
Taxon_name_ids for which all Combinations will be returned.
-
#combinationify ⇒ Object
!! This parameter is not like the others, it is applied POST result, see also synonymify and validify.
-
#combinations ⇒ Object
This parameter should be used along side species or genus group limits.
-
#descendants ⇒ Boolean
True - only descendants NOT SELF false - self AND descendants nil - ignored Ignored when taxon_name_id.empty?.
-
#descendants_max_depth ⇒ Integer?
A positive integer indicating how many levels deep of descendants to retrieve.
-
#epithet_only ⇒ Object
-
#etymology ⇒ Object
['true' or 'false'] on initialize whether the name has etymology.
-
#geo_json ⇒ Object
Returns the value of attribute geo_json.
-
#latinized ⇒ Boolean?
&latinized=<"true"|"false"> if 'true' then return only genus group names with gender and species group names with part of speech if 'false' then return only genus group names without gender and species group names without part of speech if nil, ignore.
-
#leaves ⇒ Boolean?
TODO: inverse is duplicated in autocomplete.
-
#name ⇒ Array
-
#name_exact ⇒ Boolean
-
#nomenclature_code ⇒ String?
Accessor for attr :nomenclature_code, wrap with needed wildcards.
-
#nomenclature_date ⇒ Boolean
With/out cached nomenclature date set.
-
#nomenclature_group ⇒ String?
Accessor for attr :nomenclature_group, wrap with needed wildcards.
-
#not_specified ⇒ Object
-
#original_combination ⇒ Boolean?
True - name has at least one element of original combination false - name has no element of original combination nil - ignored.
-
#otu_id ⇒ Array?
-
#otus ⇒ Object
['true' or 'false'] on initialize whether the name has an Otu.
-
#parent_id ⇒ Object
Return the taxon names with this/these parent_ids.
-
#rank ⇒ Array
-
#relation_to_relationship ⇒ String?
&relation_to_relationship=<subject|object|either> All names that are subject|object|either of any relationship.
-
#sort ⇒ String?
-
#synonymify ⇒ Object
!! This parameter is not like the others, it is applied POST result, see also combinationify and validify.
-
#taxon_name_author_id ⇒ Array
-
#taxon_name_author_id_or ⇒ Boolean
-
#taxon_name_classification ⇒ Object
-
#taxon_name_id ⇒ Object
Return the taxon name(s) with this/these ids.
-
#taxon_name_relationship ⇒ Object
Each entry must have a 'type' Each entry must have one (and only one) of 'subject_taxon_name_id' or 'object_taxon_name_id'.
-
#taxon_name_relationship_target ⇒ Boolean
Applies only to taxon_name_relationship_query_facet, is only present in queries sent from Filter TaxonNameRelationship.
-
#taxon_name_relationship_type_either ⇒ Object
-
#taxon_name_relationship_type_object ⇒ Object
-
#taxon_name_relationship_type_subject ⇒ Object
-
#taxon_name_type ⇒ String?
&taxon_name_type=<Protonym|Combination|Hybrid>.
-
#type_metadata ⇒ Object
['true' or 'false'] on initialize whether the name has TypeMaterial.
-
#validify ⇒ Boolean
name is returned !! This param is not like the others.
-
#validity ⇒ Object
['true' or 'false'] on initialize true if only valid, false if only invalid, nil if both.
-
#verbatim_author ⇒ Object
-
#verbatim_name ⇒ Boolean
If true then verbatim_name is populated.
-
#year ⇒ Object
Matches against cached_author_year.
-
#year_end ⇒ Object
Matches against cached_nomenclature_date.
-
#year_start ⇒ Object
Matches against cached_nomenclature_date.
#anatomical_part_query, #api, #asserted_distribution_query, #asserted_environment_query, #biological_association_query, #biological_associations_graph_query, #collecting_event_query, #collection_object_query, #content_query, #controlled_vocabulary_term_query, #conveyance_query, #data_attribute_query, #depiction_query, #descriptor_query, #document_query, #dwc_occurrence_query, #extract_query, #field_occurrence_query, #image_query, #loan_query, #object_global_id, #observation_query, #order_by, #otu_query, #page, #paginate, #params, #per, #person_query, #project_id, #recent, #recent_target, #roll_call, #sound_query, #taxon_name_query, #taxon_name_relationship_query, #venn, #venn_ignore_pagination, #venn_mode
Attributes inherited from Query
#query_string, #terms
Instance Method Summary
collapse
Methods included from Helpers
#boolean_param, #integer_param, #negate_facet, #split_pairs, #split_repeated_pairs, #tri_value_array
#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, #object_global_id_facet, #only_project?, #only_project_or_less?, #paging_state, params, #permitted_params, #process_url_into_params, #project_id_facet, query_name, #raise_multiple_nested_queries, #raise_unregistered_nested_query, #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, #end_wildcard, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #no_terms?, referenced_klass, #referenced_klass, #referenced_klass_except, #referenced_klass_intersection, #referenced_klass_union, #start_and_end_wildcard, #start_wildcard, #table, #wildcard_pieces
Constructor Details
#initialize(query_params) ⇒ Filter
Returns a new instance of Filter.
358
359
360
361
362
363
364
365
366
367
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
413
414
415
416
417
418
419
420
421
422
423
|
# File 'lib/queries/taxon_name/filter.rb', line 358
def initialize(query_params)
super
@ancestors = boolean_param(params, :ancestors)
@ancestrify = boolean_param(params, :ancestrify)
@author = params[:author]
@author_exact = boolean_param(params, :author_exact)
@authors = boolean_param(params, :authors)
@availability = boolean_param(params, :availability)
@cached = params[:cached]
@collecting_event_id = params[:collecting_event_id]
@collection_object_id = params[:collection_object_id]
@combination_taxon_name_id = params[:combination_taxon_name_id]
@combinations = boolean_param(params, :combinations)
@combinationify = boolean_param(params, :combinationify)
@descendants = boolean_param(params, :descendants)
@descendants_max_depth = params[:descendants_max_depth]
@etymology = boolean_param(params, :etymology)
@epithet_only = params[:epithet_only]
@latinized = boolean_param(params, :latinized)
@geo_json = params[:geo_json]
@leaves = boolean_param(params, :leaves)
@name = params[:name]
@name_exact = boolean_param(params, :name_exact)
@nomenclature_date = boolean_param(params, :nomenclature_date)
@nomenclature_code = params[:nomenclature_code] if params[:nomenclature_code].present?
@nomenclature_group = params[:nomenclature_group] if params[:nomenclature_group].present?
@not_specified = boolean_param(params, :not_specified)
@otu_id = params[:otu_id]
@otus = boolean_param(params, :otus)
@original_combination = boolean_param(params, :original_combination)
@parent_id = params[:parent_id]
@rank = params[:rank]
@relation_to_relationship = params[:relation_to_relationship]
@sort = params[:sort]
@synonymify = boolean_param(params, :synonymify)
@taxon_name_author_id = params[:taxon_name_author_id]
@taxon_name_author_id_or = boolean_param(params, :taxon_name_author_id_or)
@taxon_name_classification = params[:taxon_name_classification] || []
@taxon_name_id = params[:taxon_name_id]
@taxon_name_relationship = params[:taxon_name_relationship] || []
@taxon_name_relationship_target = params[:taxon_name_relationship_target]
@taxon_name_relationship_type_subject =
params[:taxon_name_relationship_type_subject] || []
@taxon_name_relationship_type_object =
params[:taxon_name_relationship_type_object] || []
@taxon_name_relationship_type_either =
params[:taxon_name_relationship_type_either] || []
@taxon_name_type = params[:taxon_name_type]
@type_metadata = boolean_param(params, :type_metadata)
@validify = boolean_param(params, :validify)
@validity = boolean_param(params, :validity)
@verbatim_author = params[:verbatim_author]
@verbatim_name = boolean_param(params, :verbatim_name)
@year = params[:year]
@year_end = params[:year_end]
@year_start = params[:year_start]
set_confidences_params(params)
set_citations_params(params)
set_depiction_params(params)
set_notes_params(params)
set_data_attributes_params(params)
set_tags_params(params)
end
|
Instance Attribute Details
#ancestors ⇒ Boolean
Returns Ignored when taxon_name_id.empty? Works as AND clause with descendants :(.
83
84
85
|
# File 'lib/queries/taxon_name/filter.rb', line 83
def ancestors
@ancestors
end
|
#ancestrify ⇒ Object
!! This parameter is not like the others, it is applied POST result, see also synonymify and validify, etc.
89
90
91
|
# File 'lib/queries/taxon_name/filter.rb', line 89
def ancestrify
@ancestrify
end
|
#author ⇒ Object
135
136
137
|
# File 'lib/queries/taxon_name/filter.rb', line 135
def author
@author
end
|
#author_exact ⇒ Boolean
138
139
140
|
# File 'lib/queries/taxon_name/filter.rb', line 138
def author_exact
@author_exact
end
|
#authors ⇒ Object
['true' or 'false'] on initialize
whether the name has an author string, from any source, provided
275
276
277
|
# File 'lib/queries/taxon_name/filter.rb', line 275
def authors
@authors
end
|
#availability ⇒ Object
['true' or 'false'] on initialize
true if only available, false if only unavailable, nil if both
168
169
170
|
# File 'lib/queries/taxon_name/filter.rb', line 168
def availability
@availability
end
|
#cached ⇒ Array
Returns of TaxonNames matching cached exactly.
131
132
133
|
# File 'lib/queries/taxon_name/filter.rb', line 131
def cached
@cached
end
|
#collecting_event_id ⇒ Array
119
120
121
|
# File 'lib/queries/taxon_name/filter.rb', line 119
def collecting_event_id
@collecting_event_id
end
|
#collection_object_id ⇒ Array
98
99
100
|
# File 'lib/queries/taxon_name/filter.rb', line 98
def collection_object_id
@collection_object_id
end
|
#combination_taxon_name_id ⇒ Array
Returns taxon_name_ids for which all Combinations will be returned.
334
335
336
|
# File 'lib/queries/taxon_name/filter.rb', line 334
def combination_taxon_name_id
@combination_taxon_name_id
end
|
#combinationify ⇒ Object
!! This parameter is not like the others, it is applied POST result, see also synonymify and validify
111
112
113
|
# File 'lib/queries/taxon_name/filter.rb', line 111
def combinationify
@combinationify
end
|
#combinations ⇒ Object
This parameter should be used along side species or genus group limits.
105
106
107
|
# File 'lib/queries/taxon_name/filter.rb', line 105
def combinations
@combinations
end
|
#descendants ⇒ Boolean
Returns true - only descendants NOT SELF
false - self AND descendants
nil - ignored
Ignored when taxon_name_id.empty?.
205
206
207
|
# File 'lib/queries/taxon_name/filter.rb', line 205
def descendants
@descendants
end
|
#descendants_max_depth ⇒ Integer?
A positive integer indicating how many levels deep of descendants to retrieve.
Ignored when descentants is false/unspecified.
Defaults to nil
212
213
214
|
# File 'lib/queries/taxon_name/filter.rb', line 212
def descendants_max_depth
@descendants_max_depth
end
|
#epithet_only ⇒ Object
94
95
96
|
# File 'lib/queries/taxon_name/filter.rb', line 94
def epithet_only
@epithet_only
end
|
#etymology ⇒ Object
['true' or 'false'] on initialize
whether the name has etymology
270
271
272
|
# File 'lib/queries/taxon_name/filter.rb', line 270
def etymology
@etymology
end
|
#geo_json ⇒ Object
Returns the value of attribute geo_json.
343
344
345
|
# File 'lib/queries/taxon_name/filter.rb', line 343
def geo_json
@geo_json
end
|
#latinized ⇒ Boolean?
Returns &latinized=<"true"|"false">
if 'true' then return only genus group names with gender and species
group names with part of speech
if 'false' then return only genus group names without gender and
species group names without part of speech
if nil, ignore.
312
313
314
|
# File 'lib/queries/taxon_name/filter.rb', line 312
def latinized
@latinized
end
|
#leaves ⇒ Boolean?
TODO: inverse is duplicated in autocomplete
303
304
305
|
# File 'lib/queries/taxon_name/filter.rb', line 303
def leaves
@leaves
end
|
#name ⇒ Array
Returns Matches against cached. See also name_exact.
124
125
126
|
# File 'lib/queries/taxon_name/filter.rb', line 124
def name
@name
end
|
#name_exact ⇒ Boolean
127
128
129
|
# File 'lib/queries/taxon_name/filter.rb', line 127
def name_exact
@name_exact
end
|
#nomenclature_code ⇒ String?
Returns accessor for attr :nomenclature_code, wrap with needed wildcards.
296
297
298
|
# File 'lib/queries/taxon_name/filter.rb', line 296
def nomenclature_code
@nomenclature_code
end
|
#nomenclature_date ⇒ Boolean
Returns with/out cached nomenclature date set.
148
149
150
|
# File 'lib/queries/taxon_name/filter.rb', line 148
def nomenclature_date
@nomenclature_date
end
|
#nomenclature_group ⇒ String?
Returns accessor for attr :nomenclature_group, wrap with needed wildcards.
292
293
294
|
# File 'lib/queries/taxon_name/filter.rb', line 292
def nomenclature_group
@nomenclature_group
end
|
#not_specified ⇒ Object
287
288
289
|
# File 'lib/queries/taxon_name/filter.rb', line 287
def not_specified
@not_specified
end
|
#original_combination ⇒ Boolean?
Returns true - name has at least one element of original combination
false - name has no element of original combination
nil - ignored.
255
256
257
|
# File 'lib/queries/taxon_name/filter.rb', line 255
def original_combination
@original_combination
end
|
#otu_id ⇒ Array?
Returns one or more OTU ids.
260
261
262
|
# File 'lib/queries/taxon_name/filter.rb', line 260
def otu_id
@otu_id
end
|
#otus ⇒ Object
['true' or 'false'] on initialize
whether the name has an Otu
265
266
267
|
# File 'lib/queries/taxon_name/filter.rb', line 265
def otus
@otus
end
|
#parent_id ⇒ Object
Return the taxon names with this/these parent_ids
196
197
198
|
# File 'lib/queries/taxon_name/filter.rb', line 196
def parent_id
@parent_id
end
|
#rank ⇒ Array
341
342
343
|
# File 'lib/queries/taxon_name/filter.rb', line 341
def rank
@rank
end
|
#relation_to_relationship ⇒ String?
Returns &relation_to_relationship=<subject|object|either>
All names that are subject|object|either of any relationship.
244
245
246
|
# File 'lib/queries/taxon_name/filter.rb', line 244
def relation_to_relationship
@relation_to_relationship
end
|
#sort ⇒ String?
330
331
332
|
# File 'lib/queries/taxon_name/filter.rb', line 330
def sort
@sort
end
|
#synonymify ⇒ Object
!! This parameter is not like the others, it is applied POST result, see also combinationify and validify
218
219
220
|
# File 'lib/queries/taxon_name/filter.rb', line 218
def synonymify
@synonymify
end
|
#taxon_name_author_id ⇒ Array
319
320
321
|
# File 'lib/queries/taxon_name/filter.rb', line 319
def taxon_name_author_id
@taxon_name_author_id
end
|
#taxon_name_author_id_or ⇒ Boolean
325
326
327
|
# File 'lib/queries/taxon_name/filter.rb', line 325
def taxon_name_author_id_or
@taxon_name_author_id_or
end
|
#taxon_name_classification ⇒ Object
248
249
250
|
# File 'lib/queries/taxon_name/filter.rb', line 248
def taxon_name_classification
@taxon_name_classification
end
|
#taxon_name_id ⇒ Object
Return the taxon name(s) with this/these ids
190
191
192
|
# File 'lib/queries/taxon_name/filter.rb', line 190
def taxon_name_id
@taxon_name_id
end
|
#taxon_name_relationship ⇒ Object
Each entry must have a 'type'
Each entry must have one (and only one) of 'subject_taxon_name_id' or 'object_taxon_name_id'
Return all taxon names in a relationship of a given type and in relation to a another name. For example, return all synonyms of Aus bus.
226
227
228
|
# File 'lib/queries/taxon_name/filter.rb', line 226
def taxon_name_relationship
@taxon_name_relationship
end
|
#taxon_name_relationship_target ⇒ Boolean
Applies only to taxon_name_relationship_query_facet, is only present
in queries sent from Filter TaxonNameRelationship.
354
355
356
|
# File 'lib/queries/taxon_name/filter.rb', line 354
def taxon_name_relationship_target
@taxon_name_relationship_target
end
|
#taxon_name_relationship_type_either ⇒ Object
239
240
241
|
# File 'lib/queries/taxon_name/filter.rb', line 239
def taxon_name_relationship_type_either
@taxon_name_relationship_type_either
end
|
#taxon_name_relationship_type_object ⇒ Object
234
235
236
|
# File 'lib/queries/taxon_name/filter.rb', line 234
def taxon_name_relationship_type_object
@taxon_name_relationship_type_object
end
|
#taxon_name_relationship_type_subject ⇒ Object
230
231
232
|
# File 'lib/queries/taxon_name/filter.rb', line 230
def taxon_name_relationship_type_subject
@taxon_name_relationship_type_subject
end
|
#taxon_name_type ⇒ String?
Returns &taxon_name_type=<Protonym|Combination|Hybrid>.
316
317
318
|
# File 'lib/queries/taxon_name/filter.rb', line 316
def taxon_name_type
@taxon_name_type
end
|
['true' or 'false'] on initialize
whether the name has TypeMaterial
280
281
282
|
# File 'lib/queries/taxon_name/filter.rb', line 280
def type_metadata
@type_metadata
end
|
#validify ⇒ Boolean
name is returned
!! This param is not like the others. !!
175
176
177
|
# File 'lib/queries/taxon_name/filter.rb', line 175
def validify
@validify
end
|
#validity ⇒ Object
['true' or 'false'] on initialize
true if only valid, false if only invalid, nil if both
163
164
165
|
# File 'lib/queries/taxon_name/filter.rb', line 163
def validity
@validity
end
|
#verbatim_author ⇒ Object
179
180
181
|
# File 'lib/queries/taxon_name/filter.rb', line 179
def verbatim_author
@verbatim_author
end
|
#verbatim_name ⇒ Boolean
Returns if true then verbatim_name is populated.
184
185
186
|
# File 'lib/queries/taxon_name/filter.rb', line 184
def verbatim_name
@verbatim_name
end
|
#year ⇒ Object
Matches against cached_author_year.
143
144
145
|
# File 'lib/queries/taxon_name/filter.rb', line 143
def year
@year
end
|
#year_end ⇒ Object
Matches against cached_nomenclature_date
158
159
160
|
# File 'lib/queries/taxon_name/filter.rb', line 158
def year_end
@year_end
end
|
#year_start ⇒ Object
Matches against cached_nomenclature_date
153
154
155
|
# File 'lib/queries/taxon_name/filter.rb', line 153
def year_start
@year_start
end
|
Instance Method Details
#all(nil_empty = false) ⇒ ActiveRecord::Relation
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
|
# File 'lib/queries/taxon_name/filter.rb', line 1143
def all(nil_empty = false)
paging_state = disable_paging
q = super
q = ancestrify_result(q) if ancestrify
q = validify_result(q) if validify
q = combinationify_result(q) if combinationify
q = synonimify_result(q) if synonymify
if sort
q = order_clause(q)
paging_state[:ordered] = true
end
q = self.class.set_paging(q, paging_state)
q
end
|
#ancestor_facet ⇒ Scope
568
569
570
571
572
573
574
575
576
577
578
|
# File 'lib/queries/taxon_name/filter.rb', line 568
def ancestor_facet
return nil if taxon_name_id.empty? || !(ancestors == true)
ancestors_subquery = ::TaxonNameHierarchy.where(
::TaxonNameHierarchy.arel_table[:ancestor_id].eq(::TaxonName.arel_table[:id]).and(
::TaxonNameHierarchy.arel_table[:descendant_id].in(taxon_name_id)
)
)
::TaxonName.where(ancestors_subquery.arel.exists)
end
|
#ancestrify_result(q) ⇒ Object
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
|
# File 'lib/queries/taxon_name/filter.rb', line 1112
def ancestrify_result(q)
s = ::TaxonName
.with(tn_q4: q)
.joins('JOIN taxon_name_hierarchies tnh on tnh.ancestor_id = taxon_names.id')
.joins('JOIN tn_q4 ON tn_q4.id = tnh.descendant_id')
.distinct
.to_sql
::TaxonName.from('(' + s + ') as taxon_names')
end
|
#and_clauses ⇒ ActiveRecord::Relation
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
|
# File 'lib/queries/taxon_name/filter.rb', line 1016
def and_clauses
[
nomenclature_date_facet,
author_facet,
cached_facet,
name_facet,
parent_id_facet,
rank_facet,
taxon_name_type_facet,
validity_facet,
availability_facet,
verbatim_author_facet,
verbatim_name_facet,
with_nomenclature_code,
with_nomenclature_group,
year_facet,
]
end
|
#asserted_distribution_query_facet ⇒ Object
939
940
941
942
943
944
945
946
947
948
|
# File 'lib/queries/taxon_name/filter.rb', line 939
def asserted_distribution_query_facet
return nil if asserted_distribution_query.nil?
s = 'WITH query_ad_tn AS (' + asserted_distribution_query.all.to_sql + ') ' +
::TaxonName
.joins(:otus)
.joins("JOIN query_ad_tn ON query_ad_tn.asserted_distribution_object_id = otus.id AND query_ad_tn.asserted_distribution_object_type = 'Otu'")
.to_sql
::TaxonName.from('(' + s + ') as taxon_names').distinct
end
|
#author_facet ⇒ Object
837
838
839
840
841
842
843
844
|
# File 'lib/queries/taxon_name/filter.rb', line 837
def author_facet
return nil if author.blank?
if author_exact
table[:cached_author].eq(author.strip)
else
table[:cached_author].matches('%' + author.strip.gsub(/\s/, '%') + '%')
end
end
|
#authors_facet ⇒ Scope
This is not true! It includes records that are year only.
592
593
594
595
596
597
|
# File 'lib/queries/taxon_name/filter.rb', line 592
def authors_facet
return nil if authors.nil?
authors ?
::TaxonName.where.not(cached_author_year: nil) :
::TaxonName.where(cached_author_year: nil)
end
|
#availability_facet ⇒ Object
869
870
871
872
873
874
875
876
|
# File 'lib/queries/taxon_name/filter.rb', line 869
def availability_facet
return nil if availability.nil?
if availability
table[:cached_is_available].eq(true)
else
table[:cached_is_available].eq(false)
end
end
|
#biological_association_query_facet ⇒ Object
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
|
# File 'lib/queries/taxon_name/filter.rb', line 972
def biological_association_query_facet
return nil if biological_association_query.nil?
s = 'WITH query_tn_ba AS (' + biological_association_query.all.to_sql + ') '
a = ::TaxonName
.joins(:otus)
.joins("JOIN query_tn_ba as query_tn_ba1 on query_tn_ba1.biological_association_subject_id = otus.id AND query_tn_ba1.biological_association_subject_type = 'Otu'").to_sql
b = ::TaxonName
.joins(:otus)
.joins("JOIN query_tn_ba as query_tn_ba2 on query_tn_ba2.biological_association_object_id = otus.id AND query_tn_ba2.biological_association_object_type = 'Otu'").to_sql
s << ::TaxonName.from("((#{a}) UNION (#{b})) as taxon_names").to_sql
::TaxonName.from('(' + s + ') as taxon_names')
end
|
#cached_facet ⇒ Object
827
828
829
830
|
# File 'lib/queries/taxon_name/filter.rb', line 827
def cached_facet
return nil if cached.empty?
table[:cached].in(cached)
end
|
#collecting_event_id_facet ⇒ Object
903
904
905
906
907
908
|
# File 'lib/queries/taxon_name/filter.rb', line 903
def collecting_event_id_facet
return nil if collecting_event_id.empty?
::TaxonName
.joins(:collection_objects)
.where(collection_objects: { collecting_event_id: })
end
|
#collecting_event_query_facet ⇒ Object
961
962
963
964
965
966
967
968
969
970
|
# File 'lib/queries/taxon_name/filter.rb', line 961
def collecting_event_query_facet
return nil if collecting_event_query.nil?
s = 'WITH query_ce_tns AS (' + collecting_event_query.all.to_sql + ') ' +
::TaxonName
.joins(:collection_objects)
.joins('JOIN query_ce_tns as query_ce_tns1 on collection_objects.collecting_event_id = query_ce_tns1.id')
.to_sql
::TaxonName.from('(' + s + ') as taxon_names').distinct
end
|
#collection_object_id_facet ⇒ Object
580
581
582
583
|
# File 'lib/queries/taxon_name/filter.rb', line 580
def collection_object_id_facet
return nil if collection_object_id.empty?
::TaxonName.joins(:collection_objects).where(collection_objects: { id: collection_object_id })
end
|
#collection_object_query_facet ⇒ Object
950
951
952
953
954
955
956
957
958
959
|
# File 'lib/queries/taxon_name/filter.rb', line 950
def collection_object_query_facet
return nil if collection_object_query.nil?
s = 'WITH query_collection_objects AS (' + collection_object_query.all.to_sql + ') ' +
::TaxonName
.joins(:collection_objects)
.joins('JOIN query_collection_objects as query_collection_objects1 on collection_objects.id = query_collection_objects1.id')
.to_sql
::TaxonName.from('(' + s + ') as taxon_names').distinct
end
|
#combination_taxon_name_id_facet ⇒ Object
892
893
894
895
896
897
898
899
900
901
|
# File 'lib/queries/taxon_name/filter.rb', line 892
def combination_taxon_name_id_facet
return nil if combination_taxon_name_id.empty?
::Combination.joins(:related_taxon_name_relationships)
.where(
taxon_name_relationships: {
type: ::TAXON_NAME_RELATIONSHIP_COMBINATION_TYPES.values,
subject_taxon_name_id: combination_taxon_name_id,
},
).distinct
end
|
#combinationify_result(q) ⇒ Object
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
|
# File 'lib/queries/taxon_name/filter.rb', line 1100
def combinationify_result(q)
s = ::TaxonName
.with(tn_q3: q)
.joins('JOIN tn_q3 ON tn_q3.id = taxon_names.cached_valid_taxon_name_id')
.where("taxon_names.type = 'Combination'")
.to_sql
a = ::TaxonName.from('(' + s + ') as taxon_names').distinct
referenced_klass_union([q, a])
end
|
#combinations_facet ⇒ Object
910
911
912
913
914
915
916
917
918
|
# File 'lib/queries/taxon_name/filter.rb', line 910
def combinations_facet
return nil if combinations.nil?
a = ::Protonym.joins(:combination_relationships)
if combinations
a
else
referenced_klass_except(a)
end
end
|
#descendant_facet ⇒ Scope
Returns match only names that are a descendant of some taxon_name_id.
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
|
# File 'lib/queries/taxon_name/filter.rb', line 538
def descendant_facet
return nil if taxon_name_id.empty? || descendants.nil?
h = ::TaxonNameHierarchy.arel_table
if descendants
descendants_subquery = ::TaxonNameHierarchy.where(
h[:descendant_id].eq(::TaxonName.arel_table[:id]).and(
h[:ancestor_id].in(taxon_name_id)
)
).where(h[:ancestor_id].not_eq(h[:descendant_id]))
if descendants_max_depth.present?
descendants_subquery = descendants_subquery.where(::TaxonNameHierarchy.arel_table[:generations].lteq(descendants_max_depth.to_i))
end
::TaxonName.where(descendants_subquery.arel.exists)
else
q = ::TaxonName.joins('JOIN taxon_name_hierarchies ON taxon_name_hierarchies.descendant_id = taxon_names.id')
.where(taxon_name_hierarchies: {ancestor_id: taxon_name_id})
if descendants_max_depth.present?
q = q.where(::TaxonNameHierarchy.arel_table[:generations].lteq(descendants_max_depth.to_i))
end
q
end
end
|
#geo_json_facet ⇒ Object
494
495
496
497
498
499
500
501
502
503
|
# File 'lib/queries/taxon_name/filter.rb', line 494
def geo_json_facet
return nil if geo_json.nil?
otus = ::Queries::Otu::Filter.new(geo_json:).all
collection_objects = ::Queries::CollectionObject::Filter.new(geo_json:).all
a = ::TaxonName.joins(:taxon_taxon_determinations).where(taxon_determinations: { taxon_determination_object: collection_objects })
b = ::TaxonName.joins(:otus).where(otus:)
::TaxonName.from("((#{a.to_sql}) UNION (#{b.to_sql})) as taxon_names")
end
|
#latinized_facet ⇒ Scope
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
|
# File 'lib/queries/taxon_name/filter.rb', line 647
def latinized_facet
return nil if latinized.nil?
tnc = ::TaxonNameClassification.arel_table
if latinized == true
::TaxonName.where(
::TaxonNameClassification.where(
tnc[:taxon_name_id].eq(table[:id]).and(
tnc[:type].in(LATINIZED_TAXON_NAME_CLASSIFICATION_NAMES)
)
).arel.exists
)
else
::TaxonName
.where(
table[:rank_class].in(GENUS_AND_SPECIES_RANK_NAMES)
)
.where.not(
::TaxonNameClassification.where(
tnc[:taxon_name_id].eq(table[:id]).and(
tnc[:type].in(LATINIZED_TAXON_NAME_CLASSIFICATION_NAMES)
)
).arel.exists
)
end
end
|
#leaves_facet ⇒ Scope
641
642
643
644
|
# File 'lib/queries/taxon_name/filter.rb', line 641
def leaves_facet
return nil if leaves.nil?
leaves ? ::TaxonName.leaves : ::TaxonName.not_leaves
end
|
#merge_clauses ⇒ Object
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
|
# File 'lib/queries/taxon_name/filter.rb', line 1035
def merge_clauses
clauses = [
asserted_distribution_query_facet,
biological_association_query_facet,
collecting_event_query_facet,
collection_object_query_facet,
otu_query_facet,
sound_query_facet,
taxon_name_relationship_query_facet,
ancestor_facet,
authors_facet,
collecting_event_id_facet,
collection_object_id_facet,
combination_taxon_name_id_facet,
combinations_facet,
descendant_facet,
latinized_facet,
leaves_facet,
not_specified_facet,
original_combination_facet,
otu_id_facet,
otus_facet,
relation_to_relationship_facet,
taxon_name_author_id_facet,
taxon_name_classification_facet,
taxon_name_relationship_type_facet,
type_metadata_facet,
with_etymology_facet,
year_range_facet,
]
taxon_name_relationship.each do |hsh|
clauses << taxon_name_relationship_facet(hsh)
end
clauses.compact
end
|
#model_id_facet ⇒ Object
1075
1076
1077
1078
|
# File 'lib/queries/taxon_name/filter.rb', line 1075
def model_id_facet
return nil if taxon_name_id.empty? || !descendants.nil? || ancestors
table[:id].in(taxon_name_id)
end
|
#name_facet ⇒ Object
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
|
# File 'lib/queries/taxon_name/filter.rb', line 809
def name_facet
return nil if name.empty?
if name_exact
if (epithet_only)
table[:name].in(name)
else
table[:cached].in(name).or(table[:cached_original_combination].in(name))
end
else
if (epithet_only)
table[:name].matches_any(name.collect { |n| '%' + n.gsub(/\s+/, '%') + '%' })
else
table[:cached].matches_any(name.collect { |n| '%' + n.gsub(/\s+/, '%') + '%' }).or(table[:cached_original_combination].matches_any(name.collect { |n| '%' + n.gsub(/\s+/, '%') + '%' }))
end
end
end
|
#nomenclature_date_facet ⇒ Object
527
528
529
530
531
532
533
534
|
# File 'lib/queries/taxon_name/filter.rb', line 527
def nomenclature_date_facet
return nil if nomenclature_date.nil?
if nomenclature_date
table[:cached_nomenclature_date].not_eq(nil)
else
table[:cached_nomenclature_date].eq(nil)
end
end
|
#not_specified_facet ⇒ Object
505
506
507
508
509
510
511
512
513
514
515
516
|
# File 'lib/queries/taxon_name/filter.rb', line 505
def not_specified_facet
return nil if not_specified.nil?
if not_specified
::TaxonName.where(table[:cached].matches('%NOT SPECIFIED%').or(
table[:cached_original_combination].matches('%NOT SPECIFIED%')
))
else
::TaxonName.where(table[:cached].does_not_match('%NOT SPECIFIED%').and(
table[:cached_original_combination].does_not_match('%NOT SPECIFIED%')
))
end
end
|
#order_clause(query) ⇒ Object
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
|
# File 'lib/queries/taxon_name/filter.rb', line 1124
def order_clause(query)
case sort
when 'alphabetical'
::TaxonName.select('*').from(
query.order('taxon_names.cached'), :inner_query
)
when 'classification'
::TaxonName.select('*').from(
query
.joins('INNER JOIN taxon_name_hierarchies ON taxon_names.id = taxon_name_hierarchies.descendant_id')
.order('taxon_name_hierarchies.generations, taxon_name_hierarchies.ancestor_id, taxon_names.cached'),
:inner_query
)
else
query
end
end
|
#original_combination_facet ⇒ Object
518
519
520
521
522
523
524
525
|
# File 'lib/queries/taxon_name/filter.rb', line 518
def original_combination_facet
return nil if original_combination.nil?
if original_combination
::Protonym.joins(:original_combination_relationships).distinct
else
::Protonym.left_joins(:original_combination_relationships).where(taxon_name_relationships: {id: nil})
end
end
|
#otu_id_facet ⇒ Object
585
586
587
588
|
# File 'lib/queries/taxon_name/filter.rb', line 585
def otu_id_facet
return nil if otu_id.empty?
::TaxonName.joins(:otus).where(otus: { id: otu_id })
end
|
#otu_query_facet ⇒ Object
920
921
922
923
924
925
926
927
928
929
|
# File 'lib/queries/taxon_name/filter.rb', line 920
def otu_query_facet
return nil if otu_query.nil?
s = 'WITH query_otu_tn AS (' + otu_query.all.to_sql + ') ' +
::TaxonName
.joins(:otus)
.joins('JOIN query_otu_tn as query_otu_tn1 on otus.id = query_otu_tn1.id') .to_sql
::TaxonName.from('(' + s + ') as taxon_names').distinct
end
|
#otus_facet ⇒ Scope
778
779
780
781
782
|
# File 'lib/queries/taxon_name/filter.rb', line 778
def otus_facet
return nil if otus.nil?
subquery = ::Otu.where(::Otu.arel_table[:taxon_name_id].eq(::TaxonName.arel_table[:id])).arel.exists
::TaxonName.where(otus ? subquery : subquery.not)
end
|
#parent_id_facet ⇒ Object
832
833
834
835
|
# File 'lib/queries/taxon_name/filter.rb', line 832
def parent_id_facet
return nil if parent_id.empty?
table[:parent_id].in(parent_id)
end
|
#rank_facet ⇒ Arel::Nodes::Grouping?
791
792
793
794
795
796
|
# File 'lib/queries/taxon_name/filter.rb', line 791
def rank_facet
return nil if rank.blank?
r = rank.collect { |i| "%#{i}" }
table[:rank_class].matches_any(r)
end
|
#relation_to_relationship_facet ⇒ Scope
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
|
# File 'lib/queries/taxon_name/filter.rb', line 696
def relation_to_relationship_facet
return nil if relation_to_relationship.nil?
if relation_to_relationship == 'subject'
::TaxonName.with_taxon_name_relationships_as_subject.distinct
elsif relation_to_relationship == 'object'
::TaxonName.with_taxon_name_relationships_as_object.distinct
else
::TaxonName.joins('join taxon_name_relationships ON ' \
'taxon_names.id = taxon_name_relationships.subject_taxon_name_id OR ' \
'taxon_names.id = taxon_name_relationships.object_taxon_name_id'
).distinct
end
end
|
#sound_query_facet ⇒ Object
931
932
933
934
935
936
937
|
# File 'lib/queries/taxon_name/filter.rb', line 931
def sound_query_facet
return nil if sound_query.nil?
otus = otus_from_sound_query
return nil if otus.nil?
::TaxonName.joins(:otus).where(otus: {id: otus.select(:id)}).distinct
end
|
#synonimify_result(q) ⇒ Object
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
|
# File 'lib/queries/taxon_name/filter.rb', line 1089
def synonimify_result(q)
s = ::TaxonName
.with(tn_q2: q)
.joins('JOIN tn_q2 ON tn_q2.id = taxon_names.cached_valid_taxon_name_id')
.to_sql
a = ::TaxonName.from('(' + s + ') as taxon_names').distinct
referenced_klass_union([q, a])
end
|
#taxon_name_author_id_facet ⇒ Object
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
|
# File 'lib/queries/taxon_name/filter.rb', line 726
def taxon_name_author_id_facet
return nil if taxon_name_author_id.empty?
o = 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('TaxonName'))
.and(c[:type].eq('TaxonNameAuthor'))
)
e = c[:id].not_eq(nil)
f = c[:person_id].in(taxon_name_author_id)
b = b.where(e.and(f))
b = b.group(a['id'])
b = b.having(a['id'].count.eq(taxon_name_author_id.length)) unless taxon_name_author_id_or
b = b.as('tn_z1_')
::TaxonName.joins(Arel::Nodes::InnerJoin.new(b, Arel::Nodes::On.new(b['id'].eq(o['id']))))
end
|
#taxon_name_classification_facet ⇒ Scope
#taxon_name_relationship_facet(hsh) ⇒ Scope
Returns wrapped in descendant_facet!.
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
|
# File 'lib/queries/taxon_name/filter.rb', line 679
def taxon_name_relationship_facet(hsh)
hsh = hsh.symbolize_keys
param_key = hsh[:subject_taxon_name_id] ? :subject_taxon_name_id : :object_taxon_name_id
join_key = hsh[:subject_taxon_name_id] ? :object_taxon_name_id : :subject_taxon_name_id
::TaxonName.where(
::TaxonNameRelationship.where(
::TaxonNameRelationship.arel_table[join_key].eq(::TaxonName.arel_table[:id]).and(
::TaxonNameRelationship.arel_table[param_key].eq(hsh[param_key])
).and(
::TaxonNameRelationship.arel_table[:type].eq(hsh[:type])
)
).arel.exists
)
end
|
#taxon_name_relationship_query_facet ⇒ Object
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
|
# File 'lib/queries/taxon_name/filter.rb', line 989
def taxon_name_relationship_query_facet
return nil if taxon_name_relationship_query.nil?
a = nil
b = nil
if taxon_name_relationship_target == 'subject' ||
taxon_name_relationship_target.nil?
a = ::TaxonName
.with(tnr_query: taxon_name_relationship_query.all)
.joins(:taxon_name_relationships)
.where('taxon_name_relationships.id IN (SELECT id FROM tnr_query)')
.distinct
end
if taxon_name_relationship_target == 'object' ||
taxon_name_relationship_target.nil?
b = ::TaxonName
.with(tnr_query: taxon_name_relationship_query.all)
.joins(:related_taxon_name_relationships)
.where('taxon_name_relationships.id IN (SELECT id FROM tnr_query)')
.distinct
end
referenced_klass_union([a,b])
end
|
#taxon_name_relationship_type_facet ⇒ Scope
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
|
# File 'lib/queries/taxon_name/filter.rb', line 608
def taxon_name_relationship_type_facet
if taxon_name_relationship_type_subject.empty? &&
taxon_name_relationship_type_object.empty? &&
taxon_name_relationship_type_either.empty?
return nil
end
s = nil
o = nil
e = nil
if taxon_name_relationship_type_subject.present?
s = ::TaxonName.as_subject_with_taxon_name_relationship(
taxon_name_relationship_type_subject
).distinct
end
if taxon_name_relationship_type_object.present?
o = ::TaxonName.as_object_with_taxon_name_relationship(
taxon_name_relationship_type_object
).distinct
end
if taxon_name_relationship_type_either.present?
e = ::TaxonName.with_taxon_name_relationship(
taxon_name_relationship_type_either
)
end
referenced_klass_union([s, o, e])
end
|
#taxon_name_type_facet ⇒ Object
804
805
806
807
|
# File 'lib/queries/taxon_name/filter.rb', line 804
def taxon_name_type_facet
return nil if taxon_name_type.blank?
table[:type].eq(taxon_name_type)
end
|
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
|
# File 'lib/queries/taxon_name/filter.rb', line 755
def type_metadata_facet
return nil if type_metadata.nil?
type_material_exists = ::TypeMaterial
.where(::TypeMaterial.arel_table[:protonym_id].eq(::TaxonName.arel_table[:id]))
.arel.exists
typification_rel_exists = ::TaxonNameRelationship
.where(::TaxonNameRelationship.arel_table[:object_taxon_name_id].eq(::TaxonName.arel_table[:id]))
.where("taxon_name_relationships.type LIKE 'TaxonNameRelationship::Typification::%'")
.arel.exists
if type_metadata
::TaxonName.where(type_material_exists.or(typification_rel_exists))
else
::TaxonName.where(type_material_exists.not.and(typification_rel_exists.not))
end
end
|
#validify_result(q) ⇒ Object
1080
1081
1082
1083
1084
1085
1086
1087
|
# File 'lib/queries/taxon_name/filter.rb', line 1080
def validify_result(q)
s = ::TaxonName
.with(tn_q1: q)
.joins('JOIN tn_q1 ON tn_q1.cached_valid_taxon_name_id = taxon_names.id')
.to_sql
::TaxonName.from('(' + s + ') as taxon_names').distinct
end
|
#validity_facet ⇒ Object
860
861
862
863
864
865
866
867
|
# File 'lib/queries/taxon_name/filter.rb', line 860
def validity_facet
return nil if validity.nil?
if validity
table[:cached_is_valid].eq(true)
else
table[:cached_is_valid].eq(false)
end
end
|
#verbatim_author_facet ⇒ Object
878
879
880
881
|
# File 'lib/queries/taxon_name/filter.rb', line 878
def verbatim_author_facet
return nil if verbatim_author.blank?
table[:verbatim_author].eq(verbatim_author)
end
|
#verbatim_name_facet ⇒ Object
883
884
885
886
887
888
889
890
|
# File 'lib/queries/taxon_name/filter.rb', line 883
def verbatim_name_facet
return nil if verbatim_name.nil?
if verbatim_name
table[:verbatim_name].not_eq(nil)
else
table[:verbatim_name].eq(nil)
end
end
|
#with_etymology_facet ⇒ Scope
600
601
602
603
604
605
|
# File 'lib/queries/taxon_name/filter.rb', line 600
def with_etymology_facet
return nil if etymology.nil?
etymology ?
::TaxonName.where.not(etymology: nil) :
::TaxonName.where(etymology: nil)
end
|
#with_nomenclature_code ⇒ Arel::Nodes::Grouping?
799
800
801
802
|
# File 'lib/queries/taxon_name/filter.rb', line 799
def with_nomenclature_code
return nil if nomenclature_code.nil?
table[:rank_class].matches(nomenclature_code)
end
|
#with_nomenclature_group ⇒ Arel::Nodes::Grouping?
785
786
787
788
|
# File 'lib/queries/taxon_name/filter.rb', line 785
def with_nomenclature_group
return nil if nomenclature_group.blank?
table[:rank_class].matches(nomenclature_group)
end
|
#year_facet ⇒ Object
846
847
848
849
850
851
852
|
# File 'lib/queries/taxon_name/filter.rb', line 846
def year_facet
return nil if year.blank?
s = Date.new(@year.to_i)
e = Date.new(@year.to_i, 12, 31)
table[:cached_nomenclature_date].between(s..e)
end
|
#year_range_facet ⇒ Object
854
855
856
857
858
|
# File 'lib/queries/taxon_name/filter.rb', line 854
def year_range_facet
return nil if year_end.nil? && year_start.nil?
s, e = [year_start, year_end].compact
::TaxonName.where(cached_nomenclature_date: (s..e))
end
|