Class: Queries::Content::Filter
  
  
  
  
  
    - Inherits:
- 
      Query::Filter
      
        
        show all
      
    
      - Includes:
- Queries::Concerns::Citations, Queries::Concerns::Confidences, 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 
Query::Filter::FILTER_QUERIES, Query::Filter::SUBQUERIES
  Instance Attribute Summary collapse
  
  
  
  
  #api, #asserted_distribution_query, #biological_association_query, #biological_associations_graph_query, #collecting_event_query, #collection_object_query, #content_query, #controlled_vocabulary_term_query, #conveyance_query, #data_attribute_query, #depiction_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, #roll_call, #sound_query, #taxon_name_query, #taxon_name_relationship_query, #venn, #venn_ignore_pagination, #venn_mode
  
  
  Attributes inherited from Query
  #query_string, #terms
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  
  
  
  #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, base_query_to_h, #deep_permit, #disable_paging, included_annotator_facets, instantiated_base_filter, inverted_subqueries, #model_id_facet, #object_global_id_facet, #only_project?, #paging_state, params, #permitted_params, #process_url_into_params, #project_id_facet, query_name, #set_nested_queries, #set_paging, set_paging, #shared_and_clauses, #subquery_vector, #target_and_clauses, #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.
   
 
  
    | 
36
37
38
39
40
41
42
43
44
45
46
47 | # File 'lib/queries/content/filter.rb', line 36
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_confidences_params(params) 
  set_citations_params(params)
  set_depiction_params(params)
end | 
 
  
 
  
    Instance Attribute Details
    
      
      
      
  
  
    #exact  ⇒ Boolean? 
  
  
  
  
    | 
21
22
23 | # File 'lib/queries/content/filter.rb', line 21
def exact
  @exact
end | 
 
    
      
      
      
  
  
    #otu_id  ⇒ Array 
  
  
  
  
    | 
25
26
27 | # File 'lib/queries/content/filter.rb', line 25
def otu_id
  @otu_id
end | 
 
    
      
      
      
  
  
    #text  ⇒ String? 
  
  
  
  
    
Returns text to match against.
   
 
  
    | 
33
34
35 | # File 'lib/queries/content/filter.rb', line 33
def text
  @text
end | 
 
    
      
      
      
  
  
    #topic_id  ⇒ Array 
  
  
  
  
    | 
29
30
31 | # File 'lib/queries/content/filter.rb', line 29
def topic_id
  @topic_id
end | 
 
    
   
  
    Instance Method Details
    
      
  
  
    #and_clauses  ⇒ Object 
  
  
  
  
    | 
112
113
114
115
116
117
118
119 | # File 'lib/queries/content/filter.rb', line 112
def and_clauses
  [
    content_id_facet,
    otu_id_facet,
    text_facet,
    topic_id_facet,
  ]
end | 
 
    
      
  
  
    #content_id  ⇒ Object 
  
  
  
  
    | 
57
58
59 | # File 'lib/queries/content/filter.rb', line 57
def content_id
  [@content_id].flatten.compact
end | 
 
    
      
  
  
    #content_id_facet  ⇒ Arel::Node? 
  
  
  
  
    | 
78
79
80
81 | # File 'lib/queries/content/filter.rb', line 78
def content_id_facet
  return nil if content_id.empty?
  table[:id].in(content_id)
end | 
 
    
      
  
  
    #merge_clauses  ⇒ Object 
  
  
  
  
    | 
121
122
123
124
125
126 | # File 'lib/queries/content/filter.rb', line 121
def merge_clauses
  [
    otu_query_facet,
    taxon_name_query_facet,
  ]
end | 
 
    
      
  
  
    #otu_id_facet  ⇒ Arel::Node? 
  
  
  
  
    | 
72
73
74
75 | # File 'lib/queries/content/filter.rb', line 72
def otu_id_facet
  return nil if otu_id.empty?
  table[:otu_id].in(otu_id)
end | 
 
    
      
  
  
    #otu_query_facet  ⇒ Object 
  
  
  
  
    | 
89
90
91
92
93
94
95
96
97
98 | # File 'lib/queries/content/filter.rb', line 89
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_facet  ⇒ Object 
  
  
  
  
    | 
100
101
102
103
104
105
106
107
108
109
110 | # File 'lib/queries/content/filter.rb', line 100
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_facet  ⇒ Arel::Node? 
  
  
  
  
    | 
62
63
64
65
66
67
68
69 | # File 'lib/queries/content/filter.rb', line 62
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_facet  ⇒ Arel::Node? 
  
  
  
  
    | 
84
85
86
87 | # File 'lib/queries/content/filter.rb', line 84
def topic_id_facet
  return nil if topic_id.empty?
  table[:topic_id].in(topic_id)
end |