Box.net Search pagination

316 views Asked by At

I'm trying to get a list of all my files in box, and I don't want to go over each and every folder and extract the files, it takes too much time if I have lots of files. So what I came up with is using the search method over the root folder using the query "0 1 2 3 4 5 6 7 8 9". The reason I use this query is that the search method also search the file ID, and every files ID must contain one of these numbers.

My problem is that I get maximum 200 results, while I have much more files in my box account. I'm using the Java SDK, if I use the REST api I can use limit and offset, but in the Java SDK I don't have such option. I have also tried using an iterator but it still came up only with 200 results.

Any ideas?

This is my code:

BoxFolder folder = new BoxFolder(api, "0");
    Iterable<BoxItem.Info> results = folder.search("0 1 2 3 4 5 6 7 8 9");
    int i = 1;

    for (BoxItem.Info result : results) {
        // Do something with the search result.
        System.out.println(i + ") " + result.getName());
        i++;

    }
1

There are 1 answers

1
Greg On

The iterator should be handling paging for you automatically, which is why there isn't a way of manually specifying the offset. If you're getting more results when using the REST API directly, then there might be a bug. If so, could you file an issue on GitHub.

I should also mention that search isn't a very reliable way of getting all the items in your account. File IDs aren't guaranteed to always be numbers, and indexing delays means that new items don't show up in search results right away.