Latest 0.3
Homepage https://github.com/czechboy0/hit
License MIT
Platforms ios 8.0, osx 10.10, watchos 2.0, requires ARC
Authors

Build Status CocoaPods Spec Swift Version

Lightweight full-text search engine written in Swift.

Work In Progress.

features

  • prefix search
  • exact word-match search

usage

Let’s say you have a list of funny quotes from all yours friends and you suddenly remember that there’s a gem mentioning a ‘scar’. Instead of having to go through all your friends’ quotes one by one until you find it, use hit instead! Just run your data to get an Index and then ask it to give you back who‘s responsible for that quote and in what context it was said.

Let’s look at our data

let quotes = [
    (string: "Hasta la Pizza, baby", identifier: "Dino"),
    (string: "Sorry I'm late, my car aborted half way to work", identifier: "Rob"),
    (string: "Icecream always makes me think of Scary Movie. Get it? I scream?", identifier: "Sarah"),
    (string: "Who is not been scarred by love has not lived.", identifier: "John")
]

//create an empty index
let index = Index()

//feed it your data
index.updateIndexFromRawStringsAndIdentifiers(quotes, save: false)

and we remember that someone said something ridiculously cheezy about scars, let’s go for it and search for scar, hoping we’ll get a hit.

//search for stuff!
let results = index.prefixSearch("scar")

//look at results
/*
*   -> 2 results : [
*                       "scary" -> [ "Sarah" : Range(34..<39) ],
*                       "scarred" -> [ "John" : Range(16..<23) ]
*                  ]
*/

Turns out we got two. One from Sarah about Scary Movie:

Icecream always makes me think of Scary Movie. Get it? I scream?
                                  |---|
                                  34 39

and another one from John about, right that’s the ridiculous one, well, read it yourself:

Who is not been scarred by love has not lived.
                |-----|
                16   23

Cool (?), our results actually tell us that he used the exact word scarred in the range of 16..<23. That would be useful to know if we wanted to highlight the word itself.

author

Honza Dvorsky
honzadvorsky.com
@czechboy0

Latest podspec

{
    "name": "hit",
    "version": "0.3",
    "summary": "Lightweight full-text search written in Swift",
    "description": "`hit` helps you quickly search your data for either a prefix or an exact match.",
    "homepage": "https://github.com/czechboy0/hit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Honza Dvorsky": "http://honzadvorsky.com"
    },
    "social_media_url": "https://twitter.com/czechboy0",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "watchos": "2.0"
    },
    "source": {
        "git": "https://github.com/czechboy0/hit.git",
        "tag": "v0.3"
    },
    "source_files": "hit/*.{swift}",
    "requires_arc": true
}

Pin It on Pinterest

Share This