Class: HaveAPI::DocumentationSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/haveapi/documentation_search.rb,
lib/haveapi/documentation_search_index.rb

Defined Under Namespace

Modules: Helpers Classes: Index

Constant Summary collapse

LIMIT =
20
KIND_ORDER =
{ resource: 0, action: 1, parameter: 2 }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index:, query:) ⇒ DocumentationSearch

Returns a new instance of DocumentationSearch.



16
17
18
19
20
21
# File 'lib/haveapi/documentation_search.rb', line 16

def initialize(index:, query:)
  @index = index
  @query = query
  @needle = query.downcase
  @tokens = @needle.split(/[[:space:]]+/)
end

Class Method Details

.parameter_anchor(resource_path:, action_name:, direction:, parameter_name:, authentication: nil) ⇒ Object



11
12
13
14
# File 'lib/haveapi/documentation_search.rb', line 11

def self.parameter_anchor(resource_path:, action_name:, direction:, parameter_name:, authentication: nil)
  tuple = [authentication&.to_s, resource_path.map(&:to_s), action_name.to_s, direction.to_s, parameter_name.to_s]
  "parameter-#{JSON.generate(tuple).unpack1('H*')}"
end

Instance Method Details

#call ⇒ Object



23
24
25
26
27
# File 'lib/haveapi/documentation_search.rb', line 23

def call
  @matches = []
  records unless @tokens.empty?
  { query: @query, results: @matches.first(LIMIT).map(&:last), more: @matches.length > LIMIT }
end