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

Parameters:

  • args (Hash)


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

def initialize(string)
  build_terms(string)
end

Instance Method Details

- (Scope) all

Returns:

  • (Scope)


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

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

- (String) build_terms(string)

Parameters:

  • string (String)

Returns:

  • (String)


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

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

- (Arel::Nodes::Matches) geographic_area_named

Returns:

  • (Arel::Nodes::Matches)


90
91
92
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 90

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

- (Arel::Table) geographic_area_table

Returns:

  • (Arel::Table)


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

def geographic_area_table
  GeographicArea.arel_table
end

- (Arel::Nodes::Matches) identified_by

Returns:

  • (Arel::Nodes::Matches)


85
86
87
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 85

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

- (Arel::Table) identifier_table

Returns:

  • (Arel::Table)


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

def identifier_table
  Identifier.arel_table
end

- (Arel::Table) table

Returns:

  • (Arel::Table)


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

def table
  CollectingEvent.arel_table
end

- (Array) terms

Returns:

  • (Array)


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

def terms
  @terms
end

- (Void) terms=(string)

Parameters:

  • string (String)

Returns:

  • (Void)


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

def terms=(string)
  build_terms(string)
end

- (String) where_sql

Returns:

  • (String)


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

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

- (Arel::Nodes::Matches) with_cached

Returns:

  • (Arel::Nodes::Matches)


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

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

- (Arel::Nodes::Equality) with_id

Returns:

  • (Arel::Nodes::Equality)


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

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

- (Arel::Nodes::Equality) with_verbatim_locality

Returns:

  • (Arel::Nodes::Equality)


80
81
82
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 80

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

- (Arel::Nodes::Equality) with_verbatim_trip_code

Returns:

  • (Arel::Nodes::Equality)


75
76
77
# File 'lib/queries/collecting_event_autocomplete_query.rb', line 75

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