Module: Queries::Concerns::Identifiers
- Extended by:
- ActiveSupport::Concern
- Includes:
- Helpers
- Included in:
- Queries::CollectingEvent::Filter, Queries::CollectionObject::Filter, Extract::Filter, Image::Filter, Query
- Defined in:
- lib/queries/concerns/identifiers.rb
Overview
Helpers for queries that reference Identifier
For filter queries: !! requires a `query_base` method !! requires `set_identifiers` be called in initialize()
See spec/lib/queries/collection_object/filter_spec.rb for existing spec tests
Instance Method Summary collapse
-
#autocomplete_identifier_cached_exact ⇒ Object
Autocomplete for tables referencing identifiers See lib/queries/identifiers/autocomplete for autocomplete for identifiers.
- #autocomplete_identifier_cached_like ⇒ Object
- #autocomplete_identifier_identifier_exact ⇒ Object
- #autocomplete_identifier_matching_cached_anywhere ⇒ Object
- #autocomplete_identifier_matching_cached_fragments_anywhere ⇒ Object
- #between ⇒ Object
- #cast ⇒ Object
- #identifier_between_facet ⇒ Object
- #identifier_facet ⇒ Object
- #identifier_namespace_facet ⇒ Object
- #identifier_table ⇒ Arel::Table
- #identifier_type_facet ⇒ Object
- #identifiers_facet ⇒ Object
- #query_base ⇒ Object private
- #set_identifier(params) ⇒ Object
- #substring ⇒ Object
- #with_identifier_cached ⇒ Arel::Nodes::Equality
- #with_identifier_cached_like_fragments ⇒ Arel::Nodes::Grouping
- #with_identifier_cached_wildcard_end ⇒ Arel::Nodes::Equality
- #with_identifier_cached_wildcarded ⇒ Arel::Nodes::Equality
- #with_identifier_identifier ⇒ Arel::Nodes::Equality
- #with_identifier_wildcard_end ⇒ Object
Methods included from Helpers
Instance Method Details
#autocomplete_identifier_cached_exact ⇒ Object
Autocomplete for tables referencing identifiers See lib/queries/identifiers/autocomplete for autocomplete for identifiers
May need to alter base query here
171 172 173 |
# File 'lib/queries/concerns/identifiers.rb', line 171 def autocomplete_identifier_cached_exact query_base.joins(:identifiers).where(with_identifier_cached.to_sql) end |
#autocomplete_identifier_cached_like ⇒ Object
179 180 181 |
# File 'lib/queries/concerns/identifiers.rb', line 179 def autocomplete_identifier_cached_like query_base.joins(:identifiers).where(with_identifier_cached_wildcarded.to_sql) end |
#autocomplete_identifier_identifier_exact ⇒ Object
175 176 177 |
# File 'lib/queries/concerns/identifiers.rb', line 175 def autocomplete_identifier_identifier_exact query_base.joins(:identifiers).where(with_identifier_identifier.to_sql) end |
#autocomplete_identifier_matching_cached_anywhere ⇒ Object
183 184 185 |
# File 'lib/queries/concerns/identifiers.rb', line 183 def autocomplete_identifier_matching_cached_anywhere query_base.joins(:identifiers).where(with_identifier_cached_wildcarded.to_sql) end |
#autocomplete_identifier_matching_cached_fragments_anywhere ⇒ Object
187 188 189 |
# File 'lib/queries/concerns/identifiers.rb', line 187 def autocomplete_identifier_matching_cached_fragments_anywhere query_base.joins(:identifiers).where(with_identifier_cached_like_fragments.to_sql) end |
#between ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/queries/concerns/identifiers.rb', line 75 def between Arel::Nodes::Between.new( cast, Arel::Nodes::And.new( [ Arel::Nodes::SqlLiteral.new(identifier_start), Arel::Nodes::SqlLiteral.new(identifier_end) ] ) ) end |
#cast ⇒ Object
67 68 69 |
# File 'lib/queries/concerns/identifiers.rb', line 67 def cast Arel::Nodes::NamedFunction.new('CAST', [substring]) end |
#identifier_between_facet ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/queries/concerns/identifiers.rb', line 121 def identifier_between_facet return nil if @identifier_start.nil? @identifier_end = @identifier_start if @identifier_end.nil? w = between w = w.and(identifier_table[:namespace_id].eq(namespace_id)) if namespace_id query_base.joins(:identifiers).where(w) end |
#identifier_facet ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/queries/concerns/identifiers.rb', line 96 def identifier_facet return nil if identifier.blank? q = query_base.joins(:identifiers) w = identifier_exact ? identifier_table[:cached].eq(identifier) : identifier_table[:cached].matches('%' + identifier + '%') w = w.and(identifier_table[:namespace_id].eq(namespace_id)) if namespace_id q.where(w) end |
#identifier_namespace_facet ⇒ Object
115 116 117 118 119 |
# File 'lib/queries/concerns/identifiers.rb', line 115 def identifier_namespace_facet return nil if namespace_id.blank? q = query_base.joins(:identifiers) q.where(identifier_table[:namespace_id].eq(namespace_id)) end |
#identifier_table ⇒ Arel::Table
63 64 65 |
# File 'lib/queries/concerns/identifiers.rb', line 63 def identifier_table ::Identifier.arel_table end |
#identifier_type_facet ⇒ Object
108 109 110 111 112 113 |
# File 'lib/queries/concerns/identifiers.rb', line 108 def identifier_type_facet return nil if identifier_type.empty? q = query_base.joins(:identifiers) w = identifier_table[:type].eq_any(identifier_type) q.where(w) end |
#identifiers_facet ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/queries/concerns/identifiers.rb', line 85 def identifiers_facet return nil if identifiers.nil? if identifiers query_base.joins(:identifiers).distinct else query_base.left_outer_joins(:identifiers) .where(identifiers: {id: nil}) .distinct end end |
#query_base ⇒ Object (private)
193 194 195 |
# File 'lib/queries/concerns/identifiers.rb', line 193 def query_base table.name.classify.safe_constantize end |
#set_identifier(params) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/queries/concerns/identifiers.rb', line 51 def set_identifier(params) @namespace_id = params[:namespace_id] @identifier_start = params[:identifier_start] @identifier_end = params[:identifier_end] @identifier = params[:identifier] @identifiers = boolean_param(params, :identifiers) @identifier_exact = boolean_param(params, :identifier_exact) @identifier_type = params[:identifier_type] || [] end |
#substring ⇒ Object
71 72 73 |
# File 'lib/queries/concerns/identifiers.rb', line 71 def substring Arel::Nodes::NamedFunction.new('SUBSTRING', [ identifier_table[:identifier], Arel::Nodes::SqlLiteral.new("'([\\d]{1,9})$'") ]).as('integer') end |
#with_identifier_cached ⇒ Arel::Nodes::Equality
137 138 139 |
# File 'lib/queries/concerns/identifiers.rb', line 137 def with_identifier_cached identifier_table[:cached].eq(query_string) end |
#with_identifier_cached_like_fragments ⇒ Arel::Nodes::Grouping
158 159 160 161 162 |
# File 'lib/queries/concerns/identifiers.rb', line 158 def with_identifier_cached_like_fragments a = [ start_and_end_wildcard ] a = a + wildcard_wrapped_integers identifier_table[:cached].matches_any(a) end |
#with_identifier_cached_wildcard_end ⇒ Arel::Nodes::Equality
146 147 148 |
# File 'lib/queries/concerns/identifiers.rb', line 146 def with_identifier_cached_wildcard_end identifier_table[:cached].matches(end_wildcard) end |
#with_identifier_cached_wildcarded ⇒ Arel::Nodes::Equality
151 152 153 |
# File 'lib/queries/concerns/identifiers.rb', line 151 def with_identifier_cached_wildcarded identifier_table[:cached].matches(start_and_end_wildcard) end |
#with_identifier_identifier ⇒ Arel::Nodes::Equality
132 133 134 |
# File 'lib/queries/concerns/identifiers.rb', line 132 def with_identifier_identifier identifier_table[:identifier].eq(query_string) end |
#with_identifier_wildcard_end ⇒ Object
141 142 143 |
# File 'lib/queries/concerns/identifiers.rb', line 141 def with_identifier_wildcard_end identifier_table[:identifier].matches(end_wildcard) end |