IOS-how to create an index to implement a local text search engine that allows for error-tolerant searches ?, Ios-Index
1. Preface implements a local search engine that allows for error-tolerant searches, that is, the search results do not need to be exactly matched with the search keywords. For example, search for "eric wang" and search results can include Erica Watts. The search efficiency is very high. here we need to use the Lib of Jerome Morissard. You can download it from my github. https://github.com/SaupClear/qingchegithub 2. permissiveResearch usage 2. 1. import core. h file 2. 2. when the text input control changes, we start to implement text search. That is, we start to search for the following proxy method each time it is called. 2. 3. initialize the data warehouse to be retrieved
# Pragma mark retrieval data warehouse initialization/*** retrieval data initialization */-(void) rebuildDatabase {// The data to be retrieved in your own code NSArray * allmenus = self. mainDelegate. gbdata. objMenu. menuItemArray; // Add the data objects to be retrieved in your code to the retrieval data warehouse and associate them with name for (MenuItemObject * objmenu in allmenus) {// The first parameter is the object obj to be retrieved for you, and the second parameter is the object obj for you. name (for example, according to name. search) [[PermissiveResearchDatabase sharedDatabase] addRetainedObjet: objmenu forKey: objmenu. displayname] ;}}
2. 4. Start Retrieval
Ten Steps to search
// 1. first, clear the search result array [self. arraySearchMenu removeAllObjects]; // 2. the text control character entered by the user is simply processed NSString * final = [textField. text stringByReplacingCharactersInRange: range withString: string]; // 3. start NSLog retrieval (@ "Start search by matrix"); // 4. eliminate all [[ScoringOperationQueue mainQueue] cancelAllOperations]; // 5. initialize ExactScoringOperation * ope = [[ExactScoringOperation alloc] init]; // 6. the value of the string to be retrieved is ope. searchedString = final; // 7. searchCompletionBlock block = ^ (NSArray * results) {dispatch_async (dispatch_get_main_queue (), ^ {// 8. note: All objects retrieved here are PermissiveObject // The objects you need to retrieve are actually in PermissiveObject. in refencedObject, NSMutableArray * permissiveObj = [NSMutableArray arrayWithArray: results]; // 9. retrieve all the data you need and add the data to the search results for (PermissiveObject * perobj in permissiveObj) {MenuSearchObject * obj = [[MenuSearchObject alloc] init]; menuItemObject * objMenu = perobj. refencedObject; // test log NSLog (@ "% @", objmenu. displayname); obj. menuid = [NSNumber numberWithInteger: objMenu. menuid. integerValue]; [self. arraySearchMenu addObject: obj]; // add filter menu objection} // 10. refresh the tableView [self. searchTableview reloadData]; NSLog (@ "End search by matrix") ;}; // The [ope setCustomCompletionBlock: block] is retrieved. // The End operation is added. [[ScoringOperationQueue mainQueue] addOperation: ope];
If you have any questions, please leave a message below. If you have time, I will reply one by one. Thank you. Author: Clear Saup
Source: http://www.cnblogs.com/qingche/
The copyright of this article is shared by the author and the blog. You are welcome to repost it, but you must keep this statement and provide a connection to the original article on the article page.