• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Data search optimizations
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data search optimizations


  • Subject: Re: Core Data search optimizations
  • From: Heath Borders <email@hidden>
  • Date: Thu, 14 Jul 2011 14:15:23 -0500

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 <email@hidden> 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 (email@hidden)
>
> 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:
>
> This email sent to email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >Core Data search optimizations (From: Indragie Karunaratne <email@hidden>)

  • Prev by Date: Re: getting path for files in test bundle
  • Next by Date: Re: Exposing NSTableView's usesAlternatingRowBackgroundColors in the user preferences
  • Previous by thread: Core Data search optimizations
  • Next by thread: Re: Core Data search optimizations
  • Index(es):
    • Date
    • Thread