I've across this "view" that emits keys allowing me to query by partial
words:
[vistaRuteroMedicosFTS setMapBlock:^(NSDictionary *doc, CBLMapEmitBlock
emit) {
if([doc[@"type"] isEqualToString:@"RuteroMedicos"] &&
[doc[@"estado_contacto"] integerValue] != 4 && [doc[@"estado_contacto"]
integerValue] != 2){
NSString *datoTexto = [NSString stringWithFormat:@"%@ %@ %@ %@
%@", doc[@"codigo_contacto"], doc[@"nombres"], doc[@"apellidos"],
doc[@"nombre_especialidad"], doc[@"direccion_visita"]];
// Tokenizar y generar keys
NSArray *tokens = [[datoTexto lowercaseString]
componentsSeparatedByCharactersInSet:[NSCharacterSet
whitespaceAndNewlineCharacterSet]];
tokens = [tokens filteredArrayUsingPredicate:[NSPredicate
predicateWithFormat:@"SELF != ''"]];
// Por cada key, generar las secuencias posibles y emitir las
claves
for(NSString *tok in tokens){
NSInteger inicioTok = 0;
NSInteger longTok = 0;
// "abre" las coincidencias desde el inicio
NSString *emitTok;
for(longTok = 1; longTok < [tok length]; longTok ++){
emitTok = [tok
substringWithRange:NSMakeRange(inicioTok, longTok)];
CLSNSLog(@"Token emitido: '%@'", emitTok);
emit(@[emitTok, doc[@"codigo_contacto"]], nil);
}
// "cierra" las coincidencias hasta el fin
for(inicioTok = 0; inicioTok < [tok length]; inicioTok ++){
longTok = [tok length] - inicioTok;
emitTok = [tok
substringWithRange:NSMakeRange(inicioTok, longTok)];
CLSNSLog(@"Token emitido: '%@'", emitTok);
emit(@[emitTok, doc[@"codigo_contacto"]], nil);
}
}
}
} reduceBlock:^id(NSArray *keys, NSArray *values, BOOL rereduce) {
CLSNSLog(@"keys: %@", keys[0][1]);
return keys[0][1];
} version:@"2.9"];
But can't figure how to emit unique keys, it emits repeating keys for about
17K rows.
thanks.
El viernes, 14 de febrero de 2014 15:29:35 UTC-5, Frederic Yesid Peña
Sánchez escribió:
>
> Hi.
>
> We need to enable searching by FullTextSearch, but don't know how to do
> "partial" word search, so if i have the phrase "The quick brown fox",
> searching for "uic" should match.
>
> (May be this question is for SqLite but SO does not help...)
>
> My View:
>
> [vistaContactos setMapBlock:^(NSDictionary *doc, CBLMapEmitBlock emit) {
>
> if([doc[@"type"] isEqualToString:@"RuteroMedicos"] && [doc[
> @"estado_contacto"] integerValue] != 4 && [doc[@"estado_contacto"]
> integerValue] != 2){
>
>
>
> NSString *datoTexto = [NSString stringWithFormat:@"%@ %@
> %@ %@ %@", doc[@"codigo_contacto"], doc[@"nombres"], doc[@"apellidos"],
> doc[@"nombre_especialidad"], doc[@"direccion_visita"]];
>
>
>
> emit(CBLTextKey(datoTexto), doc);
>
>
>
> }
> } version:@"2.0"];
>
--
You received this message because you are subscribed to the Google Groups
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/mobile-couchbase/783ae634-a7ed-4e0f-ad52-970b7956a164%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.