-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No Offset Based Pagination in Search #187
Comments
I ran into the same issue where I needed more than 100 results. I modified the search.js file max results to 2500 or 5000.The search takes a little longer, but I get all the results I need. Location on a PC
'use strict';
const BoxCommand = require('../box-command');
const { flags } = require('@oclif/command');
const _ = require('lodash');
const BoxCLIError = require('../cli-error');
const RESULTS_LIMIT = 5000; |
Thanks @ianhorn , I think I can work with that just enough to get me out of a hole. :-) @sujaygarlanka Thank you. Just so I understand, do I take it the code is essentially interpreted at run time? |
@vroommm I'm not sure I'm following. You will need to drill down to the If I understand your question correctly, once you have edited the Example box search FILENAME -s |
@ianhorn The file I was looking at is under I've made the change you suggested and it WORKS!!! (but you knew that!)
So although I can't get back the marbles I lost battling with this, I can at least keep the few I have remaining for a little longer... Thanks... FYI: The above results also answer my secondary question... Although I can read java, and have dabbled, I've never knowingly used Node. An understanding of the architecture, however superficial is always nice... |
@vroommm I'm glad you found the correct Out of curiosity, once you changed the |
@ianhorn Haven't tried anything fancy with limit stuff yet. I will if/when I get a moment. I'm resisting the urge for one more compile and moving on... |
@ianhorn The one thing I was trying to do, with moderate success, was to batch the files by date range... I was using a bulk import input file like this...
that kind of worked... but only if there were less than 100 files on the day in question... not something I could guarantee. |
@ianhorn @sujaygarlanka
The last one can be really useful to combine with sort so you can use it to get the latest, oldest, first, last based on the sort direction and sort term... As it turns out the code is pretty simple (even I managed it): const RESULTS_LIMIT = 100;
//... omit a bit...
class SearchCommand extends BoxCommand {
async run() {
const { flags, args } = this.parse(SearchCommand);
//Set the limit to the default unless we passed a value
let options = {};
if (flags.limit){
options.limit = flags.limit;
} else {
options.limit = RESULTS_LIMIT;
}
//... omit a bit more
// Limit the search results to avoid slamming the API
let limitedResults = [];
for await (let result of { [Symbol.asyncIterator]: () => results }) {
let numResults = limitedResults.push(result);
//edit by vroommm to use the current options value
if (numResults >= options.limit) {
break;
}
}
await this.output(limitedResults);
//... gosh how much are we leaving out
SearchCommand.description = 'Search for files and folders in your Enterprise';
SearchCommand.examples = [
'box search "Q3 OKR"',
'box search --mdfilter "enterprise.employeeRecord.name=John Doe"',
'box search *.pdf --limit=250'
];
SearchCommand._endpoint = 'get_search';
SearchCommand.flags = {
...BoxCommand.flags,
limit: flags.integer({
description: 'The max number of records to return in the result set DEFAULT: 100'
}),
//... phew we're done leaving stuff out |
@sujaygarlanka @ianhorn //... stuff before
if (flags.offset){
options.offset = flags.offset;
}
//... really you're omitting some more
offset: flags.integer({
description: 'The 0 based page to return, default=0 or omitted for first page, 1= second etc..'
}),
limit: flags.integer({
description: 'The max number of records to return in the result set DEFAULT: 100'
}), Which means you can get the nth value for any search by using...
and of course you can use it to get pages of multiple records as:
Finally this approach should work for all the offset paginated box CLI methods... |
minor note: when
but these will cause errors:
|
Good job @vroommm. That's impressive. I really struggle with node javascript but have started to have some success. |
@vroommm Also, regarding the issues with the bulk command, it may be limited to 100 because you set |
I'd agree with that. Only possible extra would be a form of validation, e.g. if (offset!=0 && (offset % limit != 0)) { ...then its not a valid combo so throw an error} The default RESULT_LIMIT of 100 is a safe bet to leave as is, because as written:
Happy Days :-) |
@sujaygarlanka If it were possible to have a You would be able to get the number of results to expect without actually pulling them over the network... so if
|
SDK-1379 |
This issue has been automatically marked as stale because it has not been updated in the last 30 days. It will be closed if no further activity occurs within the next 7 days. Feel free to reach out or mention Box SDK team member for further help and resources if they are needed. |
Description of the Issue
There doesn't seem to be a way to use Offset based pagination with the box search command
https://developer.box.com/guides/api-calls/pagination/offset-based/
Instead there is a hard limit on the size of the search Result defined as 100. This is smaller than the max results size in the REST API which is 200 results.
https://developer.box.com/reference/get-search/
The limitation is significant because search is the only method I have found to recurse over a folder structure and get all items matching a pattern in one step for example... find me all the pdfs in my folders under a given start folder..
(deep apologies if the code is pants I'm no expert!!!)
there is no method to pass an offset to get a specific set of results.
there is no way to get
total_count
the absolute result set size as per the docsMaybe the best option here is to wrap all of this into the search options interface so we can have
box search abc
would fetch the first 100 records as it does now...box search:total_count --limit=200
would fetch back the total number of pages if the limit is 200 per pagebox search abc* --limit=200 --offset=2
fetches 200 entries from the 3rd page of the collectionVersions Used
Box CLI: @box/cli/2.4.0 win32-x64 node-v12.6.0
Operating System: Windows 10
Steps to Reproduce
Error Message, Including Stack Trace
N/A
The text was updated successfully, but these errors were encountered: