Class: Queries::GeographicArea::Filter
- Inherits:
-
Query::Filter
- Object
- Query
- Query::Filter
- Queries::GeographicArea::Filter
- Defined in:
- lib/queries/geographic_area/filter.rb
Constant Summary collapse
- PARAMS =
[ :containing_point, :geographic_area_id, :geographic_items, :name, geographic_area_id: [] ].freeze
Constants inherited from Query::Filter
Query::Filter::FILTER_QUERIES, Query::Filter::SUBQUERIES
Instance Attribute Summary collapse
- #containing_point ⇒ Object
-
#geographic_area_id ⇒ Object
Array.
- #geographic_items ⇒ Object
-
#name ⇒ Object
Array.
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, #data_attribute_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, #taxon_name_query, #venn, #venn_mode
Attributes inherited from Query
Instance Method Summary collapse
- #and_clauses ⇒ Object
- #containing_point_facet ⇒ Object
- #geographic_items_facet ⇒ Object
-
#initialize(query_params) ⇒ Filter
constructor
A new instance of Filter.
- #merge_clauses ⇒ Object
- #name_facet ⇒ Object
-
#project_id_facet ⇒ Object
Required, disable default facet.
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, included_annotator_facets, instantiated_base_filter, inverted_subqueries, #model_id_facet, #object_global_id_facet, #only_project?, params, #permitted_params, #process_url_into_params, query_name, #query_name, #set_nested_queries, #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.
35 36 37 38 39 40 |
# File 'lib/queries/geographic_area/filter.rb', line 35 def initialize(query_params) super @name = params[:name] @containing_point = params[:containing_point] @geographic_items = boolean_param(params, :geographic_items) end |
Instance Attribute Details
#containing_point ⇒ Object
27 28 29 |
# File 'lib/queries/geographic_area/filter.rb', line 27 def containing_point @containing_point end |
#geographic_area_id ⇒ Object
Returns Array.
21 22 23 |
# File 'lib/queries/geographic_area/filter.rb', line 21 def geographic_area_id @geographic_area_id end |
#geographic_items ⇒ Object
33 34 35 |
# File 'lib/queries/geographic_area/filter.rb', line 33 def geographic_items @geographic_items end |
#name ⇒ Object
Returns Array.
17 18 19 |
# File 'lib/queries/geographic_area/filter.rb', line 17 def name @name end |
Instance Method Details
#and_clauses ⇒ Object
76 77 78 |
# File 'lib/queries/geographic_area/filter.rb', line 76 def and_clauses [ name_facet ] end |
#containing_point_facet ⇒ Object
60 61 62 63 64 65 |
# File 'lib/queries/geographic_area/filter.rb', line 60 def containing_point_facet return nil if containing_point.nil? a = ::GeographicArea.joins(:geographic_items).where("ST_Contains(polygon::geometry, GeomFromEWKT('srid=4326;#{containing_point}'))") b = ::GeographicArea.joins(:geographic_items).where("ST_Contains(multi_polygon::geometry, GeomFromEWKT('srid=4326;#{containing_point}'))") referenced_klass_union([a,b]) end |
#geographic_items_facet ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/queries/geographic_area/filter.rb', line 67 def geographic_items_facet return nil if geographic_items.nil? if geographic_items ::GeographicArea.joins(:geographic_items) else ::GeographicArea.where.missing(:geographic_items) end end |
#merge_clauses ⇒ Object
80 81 82 83 84 85 |
# File 'lib/queries/geographic_area/filter.rb', line 80 def merge_clauses [ containing_point_facet, geographic_items_facet, ] end |
#name_facet ⇒ Object
55 56 57 58 |
# File 'lib/queries/geographic_area/filter.rb', line 55 def name_facet return nil if name.blank? table[:name].eq(name) end |
#project_id_facet ⇒ Object
Required, disable default facet
51 52 53 |
# File 'lib/queries/geographic_area/filter.rb', line 51 def project_id_facet nil end |