> On Feb 2, 2015, at 5:36 PM, Kevin Lord <[email protected]> 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/41B6BFDD-D3C2-44CD-9B2F-6298A0CE763A%40couchbase.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to