Class: Queries::Source::Filter

Inherits:
Query
  • Object
show all
Defined in:
lib/queries/source/filter.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

- (ActiveRecord::Relation) all

Returns:

  • (ActiveRecord::Relation)


39
40
41
42
# File 'lib/queries/source/filter.rb', line 39

def all
  return ::Source.none.limit(0) if query_string.blank?
  ::Source.where(where_sql).limit(500).distinct.order(:cached)
end

- (ActiveRecord::Relation) by_project_all

Returns:

  • (ActiveRecord::Relation)


45
46
47
# File 'lib/queries/source/filter.rb', line 45

def by_project_all
  ::Source.where(where_sql).limit(500).distinct.order(:cached).joins(:project_sources).where(member_of_project_id.to_sql)
end

- (ActiveRecord::Relation?) fragment_year_matches

Returns if user provides 5 or fewer strings and any number of years look for any string && year

Returns:

  • (ActiveRecord::Relation, nil)

    if user provides 5 or fewer strings and any number of years look for any string && year



28
29
30
31
32
33
34
35
36
# File 'lib/queries/source/filter.rb', line 28

def fragment_year_matches
  if fragments.any?
    s = table[:cached].matches_any(fragments)
    s = s.and(table[:year].eq_any(years)) if !years.empty?
    s
  else
    nil
  end
end

- (Arel::Nodes::Equatity) member_of_project_id

Returns:

  • (Arel::Nodes::Equatity)


60
61
62
# File 'lib/queries/source/filter.rb', line 60

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

- (ActiveRecord::Relation) or_clauses

Returns:

  • (ActiveRecord::Relation)


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/queries/source/filter.rb', line 6

def or_clauses
  clauses = [
    only_ids,               # only intgers provided
    cached,                 # should hit titles when provided alone, unfragmented string matches
    fragment_year_matches   # keyword style ANDs years
  ].compact

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

- (Arel::Table) project_sources_table

Returns:

  • (Arel::Table)


55
56
57
# File 'lib/queries/source/filter.rb', line 55

def project_sources_table
  ::ProjectSource.arel_table
end

- (Arel::Table) table

Returns:

  • (Arel::Table)


50
51
52
# File 'lib/queries/source/filter.rb', line 50

def table
  ::Source.arel_table
end

- (String) where_sql

Returns:

  • (String)


21
22
23
24
# File 'lib/queries/source/filter.rb', line 21

def where_sql
  return ::Source.none if or_clauses.nil?
  or_clauses.to_sql
end