Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cbess/cbsearchkit
Simple and flexible full text search for iOS and Mac. Uses the sqlite3 FTS3/4 engine.
https://github.com/cbess/cbsearchkit
fts objective-c search sqlite3-fts3
Last synced: about 1 month ago
JSON representation
Simple and flexible full text search for iOS and Mac. Uses the sqlite3 FTS3/4 engine.
- Host: GitHub
- URL: https://github.com/cbess/cbsearchkit
- Owner: cbess
- License: mit
- Created: 2014-03-07T06:25:08.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-03-19T15:31:27.000Z (over 1 year ago)
- Last Synced: 2024-04-14T15:44:19.461Z (7 months ago)
- Topics: fts, objective-c, search, sqlite3-fts3
- Language: Objective-C
- Homepage:
- Size: 95.7 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
CBSearchKit
===========Simple and flexible full text search for iOS and Mac. Using the sqlite3 FTS3/4 engine.
## Setup
- Link `libsqlite3.dylib`
- Add `pod 'CBSearchKit', :git => 'https://github.com/cbess/CBSearchKit.git', :tag => 'v0.6.0'` to `Podfile`
- Run `pod update`## Example Usage
```objc
- (NSArray *)buildIndex {
// create in-memory index
self.indexer = [[CBSIndexer alloc] initWithDatabaseNamed:nil];CBSIndexDocument *document = [CBSIndexDocument new];
document.indexItemIdentifier = @"one-id";
document.indexTextContents = @"this is one";
document.indexMeta = @{@"idx": @1, @"name": @"one"};CBSIndexDocument *document2 = [CBSIndexDocument new];
document2.indexTextContents = @"this is two";
document2.indexMeta = @{@"idx": @2, @"name": @"two"};CBSIndexDocument *document3 = [CBSIndexDocument new];
document3.indexTextContents = @"this is three";
document3.indexMeta = @{@"idx": @3, @"test": @"three", @"name": @"three"};NSArray *documents = @[document, document2, document3];
XCTestExpectation *expectation = [self expectationWithDescription:@"build index"];
[self.indexer addItems:documents completionHandler:^(NSArray *indexItems, NSError *error) {
XCTAssertNil(error, @"unable to build the index");
XCTAssertEqual(indexItems.count, documents.count, @"wrong count indexed");[expectation fulfill];
}];[self waitForExpectationsWithTimeout:3 handler:nil];
return documents;
}- (void)testSearch {
NSArray *indexedDocuments = [self buildIndex];XCTAssertEqual([self.indexer itemCount], indexedDocuments.count, @"Bad count");
id oneDoc = indexedDocuments.firstObject;
static NSString * const searchText = @"one";XCTestExpectation *expectation = [self expectationWithDescription:@"search index"];
CBSSearcher *searcher = [[CBSSearcher alloc] initWithIndexer:self.indexer];
searcher.orderType = CBSSearcherOrderTypeRelevance;
[searcher itemsWithText:searchText itemType:CBSIndexItemTypeIgnore completionHandler:^(NSArray *items, NSError *error) {
XCTAssertEqual(items.count, 1, @"Should be only one item");
XCTAssertNil(error, @"Error: %@", error);id item = items.lastObject;
NSDictionary *meta = [item indexMeta];XCTAssertNotNil(meta, @"No meta");
XCTAssertEqualObjects(meta[@"idx"], [oneDoc indexMeta][@"idx"], @"Wrong meta value");
XCTAssertEqualObjects([item indexItemIdentifier], [oneDoc indexItemIdentifier], @"Wrong index identifier");[expectation fulfill];
}];[self waitForExpectationsWithTimeout:7 handler:nil];
}
```See [unit tests](CBSearchKitTests) for more examples.
[Soli Deo Gloria](http://perfectGod.com)