Class: Queries::CollectingEventAutocompleteQuery

Inherits:
Object
  • Object
show all
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 Method Summary (collapse)

Constructor Details

- (CollectingEventAutocompleteQuery) initialize(string)

Returns a new instance of CollectingEventAutocompleteQuery



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

def initialize(string)
  build_terms(string)
end

Instance Method Details

- (Object) all



34
35
36
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 34

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

- (Object) build_terms(string)



21
22
23
24
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 21

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



70
71
72
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 70

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

- (Object) geographic_area_table



38
39
40
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 38

def geographic_area_table 
  GeographicArea.arel_table
end

- (Object) identified_by



66
67
68
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 66

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

- (Object) identifier_table



42
43
44
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 42

def identifier_table
  Identifier.arel_table
end

- (Object) table



46
47
48
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 46

def table
  CollectingEvent.arel_table
end

- (Object) terms



26
27
28
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 26

def terms
  @terms
end

- (Object) terms=(string)



17
18
19
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 17

def terms=(string)
  build_terms(string)
end

- (Object) where_sql



30
31
32
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 30

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



54
55
56
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 54

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

- (Object) with_id



50
51
52
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 50

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

- (Object) with_verbatim_locality



62
63
64
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 62

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

- (Object) with_verbatim_trip_code



58
59
60
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 58

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