Class: ActiveKit::Search::Suggestion

Inherits:
Object
  • Object
show all
Defined in:
lib/active_kit/search/suggestion.rb

Instance Method Summary collapse

Constructor Details

#initialize(current_class:, describer:) ⇒ Suggestion

Returns a new instance of Suggestion.



4
5
6
7
8
9
10
# File 'lib/active_kit/search/suggestion.rb', line 4

def initialize(current_class:, describer:)
  @redis = ActiveKit::Search.redis
  @current_class = current_class
  @describer = describer
  @current_class_name = current_class.to_s.parameterize.pluralize
  @describer_name = describer.name.to_s
end

Instance Method Details

#add(term:, score: 1, increment: true) ⇒ Object



12
13
14
15
# File 'lib/active_kit/search/suggestion.rb', line 12

def add(term:, score: 1, increment: true)
  command = ["FT.SUGADD", key, term, score, (increment ? 'INCR' : '')]
  @redis.call(command)
end

#del(term:) ⇒ Object



24
25
26
27
# File 'lib/active_kit/search/suggestion.rb', line 24

def del(term:)
  command = ["FT.SUGDEL", key, term]
  @redis.call(command)
end

#fetch(prefix:) ⇒ Object



17
18
19
20
21
22
# File 'lib/active_kit/search/suggestion.rb', line 17

def fetch(prefix:)
  command = ["FT.SUGGET", key, prefix, "FUZZY", "MAX", "10", "WITHSCORES"]
  results = @redis.call(command)

  SuggestionResult.new(prefix: prefix, results: results)
end

#lenObject



29
30
31
32
# File 'lib/active_kit/search/suggestion.rb', line 29

def len
  command = ["FT.SUGLEN", key]
  @redis.call(command)
end