Class: Queries::TagAutocompleteQuery

Inherits:
Query
  • Object
show all
Defined in:
lib/queries/tag_autocomplete_query.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, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_identifier_cached_exact, #autocomplete_identifier_cached_like, #autocomplete_ordered_wildcard_pieces_in_cached, #autocomplete_start_date, #build_terms, #cached, #combine_or_clauses, #end_wildcard, #exactly_named, #fragments, #identifier_table, #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, #with_id, #with_identifier, #with_identifier_like, #with_project_id, #with_start_date, #year_letter, #years

Constructor Details

This class inherits a constructor from Queries::Query

Instance Method Details

- (Scope) all

Returns:

  • (Scope)


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

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

- (Arel::Nodes::Matches) keyword_definition_matches

Returns:

  • (Arel::Nodes::Matches)


46
47
48
# File 'lib/queries/tag_autocomplete_query.rb', line 46

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

- (Arel::Nodes::Matches) keyword_named

Returns:

  • (Arel::Nodes::Matches)


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

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

- (Arel::Table) keyword_table

Returns:

  • (Arel::Table)


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

def keyword_table
  Keyword.arel_table
end

- (Arel::Nodes::Grouping) or_clauses

Returns:

  • (Arel::Nodes::Grouping)


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

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

- (Arel::Table) table

Returns:

  • (Arel::Table)


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

def table
  Tag.arel_table
end

- (String) where_sql

Returns:

  • (String)


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

def where_sql
  with_project_id.and(or_clauses).to_sql
end