Couchbase lite query by a combination of a range of keys and a set of discrete keys


#1

Consider the following Android code:

    Database database = storageManager.getDatabase();
    com.couchbase.lite.View listingsView = database.getView("listings");
    listingsView.setMap(new Mapper() {
        @Override
        public void map(Map<String, Object> document, Emitter emitter) {
            if (document.containsKey("docType")) {
                String docType = (String) document.get("docType");
                if (docType.equals("listing")) {
                    emitter.emit(Arrays.asList(document.get("propertyType"), document.get("price")), document.get("description"));
                }
            }
        }
    }, "6");

    Query q = database.getView("listings").createQuery();
    q.setStartKey(Arrays.asList("AAA", 950));
    q.setEndKey(Arrays.asList("AAA", 2050));

In this application there are three property types AAA, BBB and CCC. The query above produces the result I want, i.e. all properties with propertyType=AAA with price ranging from 950 to 2050.

Question:

How can I include CCC (but not BBB) type properties in this query too. If I supply CCC to the end key then the result will include BBB type properties as well, it also messes up the price range query. I know I can run this query twice with different parameters, but then is there a way to merge the results? If not it get’s a bit difficult to drive the UI with this query. I am planning to use this as a live query as well.

Any suggestions are much appreciated!