Full-Text Search
Full-Text Search
To find files and folders within a Box account that match a given search query, use the query search method within the SDK, passing in keywords and filters as needed.
Define your search terms and filters by using the available fields
. Next, call
the search endpoint with the defined criteria to return the give files and
folders that are matched.
cURL
curl -X GET https://api.box.com/2.0/search?query=sales \
-H 'Authorization: Bearer <ACCESS_TOKEN>'
.NET
// Search for PDF or Word documents matching "Meeting Notes"
BoxCollection<BoxItem> results = await client.SearchManager
.QueryAsync("Meeting Notes", fileExtensions: new { "pdf", "docx" });
Java
// Find the first 10 files matching "taxes"
long offsetValue = 0;
long limitValue = 10;
BoxSearch boxSearch = new BoxSearch(api);
BoxSearchParameters searchParams = new BoxSearchParameters();
searchParams.setQuery("taxes");
searchParams.setType("file");
PartialCollection<BoxItem.Info> searchResults = boxSearch.searchRange(offsetValue, limitValue, searchParams);
Python
items = client.search().query(query='TEST QUERY', limit=100, file_extensions=['pdf', 'doc'])
for item in items:
print('The item ID is {0} and the item name is {1}'.format(item.id, item.name))
Node
// Search for PDF or Word documents matching "Mobile"
client.search.query(
'Mobile',
{
fields: 'name,modified_at,size,extension,permissions,sync_state',
file_extensions: 'pdf,doc',
limit: 200,
offset: 0
})
.then(results => {
/* results -> {
total_count: 1,
entries:
[ { type: 'file',
id: '11111',
sequence_id: '1',
etag: '1',
sha1: 'f89d97c5eea0a68e2cec911s932eca34a52355d2',
name: 'Box for Sales - Empowering Your Mobile Worker White paper 2pg (External).pdf',
description: '',
size: 408979,
path_collection:
{ total_count: 2,
entries:
[ { type: 'folder',
id: '0',
sequence_id: null,
etag: null,
name: 'All Files' },
{ type: 'folder',
id: '22222',
sequence_id: '1',
etag: '1',
name: 'Marketing Active Work' } ] },
created_at: '2014-05-17T12:59:45-07:00',
modified_at: '2014-05-17T13:00:20-07:00',
trashed_at: null,
purged_at: null,
content_created_at: '2014-05-17T12:58:58-07:00',
content_modified_at: '2014-05-17T12:58:58-07:00',
created_by:
{ type: 'user',
id: '33333',
name: 'Example User',
login: 'user@example.com' },
modified_by:
{ type: 'user',
id: '33333',
name: 'Example User',
login: 'user@example.com' },
owned_by:
{ type: 'user',
id: '33333',
name: 'Example User',
login: 'user@example.com' },
shared_link: null,
parent:
{ type: 'folder',
id: '22222',
sequence_id: '1',
etag: '1',
name: 'Marketing Active Work' },
item_status: 'active' } ],
limit: 200,
offset: 0 }
*/
});
iOS
client.search.query(query: "Quarterly Business Review") { results in
switch results {
case let .success(iterator):
for i in 1 ... 10 {
iterator.next { result in
switch result {
case let .success(item):
switch item {
case let .file(file):
print("- File \(file.name) (ID: \(file.id))")
case let .folder(folder):
print("- Folder \(file.name) (ID: \(file.id))")
case let .webLink(webLink):
print("- Web Link \(file.name) (ID: \(file.id))")
}
case let .failure(error):
print(error)
}
}
}
case let .failure(error):
print(error)
}
}