class Fzy::PreparedHaystack

Overview

This class should be used if you plan to do more than one search on the same haystack. It just cache some stuff making following searches faster.

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

Usually you never need to use any methods from this object, just create it and call Fzy.search.

NOTE This class DO NOT dup the haystack it receive in the constructor, storing just a reference to it, so if you change it without creating another PreparedHaystack you are going to get a undefined behavior.

Defined in:

fzy.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(haystack : Array(String)) #

Creates a new PreparedHaystack.


[View source]

Instance Method Detail

def bonus(index) : Array(Float32) #

Return the cached bonus for a haystack at given index.


[View source]
def haystack : Array(String) #

Return the same haystack used in the constructor


[View source]
def lower_haystack : Array(String) #

Cached lowercase version of #haystack.


[View source]
def search(needle : String) : Array(Match) #

[View source]