by the way . where is " feature/query" ? i
thanks

在 2014年9月30日星期二UTC+8下午11时51分14秒,Jens Alfke写道:
>
>
> On Sep 29, 2014, at 10:16 PM, peng liu <[email protected] <javascript:>> 
> wrote:
>
> i have a user model. and has "pro" and "older",i want query "pro> 75 and 
> 5<older<10" ,how to do that on couchbase ios? i have try set startKey and 
> endKey but not work.
>
>
> Unfortunately you can't do that query with just an index lookup. You've 
> got the index keys set up correctly, but the way the rows are ordered 
> doesn't allow more than one of the keys to be range-checked. The best you 
> can do is query over the desired range of the primary key; you'll have to 
> filter on the secondary key yourself.
>
> So in your example, you would set
> query.startKey = @{@75, @{}}
> and no endKey. You'd then iterate the results and manually test the 
> secondary key:
> for (CBLQueryRow* row in [query run: &error]) {
> int older = [row.key2 intValue];
> if (older > 5 && older < 10) {
> … use the row …
> }
> }
>
> This is actually a perfect use case for the new postFilter attribute 
> that's available on the feature/query branch. On that branch you can modify 
> the query like this:
> query.postFilter = [NSPredicate predicateWithFormat: @"key2 > 5 and key2 < 
> 10"];
> and it will then produce only the results you want.
>
> (And in fact this is exactly what a SQL query would do — the query planner 
> would realize the index lookup could only filter on the primary key, so it 
> would then internally post-filter the results to check the secondary key. 
> The CBLQueryPlanner class that's also available on the feature/query branch 
> will do the same thing if you give it a query like this, including 
> designing the view for you!)
>
> —Jens
>
> PS: The cool new query tools on the feature/query branch are just one of 
> the upcoming features I'll be talking about in my "The Future Of Couchbase 
> Lite" talk at the Couchbase Connect conference next Tuesday! Be there!
>

-- 
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/56025466-5e0c-457a-baef-369695cb1866%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to