Class: Queries::TaxonNameRelationship::Filter
- Inherits:
-
Query::Filter
show all
- Includes:
- Concerns::Citations, Concerns::Notes, Concerns::Verifiers, Helpers
- Defined in:
- lib/queries/taxon_name_relationship/filter.rb
Constant Summary
collapse
- PARAMS =
[
:ancestors,
:descendants,
:object_taxon_name_id,
:subject_taxon_name_id,
:taxon_name_id,
:taxon_name_relationship_set,
:taxon_name_relationship_type,
:taxon_name_relationship_id,
:taxon_name_subject_object,
object_taxon_name_id: [],
subject_taxon_name_id: [],
taxon_name_id: [],
taxon_name_relationship_id: [],
taxon_name_relationship_set: [],
taxon_name_relationship_type: [],
].freeze
Query::Filter::FILTER_QUERIES, Query::Filter::SUBQUERIES
Instance Attribute Summary collapse
#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
#query_string, #terms
Instance Method Summary
collapse
Methods included from Helpers
#boolean_param, #integer_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, 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
Returns a new instance of Filter.
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 75
def initialize(query_params)
super
@ancestors = boolean_param(params, :ancestors)
@descendants = boolean_param(params, :descendants)
@object_taxon_name_id = params[:object_taxon_name_id]
@subject_taxon_name_id = params[:subject_taxon_name_id]
@taxon_name_id = params[:taxon_name_id]
@taxon_name_relationship_set = params[:taxon_name_relationship_set]
@taxon_name_relationship_type = params[:taxon_name_relationship_type]
@taxon_name_relationship_id = params[:taxon_name_relationship_id]
@taxon_name_subject_object = params[:taxon_name_subject_object]
set_citations_params(params)
set_notes_params(params)
set_verifiers_params(params)
end
|
Instance Attribute Details
#ancestors ⇒ Object
30
31
32
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 30
def ancestors
@ancestors
end
|
#descendants ⇒ Object
34
35
36
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 34
def descendants
@descendants
end
|
#object_taxon_name_id ⇒ Object
Match all relationships where object is this ID
57
58
59
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 57
def object_taxon_name_id
@object_taxon_name_id
end
|
#subject_taxon_name_id ⇒ Object
Match all relationships where subject is this ID
52
53
54
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 52
def subject_taxon_name_id
@subject_taxon_name_id
end
|
#taxon_name_id ⇒ Object
43
44
45
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 43
def taxon_name_id
@taxon_name_id
end
|
#taxon_name_relationship_id ⇒ Object
37
38
39
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 37
def taxon_name_relationship_id
@taxon_name_relationship_id
end
|
#taxon_name_relationship_set ⇒ Object
See corresponding constants in config/intialize/constants/taxon_name_relationships.rb
66
67
68
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 66
def taxon_name_relationship_set
@taxon_name_relationship_set
end
|
#taxon_name_relationship_type ⇒ Object
47
48
49
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 47
def taxon_name_relationship_type
@taxon_name_relationship_type
end
|
#taxon_name_subject_object ⇒ Object
72
73
74
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 72
def taxon_name_subject_object
@taxon_name_subject_object
end
|
Instance Method Details
#ancestor_facet ⇒ Object
148
149
150
151
152
153
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 148
def ancestor_facet
return nil if taxon_name_id.empty? || !ancestors
names = ::Queries::TaxonName::Filter.new(taxon_name_id:, ancestors:).all
relationships_for_taxon_names_condition(names)
end
|
#and_clauses ⇒ Object
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 208
def and_clauses
[
ancestor_facet,
descendant_facet,
taxon_name_relationship_type_facet,
taxon_name_relationship_set_facet,
taxon_name_id_facet,
as_subject_facet,
as_object_facet,
]
end
|
#as_object_facet ⇒ ActiveRecord::Relation?
187
188
189
190
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 187
def as_object_facet
return nil if object_taxon_name_id.empty?
table[:object_taxon_name_id].in(object_taxon_name_id)
end
|
#as_subject_facet ⇒ ActiveRecord::Relation?
181
182
183
184
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 181
def as_subject_facet
return nil if subject_taxon_name_id.empty?
table[:subject_taxon_name_id].in(subject_taxon_name_id)
end
|
#descendant_facet ⇒ Object
155
156
157
158
159
160
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 155
def descendant_facet
return nil if taxon_name_id.empty? || descendants.nil?
names = ::Queries::TaxonName::Filter.new(taxon_name_id:, descendants:).all
relationships_for_taxon_names_condition(names)
end
|
#merge_clauses ⇒ Object
220
221
222
223
224
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 220
def merge_clauses
[
taxon_name_query_facet,
]
end
|
#relationship_types ⇒ Array
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 118
def relationship_types
return [] unless taxon_name_relationship_set && taxon_name_relationship_set.any?
t = []
taxon_name_relationship_set.each do |i|
t += ::STATUS_TAXON_NAME_RELATIONSHIP_NAMES if i == 'status'
t += ::TAXON_NAME_RELATIONSHIP_NAMES_SYNONYM if i == 'synonym'
t += ::TAXON_NAME_RELATIONSHIP_NAMES_CLASSIFICATION if i == 'classification'
t += ::TAXON_NAME_RELATIONSHIP_NAMES_MISSPELLING if i == 'misspelling'
end
t
end
|
#relationships_for_taxon_names_condition(taxon_names) ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 163
def relationships_for_taxon_names_condition(taxon_names)
if taxon_names.is_a?(ActiveRecord::Relation)
taxon_names = taxon_names.reselect(:id).arel
end
if taxon_name_subject_object == 'subject'
table[:subject_taxon_name_id].in(taxon_names)
elsif taxon_name_subject_object == 'object'
table[:object_taxon_name_id].in(taxon_names)
else
table[:subject_taxon_name_id].in(taxon_names)
.or(
table[:object_taxon_name_id].in(taxon_names)
)
end
end
|
#taxon_name_id_facet ⇒ Object
141
142
143
144
145
146
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 141
def taxon_name_id_facet
return nil if
taxon_name_id.empty? || !ancestors.nil? || !descendants.nil?
relationships_for_taxon_names_condition(taxon_name_id)
end
|
#taxon_name_query_facet ⇒ Object
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 192
def taxon_name_query_facet
return nil if taxon_name_query.nil?
a = ::TaxonNameRelationship
.with(tn_query: taxon_name_query.all)
.joins(:subject_taxon_name)
.where('taxon_name_relationships.subject_taxon_name_id IN (SELECT id FROM tn_query)')
b = ::TaxonNameRelationship
.with(tn_query: taxon_name_query.all)
.joins(:object_taxon_name)
.where('taxon_name_relationships.object_taxon_name_id IN (SELECT id FROM tn_query)')
referenced_klass_union([a,b])
end
|
#taxon_name_relationship_set_facet ⇒ Object
131
132
133
134
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 131
def taxon_name_relationship_set_facet
return nil unless taxon_name_relationship_set && taxon_name_relationship_set.any?
table[:type].in(relationship_types)
end
|
#taxon_name_relationship_type_facet ⇒ Object
136
137
138
139
|
# File 'lib/queries/taxon_name_relationship/filter.rb', line 136
def taxon_name_relationship_type_facet
return nil unless taxon_name_relationship_type && taxon_name_relationship_type.any?
table[:type].in(taxon_name_relationship_type)
end
|