Class: Queries::Organization::Autocomplete

Inherits:
Query::Autocomplete show all
Defined in:
lib/queries/organization/autocomplete.rb

Instance Attribute Summary collapse

Attributes inherited from Query::Autocomplete

#dynamic_limit, #project_id, #query_string

Attributes inherited from Query

#query_string, #terms

Instance Method Summary collapse

Methods inherited from Query::Autocomplete

#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, #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, **params) ⇒ Autocomplete

Returns a new instance of Autocomplete.



12
13
14
15
16
# File 'lib/queries/organization/autocomplete.rb', line 12

def initialize(string, **params)
  @role_type = params[:role_type]

  super
end

Instance Attribute Details

#role_typeArray

Parameters:

  • limit_to_role (String, Array)

    any Role class, like ‘TaxonNameAuthor`, `SourceAuthor`, `SourceEditor`, `Collector`, etc.

Returns:

  • (Array)


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

def role_type
  @role_type
end

Instance Method Details

#autocompleteArray

Returns TODO: optimize limits.

Returns:

  • (Array)

    TODO: optimize limits



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/queries/organization/autocomplete.rb', line 34

def autocomplete
  queries = [
    autocomplete_identifier_cached_like,
    autocomplete_name_wildcard_end
  ]

  queries.compact!

  return [] if queries.nil?

  result = []
  queries.each do |q|
    if role_type.present?
      q = q.joins(:roles).where(role_match.to_sql)
    end
    result += q.to_a
    result.uniq!
    break if result.count > 39
  end
  result[0..39]
end

#autocomplete_name_wildcard_endObject



27
28
29
30
# File 'lib/queries/organization/autocomplete.rb', line 27

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

#role_matchArel::Nodes::Equatity

Returns:

  • (Arel::Nodes::Equatity)


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

def role_match
  roles_table[:type].in(role_type)
end