Class: Queries::Identifier::Autocomplete

Inherits:
Query
  • Object
show all
Defined in:
lib/queries/identifier/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_ordered_wildcard_pieces_in_cached, #autocomplete_start_date, #build_terms, #cached, #combine_or_clauses, #end_wildcard, #exactly_named, #fragments, #initialize, #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_project_id, #with_start_date, #year_letter, #years

Constructor Details

This class inherits a constructor from Queries::Query

Instance Method Details

- (Object) autocomplete



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/queries/identifier/autocomplete.rb', line 5

def autocomplete
  queries = [
    autocomplete_exact_identifier,
    autocomplete_exact_cached,
    autocomplete_matching_cached,
    autocomplete_matching_cached_anywhere
 ]

  queries.compact!

  updated_queries = []
  queries.each_with_index do |q ,i|
    a = q.where(with_project_id.to_sql) 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 > 29
  end
  result[0..29]
end

- (Object) autocomplete_exact_cached



40
41
42
# File 'lib/queries/identifier/autocomplete.rb', line 40

def autocomplete_exact_cached
  base_query.where(with_cached.to_sql).limit(2)
end

- (Object) autocomplete_exact_identifier



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

def autocomplete_exact_identifier
  base_query.where(with_identifier.to_sql).limit(15)
end

- (Object) autocomplete_matching_cached



44
45
46
# File 'lib/queries/identifier/autocomplete.rb', line 44

def autocomplete_matching_cached 
  base_query.where(with_identifier_wildcard_end).order('LENGTH(cached)').limit(20)
end

- (Object) autocomplete_matching_cached_anywhere



48
49
50
# File 'lib/queries/identifier/autocomplete.rb', line 48

def autocomplete_matching_cached_anywhere 
  base_query.where(with_identifier_wildcard_anywhere).order('LENGTH(cached)').limit(20)
end

- (Object) base_query



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

def base_query
  ::Identifier.select('identifiers.*')
end

- (Arel::Table) table

Returns:

  • (Arel::Table)


54
55
56
# File 'lib/queries/identifier/autocomplete.rb', line 54

def table
  ::Identifier.arel_table
end