Thanks Jens, that makes sense.

As for your last example, that would allow me to do whole matches on the 
individual parts of the string. However, and this is stretching this 
particular example a bit, what if I wanted to match on a partial first name 
or last name? Say I've broken the name up as much as I can beforehand, and 
emitted the multiple keys, but I'd like to get all results that start with 
"Jon" including both "Jon" and "Jonathan". Also, potentially more 
difficult, I'd like to match the ending of an individual name component? 
Would I need to move to the postFilter predicate for this? 

On Tuesday, February 3, 2015 at 3:11:55 AM UTC-4, Jens Alfke wrote:
>
>
> On Feb 2, 2015, at 5:36 PM, Kevin Lord <[email protected] <javascript:>> 
> wrote:
>
> Is it possible to use any kind of regular expressions or wildcards in 
> string keys when querying a view? I would really like to match on portions 
> of a string aside from the beginning.
>
>
> In general, you can do this by querying the entire view (i.e. not setting 
> any startKey or endKey) and then using a postFilter predicate to do the 
> string matching.
>
> That may sound inefficient — and it is! — but that kind of search is 
> inevitably inefficient since it can't use an index to narrow down the keys. 
> (A SQL query would do exactly the same thing, behind the scenes.)
>
> eg. if I have a name property, with document that has the value "John 
> Michael Smith", I would like to query using a key "*Smith" or "*Michael*" 
> etc.
>
>
> A much more efficient way to do a search like this would be to make your 
> map function emit each component of the name as a separate key. For 
> example, something like
> emit(doc.firstName, nil);
> if (doc.middleName) emit(doc.middleName, nil);
> emit(doc.lastName, nil);
> (You don't have to store the name broken into components like that; if 
> it's in a single string property, the map function can just split it by 
> spaces and emit each component.)
> Then you can query for a name component like "Smith" or "Michael" by 
> setting that as the key, and find all instances of it.
>
> —Jens
>

-- 
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/d91cb99f-334c-46b4-8cfc-134bdfe8dc97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to