Class: Queries::CollectingEvent::Autocomplete

Inherits:
Query
  • Object
show all
Defined in:
lib/queries/collecting_event/autocomplete.rb

Instance Attribute Summary

Attributes inherited from Query

#dynamic_limit, #options, #project_id, #query_string, #terms

Instance Method Summary (collapse)

Methods inherited from Query

#alphabetic_strings, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_identifier_cached_exact, #autocomplete_identifier_cached_like, #autocomplete_ordered_wildcard_pieces_in_cached, #autocomplete_start_date, #build_terms, #cached, #combine_or_clauses, #end_wildcard, #exactly_named, #fragments, #identifier_table, #integers, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_cached, #named, #no_digits, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #simple_date, #start_and_end_wildcard, #start_wildcard, #wildcard_pieces, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_id, #with_identifier, #with_identifier_like, #with_project_id, #with_start_date, #year_letter, #years

Constructor Details

- (Autocomplete) initialize(string, project_id: nil)

Returns a new instance of Autocomplete



16
17
18
# File 'lib/queries/collecting_event/autocomplete.rb', line 16

def initialize(string, project_id: nil)
  super
end

Instance Method Details

- (Object) autocomplete



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/queries/collecting_event/autocomplete.rb', line 50

def autocomplete
  queries = [
    autocomplete_verbatim_trip_identifier_match,
    autocomplete_identifier_cached_exact,

    autocomplete_start_date_wild_card(:verbatim_locality), 
    autocomplete_start_date_wild_card(:cached),

    autocomplete_start_date,

    autocomplete_verbatim_locality_wildcard_end,
    autocomplete_verbatim_locality_wildcard_end_starting_year,
    autocomplete_cached_wildcard_anywhere,
    autocomplete_identifier_cached_like,


    # verbatim locality exact match (?) start date
    # ce_cached wildcard wrapped autocomplete start date
             # date (exact date)

  ].compact!

  return [] if queries.nil?
  updated_queries = []

  queries.each_with_index do |q ,i|
    a = q.where(project_id: project_id) if project_id
    a ||= q 
    updated_queries[i] = a
  end

  result = []
  updated_queries.each do |q|
    result += q.to_a
    result.uniq!
    break if result.count > 39 
  end
  result[0..39]
end

- (Object) autocomplete_start_date_wild_card(field = :verbatim_locality)



24
25
26
27
28
29
# File 'lib/queries/collecting_event/autocomplete.rb', line 24

def autocomplete_start_date_wild_card(field = :verbatim_locality) 
  a = with_start_date 
  b = fragments
  return nil if a.nil? || b.empty? || field.nil?
  base_query.where( a.and(table[field].matches(b.join)).to_sql).limit(20)
end

- (Object) autocomplete_verbatim_locality_wildcard_end



35
36
37
38
# File 'lib/queries/collecting_event/autocomplete.rb', line 35

def autocomplete_verbatim_locality_wildcard_end
  return nil if query_string.length < 7
  base_query.where( table[:verbatim_locality].matches(query_string + '%').to_sql).limit(20)
end

- (Object) autocomplete_verbatim_locality_wildcard_end_starting_year



40
41
42
43
44
45
46
47
48
# File 'lib/queries/collecting_event/autocomplete.rb', line 40

def autocomplete_verbatim_locality_wildcard_end_starting_year
  a = years 
  return nil if query_string.length < 7 || a.empty?
  base_query.where( 
                   table[:start_date_year].eq_any(a).
                   and( table[:verbatim_locality].matches(fragments.join))
    .to_sql)
    .limit(20)
end

- (Object) autocomplete_verbatim_trip_identifier_match



31
32
33
# File 'lib/queries/collecting_event/autocomplete.rb', line 31

def autocomplete_verbatim_trip_identifier_match
  base_query.where( table[:verbatim_trip_identifier].matches(query_string + '%').to_sql).limit(20)
end

- (Object) base_query



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

def base_query
  ::CollectingEvent.select('collecting_events.*')
end

- (Arel::Nodes::Matches) geographic_area_named

Returns:

  • (Arel::Nodes::Matches)


111
112
113
# File 'lib/queries/collecting_event/autocomplete.rb', line 111

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

- (Arel::Table) geographic_area_table

Returns:

  • (Arel::Table)


91
92
93
# File 'lib/queries/collecting_event/autocomplete.rb', line 91

def geographic_area_table
  ::GeographicArea.arel_table
end

- (Arel::Table) table

Returns:

  • (Arel::Table)


96
97
98
# File 'lib/queries/collecting_event/autocomplete.rb', line 96

def table
  ::CollectingEvent.arel_table
end

- (Arel::Nodes::Equality) with_verbatim_locality

Returns:

  • (Arel::Nodes::Equality)


106
107
108
# File 'lib/queries/collecting_event/autocomplete.rb', line 106

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

- (Arel::Nodes::Equality) with_verbatim_trip_code

Returns:

  • (Arel::Nodes::Equality)


101
102
103
# File 'lib/queries/collecting_event/autocomplete.rb', line 101

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