https://github.com/ukushu/Ifrit.git
[email protected]:ukushu/Ifrit.git
Ifrit is a super lightweight library which provides a simple way to do fuzzy searching.
This repository is based on archived repository Fuze-Swift by ( https://github.com/krisk/fuse-swift)
+ Fuze-Swift support Pods and Packages :)
- Ifrit supports only Packages :(
- Fuze-Swift is dead :(
+ Ifrit is live :)
- Fuze-Swift have threading issue - crashes is possible :(
+ Ifrit is a Fuze-Swift with fixed Threading issues - no crashes :)
- Fuze-Swift written for xcode 11 and have warnings :(
+ Ifrit code is updated to swift 5 standards and there are no build warnings :)
+ Ifrit have refactored end extended tests :)
let fuse = Fuse()
let result = fuse.search("od mn war", in: "Old Man's War")
print(result?.score) // 0.44444444444444442
print(result?.ranges) // [CountableClosedRange(0...0), CountableClosedRange(2...6), CountableClosedRange(9...12)]
let books = ["The Silmarillion", "The Lock Artist", "The Lost Symbol"]
let fuse = Fuse()
let results = fuse.search("Te silm", in: books)
results.forEach { item in
print("index: " + item.index)
print("score: " + item.score)
print("ranges: " + item.ranges)
}
fuse.search("Te silm", in: books, completion: { results in
results.forEach { item in
print("index: " + item.index)
print("score: " + item.score)
print("ranges: " + item.ranges)
}
})
struct Book: Fuseable {
let title: String
let author: String
var properties: [FuseProperty] {
return [
FuseProperty(value: title, weight: 0.3),
FuseProperty(value: author, weight: 0.7)
]
}
}
let books: [Book] = [
Book(title: "Old Man's War fiction", author: "John X"),
Book(title: "Right Ho Jeeves", author: "P.D. Mans")
]
let fuse = Fuse()
let results = fuse.search("man", in: books)
results.forEach { item in
print("index: " + item.index)
print("score: " + item.score)
print("results: " + item.results)
print("---------------")
}
// Output:
//
// index: 1
// score: 0.015000000000000003
// results: [(value: "P.D. Mans", score: 0.015000000000000003, ranges: [CountableClosedRange(5...7)])]
// ---------------
// index: 0
// score: 0.027999999999999997
// results: [(value: "Old Man\'s War fiction", score: 0.027999999999999997, ranges: [CountableClosedRange(4...6)])]
fuse.search("Man", in: books, completion: { results in
results.forEach { item in
print("index: " + item.index)
print("score: " + item.score)
print("results: " + item.results)
print("---------------")
}
})
Fuse
takes the following options:
location
: Approximately where in the text is the pattern expected to be found. Defaults to0
distance
: Determines how close the match must be to the fuzzylocation
(specified above). An exact letter match which isdistance
characters away from the fuzzy location would score as a complete mismatch. A distance of0
requires the match be at the exactlocation
specified, adistance
of1000
would require a perfect match to be within800
characters of the fuzzy location to be found using a0.8
threshold. Defaults to100
threshold
: At what point does the match algorithm give up. A threshold of0.0
requires a perfect match (of both letters and location), a threshold of1.0
would match anything. Defaults to0.6
maxPatternLength
: The maximum valid pattern length. The longer the pattern, the more intensive the search operation will be. If the pattern exceeds themaxPatternLength
, thesearch
operation will returnnil
. Why is this important? Read this. Defaults to32
isCaseSensitive
: Indicates whether comparisons should be case sensitive. Defaults tofalse
!!!!!!!!!!! Ifrit repository have no example project. !!!!!!!!!!!
As example project you can use project from original Fuse-Swift repository To run the example project:
- clone the Fuse-Swift( https://github.com/krisk/fuse-swift.git ) repo
- and run
pod install
from the Example directory first.
- Add a dependency on Fuse:
- CocoaPods: add
pod 'Fuse'
to yourPodfile
. - Carthage: add
github "krisk/fuse-swift"
to yourCartfile
.
- Add
import Fuse
to your source files.