Latest 1.1.0
Homepage https://github.com/viktorasl/FuzzySearch
License MIT
Platforms ios 8.0, osx 10.10, tvos 9.0
Authors

FuzzySearch

Build Status
Swift Package Manager Compatible
CocoaPods Compatible
Platform
License

Lightweight Fuzzy evaluation protocol with CollectionType extension

Requirements

iOS 8.0+
Swift 3.0

Usage

Implementing FuzzySearchable protocol

struct PlayerModel {
  let name: String
  let position: String
  let goals: Int
}

Implementation of FuzzySearchable protocol defines against what search patterns will be evaluated.

extension PlayerModel: FuzzySearchable {
  var fuzzyStringToMatch: String {
    return name
  }
}

Evaluating single FuzzySearchable instance

let maradona = PlayerModel(name: "Diego Maradona", position: "F", goals: 16)
maradona.fuzzyMatch("diema") // FuzzySearchResult(weight: 15, parts: [(0,3), (6,2)])

FuzzySearchResult

Result of evaluation carries two properties:

  • weight – weight of the match
  • partsNSRange‘s of pattern matching against fuzzyStringToMatch

Evaluating collection of FuzzySearchables

When evaluating collection of FuzzySearchables result is an array of tuples (item: Generator.Element, result: FuzzySearchResult) which is filtered and sorted depending on weight.


let players = [
  PlayerModel(name: "Diego Maradona", position: "CF", goals: 16),
  PlayerModel(name: "David Beckham", position: "CAM", goals: 8),
  PlayerModel(name: "Lionel Messi", position: "RW", goals: 15)
]
players.fuzzyMatch("di")
//[
// (
//  FuzzySearchTests.PlayerModel(name: "Diego Maradona", position: "CF", goals: 16),
//  FuzzySearch.FuzzySearchResult(weight: 4, parts: [(0,2)])
// ), (
//  FuzzySearchTests.PlayerModel(name: "David Beckham", position: "CAM", goals: 8),
//  FuzzySearch.FuzzySearchResult(weight: 2, parts: [(0,1), (3,1)])
// )
//]

License

FuzzySearch is released under the MIT license.

Latest podspec

{
    "name": "FuzzySearchi",
    "version": "1.1.0",
    "license": "MIT",
    "summary": "Lightweight Fuzzy evaluation protocol with CollectionType extension",
    "homepage": "https://github.com/viktorasl/FuzzySearch",
    "authors": {
        "Viktoras Laukeviu010dius": "[email protected]"
    },
    "source": {
        "git": "https://github.com/viktorasl/FuzzySearch.git",
        "tag": "1.1.0"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "tvos": "9.0"
    },
    "source_files": "Source/*.swift",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This