Class: ActiveKit::Search::Searching
- Inherits:
-
Bedrock::Bedrocking
- Object
- Bedrock::Bedrocking
- ActiveKit::Search::Searching
- Defined in:
- lib/active_kit/search/searching.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#next_page ⇒ Object
readonly
Returns the value of attribute next_page.
-
#previous_page ⇒ Object
readonly
Returns the value of attribute previous_page.
Instance Method Summary collapse
- #add_attribute(name:, options:) ⇒ Object
- #attributes_present? ⇒ Boolean
- #clear(record: nil) ⇒ Object
- #drop ⇒ Object
- #fetch(**options) ⇒ Object
-
#initialize(describer:, current_class:) ⇒ Searching
constructor
A new instance of Searching.
- #next_page? ⇒ Boolean
- #previous_page? ⇒ Boolean
- #reload(record: nil) ⇒ Object
- #suggestions(prefix:) ⇒ Object
Constructor Details
#initialize(describer:, current_class:) ⇒ Searching
Returns a new instance of Searching.
6 7 8 9 10 11 12 |
# File 'lib/active_kit/search/searching.rb', line 6 def initialize(describer:, current_class:) super @index = Index.new(current_class: @current_class, describer: describer) @key = Key.new(index: @index, describer: describer) @suggestion = Suggestion.new(current_class: @current_class, describer: describer) end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
4 5 6 |
# File 'lib/active_kit/search/searching.rb', line 4 def current_page @current_page end |
#next_page ⇒ Object (readonly)
Returns the value of attribute next_page.
4 5 6 |
# File 'lib/active_kit/search/searching.rb', line 4 def next_page @next_page end |
#previous_page ⇒ Object (readonly)
Returns the value of attribute previous_page.
4 5 6 |
# File 'lib/active_kit/search/searching.rb', line 4 def previous_page @previous_page end |
Instance Method Details
#add_attribute(name:, options:) ⇒ Object
59 60 61 |
# File 'lib/active_kit/search/searching.rb', line 59 def add_attribute(name:, options:) @index.add_attribute_to_schema(name: name, options: ) end |
#attributes_present? ⇒ Boolean
63 64 65 |
# File 'lib/active_kit/search/searching.rb', line 63 def attributes_present? @index.schema.present? end |
#clear(record: nil) ⇒ Object
19 20 21 22 |
# File 'lib/active_kit/search/searching.rb', line 19 def clear(record: nil) record ? @key.clear(record: record) : @current_class.all.each { |rec| @key.clear(record: rec) } @index.reload end |
#drop ⇒ Object
44 45 46 47 48 49 |
# File 'lib/active_kit/search/searching.rb', line 44 def drop total_count = @index.fetch(offset: 0, limit: 0).count keys = @index.fetch(offset: 0, limit: total_count).keys @key.drop(keys: keys) @index.drop end |
#fetch(**options) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/active_kit/search/searching.rb', line 24 def fetch(**) search_result = @index.fetch(**) if search_result.keys.any? @suggestion.add(term: search_result.term) else @suggestion.del(term: search_result.term) end @current_page = search_result.current_page @previous_page = search_result.previous_page @next_page = search_result.next_page search_result end |
#next_page? ⇒ Boolean
55 56 57 |
# File 'lib/active_kit/search/searching.rb', line 55 def next_page? !!@next_page end |
#previous_page? ⇒ Boolean
51 52 53 |
# File 'lib/active_kit/search/searching.rb', line 51 def previous_page? !!@previous_page end |
#reload(record: nil) ⇒ Object
14 15 16 17 |
# File 'lib/active_kit/search/searching.rb', line 14 def reload(record: nil) record ? @key.reload(record: record) : @current_class.all.each { |rec| @key.reload(record: rec) } @index.reload end |
#suggestions(prefix:) ⇒ Object
40 41 42 |
# File 'lib/active_kit/search/searching.rb', line 40 def suggestions(prefix:) @suggestion.fetch(prefix: prefix) end |