Class: Queries::CollectingEventAutocompleteQuery

Inherits:
Object
  • Object
show all
Includes:
Arel::Nodes
Defined in:
lib/queries/collecting_event_autocomplete_query.rb

Overview

Presently, search by:

!! UPDATE THIS
 id
 cached (term, term[n], term[n]%)
 identifier#cached
 geographic_area#name (term, term%)

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (CollectingEventAutocompleteQuery) initialize(string)

Returns a new instance of CollectingEventAutocompleteQuery



15
16
17
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 15

def initialize(string)
  build_terms(string)
end

Instance Attribute Details

- (Object) terms

Returns the value of attribute terms



13
14
15
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 13

def terms
  @terms
end

Instance Method Details

- (Object) all



36
37
38
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 36

def all 
  CollectingEvent.includes(:geographic_area, :identifiers).where(where_sql).references(:geographic_areas, :identifiers).limit(40)
end

- (Object) build_terms(string)



23
24
25
26
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 23

def build_terms(string)
  string = string.to_s
  @terms ||= [string, "%#{string}", "%#{string}%", "%#{string}%"] + string.split(/\s/).collect{|t| [t, "#{t}%"]}.flatten 
end

- (Object) geographic_area_named



72
73
74
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 72

def geographic_area_named
  geographic_area_table[:name].matches_any(@terms)
end

- (Object) geographic_area_table



40
41
42
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 40

def geographic_area_table 
  GeographicArea.arel_table
end

- (Object) identified_by



68
69
70
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 68

def identified_by
  identifier_table[:cached].matches_any(@terms) 
end

- (Object) identifier_table



44
45
46
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 44

def identifier_table
  Identifier.arel_table
end

- (Object) table



48
49
50
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 48

def table
  CollectingEvent.arel_table
end

- (Object) where_sql



32
33
34
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 32

def where_sql
  with_id.or(identified_by).or(with_verbatim_locality).or(with_cached).or(geographic_area_named).to_sql
end

- (Object) with_cached



56
57
58
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 56

def with_cached
  table[:cached].matches_any(@terms)
end

- (Object) with_id



52
53
54
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 52

def with_id 
  table[:id].eq(@terms.first.to_i)
end

- (Object) with_verbatim_locality



64
65
66
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 64

def with_verbatim_locality
  table[:verbatim_locality].eq_any(@terms)
end

- (Object) with_verbatim_trip_code



60
61
62
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 60

def with_verbatim_trip_code
  table[:verbatim_trip_code].eq_any(@terms)
end