Class: Queries::Organization::Autocomplete

Inherits:
Query
  • Object
show all
Defined in:
lib/queries/organization/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_exact_id, #autocomplete_ordered_wildcard_pieces_in_cached, #autocomplete_start_date, #build_terms, #cached, #combine_or_clauses, #end_wildcard, #exactly_named, #fragments, #integers, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_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_cached, #with_cached_like, #with_id, #with_project_id, #with_start_date, #year_letter, #years

Constructor Details

- (Autocomplete) initialize(string)

Returns a new instance of Autocomplete



7
8
9
# File 'lib/queries/organization/autocomplete.rb', line 7

def initialize(string)
  super
end

Instance Method Details

- (Array) autocomplete

Returns TODO: optimize limits

Returns:

  • (Array)

    TODO: optimize limits



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/queries/organization/autocomplete.rb', line 29

def autocomplete
  queries = [
    autocomplete_identifier_cached_like,
    autocomplete_name_wildcard_end
  ]

  queries.compact!

  return [] if queries.nil?

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

- (Object) autocomplete_name_wildcard_end

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


22
23
24
25
# File 'lib/queries/organization/autocomplete.rb', line 22

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

- (Object) base_query



11
12
13
# File 'lib/queries/organization/autocomplete.rb', line 11

def base_query
  ::Organization.select('organizations.*')
end

- (Arel::Table) table

Returns:

  • (Arel::Table)


49
50
51
# File 'lib/queries/organization/autocomplete.rb', line 49

def table
  ::Organization.arel_table
end