Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hugopl/fzy
A Crystal port of awesome Fzy project, a fuzzy finder algorithm.
https://github.com/hugopl/fzy
crystal fuzzy-search fzy
Last synced: 6 days ago
JSON representation
A Crystal port of awesome Fzy project, a fuzzy finder algorithm.
- Host: GitHub
- URL: https://github.com/hugopl/fzy
- Owner: hugopl
- License: mit
- Created: 2020-01-24T04:50:41.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-03-30T18:35:56.000Z (7 months ago)
- Last Synced: 2024-10-25T01:37:03.193Z (15 days ago)
- Topics: crystal, fuzzy-search, fzy
- Language: Crystal
- Homepage:
- Size: 88.9 KB
- Stars: 45
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - fzy - A Crystal port of awesome Fzy project fuzzy finder algorithm (Algorithms and Data structures)
README
# fzy.cr
![Build Status](https://github.com/hugopl/fzy/actions/workflows/ci.yml/badge.svg?branch=master)
A Crystal port of awesome [Fzy](https://github.com/jhawthorn/fzy) fuzzy finder algorithm.
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
fzy:
github: hugopl/fzy
```2. Run `shards install`
## Usage
```crystal
require "fzy"matches = Fzy.search("hey", %w(Hey Whatever Halley))
matches.each do |match|
puts "value: #{match.value}"
puts "score: #{match.score}"
puts " pos: #{match.positions.inspect}"
puts "index: #{match.index}"
end
```Should print
```
value: Hey
score: Infinity
pos: [0, 1, 2]
index: 0
value: Halley
score: 1.87
pos: [0, 4, 5]
index: 2
```If you need to do many searches on the same set of data you can speed up things by
using a prepared haystack.```crystal
require "fzy"haystack = %w(Hey Halley Whatever)
prepared_haystack = Fzy::PreparedHaystack.new(haystack)
matches = Fzy.search("hey", prepared_haystack)
matches.each do |match|
puts "value: #{match.value}"
puts "score: #{match.score}"
puts " pos: #{match.positions.inspect}"
end# Reusing the prepared haystack makes the search faster.
matches = Fzy.search("ho let's go!", prepared_haystack)
```## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## Contributors
- [Hugo Parente Lima](https://github.com/hugopl) - creator and maintainer