> On Aug 4, 2015, at 12:59 AM, Marco Betschart <[email protected]> wrote: > > - I got multiple optional filter criterias such as "Name", "Gender" or "Group" > - The sort order should be [firstName,lastName]
This kind of query is too complex for a view to do on its own. The problem is that you’re selecting based on different criteria than you’re sorting on. (This is true of any index; SQL databases have the same constraints but the query engine works around it.) The best approach is to define the view so you can efficiently filter, and then add a custom sortDescriptor to the query. This will do the sorting in memory, but it should be fast enough unless the query returns a huge number of rows. Sorting by multiple optional criteria can be tricky. You won’t be able to do all combinations of name/gender/group filtering using a single index. (Again, this is true of any kind of index.) It’ll require multiple views. Have you looked at CBLQueryBuilder <https://github.com/couchbase/couchbase-lite-ios/wiki/Query-Builder>? It should be able to do what you’re asking. You specify the filter criteria as an NSPredicate and the sort order as an NSSortDescriptor, and it generates a view and does any custom sorting. (We don’t have official docs for it yet but the wiki page I linked to should be enough to get you started. Feel free to ask questions here.) —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/22D444AC-F9AA-4CA1-9D2D-F862941D8705%40couchbase.com. For more options, visit https://groups.google.com/d/optout.
