About Search

About Search

Contents

Introduction

Use search method to retrieve all files and folders stored in a user’s Personal Cloud Storage account that match the specified criteria.

Examples

  1. Add Cloud SDK for Android to an existing or a new Android project.
  2. Initialize the CloudAPI class object with the application key, secret and the callback URL you obtained from the ThingSpace portal.
  3. Authorize the application by calling CloudAPI#authorize().
  4. Perform search using the code samples listred below.

Code Sample

try {
    cloudAPI.search(this, CloudAPI.QueryType.SQL, searchQuery, groupBy, sortBy, limit, new SearchCallback() {

        @Override
        public void onError(final SearchException exception) {
            Log.e("Search Result", "Search error: " + exception);
        }

        @Override
        public void onSuccess(final ItemList<FullviewItem> itemList, final boolean isOffline) {
            Log.e("Search result", "search count: " + itemList.getCount() + " Offline: " + isOffline);
            for (int count = 0; count < itemList.getCount(); count++) {
                FullviewItem fullviewItem = itemList.getItem(count);
                Log.d("Search Result", "Name: " + fullviewItem.getName());
            }
        }
    });
} catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
        Log.d("Search", "User not authorized, please call CloudAPI#authorize()");
    }
}```

### Search Query Examples

#### Search by Extension

This query lists all files with a `jpg` extension:

```java
searchQuery = CloudAPI.Search.NAME + " LIKE '%jpg%’”; 

Search for File Type

This query lists all mustic files from a specified album:

searchQuery = CloudAPI.Search.MIME_TYPE + " LIKE ‘%audio%’ AND ” + CloudAPI.Search.ALBUM + “=‘xyz’";

Search by Creation Date

This query retrieves all photos captured between specified dates:

searchQuery = CloudAPI.Search.MIME_TYPE + “ like '%image%’ AND (“ + CloudAPI.Search.CAPTURED_DATE + ">= '2015-05-01%' AND “ + CloudAPI.Search.CAPTURED_DATE + " <= '2016-05-01%’)"

groupBy Examples

Group by Album

groupBy = CloudAPI.Search.ALBUM

Group by Genre

groupBy = CloudAPI.Search.GENRE

sortBy Examples

Sort by Name

CloudAPI.Search.NAME

Sort by Creation Date

CloudAPI.Search.CREATED_DATE + " DESC"

Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.