module

Fzy

This class should be used if you plan to do more than one search on the same haystack.

It's the same of doing collection.map { |e| Hay.new(e) }

haystack = %w(dog cat bat tiger)
prepared_haystack = PreparedHaystack.new(haystack)
Fzy.search(prepared_haystack).each do |match|
  puts "found #{match.value} with score #{match.score}"
end

Constants

BonusProc = Proc(String, Array(Float32))
VERSION = {{ (`shards version /tmp/tmp.EGgAfP/src/src`).strip.stringify }}

Instance methods

filepath_bonus(key : String) : Array(Float32)

Match bonus used when doign fzy search on file paths.

Add bonus when:

  • A slash matches.
  • A match after a _, -, ' ' or ..
  • A match after a case change.
Source
search(needle : String, haystack : Enumerable(Hay(T)), *, store_positions : Bool = false) : Array(Match(T)) forall T
Source
search(needle : String, haystack : Enumerable(String), *, store_positions : Bool = false) : Array(Match(String))

Search a needle in a haystack and returns an array of matches.

Note: If you plan to redo the search several times, consider using search(String, Enumerable(Hay(T))

results = Fzy.search("hey", %w(Hey Halley Whatever), store_positions: true)
results.each do |result|
  puts "value: #{result.value}"
  puts "score: #{result.score}"
  puts "  pos: #{result.positions.inspect}"
end
Source
search(needle : String, haystack : Array(Match(T)), *, store_positions : Bool = false) : Array(Match(T)) forall T
Source
search(needle : String, haystack : Fzy::PreparedHaystack(T), *, store_positions : Bool = false) : Array(Match(T)) forall T
Source

Nested types