2

I'm working on an iOS app. I have a Core Data database with a lot of company names.

When the user insert a company name that does not exist, I would like to show "similar" company names. For example, if the user entered "Aple", I would like to show "Did you mean Apple?".

I know that the technique of finding strings that match a pattern approximately (rather than exactly) is called approximate string matching or, colloquially, fuzzy string searching.

In theory, there are many algorithms, more or less valid: the Levenshtein distance computing algorithm and so on.

But in practice, is there someone who has already implemented something similar that can be used easily with core data?

Dev
  • 7,027
  • 6
  • 37
  • 65

2 Answers2

1

I found a solution. Use this NSString's category available on GitHub: NSString-DamerauLevenshtein.

Dev
  • 7,027
  • 6
  • 37
  • 65
0

Try looking at Soundex, I believe that is part of the core featureset for SQLite, if that is your underlying data store.

Simon Lee
  • 22,304
  • 4
  • 41
  • 45
  • Soundex will only work for the english language, from most european languages try double metaphone. But I don't think SQLite will support this, so ou might have to calculate the value before hand and search on that. – rckoenes Dec 13 '11 at 16:33
  • 1
    Soundex is only available if the SQLITE_SOUNDEX compile-time option is used when SQLite is built. If I am not wrong, the iOS Sqlite does not have Soundex (and in any case would not be easy to use with Core Data)... – Dev Dec 13 '11 at 16:49