Class: ActiveKit::Search::SuggestionResult

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix:, results:) ⇒ SuggestionResult

Returns a new instance of SuggestionResult.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/active_kit/search/suggestion_result.rb', line 6

def initialize(prefix:, results:)
  @prefix = prefix

  if results
    @documents = results.each_slice(2).map { |key, value| [key, value] }.to_h
    @keys = @documents.keys
    @scores = @documents.values
  else
    @documents = {}
    @keys = []
    @scores = []
  end
end

Instance Attribute Details

#documentsObject (readonly)

Returns the value of attribute documents.



4
5
6
# File 'lib/active_kit/search/suggestion_result.rb', line 4

def documents
  @documents
end

#keysObject (readonly)

Returns the value of attribute keys.



4
5
6
# File 'lib/active_kit/search/suggestion_result.rb', line 4

def keys
  @keys
end

#prefixObject (readonly)

Returns the value of attribute prefix.



4
5
6
# File 'lib/active_kit/search/suggestion_result.rb', line 4

def prefix
  @prefix
end

#scoresObject (readonly)

Returns the value of attribute scores.



4
5
6
# File 'lib/active_kit/search/suggestion_result.rb', line 4

def scores
  @scores
end