About Search

About Search

Contents

Introduction

getSearch method allows you to search for files and folders in a user’s Verizon Personal Cloud Storage account. The Java SDK includes the SearchBuilder class which allows you to build lucene-style search queries.

Examples

NOTE: Searches of higher complexity can be constructed by building lucene-style search strings directly.

Using SearchTemplate to Search for Files

Code Sample

// search for all files named ‘xyz’:
    SearchTemplate st = new SearchTemplate.Builder().name("xyz").build();
    Search search = client.getSearch(st.getQuery(), null, null, null);

// search for all audio files:
    SearchTemplate st = new SearchTemplate.Builder().contentType("audio/*").build();
    Search search = client.getSearch(st.getQuery(), null, null, null);        

Code Sample

// search for all files whose name starts with ‘x’: 
	SearchTemplate st = new SearchTemplate.Builder().name(“x*”).build(); 
	Search search = client.getSearch(st.getQuery(), null, null, null);

Code Sample

// search for all files named ‘a’ or ‘b’ 
	SearchTemplate st = new SearchTemplate.Builder().names(“a”, “b”).build(); 
	Search search = client.getSearch(st.getQuery(), null, null, null);

Search for All Files in a Specified Genre Added After a Specified Date

Code Sample

// search for all files in a certain genre that were added after a certain date
	SearchTemplate st = new SearchTemplate.Builder().genre(“rock”).creationDate(new 	Date(752184430123L)).build();
	Search search = client.getSearch(st.getQuery(), null, null, null);

Combining Multiple SearchTemplate Objects

Code Sample

// search for all files that were either added in 2015, or are named ‘exception.txt’:
	SearchTemplate st1 = new SearchTemplate.Builder().creationDate(new Date(1420070400L), new Date(1451606399L)).build();
	SearchTemplate st2 = new SearchTemplate.Builder().name(“exception.txt”).build();
	SearchTemplate st = new SearchTemplate.Builder().or(st1, st2).build();
	Search search = client.getSearch(st.getQuery(), null, null, null);

Search forRecently Updated Files

Code Sample

//search for files added after a certain date
    public List<FileMetadata> latestFiles(OAuthToken token, Date createdAfter) throws IOException, CloudHttpException
    {
        CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
        CloudClientContext context = new CloudClientContext(app, token);
        CloudClient client = new CloudClient(context);
        
        // search will exclude folders, and only those files created after 'createdAfter'
        SearchTemplate template = new SearchTemplate.Builder().files().creationDate(createdAfter).build();
        Search search = client.getSearch(template, null, null, null);
        return search.getFile();
    }

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