All Projects → sahilm → Fuzzy

sahilm / Fuzzy

Licence: mit
Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Fuzzy

Tntsearch
A fully featured full text search engine written in PHP
Stars: ✭ 2,693 (+175.08%)
Mutual labels:  fuzzy-search, fuzzy
Flexsearch
Next-Generation full text search library for Browser and Node.js
Stars: ✭ 8,108 (+728.19%)
Mutual labels:  fuzzy-search, fuzzy
Fz
Cli shell plugin, the missing fuzzy tab completion feature of z jump around command.
Stars: ✭ 359 (-63.33%)
Mutual labels:  fuzzy-search, fuzzy
Fzy.js
A javascript port of fzy's scoring algorithm. As seen on GitHub.com!
Stars: ✭ 82 (-91.62%)
Mutual labels:  fuzzy-search, fuzzy
Awgo
Go library for Alfred 3 + 4 workflows
Stars: ✭ 556 (-43.21%)
Mutual labels:  fuzzy-search, fuzzy
Leaderf
An efficient fuzzy finder that helps to locate files, buffers, mrus, gtags, etc. on the fly for both vim and neovim.
Stars: ✭ 1,733 (+77.02%)
Mutual labels:  fuzzy-search, fuzzy
Alfred Fuzzy
Fuzzy search helper for Alfred 3+ workflows
Stars: ✭ 67 (-93.16%)
Mutual labels:  fuzzy-search, fuzzy
Fzy
🔍 A simple, fast fuzzy finder for the terminal
Stars: ✭ 2,295 (+134.42%)
Mutual labels:  fuzzy-search, fuzzy
string-similarity-js
Lightweight string similarity function for javascript
Stars: ✭ 29 (-97.04%)
Mutual labels:  fuzzy-search, fuzzy
Kubectl Fzf
A fast kubectl autocompletion with fzf
Stars: ✭ 315 (-67.82%)
Mutual labels:  fuzzy-search
Fuzzysearch
🐷 Tiny and fast fuzzy search in Go
Stars: ✭ 602 (-38.51%)
Mutual labels:  fuzzy-search
Vue Fuse
Stars: ✭ 281 (-71.3%)
Mutual labels:  fuzzy-search
Ugrep
🔍NEW ugrep v3.1: ultra fast grep with interactive query UI and fuzzy search: search file systems, source code, text, binary files, archives (cpio/tar/pax/zip), compressed files (gz/Z/bz2/lzma/xz/lz4), documents and more. A faster, user-friendly and compatible grep replacement.
Stars: ✭ 626 (-36.06%)
Mutual labels:  fuzzy-search
Fuzzy
Spell checking and fuzzy search suggestion written in Go
Stars: ✭ 290 (-70.38%)
Mutual labels:  fuzzy
Fuse Swift
A lightweight fuzzy-search library, with zero dependencies
Stars: ✭ 767 (-21.65%)
Mutual labels:  fuzzy-search
Liquidmetal
💦🤘 A mimetic poly-alloy of the Quicksilver scoring algorithm, essentially LiquidMetal. </Schwarzenegger Voice>
Stars: ✭ 279 (-71.5%)
Mutual labels:  fuzzy-search
fzf-folds.vim
Vim plugin that lets you fuzzy search for folds in a file
Stars: ✭ 15 (-98.47%)
Mutual labels:  fuzzy-search
Minisearch
Tiny and powerful JavaScript full-text search engine for browser and Node
Stars: ✭ 737 (-24.72%)
Mutual labels:  fuzzy-search
Cassandra Lucene Index
Lucene based secondary indexes for Cassandra
Stars: ✭ 584 (-40.35%)
Mutual labels:  fuzzy-search
Pick
A fuzzy search tool for the command-line
Stars: ✭ 697 (-28.8%)
Mutual labels:  fuzzy-search

gopher looking for stuff gopher found stuff

fuzzy

Build Status Documentation

Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al. This library is external dependency-free. It only depends on the Go standard library.

Features

  • Intuitive matching. Results are returned in descending order of match quality. Quality is determined by:

    • The first character in the pattern matches the first character in the match string.
    • The matched character is camel cased.
    • The matched character follows a separator such as an underscore character.
    • The matched character is adjacent to a previous match.
  • Speed. Matches are returned in milliseconds. It's perfect for interactive search boxes.

  • The positions of matches are returned. Allows you to highlight matching characters.

  • Unicode aware.

Demo

Here is a demo of matching various patterns against ~16K files from the Unreal Engine 4 codebase.

demo

You can run the demo yourself like so:

cd _example/
go get github.com/jroimartin/gocui
go run main.go

Usage

The following example prints out matches with the matched chars in bold.

package main

import (
	"fmt"

	"github.com/sahilm/fuzzy"
)

func main() {
	const bold = "\033[1m%s\033[0m"
	pattern := "mnr"
	data := []string{"game.cpp", "moduleNameResolver.ts", "my name is_Ramsey"}

	matches := fuzzy.Find(pattern, data)

	for _, match := range matches {
		for i := 0; i < len(match.Str); i++ {
			if contains(i, match.MatchedIndexes) {
				fmt.Print(fmt.Sprintf(bold, string(match.Str[i])))
			} else {
				fmt.Print(string(match.Str[i]))
			}
		}
		fmt.Println()
	}
}

func contains(needle int, haystack []int) bool {
	for _, i := range haystack {
		if needle == i {
			return true
		}
	}
	return false
}

If the data you want to match isn't a slice of strings, you can use FindFrom by implementing the provided Source interface. Here's an example:

package main

import (
	"fmt"

	"github.com/sahilm/fuzzy"
)

type employee struct {
	name string
	age  int
}

type employees []employee

func (e employees) String(i int) string {
	return e[i].name
}

func (e employees) Len() int {
	return len(e)
}

func main() {
	emps := employees{
		{
			name: "Alice",
			age:  45,
		},
		{
			name: "Bob",
			age:  35,
		},
		{
			name: "Allie",
			age:  35,
		},
	}
	results := fuzzy.FindFrom("al", emps)
	for _, r := range results {
		fmt.Println(emps[r.Index])
	}
}

Check out the godoc for detailed documentation.

Installation

go get github.com/sahilm/fuzzy or use your favorite dependency management tool.

Speed

Here are a few benchmark results on a normal laptop.

BenchmarkFind/with_unreal_4_(~16K_files)-4         	     100	  12915315 ns/op
BenchmarkFind/with_linux_kernel_(~60K_files)-4     	      50	  30885038 ns/op

Matching a pattern against ~60K files from the Linux kernel takes about 30ms.

Contributing

Everyone is welcome to contribute. Please send me a pull request or file an issue. I promise to respond promptly.

Credits

  • @ericpauley & @lunixbochs contributed Unicode awareness and various performance optimisations.

  • The algorithm is based of the awesome work of forrestthewoods. See this blog post for details of the algorithm.

  • The artwork is by my lovely wife Sanah. It's based on the Go Gopher.

  • The Go gopher was designed by Renee French (http://reneefrench.blogspot.com/). The design is licensed under the Creative Commons 3.0 Attributions license.

License

The MIT License (MIT)

Copyright (c) 2017 Sahil Muthoo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].