Class: Queries::TagAutocompleteQuery

Inherits:
Query
  • Object
show all
Includes:
Arel::Nodes
Defined in:
lib/queries/tag_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, #cached, #end_wildcard, #exactly_named, #fragments, #identifier_table, #initialize, #integers, #named, #no_digits, #only_ids, #only_integers?, #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

- (Scope) all

Returns:

  • (Scope)


25
26
27
# File 'lib/queries/tag_autocomplete_query.rb', line 25

def all 
  Tag.includes(:keyword).where(where_sql).references(:keywords).merge(Keyword.order(:name)).limit(50)
end

- (Object) keyword_definition_matches



41
42
43
# File 'lib/queries/tag_autocomplete_query.rb', line 41

def keyword_definition_matches
  keyword_table[:definition].matches_any(terms)
end

- (Object) keyword_named



37
38
39
# File 'lib/queries/tag_autocomplete_query.rb', line 37

def keyword_named
  keyword_table[:name].matches_any(terms)
end

- (Object) keyword_table



29
30
31
# File 'lib/queries/tag_autocomplete_query.rb', line 29

def keyword_table
  Keyword.arel_table
end

- (Object) or_clauses



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/queries/tag_autocomplete_query.rb', line 10

def or_clauses
  clauses = [
    keyword_named,
    keyword_definition_matches, 
    with_id
  ].compact

  a = clauses.shift
  clauses.each do |b|
    a = a.or(b)
  end
  a
end

- (Object) table



33
34
35
# File 'lib/queries/tag_autocomplete_query.rb', line 33

def table
  Tag.arel_table
end

- (Object) where_sql



6
7
8
# File 'lib/queries/tag_autocomplete_query.rb', line 6

def where_sql
  with_project_id.and(or_clauses).to_sql
end