Class: Queries::Loan::Autocomplete
  
  
  
  Instance Attribute Summary
  
  
  #dynamic_limit, #project_id, #query_string
  
  
  Attributes inherited from Query
  #query_string, #terms
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_common_name_exact, #autocomplete_common_name_like, #autocomplete_exact_id, #autocomplete_exactly_named, #autocomplete_named, #autocomplete_ordered_wildcard_pieces_in_cached, #cached_facet, #combine_or_clauses, #common_name_name, #common_name_table, #common_name_wild_pieces, #exactly_named, #fragments, #integers, #least_levenshtein, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #safe_integers, #scope, #string_fragments, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #year_letter, #years
  
  
  
  
  
  
  
  
  
  
  Methods inherited from Query
  #alphabetic_strings, #alphanumeric_strings, base_name, #base_name, #base_query, #build_terms, #cached_facet, #end_wildcard, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #no_terms?, referenced_klass, #referenced_klass, #referenced_klass_except, #referenced_klass_intersection, #referenced_klass_union, #start_and_end_wildcard, #start_wildcard, #table, #wildcard_pieces
  
  
  Constructor Details
  
    
  
  
    #initialize(string, project_id: nil)  ⇒ Autocomplete 
  
  
  
  
    
Returns a new instance of Autocomplete.
   
 
  
    | 
8
9
10 | # File 'lib/queries/loan/autocomplete.rb', line 8
def initialize(string, project_id: nil)
  super
end | 
 
  
 
  
    Instance Method Details
    
      
  
  
    #autocomplete  ⇒ Array 
  
  
  
  
    | 
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 | # File 'lib/queries/loan/autocomplete.rb', line 18
def autocomplete
  return [] if query_string.blank?
  queries = [
    autocomplete_recipient_email,
    autocomplete_exact_date_sent,
    autocomplete_exact_date_requested,
    autocomplete_exact_date_received,
    autocomplete_exact_id,
    autocomplete_identifier_identifier_exact,
    autocomplete_identifier_cached_like,
    autocomplete_identifier_matching_cached_fragments_anywhere,
    autocomplete_by_role
  ]
  queries.compact!
  updated_queries = []
  queries.each_with_index do |q,i|
    a = q
    a = q.where(project_id: project_id) if project_id.present?
    updated_queries[i] = a
  end
  result = []
  updated_queries.each do |q|
    result += q.to_a
    result.uniq!
    break if result.count > 19
  end
  result[0..40]
end | 
 
    
      
  
  
    #autocomplete_by_role  ⇒ Object 
  
  
  
  
    | 
71
72
73
74
75 | # File 'lib/queries/loan/autocomplete.rb', line 71
def autocomplete_by_role
  r = ::Person.arel_table
  o = r[:cached].matches('%' + query_string + '%')
  ::Loan.joins(:people).where(roles: { type: ['LoanRecipient', 'LoanSupervisor']}).where(o.to_sql)
end | 
 
    
      
  
  
    #autocomplete_exact_date_received  ⇒ Object 
  
  
  
  
    | 
66
67
68
69 | # File 'lib/queries/loan/autocomplete.rb', line 66
def autocomplete_exact_date_received
  o = table[:date_received].eq(query_string)
  ::Loan.where(o.to_sql)
end | 
 
    
      
  
  
    #autocomplete_exact_date_requested  ⇒ Object 
  
  
  
  
    | 
61
62
63
64 | # File 'lib/queries/loan/autocomplete.rb', line 61
def autocomplete_exact_date_requested
  o = table[:date_requested].eq(query_string)
  ::Loan.where(o.to_sql)
end | 
 
    
      
  
  
    #autocomplete_exact_date_sent  ⇒ Object 
  
  
  
  
    | 
56
57
58
59 | # File 'lib/queries/loan/autocomplete.rb', line 56
def autocomplete_exact_date_sent
  o = table[:date_sent].eq(query_string)
  ::Loan.where(o.to_sql)
end | 
 
    
      
  
  
    #autocomplete_recipient_email  ⇒ Object 
  
  
  
  
    | 
51
52
53
54 | # File 'lib/queries/loan/autocomplete.rb', line 51
def autocomplete_recipient_email
  o = table[:recipient_email].matches('%' + query_string + '%')
  ::Loan.where(o.to_sql)
end | 
 
    
      
  
  
    #where_sql  ⇒ String 
  
  
  
  
    | 
13
14
15 | # File 'lib/queries/loan/autocomplete.rb', line 13
def where_sql
  with_project_id.and(or_and).to_sql
end |