In fact, I'm working on an iPhone based on Core Data. I have two objects that contain more than 200,000 rows each, and I am experiencing some performance issues when retrieving data. For each sample request, I have to wait 1 to 2 seconds before getting the results. I’m thinking about introducing a special search engine to index my data, but the problem is that the entire database is editable. Content can be changed at any time, so indexing a dynamic content database is stupid.
I am wondering if Core Data is enough to provide instant search. In Apple's documentation, a thousand string objects are considered small. Is it correct?
Does anyone have a solution to improve the speed of Core Data ...? Or should I implement my own search engine?
The goal is to provide an instant search, search by type of mecanism.
[UPDATE] Below is a snippet of one of my select queries ...
NSString *predicateString = [NSString stringWithFormat:@"^(.*\\b)?%@(\\b.*)?$", searchString];
NSString *predicate = [NSString stringWithString:@"text MATCHES[cd] %@"];
NSArray *arguments = [NSArray arrayWithObjects:predicateString, nil];
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:[[HYDataManager instance] managedObjectContext]]];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:predicate argumentArray:arguments]];
[fetchRequest setSortDescriptors:[NSArray arrayWithObjects:[[NSSortDescriptor alloc] initWithKey:@"length" ascending:YES], [[NSSortDescriptor alloc] initWithKey:@"subEntity.attr1" ascending:YES], [[NSSortDescriptor alloc] initWithKey:@"subEntity.attr2" ascending:YES], nil]];
[fetchRequest setResultType:NSDictionaryResultType];
[fetchRequest setReturnsDistinctResults:YES];
[fetchRequest setPropertiesToFetch:[NSArray arrayWithObject:@"subEntity"]];
NSFetchedResultsController *controller = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[[HYDataManager instance] managedObjectContext] sectionNameKeyPath:nil acheName:nil];
user179476
source
share