Class: Georeference::Filter
- Inherits:
-
Queries::Query
- Object
- Queries::Query
- Georeference::Filter
- Defined in:
- lib/queries/georeference/filter.rb
Overview
TODO: Unify all and filter
Instance Attribute Summary collapse
-
#collecting_event_id ⇒ Object
Query variables.
-
#collecting_event_ids ⇒ Object
Query variables.
Attributes inherited from Queries::Query
#dynamic_limit, #options, #project_id, #query_string, #terms
Instance Method Summary collapse
- #all ⇒ ActiveRecord::Relation
- #and_clauses ⇒ ActiveRecord::Relation?
- #collecting_event_table ⇒ Object
-
#ids_for_collecting_events ⇒ Array
Of otu_id.
-
#initialize(params) ⇒ Filter
constructor
A new instance of Filter.
- #matching_collecting_event_id ⇒ Object
- #matching_collecting_event_ids ⇒ Object
- #merge_clauses ⇒ Object
- #table ⇒ Object
Methods inherited from Queries::Query
#alphabetic_strings, #alphanumeric_strings, #attribute_exact_facet, #autocomplete, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_common_name_exact, #autocomplete_common_name_like, #autocomplete_exact_id, #autocomplete_exactly_named, #autocomplete_named, #autocomplete_ordered_wildcard_pieces_in_cached, #build_terms, #cached, #combine_or_clauses, #common_name_name, #common_name_table, #common_name_wild_pieces, #end_wildcard, #exactly_named, #fragments, #integers, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #no_terms?, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #start_and_end_wildcard, #start_wildcard, #string_fragments, #wildcard_pieces, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #year_letter, #years
Constructor Details
#initialize(params) ⇒ Filter
Returns a new instance of Filter.
10 11 12 13 14 15 |
# File 'lib/queries/georeference/filter.rb', line 10 def initialize(params) params.reject! { |_k, v| v.blank? } @collecting_event_id = params[:collecting_event_id] @collecting_event_ids = [params[:collecting_event_ids]].flatten end |
Instance Attribute Details
#collecting_event_id ⇒ Object
Query variables
7 8 9 |
# File 'lib/queries/georeference/filter.rb', line 7 def collecting_event_id @collecting_event_id end |
#collecting_event_ids ⇒ Object
Query variables
7 8 9 |
# File 'lib/queries/georeference/filter.rb', line 7 def collecting_event_ids @collecting_event_ids end |
Instance Method Details
#all ⇒ ActiveRecord::Relation
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/queries/georeference/filter.rb', line 73 def all a = and_clauses b = merge_clauses if a && b b.where(a).distinct elsif a ::Georeference.where(a).distinct elsif b b.distinct else ::Georeference.all end end |
#and_clauses ⇒ ActiveRecord::Relation?
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/queries/georeference/filter.rb', line 42 def and_clauses clauses = [ matching_collecting_event_id, matching_collecting_event_ids, # Queries::Annotator.annotator_params(options, ::Citation), ].compact return nil if clauses.empty? a = clauses.shift clauses.each do |b| a = a.and(b) end a end |
#collecting_event_table ⇒ Object
21 22 23 |
# File 'lib/queries/georeference/filter.rb', line 21 def collecting_event_table ::CollectingEvent.arel_table end |
#ids_for_collecting_events ⇒ Array
Returns of otu_id.
37 38 39 |
# File 'lib/queries/georeference/filter.rb', line 37 def ids_for_collecting_events ([collecting_event_id] + collecting_event_ids).compact.uniq end |
#matching_collecting_event_id ⇒ Object
30 31 32 33 |
# File 'lib/queries/georeference/filter.rb', line 30 def matching_collecting_event_id a = collecting_event_id a.nil? ? nil : table[:collecting_event_id].eq(a) end |
#matching_collecting_event_ids ⇒ Object
25 26 27 28 |
# File 'lib/queries/georeference/filter.rb', line 25 def matching_collecting_event_ids a = ids_for_collecting_events a.empty? ? nil : table[:collecting_event_id].eq_any(a) end |
#merge_clauses ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/queries/georeference/filter.rb', line 58 def merge_clauses clauses = [ # matching_verbatim_author ].compact return nil if clauses.empty? a = clauses.shift clauses.each do |b| a = a.merge(b) end a end |
#table ⇒ Object
17 18 19 |
# File 'lib/queries/georeference/filter.rb', line 17 def table ::Georeference.arel_table end |