Module: Caoutsearch::Search::SearchMethods
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/caoutsearch/search/search_methods.rb
Constant Summary collapse
- UNSCOPE_KEYS =
rubocop:disable Layout/HashAlignment
{ "search" => :@search_criteria, "search_criteria" => :@search_criteria, "limit" => :@current_limit, "per" => :@current_limit, "aggregate" => :@current_aggregations, "aggregations" => :@current_aggregations, "suggest" => :@current_suggestions, "suggestions" => :@current_suggestions, "context" => :@current_contexts, "order" => :@current_order, "page" => :@current_page, "offset" => :@current_offset, "fields" => :@current_fields, "source" => :@current_source }.freeze
Instance Attribute Summary collapse
-
#current_aggregations ⇒ Object
readonly
Returns the value of attribute current_aggregations.
-
#current_contexts ⇒ Object
readonly
Returns the value of attribute current_contexts.
-
#current_fields ⇒ Object
readonly
Returns the value of attribute current_fields.
-
#current_order ⇒ Object
readonly
Returns the value of attribute current_order.
-
#current_source ⇒ Object
readonly
Returns the value of attribute current_source.
-
#current_suggestions ⇒ Object
readonly
Returns the value of attribute current_suggestions.
Instance Method Summary collapse
- #aggregate ⇒ Object
- #aggregate!(*values) ⇒ Object
- #append ⇒ Object
- #append!(hash) ⇒ Object
- #context ⇒ Object
- #context!(*values) ⇒ Object
- #current_context?(name) ⇒ Boolean
- #current_limit ⇒ Object
- #current_offset ⇒ Object
- #current_page ⇒ Object
- #fields ⇒ Object (also: #returns)
- #fields!(*values) ⇒ Object
-
#find_criterion(key) ⇒ Object
Criteria handlers ————————————————————————.
- #has_criterion?(key) ⇒ Boolean
- #limit ⇒ Object (also: #per)
- #limit!(value) ⇒ Object
- #offset ⇒ Object
- #offset!(value) ⇒ Object
- #order ⇒ Object
- #order!(value) ⇒ Object
- #page ⇒ Object
- #page!(value) ⇒ Object
- #prepend ⇒ Object
- #prepend!(hash) ⇒ Object
- #search ⇒ Object
-
#search!(*values) ⇒ Object
Setters ————————————————————————.
-
#search_criteria ⇒ Object
Getters and predicates ————————————————————————.
- #search_criteria_keys ⇒ Object
- #source ⇒ Object (also: #with_sources)
- #source!(*values) ⇒ Object
- #suggest ⇒ Object
- #suggest!(values, **options) ⇒ Object
- #track_total_hits ⇒ Object
- #track_total_hits!(value = true) ⇒ Object
- #unscope ⇒ Object
-
#unscope!(key) ⇒ Object
rubocop:enable Layout/HashAlignment.
- #without_hits ⇒ Object
- #without_sources ⇒ Object
Instance Attribute Details
#current_aggregations ⇒ Object (readonly)
Returns the value of attribute current_aggregations.
8 9 10 |
# File 'lib/caoutsearch/search/search_methods.rb', line 8 def current_aggregations @current_aggregations end |
#current_contexts ⇒ Object (readonly)
Returns the value of attribute current_contexts.
8 9 10 |
# File 'lib/caoutsearch/search/search_methods.rb', line 8 def current_contexts @current_contexts end |
#current_fields ⇒ Object (readonly)
Returns the value of attribute current_fields.
8 9 10 |
# File 'lib/caoutsearch/search/search_methods.rb', line 8 def current_fields @current_fields end |
#current_order ⇒ Object (readonly)
Returns the value of attribute current_order.
8 9 10 |
# File 'lib/caoutsearch/search/search_methods.rb', line 8 def current_order @current_order end |
#current_source ⇒ Object (readonly)
Returns the value of attribute current_source.
8 9 10 |
# File 'lib/caoutsearch/search/search_methods.rb', line 8 def current_source @current_source end |
#current_suggestions ⇒ Object (readonly)
Returns the value of attribute current_suggestions.
8 9 10 |
# File 'lib/caoutsearch/search/search_methods.rb', line 8 def current_suggestions @current_suggestions end |
Instance Method Details
#aggregate ⇒ Object
45 46 47 |
# File 'lib/caoutsearch/search/search_methods.rb', line 45 def aggregate(...) spawn.aggregate!(...) end |
#aggregate!(*values) ⇒ Object
126 127 128 129 130 |
# File 'lib/caoutsearch/search/search_methods.rb', line 126 def aggregate!(*values) @current_aggregations ||= [] @current_aggregations += values.flatten self end |
#append ⇒ Object
79 80 81 |
# File 'lib/caoutsearch/search/search_methods.rb', line 79 def append(...) spawn.append!(...) end |
#append!(hash) ⇒ Object
162 163 164 165 |
# File 'lib/caoutsearch/search/search_methods.rb', line 162 def append!(hash) @append_hash = hash self end |
#context ⇒ Object
24 25 26 |
# File 'lib/caoutsearch/search/search_methods.rb', line 24 def context(...) spawn.context!(...) end |
#context!(*values) ⇒ Object
100 101 102 103 104 |
# File 'lib/caoutsearch/search/search_methods.rb', line 100 def context!(*values) @current_contexts ||= [] @current_contexts += values.flatten self end |
#current_context?(name) ⇒ Boolean
217 218 219 |
# File 'lib/caoutsearch/search/search_methods.rb', line 217 def current_context?(name) @current_contexts&.map(&:to_s)&.include?(name.to_s) end |
#current_limit ⇒ Object
203 204 205 |
# File 'lib/caoutsearch/search/search_methods.rb', line 203 def current_limit @current_limit&.to_i || 10 end |
#current_offset ⇒ Object
207 208 209 210 211 212 213 214 215 |
# File 'lib/caoutsearch/search/search_methods.rb', line 207 def current_offset if @current_offset @current_offset.to_i elsif @current_page (current_limit * (current_page - 1)) else 0 end end |
#current_page ⇒ Object
199 200 201 |
# File 'lib/caoutsearch/search/search_methods.rb', line 199 def current_page @current_page&.to_i || 1 end |
#fields ⇒ Object Also known as: returns
53 54 55 |
# File 'lib/caoutsearch/search/search_methods.rb', line 53 def fields(...) spawn.fields!(...) end |
#fields!(*values) ⇒ Object
140 141 142 143 144 |
# File 'lib/caoutsearch/search/search_methods.rb', line 140 def fields!(*values) @current_fields ||= [] @current_fields += values.flatten self end |
#find_criterion(key) ⇒ Object
Criteria handlers
223 224 225 226 227 228 |
# File 'lib/caoutsearch/search/search_methods.rb', line 223 def find_criterion(key) key = key.to_s search_criteria.find do |value| return value[key] if value.is_a?(Hash) && value.key?(key) end end |
#has_criterion?(key) ⇒ Boolean
230 231 232 233 234 235 |
# File 'lib/caoutsearch/search/search_methods.rb', line 230 def has_criterion?(key) key = key.to_s search_criteria.any? do |value| return true if value.is_a?(Hash) && value.key?(key) end end |
#limit ⇒ Object Also known as: per
36 37 38 |
# File 'lib/caoutsearch/search/search_methods.rb', line 36 def limit(...) spawn.limit!(...) end |
#limit!(value) ⇒ Object
116 117 118 119 |
# File 'lib/caoutsearch/search/search_methods.rb', line 116 def limit!(value) @current_limit = value self end |
#offset ⇒ Object
41 42 43 |
# File 'lib/caoutsearch/search/search_methods.rb', line 41 def offset(...) spawn.offset!(...) end |
#offset!(value) ⇒ Object
121 122 123 124 |
# File 'lib/caoutsearch/search/search_methods.rb', line 121 def offset!(value) @current_offset = value self end |
#order ⇒ Object
28 29 30 |
# File 'lib/caoutsearch/search/search_methods.rb', line 28 def order(...) spawn.order!(...) end |
#order!(value) ⇒ Object
106 107 108 109 |
# File 'lib/caoutsearch/search/search_methods.rb', line 106 def order!(value) @current_order = value self end |
#page ⇒ Object
32 33 34 |
# File 'lib/caoutsearch/search/search_methods.rb', line 32 def page(...) spawn.page!(...) end |
#page!(value) ⇒ Object
111 112 113 114 |
# File 'lib/caoutsearch/search/search_methods.rb', line 111 def page!(value) @current_page = value self end |
#prepend ⇒ Object
75 76 77 |
# File 'lib/caoutsearch/search/search_methods.rb', line 75 def prepend(...) spawn.prepend!(...) end |
#prepend!(hash) ⇒ Object
157 158 159 160 |
# File 'lib/caoutsearch/search/search_methods.rb', line 157 def prepend!(hash) @prepend_hash = hash self end |
#search ⇒ Object
20 21 22 |
# File 'lib/caoutsearch/search/search_methods.rb', line 20 def search(...) spawn.search!(...) end |
#search!(*values) ⇒ Object
Setters
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/caoutsearch/search/search_methods.rb', line 89 def search!(*values) values = values.flatten.filter_map do |value| value = value.stringify_keys if value.is_a?(Hash) value end @search_criteria ||= [] @search_criteria += values self end |
#search_criteria ⇒ Object
Getters and predicates
195 196 197 |
# File 'lib/caoutsearch/search/search_methods.rb', line 195 def search_criteria @search_criteria ||= [] end |
#search_criteria_keys ⇒ Object
237 238 239 240 241 |
# File 'lib/caoutsearch/search/search_methods.rb', line 237 def search_criteria_keys search_criteria.each_with_object([]) do |criterion, keys| keys.concat(criterion.keys) if criterion.is_a?(Hash) end end |
#source ⇒ Object Also known as: with_sources
58 59 60 |
# File 'lib/caoutsearch/search/search_methods.rb', line 58 def source(...) spawn.source!(...) end |
#source!(*values) ⇒ Object
146 147 148 149 150 |
# File 'lib/caoutsearch/search/search_methods.rb', line 146 def source!(*values) @current_source ||= [] @current_source += values.flatten self end |
#suggest ⇒ Object
49 50 51 |
# File 'lib/caoutsearch/search/search_methods.rb', line 49 def suggest(...) spawn.suggest!(...) end |
#suggest!(values, **options) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/caoutsearch/search/search_methods.rb', line 132 def suggest!(values, **) raise ArgumentError unless values.is_a?(Hash) @current_suggestions ||= [] @current_suggestions << [values, ] self end |
#track_total_hits ⇒ Object
71 72 73 |
# File 'lib/caoutsearch/search/search_methods.rb', line 71 def track_total_hits(...) spawn.track_total_hits!(...) end |
#track_total_hits!(value = true) ⇒ Object
152 153 154 155 |
# File 'lib/caoutsearch/search/search_methods.rb', line 152 def track_total_hits!(value = true) @track_total_hits = value self end |
#unscope ⇒ Object
83 84 85 |
# File 'lib/caoutsearch/search/search_methods.rb', line 83 def unscope(...) spawn.unscope!(...) end |
#unscope!(key) ⇒ Object
rubocop:enable Layout/HashAlignment
186 187 188 189 190 191 |
# File 'lib/caoutsearch/search/search_methods.rb', line 186 def unscope!(key) raise ArgumentError unless (variable = UNSCOPE_KEYS[key.to_s]) reset_variable(variable) self end |
#without_hits ⇒ Object
67 68 69 |
# File 'lib/caoutsearch/search/search_methods.rb', line 67 def without_hits spawn.source!(false).limit!(0) end |
#without_sources ⇒ Object
63 64 65 |
# File 'lib/caoutsearch/search/search_methods.rb', line 63 def without_sources spawn.source!(false) end |