Skip to content

Search API returns partial matches instead of exact filename match. #1669

@Inte-Takeuchi

Description

@Inte-Takeuchi

I'm using Box Java SDK 10.1.0.

Issue
I'm trying to search for a file by its exact name in Box and retrieve the file information, but I'm not getting the expected results.

Code Example

String fileName = "Test01_20251225.txt";
SearchManager searchManager = client.getSearch();
SearchForContentQueryParams queryParams = new SearchForContentQueryParams.Builder()
    .query(fileName)
    .ancestorFolderIds(java.util.Arrays.asList(folderId))
    .contentTypes(java.util.Arrays.asList(
        new EnumWrapper(SearchForContentQueryParamsContentTypesField.NAME)))
    .type(SearchForContentQueryParamsTypeField.FILE)
    .build();
SearchResultsResponse response = searchManager.searchForContent(queryParams);
SearchResults results = response.getSearchResults();
List items = results.getEntries();
for (SearchResultItem item : items) {
    if (item.isFileFull()) {
        String name = item.getFileFull().getName();
        debug("   item:[%s]", name);
        if (fileName.equals(name)) {
            fileFull = item.getFileFull();
            break;
        }
    }
}

Actual Results

  • response.getLimit() = 30
  • response.getOffset() = 0
  • response.getTotalCount() = 10
  • The Entries contain 10 files with similar names like "Test02_20251224.txt"

Expected Behavior
I would like to search for a file by its exact name and retrieve only that single matching file.

What I've Tried
I tried wrapping the query with double quotes (query("\"" + fileName + "\"")), but the results remained the same.

Question
Is it possible to retrieve only one file by specifying an exact filename match?

Metadata

Metadata

Labels

questionAdded to questions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions