Class: Queries::Content::Filter
- Inherits:
-
Query
- Object
- Query
- Queries::Content::Filter
show all
- Includes:
- Queries::Concerns::Users
- Defined in:
- lib/queries/content/filter.rb
Instance Attribute Summary collapse
Attributes inherited from Query
#dynamic_limit, #options, #query_string, #terms
Instance Method Summary
collapse
Methods inherited from Query
#alphabetic_strings, #alphanumeric_strings, #attribute_exact_facet, #autocomplete, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_common_name_exact, #autocomplete_common_name_like, #autocomplete_exact_id, #autocomplete_exactly_named, #autocomplete_named, #autocomplete_ordered_wildcard_pieces_in_cached, #build_terms, #cached, #combine_or_clauses, #common_name_name, #common_name_table, #common_name_wild_pieces, #end_wildcard, #exactly_named, #fragments, #integers, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #no_terms?, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #start_and_end_wildcard, #start_wildcard, #string_fragments, #wildcard_pieces, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #year_letter, #years
Constructor Details
#initialize(params) ⇒ Filter
Returns a new instance of Filter.
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/queries/content/filter.rb', line 33
def initialize(params)
@topic_id = params[:topic_id]
@otu_id = params[:otu_id]
@project_id = params[:project_id]
@text = params[:text]
@exact = (params[:exact]&.downcase == 'true' ? true : false) if !params[:exact].nil?
@depictions = (params[:depictions]&.downcase == 'true' ? true : false) if !params[:depictions].nil?
@citations = (params[:citations]&.downcase == 'true' ? true : false) if !params[:citations].nil?
set_user_dates(params)
end
|
Instance Attribute Details
#citations ⇒ Boolean?
Returns true - only content with citations.
30
31
32
|
# File 'lib/queries/content/filter.rb', line 30
def citations
@citations
end
|
#depictions ⇒ Boolean?
Returns true - only content with depictions.
26
27
28
|
# File 'lib/queries/content/filter.rb', line 26
def depictions
@depictions
end
|
#exact ⇒ Boolean?
20
21
22
|
# File 'lib/queries/content/filter.rb', line 20
def exact
@exact
end
|
#otu_id ⇒ Array
13
14
15
|
# File 'lib/queries/content/filter.rb', line 13
def otu_id
@otu_id
end
|
#project_id ⇒ Array
17
18
19
|
# File 'lib/queries/content/filter.rb', line 17
def project_id
@project_id
end
|
#text ⇒ Object
22
23
24
|
# File 'lib/queries/content/filter.rb', line 22
def text
@text
end
|
#topic_id ⇒ Array
9
10
11
|
# File 'lib/queries/content/filter.rb', line 9
def topic_id
@topic_id
end
|
Instance Method Details
#all ⇒ ActiveRecord::Relation
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/queries/content/filter.rb', line 148
def all
a = and_clauses
b = merge_clauses
q = nil
if a && b
q = b.where(a)
elsif a
q = ::Content.includes(:otu, :topic).where(a)
elsif b
q = b
else
q = ::Content.includes(:otu, :topic).all
end
q
end
|
#and_clauses ⇒ ActiveRecord::Relation
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/queries/content/filter.rb', line 66
def and_clauses
clauses = [
text_facet,
topic_id_facet,
otu_id_facet,
project_id_facet,
].compact
a = clauses.shift
clauses.each do |b|
a = a.and(b)
end
a
end
|
#citations_facet ⇒ Arel::Node?
116
117
118
119
120
121
122
123
|
# File 'lib/queries/content/filter.rb', line 116
def citations_facet
return nil if citations.nil?
if citations
::Content.joins(:citations)
else
::Content.left_joins(:citations).where(citations: {id: nil})
end
end
|
#depictions_facet ⇒ Arel::Node?
106
107
108
109
110
111
112
113
|
# File 'lib/queries/content/filter.rb', line 106
def depictions_facet
return nil if depictions.nil?
if depictions
::Content.joins(:depictions)
else
::Content.left_joins(:depictions).where(depictions: {id: nil})
end
end
|
#merge_clauses ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/queries/content/filter.rb', line 131
def merge_clauses
clauses = [
depictions_facet,
citations_facet,
created_updated_facet, ].compact
return nil if clauses.empty?
a = clauses.shift
clauses.each do |b|
a = a.merge(b)
end
a
end
|
#otu_id_facet ⇒ Arel::Node?
92
93
94
95
|
# File 'lib/queries/content/filter.rb', line 92
def otu_id_facet
return nil if otu_id.empty?
table[:otu_id].eq_any(otu_id)
end
|
#project_id_facet ⇒ Arel::Node?
98
99
100
101
|
# File 'lib/queries/content/filter.rb', line 98
def project_id_facet
return nil if project_id.empty?
table[:project_id].eq_any(project_id)
end
|
#table ⇒ Arel::Table
61
62
63
|
# File 'lib/queries/content/filter.rb', line 61
def table
::Content.arel_table
end
|
#text_facet ⇒ Arel::Node?
82
83
84
85
86
87
88
89
|
# File 'lib/queries/content/filter.rb', line 82
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?
126
127
128
129
|
# File 'lib/queries/content/filter.rb', line 126
def topic_id_facet
return nil if topic_id.empty?
table[:topic_id].eq_any(topic_id)
end
|