I want to handle a little mistakes from keyboard input from the user (This is a concept phase so I don't have any component's yet, so feel free to suggest one).
Let's assume that I have CoreData
entity with 1000 inputs. I want to search for only one attribute. And I want behavior like in UIFetchedResultController
(this could be one, but I also can simulate it behavior).
Once agin, let's assume that this is fruit entity contains attribute name
and the user searched for it. He wants to search banana
but he enters bansna
(or vanana
) by mistake. I want to still show him "banana" phase.
How can I do this? This can be done using NSPredicate
? Can I manipulate this "tolerance" ?
I use 1000 number of entries early, the speed of searching I assume depends of this tolerance and database size. So for this maybe i should move from mobile to REST service? Looking for advice here also.
Core Data fetch requests do not support a "fault tolerant" search. The available comparison operators for strings are
==
for exact equality,CONTAINS
, BEGINSWITH
, ENDSWITH
for substring search,LIKE
for simple wildcard matching,MATCHES
for regular expression search.But for a "fault tolerant" search you need some advanced comparison algorithm like the Levenshtein distance, which can be used to determine if one string is "close to" another string (and there are probably more algorithms).
Since a Core Data fetch request cannot use a "Objective-C based" predicate
(such as predicateWithBlock
), this means that you have to fetch all objects and
then apply the fault tolerant comparison method.