{"id":13419528,"url":"https://github.com/Blue-Rocket/BRFullTextSearch","last_synced_at":"2025-03-15T05:31:30.648Z","repository":{"id":9339542,"uuid":"11187800","full_name":"Blue-Rocket/BRFullTextSearch","owner":"Blue-Rocket","description":"Objective-C full-text search engine.","archived":false,"fork":false,"pushed_at":"2017-10-12T02:11:58.000Z","size":1764,"stargazers_count":157,"open_issues_count":2,"forks_count":26,"subscribers_count":22,"default_branch":"master","last_synced_at":"2024-10-05T10:17:06.526Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Blue-Rocket.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-04T22:37:18.000Z","updated_at":"2024-02-24T12:44:59.000Z","dependencies_parsed_at":"2022-09-10T18:50:58.678Z","dependency_job_id":null,"html_url":"https://github.com/Blue-Rocket/BRFullTextSearch","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blue-Rocket%2FBRFullTextSearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blue-Rocket%2FBRFullTextSearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blue-Rocket%2FBRFullTextSearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blue-Rocket%2FBRFullTextSearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Blue-Rocket","download_url":"https://codeload.github.com/Blue-Rocket/BRFullTextSearch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243690112,"owners_count":20331726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T22:01:17.249Z","updated_at":"2025-03-15T05:31:29.940Z","avatar_url":"https://github.com/Blue-Rocket.png","language":"C++","funding_links":[],"categories":["TODO scan for Android support in followings"],"sub_categories":[],"readme":"# BRFullTextSearch\n\nObjective-C full text search engine.\n\nThis project provides a way to integrate full-text search capabilities into your iOS\nor OS X project. First, it provides a protocol-based API for a simple text indexing\nand search framework. Second, it provides a [CLucene](http://clucene.sourceforge.net/)\nbased implementation of that framework.\n\n# Example Usage\n\nThe following snippet shows how the API works. The `CLuceneSearchService` reference\nis the only CLucene-specific portion of the code:\n\n```objc\nid\u003cBRSearchService\u003e service = [[CLuceneSearchService alloc] initWithIndexPath:@\"/some/path\"];\n\n// add a document to the index\nid\u003cBRIndexable\u003e doc = [[BRSimpleIndexable alloc] initWithIdentifier:@\"1\" data:@{\n\t\t\t\t\t   kBRSearchFieldNameTitle : @\"Special document\",\n\t\t\t\t\t   kBRSearchFieldNameValue : @\"This is a long winded note with really important details in it.\"\n\t\t\t\t\t   }];\nNSError *error = nil;\n[service addObjectToIndexAndWait:doc error:\u0026error];\n\n// search for documents and log contents of each result\nid\u003cBRSearchResults\u003e results = [service search:@\"special\"];\n[results iterateWithBlock:^(NSUInteger index, id\u003cBRSearchResult\u003eresult, BOOL *stop) {\n\tNSLog(@\"Found result: %@\", [result dictionaryRepresentation]);\n}];\n```\n\n\n# Sample projects\n\nThere are some sample projects included in the source distribution:\n\n * [SampleCocoaPodsProject](SampleCocoaPodsProject/) - a Core Data based iOS application using CocoaPods integration\n * [SampleOSXCocoaPodsProject](SampleOSXCocoaPodsProject/) - a Core Data based OS X application using CocoaPods integration\n\n# Predicate queries\n\nThe `BRSearchService` API supports `NSPredicate` based queries:\n\n```objc\n- (id\u003cBRSearchResults\u003e)searchWithPredicate:(NSPredicate *)predicate\n                                    sortBy:(NSString *)sortFieldName\n                                  sortType:(BRSearchSortType)sortType\n                                 ascending:(BOOL)ascending;\n```\n\nThis method of querying can be quite useful when constructing a query out of user-supplied query text.\nFor example, you could support _prefix_ based queries (for example, searching for `ca*` to match `cat`):\n\n```objc\n// get query as string, from text field for Example\nNSString * query = ...;\n\nstatic NSExpression *ValueExpression;\nif ( ValueExpression == nil ) {\n    ValueExpression = [NSExpression expressionForKeyPath:kBRSearchFieldNameValue];\n}\nNSArray *tokens = [[query stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]\n                   componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];\nNSMutableArray *predicates = [NSMutableArray arrayWithCapacity:([tokens count] * 2)];\nfor ( NSString *token in tokens ) {\n    [predicates addObject:[NSComparisonPredicate predicateWithLeftExpression:ValueExpression\n                                                             rightExpression:[NSExpression expressionForConstantValue:token]\n                                                                    modifier:NSDirectPredicateModifier\n                                                                        type:NSLikePredicateOperatorType\n                                                                     options:0]];\n    [predicates addObject:[NSComparisonPredicate predicateWithLeftExpression:ValueExpression\n                                                             rightExpression:[NSExpression expressionForConstantValue:token]\n                                                                    modifier:NSDirectPredicateModifier\n                                                                        type:NSBeginsWithPredicateOperatorType\n                                                                     options:0]];\n}\nNSPredicate *predicateQuery = [NSCompoundPredicate orPredicateWithSubpredicates:predicates];\nsearchResults = [searchService searchWithPredicate:predicateQuery sortBy:nil sortType:0 ascending:NO];\n```\n\n# Batch API\n\nWhen indexing many documents at once, `BRSearchService` provides a set of methods specifically designed\nfor efficient bulk operations:\n\n```objc\n// bulk block callback function.\ntypedef void (^BRSearchServiceIndexUpdateBlock)(id \u003cBRIndexUpdateContext\u003e updateContext);\n\n// perform a bulk operation, calling the passed on block\n- (void)bulkUpdateIndex:(BRSearchServiceIndexUpdateBlock)updateBlock\n                  queue:(dispatch_queue_t)finishedQueue\n               finished:(BRSearchServiceUpdateCallbackBlock)finished;\n\n// from within the block, the following methods can be used (notice the updateContext parameter):\n\n- (void)addObjectToIndex:(id \u003cBRIndexable\u003e )object context:(id \u003cBRIndexUpdateContext\u003e )updateContext;\n\n- (int)removeObjectFromIndex:(BRSearchObjectType)type withIdentifier:(NSString *)identifier\n                     context:(id \u003cBRIndexUpdateContext\u003e )updateContext;\n\n- (int)removeObjectsFromIndexMatchingPredicate:(NSPredicate *)predicate\n                                       context:(id \u003cBRIndexUpdateContext\u003e )updateContext;\n\n- (int)removeAllObjectsFromIndex:(id \u003cBRIndexUpdateContext\u003e )updateContext;\n```\n\nHere's an example of a bulk operation that adds 100,000 documents to the index; notice the strategic\nuse of `@autoreleasepool` to keep a lid on memory use during the operation:\n\n```objc\nid\u003cBRSearchService\u003e service = ...;\n[service bulkUpdateIndex:^(id\u003cBRIndexUpdateContext\u003e updateContext) {\n\n    if ( [updateContext respondsToSelector:@selector(setOptimizeWhenDone:)] ) {\n        updateContext.optimizeWhenDone = YES;\n    }\n\n    // add a bunch of documents to the index, in small autorelease batches\n    for ( int i = 0; i \u003c 100000; i+= 1000 ) {\n        @autoreleasepool {\n            for ( int j = 0; j \u003c 1000; j++ ) {\n                id\u003cBRIndexable\u003e doc = ...;\n                [service addObjectToIndex:doc context:updateContext];\n            }\n        }\n    }\n\n} queue:dispatch_get_main_queue() finished:^(int updateCount, NSError *error) {\n    // all finished here\n}];\n```\n\n# Core Data support\n\nIt's pretty easy to integrate BRFullTextSearch with Core Data, to maintain a search\nindex while changes are persisted in Core Data. One way is to listen for the\n`NSManagedObjectContextDidSaveNotification` notification and process Core Data\nchanges as index delete and update operations. The **SampleCocoaPodsProject** iOS project\ncontains an example of this integration. The app allows you to create small _sticky\nnotes_ and search the text of those notes. See the\n[CoreDataManager](SampleCocoaPodsProject/SampleCocoaPodsProject/CoreDataManager.m) class in the sample\nproject, whose `maintainSearchIndexFromManagedObjectDidSave:` method handles this.\n\nThe **SampleOSXCocoaPodsProject** OS X project also contains an example of this integration.\nSee the [CoreDataManager](SampleOSXCocoaPodsProject/SampleOSXCocoaPodsProject/CoreDataManager.m)\nclass in that project for details.\n\n\n# Project Integration\n\nYou can integrate BRFullTextSearch via [CocoaPods](http://cocoapods.org/), or\nmanually as either a dependent project or static framework.\n\n## via CocoaPods\n\nInstall CocoaPods if not already available:\n\n```bash\n$ [sudo] gem install cocoapods\n$ pod setup\n```\n\nChange to the directory of your Xcode project, and create a file named `Podfile` with\ncontents similar to this:\n\n\tplatform :ios, '5.0'\n\tpod 'BRFullTextSearch', '~\u003e 2.0'\n\nInstall into your project:\n\n``` bash\n$ pod install\n```\n\nOpen your project in Xcode using the **.xcworkspace** file CocoaPods generated.\n\n**Note:** the `use_frameworks!` option is not supported, see #4. Any pull requests\nto allow for building as a dynamic framework are very welcome!\n\n## via static framework\n\nUsing this approach you'll build a static library framework that you can manually\nintegrate into your own project.\n\nThe BRFullTextSearch Xcode project includes a target called\n**BRFullTextSearch.framework** that builds a static library framework. Build that\ntarget, which will produce a `Framework/Release/BRFullTextSearch.framework` bundle at\nthe root project directory. Copy that framework into your project and add it as a\nbuild dependency.\n\nYou must also add the following linker build dependencies, which you can do by\nclicking the **+** button in the **Link Binary With Libraries** section of the\n**Build Phases** tab in the project settings:\n\n * libz\n * libc++\n\nNext, add `-ObjC` as an *Other Linker Flags* build setting. If you do not have any\nC++ sources in your project, you probably also need to add `-stdlib=libc++` to\nthis setting as well.\n\nFinally, you'll need to add the path to the directory containing the\n`BRFullTextSearch.framework` bundle as a **Framework Search Paths** value in the\n**Build Settings** tab of the project settings.\n\nThe **SampleStaticLibraryProject** included in this repository is an example project\nset up using the static library framework integration approach. You must build\n**BRFullTextSearch.framework** first, then open this project. When you run the\nproject, it will index a set of documents using some Latin text. You can then search\nfor latin words using a simple UI.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlue-Rocket%2FBRFullTextSearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBlue-Rocket%2FBRFullTextSearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlue-Rocket%2FBRFullTextSearch/lists"}