0

In my Core Data app, I have an entity Person (which has a fullname attribute). The simplest way of searching for a name is to make the predicate search through the fields:

[predicateArray addObject:[NSPredicate predicateWithFormat:@"fullname CONTAINS[cd] %@", searchString]];

But from what I've picked up, this is a regex search that can be expensive, especially if you want to enable live searching (i.e. search while you type) and if the list is very big. Is there some better way of doing this search? Can you transform the fullName somehow to make it quicker to search on?

Z S
  • 7,039
  • 12
  • 53
  • 105
  • Did you made a test to see how many items can be searched this way in a live search? I don't know for sure but from prev experiences, I bet more that 2000 items. Do you have more than 2000 items to search for? – Rad'Val Jul 23 '11 at 23:50
  • Since it's a contacts list, it would be about a 1000 average, but you could imagine some people having a bigger list (especially organization lists). So I would like this to scale for 10,000 entries if possible. – Z S Jul 23 '11 at 23:56
  • Are you planning to hook this up to a combo box? – Chris Frederick Jul 24 '11 at 05:26

1 Answers1

0

You're probably interested in an approach similar to this one:

Core Data search optimization

Basically you create a couple of child search specific entities to optimize for the first few characters.

You're probably also looking for "begins with" instead of "contains" in your predicate, rarely do people mentally organize their contacts by the middle letters of their name. They usually start by typing "A" for Adam or Andy etc, not "am" or "nd".

Community
  • 1
  • 1
ImHuntingWabbits
  • 3,827
  • 20
  • 27