Class: Queries::SourceFilterQuery

Inherits:
Query
  • Object
show all
Includes:
Arel::Nodes
Defined in:
lib/queries/source_filter_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

- (ActiveRecord::Relation) all

Returns:

  • (ActiveRecord::Relation)


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

def all 
  Source.where(where_sql).limit(500).uniq.order(:cached)
end

- (ActiveRecord::Relation) by_project_all

Returns:

  • (ActiveRecord::Relation)


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

def by_project_all
  Source.where(where_sql).limit(500).uniq.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



29
30
31
32
33
34
35
36
37
# File 'lib/queries/source_filter_query.rb', line 29

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

- (Object) member_of_project_id



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

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

- (ActiveRecord::Relation) or_clauses

Returns:

  • (ActiveRecord::Relation)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/queries/source_filter_query.rb', line 7

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

- (Object) project_sources_table



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

def project_sources_table
  ProjectSource.arel_table
end

- (Object) table



49
50
51
# File 'lib/queries/source_filter_query.rb', line 49

def table
  Source.arel_table
end

- (String) where_sql

Returns:

  • (String)


23
24
25
# File 'lib/queries/source_filter_query.rb', line 23

def where_sql
  or_clauses.to_sql
end