+ (CBLQuery *)searchJobsInDatabase:(CBLDatabase* )db
{
CBLView *view = [db viewNamed:@"jobSearchResults"];
if (!view.mapBlock) {
[view setMapBlock: MAPBLOCK({
if ([doc[@"type"] isEqualToString:kListDocType]) {
NSString *body = stripHTMLTags(doc[@"jobNumber"]);
emit(CBLTextKey(body), doc[@"jobNumber"]);
}
}) reduceBlock:NULL version: @"1"];
}
return [view createQuery];
}
self.dataSource.query = [Job searchJobsInDatabase:database].asLiveQuery;
self.dataSource.query.fullTextQuery = @"999";
Todd
Can CBLTableViewDataSource be used with Full Text Searching? Can't seem to get it working and thought it might have something to do with the fact that the results are CBLFullTextQueryRows.
It always returns all the docs. If I break the full text query code out into a test method, it shows that it is in fact returning the correct docs. But the tableview is showing the wrong docs.
self.dataSource.query = [Job searchJobsInDatabase:database].asLiveQuery;self.dataSource.query.fullTextQuery = @"999";
*** ASSERTION FAILED: text != nil
2014-02-24 11:07:27.411 ShotBOT[3636:340b] *** Assertion failure in -[CBLSpecialKey initWithText:](), /Users/couchbase/jenkins/workspace/build_cblite_ios_stable/couchbase-lite-ios/Source/CBLView+Internal.m:383
11:07:27.412‖ WARNING*** : Exception caught in map block of view 'jobSearchResults':
text != nil
5 ShotBOT 0x00019ef9 -[CBLSpecialKey initWithPoint:] + 0
6 ShotBOT 0x00017d40 CBLTextKey + 80
7 ShotBOT 0x0000cc60 __28+[Job searchJobsInDatabase:]_block_invoke + 256
8 ShotBOT 0x00019877 __32-[CBLView(Internal) updateIndex]_block_invoke + 3344
9 ShotBOT 0x00010cba -[CBLDatabase(Internal) _inTransaction:] + 172
10 ShotBOT 0x00018a74 -[CBLView(Internal) updateIndex] + 239
11 ShotBOT 0x000550ad -[CBLDatabase(Views) queryViewNamed:options:lastSequence:status:] + 161
12 ShotBOT 0x000528d5 __21-[CBLQuery runAsync:]_block_invoke + 140
13 ShotBOT 0x0001e1b8 __35-[CBL_Server tellDatabaseNamed:to:]_block_invoke + 85
14 libobjc.A.dylib 0x01ab481f -[NSObject performSelector:withObject:] + 70
15 Foundation 0x016f79d8 __NSThreadPerformPerform + 285
16 CoreFoundation 0x01ca883f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
17 CoreFoundation 0x01ca81cb __CFRunLoopDoSources0 + 235
18 CoreFoundation 0x01cc529e __CFRunLoopRun + 910
19 CoreFoundation 0x01cc4ac3 CFRunLoopRunSpecific + 467
...
11:07:27.420‖ WARNING*** : CouchbaseLite: Failed to rebuild view 'jobSearchResults': 593
11:07:27.420‖ WARNING*** : Failed to update view index: 593
11:07:27.420| WARNING*** : <CBLLiveQuery: 0x8a8aab0>: Error updating rows: Error Domain=CBLHTTP Code=500 "500 Application callback block failed" UserInfo=0x9e58e10 {NSLocalizedFailureReason=Application callback block failed, NSLocalizedDescription=500 Application callback block failed}
One more issue with Full Text Query. It seems that it can't handle indexing on a field if one of the docs contain a property that is null if that property is being queried.
Is there no way to do a contains search? *test* does not seem to work. The docs mention doing a prefix like test* which works.
Also, I need to search across multiple properties. Is the correct way to do this is combine them into one string before sending them to CBLTextKey?
Rather than use FTS for this, maybe a NSPredicate on the datasource might be better? Do you think that would work? Not sure what the predicate string would be to drill down into the rows to get at the data….