如何使用Bluemix中的QueryResult来获取BasicDocumentRevision

时间:2016-04-28 13:33:46

标签: ibm-cloud cloudant

public List<Task> allTasks() {
    int nDocs = this.mDatastore.getDocumentCount();
    List<BasicDocumentRevision> all = this.mDatastore.getAllDocuments(0, nDocs, true);
    List<Task> tasks = new ArrayList<Task>();

    // Filter all documents down to those of type Task.
    IndexManager im = new IndexManager(mDatastore);
    List<Object> indexFields = new ArrayList<Object>();
    indexFields.add("city");
    indexFields.add("price");
    indexFields.add("Area");
    indexFields.add("Information");
    indexFields.add("imagename");

// Create the index
    im.ensureIndexed(indexFields);
    Map<String, Object> query = new HashMap<String, Object>();
    query.put("desc", "RESIDENTIAL PROPERTY");
    QueryResult result = im.find(query);


    for(BasicDocumentRevision rev :all) {
        Task t = Task.fromRevision(rev);
        if (t != null) {

            tasks.add(t);

        }
    }

    return tasks;

如何使用queryresult将其存储在任务类对象中?我希望我的查询只列在listview中。我正在使用Bluemix,它使用Cloudant syn。

1 个答案:

答案 0 :(得分:0)

您可以通过迭代QueryResult对象从QueryResult获取文档修订版,如:

for(DocumentRevision rev : result){
    Task t = Task.fromRevision(rev);
    if(task != null)
        tasks.add(t);
}