• 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: NSPredicate Matches
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPredicate Matches


  • Subject: Re: NSPredicate Matches
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Fri, 18 Dec 2009 01:03:36 +0700

On 17 Dec 2009, at 22:20, Keary Suska wrote:

> On Dec 16, 2009, at 10:18 PM, Gerriet M. Denkmann wrote:
>
>>
>> I have a Core Date entity A which has a to-many ralationship called theBs.
>> And a Core Date entity B which has a to-many ralationship called theCs.
>> And a final Core Date entity C which has an NSString attribute called someString.
>>
>> I tried to find all A entities which contain "xyz" by using an NSPredicate: "ANY theBs.theCs.someString MATCHES ".*xyz.*" "
>>
>> But all I got was an error message:
>> Can't do regex matching on object [description of an NSSet with all the someStrings connected to the first A entity].
>>
>> When I change the predicate to: "ANY theBs.theCs.someString CONTAINS  "xyz" " it kind of works, but for xyz = "change the" I get no finds, whereas for xyz = "change the price" the predicate finds one entity (correct), and for xyz = "change the p" it finds nothing again.
>
> I would expect both approaches to fail, but at least I am not surprised that "contains" gives undefined results. The issue is crossing multiple to-many relationships. AFAIK, NSPredicate can't do that. Have you tried using an array operator, such as @unionOfSets? I don't know whether it would work, but there is a theoretical possibility ;-) Otherwise, you will need to use code to get the results you need.

I have decided to use the predicate:  theBs.theCs.someString anyContains: "xyz"
and have added a category to NSSet:

- (BOOL)anyContains: (NSString *)searchString;
{
	for( NSSet *subSet in self )
	{
		for( NSString *s in subSet )
		{
			NSRange w = [ s rangeOfString: searchString  options: NSLiteralSearch ];
			if ( w.location != NSNotFound ) return YES;
		};
	};
	return NO;
}

No idea whether this is the best way to do it - but at least it works.

The problem: the first time it is used, this is very slow (about 20 seconds).
There are 30 000 A entities, each have on average 2 B entities, each of these have about half a dozen C entities.
In these 20 seconds the RSIZE increases by about 100 MB. Obviously the data gets cached in memory.

I have another app, which uses the same data but not Core Data.
Entity A corresponds to an NSDictionary which contains NSArrays (corresponding to B) which contain NSDictionaries containing NSStrings.
This app seems to be as fast as the Core Data one, but has not this long delay at the first search.

Could it be that Core Data is the wrong choice in this case? Or am I just using Core Data rather inefficiently?

Kind regards,

Gerriet.
 _______________________________________________

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

  • Follow-Ups:
    • Re: NSPredicate Matches
      • From: Keary Suska <email@hidden>
References: 
 >NSPredicate Matches (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: NSPredicate Matches (From: Keary Suska <email@hidden>)

  • Prev by Date: launching application after reboot
  • Next by Date: Re: iCal-like display class (week)?
  • Previous by thread: Re: NSPredicate Matches
  • Next by thread: Re: NSPredicate Matches
  • Index(es):
    • Date
    • Thread