Skip to main content
Question

Exact search

  • May 21, 2025
  • 2 replies
  • 29 views

Forum|alt.badge.img

I'm using the Java SDK to run a search within a specific folder. Unfortunately my search doesn't seem to work as I want it too. I want my search to be an EXACT search, so if I search for "12345-123", I want it to return only "12345-123", and not results like "12345-876". The search should search in text, title and metadata.

I tried adding quotes, as some documentation seems to indicate that should return an exact search, but that doesn't seem to do it.

 

Any ideas?

 

I'm using following code:

 

BoxSearchParameters bsp = new BoxSearchParameters();
//bsp.setQuery("\"" + query + "\"");
bsp.setQuery(query);
			
List foldersToSearch = new ArrayList();
foldersToSearch.add(folderId);
bsp.setAncestorFolderIds(foldersToSearch);

//Setup Result Partial Object
PartialCollection searchResults = null;

//Starting point of the result set
long offset = 0;

//Number of results that would be pulled back
long limit = 1000;

//Storing the full size of the results
long fullSizeOfResult = 0;

while (offset <= fullSizeOfResult) {
        searchResults = boxSearch.searchRange(offset, limit, bsp);
	fullSizeOfResult = searchResults.fullSize();

	offset += limit;
}

2 replies

Forum|alt.badge.img

 You were on the right track, but I think this might be a string formatting issue in line 2. Can you please put wrap the first \  in quotes as shown below, and then retry the request?

//bsp.setQuery(""\" + query + "\"");

Forum|alt.badge.img

Hi Murtza,

 

Thanks for taking the time to reply.
I'm afraid your code isn't valid java code?

The first " opens the string, then we escape the second " to not close the string, and then the third " closes the string.