Module: Queries::Concerns::Citations

Overview

Helpers and facets for queries that reference Citations.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.merge_clausesObject



96
97
98
99
100
101
102
103
# File 'lib/queries/concerns/citations.rb', line 96

def self.merge_clauses
  [
    :citation_documents_facet,
    :citations_facet,
    :origin_citation_facet,
    :source_query_facet,
  ]
end

.paramsObject



7
8
9
10
11
12
13
# File 'lib/queries/concerns/citations.rb', line 7

def self.params
  [
    :citations,
    :citation_documents,
    :origin_citation
  ]
end

Instance Method Details

#citation_documents_facetObject



55
56
57
58
59
60
61
62
# File 'lib/queries/concerns/citations.rb', line 55

def citation_documents_facet
  return nil if citation_documents.nil?
  if citation_documents
    referenced_klass.joins(citations: [:documents])
  else
    referenced_klass.left_joins(citations: [source: [:documents]]).where('sources.id IS NOT null and documents.id is NULL')
  end
end

#citation_tableArel::Table

Returns:

  • (Arel::Table)


51
52
53
# File 'lib/queries/concerns/citations.rb', line 51

def citation_table
  ::Citation.arel_table
end

#citations_facetObject



64
65
66
67
68
69
70
71
72
# File 'lib/queries/concerns/citations.rb', line 64

def citations_facet
  return nil if citations.nil?

  if citations
    referenced_klass.joins(:citations)
  else
    referenced_klass.where.missing(:citations)
  end
end

#origin_citation_facetObject



74
75
76
77
78
79
80
81
82
# File 'lib/queries/concerns/citations.rb', line 74

def origin_citation_facet
  return nil if origin_citation.nil?

  if origin_citation
    referenced_klass.joins(:origin_citation)
  else
    referenced_klass.where.missing(:origin_citation)
  end
end

#set_citations_params(params) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/queries/concerns/citations.rb', line 41

def set_citations_params(params)
  @citation_documents = boolean_param(params, :citation_documents)
  @citations = boolean_param(params, :citations)
  @origin_citation = boolean_param(params, :origin_citation)

  # All params are Hash here
 @source_query = ::Queries::Source::Filter.new(params[:source_query]) if params[:source_query]
end

#source_query_facetObject



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/queries/concerns/citations.rb', line 84

def source_query_facet
  return nil if source_query.nil?
  s = 'WITH query_sources AS (' + source_query.all.to_sql + ')'

  s << ' ' + referenced_klass
  .joins(:citations)
  .joins('JOIN query_sources as query_sources1 on citations.source_id = query_sources1.id')
  .to_sql

  referenced_klass.from('(' + s + ') as ' + referenced_klass.name.tableize)
end