Class: Queries::SourceAutocompleteQuery

Inherits:
Query
  • Object
show all
Includes:
Arel::Nodes
Defined in:
lib/queries/source_autocomplete_query.rb

Instance Attribute Summary

Attributes inherited from Query

#dynamic_limit, #project_id, #query_string, #terms

Instance Method Summary (collapse)

Methods inherited from Query

#build_terms, #end_wildcard, #identifier_table, #initialize, #integers, #named, #no_digits, #parent, #parent_child_join, #parent_child_where, #result, #scope, #start_and_end_wildcard, #start_wildcard, #strings, #wildcard_wrapped_integers, #with_id, #with_identifier_like, #with_project_id, #years

Constructor Details

This class inherits a constructor from Queries::Query

Instance Method Details

- (Array) all

!! needs major refactoring, thought

Returns:

  • (Array)


33
34
35
36
37
38
39
40
41
# File 'lib/queries/source_autocomplete_query.rb', line 33

def all 
  ( 
   [ Source.find_by_cached(query_string) ]  +
   Source.where(cached_full_match.and(year).to_sql).limit(5) +
   Source.where(with_id.to_sql).limit(5) +
   Source.where(cached.and(year).to_sql).limit(10) +
   Source.where(cached.to_sql).limit(20)  
  ).flatten.compact.uniq
end

- (Object) by_project_all



43
44
45
46
47
48
49
50
51
# File 'lib/queries/source_autocomplete_query.rb', line 43

def by_project_all
  ( 
   [ Source.joins(:project_sources).where(member_of_project_id.to_sql).find_by_cached(query_string) ]  +
   Source.joins(:project_sources).where(member_of_project_id.to_sql).where(cached_full_match.and(year).to_sql).limit(10) +
   Source.joins(:project_sources).where(member_of_project_id.to_sql).where(with_id.to_sql).limit(5) +
   Source.joins(:project_sources).where(member_of_project_id.to_sql).where(cached.and(year).to_sql).limit(10) +
   Source.joins(:project_sources).where(member_of_project_id.to_sql).where(cached.to_sql).limit(20)  
  ).flatten.compact.uniq
end

- (Object) cached



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

def cached
  table[:cached].matches_any(strings)
end

- (Object) cached_full_match



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

def cached_full_match
  if no_digits.blank?
    table[:id].eq('-1')
  else
    table[:cached].matches("%#{no_digits}%")
  end
end

- (Object) member_of_project_id



61
62
63
# File 'lib/queries/source_autocomplete_query.rb', line 61

def member_of_project_id
  project_sources_table[:project_id].eq(project_id)
end

- (Object) project_sources_table



57
58
59
# File 'lib/queries/source_autocomplete_query.rb', line 57

def project_sources_table
  ProjectSource.arel_table
end

- (Object) table



53
54
55
# File 'lib/queries/source_autocomplete_query.rb', line 53

def table
  Source.arel_table
end

- (Object) where_sql



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

def where_sql
  cached.or(with_id).to_sql
end

- (Object) year



15
16
17
18
19
20
21
# File 'lib/queries/source_autocomplete_query.rb', line 15

def year
  if !years.empty?
    table[:year].eq_any(years) 
  else
    table[:id].eq('-1').not
  end
end