sqlite> select *from revs;
1|1|1-2fc730769d3a7ff64c7e3e512cadb12a||0|0|{"contactData":"Tel:
+4912342340","progress":75,"type":"contacInfo","userOlder":8,"user_id":"N_older_Pro_0"}|1
2|2|1-554a468df052a997bca3a64a40a9b06d||1|0|{"contactData":"Tel:
+4912342341","progress":76,"type":"contacInfo","userOlder":5,"user_id":"N_older_Pro_1"}|1
3|3|1-e550947cda089edd35170c49c6d1023b||1|0|{"contactData":"Tel:
+4912342342","progress":65,"type":"contacInfo","userOlder":9,"user_id":"N_older_Pro_2"}|1
4|4|1-0601c2e7054bd8f1c21f26c9ebd93c3a||1|0|{"contactData":"Tel:
+4912342343","progress":60,"type":"contacInfo","userOlder":8,"user_id":"N_older_Pro_3"}|1
5|1|2-599f9eb423907d211eb7ca6ebc597ba6|1|1|0|{"contactData":"Tel:
+4912342340","progress":75,"type":"contacInfo","userOlder":8,"user_id":"N_older_Pro_0"}|1
6|5|1-f20c5c37c10192ac46cf67e53eb26a70||1|0|{"contactData":"Tel:
+4912342343_1","progress":35,"type":"contacInfo","userOlder":1,"user_id":"N_older_Pro_4"}|1
7|6|1-f88596fb5c22efb73407c4aa6b3dd2c3||1|0|{"contactData":"Tel:
+4912342343","progress":8,"type":"contacInfo","userOlder":8,"user_id":"N_older_Pro_10"}|1
8|7|1-8f55890cb67557a0f18ba5f852fca07f||1|0|{"contactData":"Tel:
+4912342343","progress":8,"type":"contacInfo","userOlder":0,"user_id":"N_older_Pro_11"}|1
and then query it :
(Querying pro:60 older: 2 ,3)
CBLView * contactInfoView = [self.database viewNamed:
@"contactDataByProgressAndOlder"];
[contactInfoView setMapBlock: MAPBLOCK({
if ([doc[@"type"] isEqualToString: @"contacInfo"]) {
if (doc[@"progress"] && doc[@"userOlder"])
emit(@[doc[@"progress"], doc[@"userOlder"]], doc);
}
}) version: @"3"];
//2 - make the query
CBLQuery* query = [contactInfoView createQuery];
NSLog(@"Querying pro:%@ older: %@ ,%@",pro, startOlder,endOlder);
query.startKey = @[pro,startOlder];
query.endKey = @[[NSNumber numberWithInteger: 75], endOlder];
return query;
and wrong result:
2014-10-30 21:36:40.068 TestCLDB[851:24414] Querying pro:60 older: 2 ,3
2014-10-30 21:36:40.070 TestCLDB[851:24414] Found document:
CBLDocument[N_ol..ro_3] ,{
"_id" = "N_older_Pro_3";
"_rev" = "1-0601c2e7054bd8f1c21f26c9ebd93c3a";
contactData = "Tel: +4912342343";
progress = 60;
type = contacInfo;
userOlder = 8;
"user_id" = "N_older_Pro_3";
}
2014-10-30 21:36:40.070 TestCLDB[851:24414] Found document:
CBLDocument[N_ol..ro_2] ,{
"_id" = "N_older_Pro_2";
"_rev" = "1-e550947cda089edd35170c49c6d1023b";
contactData = "Tel: +4912342342";
progress = 65;
type = contacInfo;
userOlder = 9;
"user_id" = "N_older_Pro_2";
}
But i query (Querying pro:60 older: 8 ,10) it's run success:
2014-10-30 21:58:40.343 TestCLDB[987:41693] Querying pro:60 older: 8 ,10
2014-10-30 21:58:40.348 TestCLDB[987:41693] Found document:
CBLDocument[N_ol..ro_3] ,{
"_id" = "N_older_Pro_3";
"_rev" = "1-0601c2e7054bd8f1c21f26c9ebd93c3a";
contactData = "Tel: +4912342343";
progress = 60;
type = contacInfo;
userOlder = 8;
"user_id" = "N_older_Pro_3";
}
2014-10-30 21:58:40.348 TestCLDB[987:41693] Found document:
CBLDocument[N_ol..ro_2] ,{
"_id" = "N_older_Pro_2";
"_rev" = "1-e550947cda089edd35170c49c6d1023b";
contactData = "Tel: +4912342342";
progress = 65;
type = contacInfo;
userOlder = 9;
"user_id" = "N_older_Pro_2";
}
2014-10-30 21:58:40.349 TestCLDB[987:41693] Found document:
CBLDocument[N_ol..ro_0] ,{
"_id" = "N_older_Pro_0";
"_rev" = "2-599f9eb423907d211eb7ca6ebc597ba6";
contactData = "Tel: +4912342340";
progress = 75;
type = contacInfo;
userOlder = 8;
"user_id" = "N_older_Pro_0";
}
so ,what's wrong ???
query range wrong or why ?
在 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/867490f8-5ac5-4537-b4c4-f229ee7a8943%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.