Module: Queries::Concerns::Citations
- Extended by:
- ActiveSupport::Concern
- Included in:
- AssertedDistribution::Filter, BiologicalAssociation::Filter, BiologicalAssociationsGraph::Filter, Queries::CollectingEvent::Filter, Queries::CollectionObject::Filter, Queries::Content::Filter, Descriptor::Filter, Extract::Filter, FieldOccurrence::Filter, Image::Filter, Observation::Filter, Otu::Filter, TaxonName::Filter
- Defined in:
- lib/queries/concerns/citations.rb
Overview
Helpers and facets for queries that reference Citations.
Class Method Summary collapse
Instance Method Summary collapse
- #citation_documents_facet ⇒ Object
- #citation_table ⇒ Arel::Table
- #citations_facet ⇒ Object
- #origin_citation_facet ⇒ Object
- #set_citations_params(params) ⇒ Object
- #source_query_facet ⇒ Object
Class Method Details
.merge_clauses ⇒ Object
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 |
.params ⇒ Object
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_facet ⇒ Object
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_table ⇒ Arel::Table
51 52 53 |
# File 'lib/queries/concerns/citations.rb', line 51 def citation_table ::Citation.arel_table end |
#citations_facet ⇒ Object
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_facet ⇒ Object
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_facet ⇒ Object
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 |