module Fzy

Overview

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

Extended Modules

Defined in:

fzy.cr
fzy/bonus.cr
fzy/hay.cr
fzy/match.cr
fzy/prepared_haystack.cr

Constant Summary

BonusProc = Proc(String, Array(Float32))
VERSION = {{ (`shards version /srv/crystaldoc.info/github-hugopl-fzy-v0.6.0/src`).strip.stringify }}

Instance Method Summary

Instance Method Detail

def 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.

[View source]
def search(needle : String, haystack : Enumerable(Hay(T)), *, store_positions : Bool = false) : Array(Match(T)) forall T #

[View source]
def 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

[View source]
def search(needle : String, haystack : Array(Match(T)), *, store_positions : Bool = false) : Array(Match(T)) forall T #

[View source]
def search(needle : String, haystack : Fzy::PreparedHaystack(T), *, store_positions : Bool = false) : Array(Match(T)) forall T #

[View source]