I would use CLucene for this. It isn't as easy to use as CoreData (it
is written in C++, so you'll need some Objective-C++ as a shim at a
minimum), but it is powerful and VERY fast.

-Heath
>From my iTouch4

On Jul 14, 2011, at 1:17 PM, Indragie Karunaratne <cocoa...@indragie.com> wrote:

> Hi guys,
>
> I'm working on a search feature in one of my Core Data based apps and I'm 
> trying to gather everyone's tips on search optimization to get it as fast as 
> I possibly can. The search needs to be fast enough that it can deliver 
> near-instantaneous results for database of 20,000+ objects.
>
> What I've done so far (as far as optimization goes)
> - Implemented the technique shown in WWDC 2010 session 137, creating a 
> keyword entity and creating a to-many relationship from my main object 
> entities to it. The keyword entity's 'name' attribute is indexed, and 
> keywords are created during the initial import procedure by splitting apart 
> relevant strings in the main entities and normalizing them (stripped of case 
> and diacritics)
> - Using >= and < binary comparators instead of BEGINSWITH, etc. My predicate 
> format is: SUBQUERY(keywords, $keyword, ($keyword.name >= $LB) AND 
> ($keyword.name < $UB)).@count != 0
>
> Where $LB is the lower bounds string and $UB is upper bounds. I create a 
> compound AND predicate using this format and the array of search terms.
>
> Right now, I'm executing a fetch once (when the user types the first letter) 
> using a fetch batch size of about 20, and then narrowing down the search 
> results using NSArray's -filteredArrayUsingPredicate method as they continue 
> typing. I also prefetch the "keywords" relationship because this is used to 
> filter. The part that takes up the most time, obviously, is the initial 
> fetch. There's a noticeable delay of ~1-2s on a library of around 15,000 
> objects. Time profiling shows that it is indeed the fetch that is causing the 
> delay:
>
> http://cl.ly/3a1b2022452M2V323f2H
>
> One other thing thats worth noting is that I have to fetch multiple entities 
> for the results. All of the entities have a "ranking" attribute, but I can't 
> fetch more than one at once so I'm forced to fetch them separately, combine 
> them into a single array, and then sort manually via 
> -sortedArrayUsingDescriptors.
>
> Any tips on how to speed this up would be greatly 
> appreciated._______________________________________________
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/heath.borders%40gmail.com
>
> This email sent to heath.bord...@gmail.com
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to