Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
iPhone SDKiPhone
iPhone SDKh"p://kishikawakatsumi.comTwi"er@k_katsumi24/7
twenty‐four
sevenh"p://d.hatena.ne.jp/KishikawaKatsumi/
iPhone SDK•      
touch   •          
on
the
WEB•LDR
touch      ••               •i‐Radio•LCD
Clock      ••Subway
Map     ...
iPhone SDKhttp://github.com/kishikawakatsumi•hatena‐touch        •DescripMonBuilder•ldr‐touch           •TiledLayerView•tv...
iPhone SDK
iPhone SDKiPhone
iPhone SDK
iPhone SDK    (SQLite? CoreData? and so on...)••
iPhone SDK                   LibraryTokyo Cabinethttp://fallabs.com/tokyocabinet/Tokyo Dystopiahttp://fallabs.com/tokyodys...
iPhone SDKTokyo CabinetDBMTokyo DystopiaTokyo CabinetFTSKitBNRPersistenceTokyo Dystopia   Cocoa Wrapper
iPhone SDK             Sample CodeFTSKithttps://github.com/kishikawakatsumi/FTSKit
iPhone SDK   FKStoredObject
iPhone SDK#import "FKStoredObject.h"@interface Address : FKStoredObject {  NSString *zipcode;  NSString *full;  NSString *...
iPhone SDK#import "FKStoredObject.h"@interface Address : FKStoredObject {  NSString *zipcode;  NSString *full;  NSString *...
@implementation Address              iPhone SDK- (void)readContentFromBuffer:(FKDataBuffer *)d {   [zipcode release];   zi...
iPhone SDK       Save
iPhone SDK      FKStore   FKStoreBackend  FKIndexManager
iPhone SDKself.store = [[[FKStore alloc] init] autorelease];FKTCBackend *backend = [[FKTCBackend alloc] initWithPath:dataP...
iPhone SDK// Mark object for insertion into object store- (void)insertObject:(FKStoredObject *)obj;// Mark object for dele...
iPhone SDKCSVParser *parser = [[[CSVParser alloc]               initWithString:csvString                   separator:@"," ...
iPhone SDK      Search
iPhone SDK- (FKResultSet *)resultSetForClass:(Class)c              mactchesText:(NSString *)text                   forKey:...
NSString *text = searchText;             iPhone SDKNSString *key = @"kana";FKResultSet *resultSet;if (searchType == FKSear...
iPhone SDKPerformance Tuning
iPhone SDK    Performance Tuning••       2:8•
iPhone SDK
iPhone SDK•
iPhone SDK
iPhone SDK
iPhone SDK             OK.
iPhone SDK
iPhone SDK       •       •       •       iPhone
iPhone SDK••
iPhone SDK- (void)searchBar:(FKSearchBar *)searchBar   textDidChange:(NSString *)searchText {   [NSObject    cancelPreviou...
- (void)searchWithSearchBar:(FKSearchBar *)searchBar {               iPhone SDK   [queue cancelAllOperations];    NSString...
iPhone SDK        API CocoaFoundation
iPhone SDK
iPhone SDKBoolean CFStringTransform (   CFMutableStringRef string,   CFRange *range,   CFStringRef transform,   Boolean re...
iPhone SDKconst   CFStringRef   kCFStringTransformStripCombiningMarks;const   CFStringRef   kCFStringTransformToLatin;cons...
iPhone SDKNSString *text = searchText;NSMutableString *toKana = [NSMutableString stringWithString:text];CFRange range = CF...
iPhone SDK
iPhone SDKCFIndex CFArrayBSearchValues (   CFArrayRef theArray,   CFRange range,   const void *value,   CFComparatorFuncti...
NSArray *sortedArray;           iPhone SDKNSNumber *target = [NSNumber numberWithInteger:10];CFIndex count = [sortedArray ...
NSBinarySearchingOptions                 iPhone SDKOptions for searches and insertions usingindexOfObject:inSortedRange:op...
iPhone SDK
iPhone SDK NSStringCFURL
iPhone SDK- (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding- (NSString*)stringByReplacing...
iPhone SDKCFStringRef CFURLCreateStringByReplacingPercentEscapes (   CFAllocatorRef allocator,   CFStringRef originalStrin...
Upcoming SlideShare
Loading in …5
×

iPhone勉強会 (2011.04.30) 全文検索 -Full Text Search on iOS-

4,840 views

Published on

iOS SDKでお手軽に高速な全文検索

Published in: Technology
  • Login to see the comments

iPhone勉強会 (2011.04.30) 全文検索 -Full Text Search on iOS-

  1. 1. iPhone SDKiPhone
  2. 2. iPhone SDKh"p://kishikawakatsumi.comTwi"er@k_katsumi24/7
twenty‐four
sevenh"p://d.hatena.ne.jp/KishikawaKatsumi/
  3. 3. iPhone SDK• 
touch • 
on
the
WEB•LDR
touch •• •i‐Radio•LCD
Clock ••Subway
Map ••MyWebClip• •
  4. 4. iPhone SDKhttp://github.com/kishikawakatsumi•hatena‐touch •DescripMonBuilder•ldr‐touch •TiledLayerView•tv‐lisMngs •UICCalendarPicker•MapKit‐Route‐DirecMons•FlipCardNavigaMonView•PhotoFlipCardView
  5. 5. iPhone SDK
  6. 6. iPhone SDKiPhone
  7. 7. iPhone SDK
  8. 8. iPhone SDK (SQLite? CoreData? and so on...)••
  9. 9. iPhone SDK LibraryTokyo Cabinethttp://fallabs.com/tokyocabinet/Tokyo Dystopiahttp://fallabs.com/tokyodystopia/BNRPersistencehttps://github.com/hillegass/BNRPersistence
  10. 10. iPhone SDKTokyo CabinetDBMTokyo DystopiaTokyo CabinetFTSKitBNRPersistenceTokyo Dystopia Cocoa Wrapper
  11. 11. iPhone SDK Sample CodeFTSKithttps://github.com/kishikawakatsumi/FTSKit
  12. 12. iPhone SDK FKStoredObject
  13. 13. iPhone SDK#import "FKStoredObject.h"@interface Address : FKStoredObject { NSString *zipcode; NSString *full; NSString *kana;}@property (nonatomic, retain) NSString *zipcode;@property (nonatomic, retain) NSString *full;@property (nonatomic, retain) NSString *kana;@end
  14. 14. iPhone SDK#import "FKStoredObject.h"@interface Address : FKStoredObject { NSString *zipcode; NSString *full; NSString *kana;}@property (nonatomic, retain) NSString *zipcode;@property (nonatomic, retain) NSString *full;@property (nonatomic, retain) NSString *kana;@end
  15. 15. @implementation Address iPhone SDK- (void)readContentFromBuffer:(FKDataBuffer *)d { [zipcode release]; zipcode = [[d readString] retain]; [full release]; full = [[d readString] retain]; [kana release]; kana = [[d readString] retain];}- (void)writeContentToBuffer:(FKDataBuffer *)d { [d writeString:zipcode]; [d writeString:full]; [d writeString:kana];}@end
  16. 16. iPhone SDK Save
  17. 17. iPhone SDK FKStore FKStoreBackend FKIndexManager
  18. 18. iPhone SDKself.store = [[[FKStore alloc] init] autorelease];FKTCBackend *backend = [[FKTCBackend alloc] initWithPath:dataPath error:nil];[store setBackend:backend];[backend release];FKTCIndexManager *indexManager = [[FKTCIndexManager alloc] initWithPath:dataPath error:nil];[store setIndexManager:indexManager];[indexManager release];[store addClass:[Address class]];
  19. 19. iPhone SDK// Mark object for insertion into object store- (void)insertObject:(FKStoredObject *)obj;// Mark object for deletion from object store- (void)deleteObject:(FKStoredObject *)obj;// Mark object to be updated in object store- (void)willUpdateObject:(FKStoredObject *)obj;- (BOOL)saveChanges:(NSError **)errorPtr;
  20. 20. iPhone SDKCSVParser *parser = [[[CSVParser alloc] initWithString:csvString separator:@"," hasHeader:YES fieldNames:nil] autorelease];NSArray *lines = [parser arrayOfParsedRows];for (NSDictionary *line in lines) { Address *record = [[Address alloc] init]; record.zipcode = [line objectForKey:@" "]; record.full = [line objectForKey:@" "]; record.kana = [line objectForKey:@" "]; [store insertObject:record]; [record release];}[store saveChanges:nil];
  21. 21. iPhone SDK Search
  22. 22. iPhone SDK- (FKResultSet *)resultSetForClass:(Class)c mactchesText:(NSString *)text forKey:(NSString *)key;- (FKResultSet *)resultSetForClass:(Class)c containsText:(NSString *)text forKey:(NSString *)key;- (FKResultSet *)resultSetForClass:(Class)c beginsWithText:(NSString *)text forKey:(NSString *)key;- (FKResultSet *)resultSetForClass:(Class)c endsWithText:(NSString *)text forKey:(NSString *)key;
  23. 23. NSString *text = searchText; iPhone SDKNSString *key = @"kana";FKResultSet *resultSet;if (searchType == FKSearchTypeStartsWith) { resultSet = [store resultSetForClass:[Address class] beginsWithText:text forKey:key];} else if (searchType == FKSearchTypeEndsWith) { resultSet = [store resultSetForClass:[Address class] endsWithText:text forKey:key];} else if (searchType == FKSearchTypeContains) { resultSet = [store resultSetForClass:[Address class] containsText:text forKey:key];} else { resultSet = [store resultSetForClass:[Address class] mactchesText:text forKey:key];}
  24. 24. iPhone SDKPerformance Tuning
  25. 25. iPhone SDK Performance Tuning•• 2:8•
  26. 26. iPhone SDK
  27. 27. iPhone SDK•
  28. 28. iPhone SDK
  29. 29. iPhone SDK
  30. 30. iPhone SDK OK.
  31. 31. iPhone SDK
  32. 32. iPhone SDK • • • iPhone
  33. 33. iPhone SDK••
  34. 34. iPhone SDK- (void)searchBar:(FKSearchBar *)searchBar textDidChange:(NSString *)searchText { [NSObject cancelPreviousPerformRequestsWithTarget:self]; [self performSelector:@selector(searchWithSearchBar:) withObject:searchBar afterDelay:0.2];}
  35. 35. - (void)searchWithSearchBar:(FKSearchBar *)searchBar { iPhone SDK [queue cancelAllOperations]; NSString *searchText = searchBar.text; if ([searchText length] == 0) { self.resultSet = nil; [listView reloadData]; return; } FKSearchOperation *searchOperation = [[FKSearchOperation alloc] init]; searchOperation.delegate = self; searchOperation.store = store; searchOperation.searchText = searchText; searchOperation.searchType = searchBar.searchType; [queue addOperation:searchOperation]; [searchOperation release];}- (void)searchOperaionDidFinished:(FKResultSet *)results { self.resultSet = results; [listView reloadData];}
  36. 36. iPhone SDK API CocoaFoundation
  37. 37. iPhone SDK
  38. 38. iPhone SDKBoolean CFStringTransform ( CFMutableStringRef string, CFRange *range, CFStringRef transform, Boolean reverse);
  39. 39. iPhone SDKconst CFStringRef kCFStringTransformStripCombiningMarks;const CFStringRef kCFStringTransformToLatin;const CFStringRef kCFStringTransformFullwidthHalfwidth;const CFStringRef kCFStringTransformLatinKatakana;const CFStringRef kCFStringTransformLatinHiragana;const CFStringRef kCFStringTransformHiraganaKatakana;const CFStringRef kCFStringTransformMandarinLatin;const CFStringRef kCFStringTransformLatinHangul;const CFStringRef kCFStringTransformLatinArabic;const CFStringRef kCFStringTransformLatinHebrew;const CFStringRef kCFStringTransformLatinThai;const CFStringRef kCFStringTransformLatinCyrillic;const CFStringRef kCFStringTransformLatinGreek;const CFStringRef kCFStringTransformToXMLHex;const CFStringRef kCFStringTransformToUnicodeName;const CFStringRef kCFStringTransformStripDiacritics;
  40. 40. iPhone SDKNSString *text = searchText;NSMutableString *toKana = [NSMutableString stringWithString:text];CFRange range = CFRangeMake(0, [text length]);CFStringTransform((CFMutableStringRef)toKana, &range, kCFStringTransformHiraganaKatakana, false);text = toKana; CF~ NS~ (toll-free bridge) Cocoa ※UI~
  41. 41. iPhone SDK
  42. 42. iPhone SDKCFIndex CFArrayBSearchValues ( CFArrayRef theArray, CFRange range, const void *value, CFComparatorFunction comparator, void *context);
  43. 43. NSArray *sortedArray; iPhone SDKNSNumber *target = [NSNumber numberWithInteger:10];CFIndex count = [sortedArray count];CFRange range = CFRangeMake(0, count);AData *data = nil;CFIndex index = CFArrayBSearchValues( (CFArrayRef)sortedArray, range, target, compareAData, NULL);if(index < count) { data = [sortedArray objetAtIndex:index];} else { // Not found.}if(NSOrderedSame != [data.number compare:target]) { // Not found.}
  44. 44. NSBinarySearchingOptions iPhone SDKOptions for searches and insertions usingindexOfObject:inSortedRange:options:usingComparator:.enum { NSBinarySearchingFirstEqual = (1 << 8), NSBinarySearchingLastEqual = (1 << 9), NSBinarySearchingInsertionIndex = (1 << 10),};typedef NSUInteger NSBinarySearchingOptions;ConstantsNSBinarySearchingFirstEqualSpecifies that the search should return the first object in the range that is equal to the given object.Available in iOS 4.0 and later.Declared in NSArray.h.NSBinarySearchingLastEqualSpecifies that the search should return the last object in the range that is equal to the given object.Available in iOS 4.0 and later.Declared in NSArray.h.NSBinarySearchingInsertionIndexReturns the index at which you should insert the object in order to maintain a sorted array.Available in iOS 4.0 and later.Declared in NSArray.h.
  45. 45. iPhone SDK
  46. 46. iPhone SDK NSStringCFURL
  47. 47. iPhone SDK- (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding- (NSString*)stringByReplacingPercentEscapesUsingEncoding:(NSStringEncoding)encoding
  48. 48. iPhone SDKCFStringRef CFURLCreateStringByReplacingPercentEscapes ( CFAllocatorRef allocator, CFStringRef originalString, CFStringRef charactersToLeaveEscaped);CFStringRefCFURLCreateStringByReplacingPercentEscapesUsingEncoding( CFAllocatorRef allocator, CFStringRef origString, CFStringRef charsToLeaveEscaped, CFStringEncoding encoding);

×