Class: Queries::Content::Filter

Inherits:
Query::Filter show all
Includes:
Queries::Concerns::Citations, Queries::Concerns::Depictions
Defined in:
lib/queries/content/filter.rb

Constant Summary collapse

PARAMS =
[
  :exact,
  :text,
  :topic_id,
  :otu_id,
  :content_id,
  topic_id: [],
  otu_id: [],
  content_id: [],
].freeze

Constants inherited from Query::Filter

Query::Filter::FILTER_QUERIES, Query::Filter::SUBQUERIES

Instance Attribute Summary collapse

Attributes inherited from Query::Filter

#api, #asserted_distribution_query, #biological_association_query, #biological_associations_graph_query, #collecting_event_query, #collection_object_query, #content_query, #controlled_vocabulary_term_query, #data_attribute_query, #descriptor_query, #document_query, #dwc_occurrence_query, #extract_query, #field_occurrence_query, #image_query, #loan_query, #object_global_id, #observation_query, #order_by, #otu_query, #page, #paginate, #params, #per, #person_query, #project_id, #recent, #recent_target, #taxon_name_query, #venn, #venn_mode

Attributes inherited from Query

#query_string, #terms

Instance Method Summary collapse

Methods inherited from Query::Filter

#all, #all_and_clauses, #all_merge_clauses, #annotator_and_clauses, #annotator_merge_clauses, annotator_params, api_except_params, api_excluded_params, #apply_venn, #attribute_exact_facet, base_filter, base_query_name, #deep_permit, included_annotator_facets, instatiated_base_filter, inverted_subqueries, #model_id_facet, #object_global_id_facet, params, #permitted_params, #process_url_into_params, #project_id_facet, query_name, #query_name, #set_nested_queries, #shared_and_clauses, #subquery_vector, #venn_query

Methods inherited from Query

#alphabetic_strings, #alphanumeric_strings, base_name, #base_name, #base_query, #build_terms, #cached_facet, #end_wildcard, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #no_terms?, referenced_klass, #referenced_klass, #referenced_klass_except, #referenced_klass_intersection, #referenced_klass_union, #start_and_end_wildcard, #start_wildcard, #table, #wildcard_pieces

Constructor Details

#initialize(query_params) ⇒ Filter

Returns a new instance of Filter.

Parameters:

  • args (Hash)


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/queries/content/filter.rb', line 35

def initialize(query_params)
  super
  @exact = boolean_param(params, :exact)
  @otu_id = params[:otu_id]
  @text = params[:text]
  @topic_id = params[:topic_id]
  @content_id = params[:content_id]

  set_citations_params(params)
  set_depiction_params(params)
end

Instance Attribute Details

#exactBoolean?

Returns:

  • (Boolean, nil)


20
21
22
# File 'lib/queries/content/filter.rb', line 20

def exact
  @exact
end

#otu_idArray

Parameters:

  • otu_id (Array, Integer, String, nil)

Returns:

  • (Array)


24
25
26
# File 'lib/queries/content/filter.rb', line 24

def otu_id
  @otu_id
end

#textString?

Returns text to match against.

Returns:

  • (String, nil)

    text to match against



32
33
34
# File 'lib/queries/content/filter.rb', line 32

def text
  @text
end

#topic_idArray

Parameters:

  • topic_id (Array, Integer, String, nil)

Returns:

  • (Array)


28
29
30
# File 'lib/queries/content/filter.rb', line 28

def topic_id
  @topic_id
end

Instance Method Details

#and_clausesObject



110
111
112
113
114
115
116
117
# File 'lib/queries/content/filter.rb', line 110

def and_clauses
  [
    content_id_facet,
    otu_id_facet,
    text_facet,
    topic_id_facet,
  ]
end

#content_idObject



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

def content_id
  [@content_id].flatten.compact
end

#content_id_facetArel::Node?

Returns:

  • (Arel::Node, nil)


76
77
78
79
# File 'lib/queries/content/filter.rb', line 76

def content_id_facet
  return nil if content_id.empty?
  table[:id].in(content_id)
end

#merge_clausesObject



119
120
121
122
123
124
# File 'lib/queries/content/filter.rb', line 119

def merge_clauses
  [
    otu_query_facet,
    taxon_name_query_facet,
  ]
end

#otu_id_facetArel::Node?

Returns:

  • (Arel::Node, nil)


70
71
72
73
# File 'lib/queries/content/filter.rb', line 70

def otu_id_facet
  return nil if otu_id.empty?
  table[:otu_id].in(otu_id)
end

#otu_query_facetObject



87
88
89
90
91
92
93
94
95
96
# File 'lib/queries/content/filter.rb', line 87

def otu_query_facet
  return nil if otu_query.nil?

  s = 'WITH query_otu_con AS (' + otu_query.all.to_sql + ') ' +
    ::Content
    .joins('JOIN query_otu_con as query_otu_con1 on contents.otu_id = query_otu_con1.id')
    .to_sql

  ::Content.from('(' + s + ') as contents')
end

#taxon_name_query_facetObject



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/queries/content/filter.rb', line 98

def taxon_name_query_facet
  return nil if taxon_name_query.nil?

  s = 'WITH query_tn_con AS (' + taxon_name_query.all.to_sql + ') ' +
    ::Content
    .joins(otu: [:taxon_name])
    .joins('JOIN query_tn_con as query_tn_con1 on taxon_names.id = query_tn_con1.id')
    .to_sql

  ::Content.from('(' + s + ') as contents')
end

#text_facetArel::Node?

Returns:

  • (Arel::Node, nil)


60
61
62
63
64
65
66
67
# File 'lib/queries/content/filter.rb', line 60

def text_facet
  return nil if text.blank?
  if exact
    table[:text].eq(text.strip)
  else
    table[:text].matches('%' + text.strip.gsub(/\s+/, '%') + '%')
  end
end

#topic_id_facetArel::Node?

Returns:

  • (Arel::Node, nil)


82
83
84
85
# File 'lib/queries/content/filter.rb', line 82

def topic_id_facet
  return nil if topic_id.empty?
  table[:topic_id].in(topic_id)
end