Skip to content

Commit

Permalink
fix paging problem and add hitlimit to ieee
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Arrow committed Feb 25, 2016
1 parent cd6d35d commit 2d06b39
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/ieee.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ IEEE.prototype.search = function(query) {
log.warn("The IEEE API does not provide supplementary materials, so the --supp will be ignored");
}

ieee.pagesize = 200;

options = {
hc: 200
hc: ieee.pagesize
};

if (!ieee.opts.all) {
Expand All @@ -39,9 +41,11 @@ IEEE.prototype.search = function(query) {

ieee.queryurl = ieee.buildQuery(query, options);
ieee.first = true;
ieee.residualhits = 0;
ieee.hitlimit = ieee.opts.hitlimit ? ieee.opts.hitlimit : 0;
ieee.hitcount = 0;
ieee.allresults = [];
ieee.iter = 0;
ieee.iter = 1;

ieee.timeouts = 0;

Expand Down Expand Up @@ -93,19 +97,26 @@ IEEE.prototype.completeCallback = function(data) {

log.info('The IEEE API does not provide fulltext HTML links, but we will try to guess them from other metadata');

// set hitlimit
if (ieee.hitlimit && ieee.hitlimit < ieee.hitcount) {
log.info('Limiting to ' + ieee.hitlimit + ' hits');
}
else { ieee.hitlimit = ieee.hitcount; }

// create progress bar
var progmsg = 'Fetching result metadata [:bar] :percent' +
' (:current/:total) [:elapseds elapsed, eta :etas]';
var progopts = {
total: ieee.hitcount,
total: ieee.hitlimit,
width: 30,
complete: chalk.green('=')
};
ieee.pageprogress = new ProgressBar(progmsg, progopts);

}

var result = data.root.document;
if(!ieee.residualhits) { var result = data.root.document; }
else { var result = data.root.document.slice(0,ieee.residualhits); }
var pretty = JSON.stringify(result, null, 2);
ieee.resultstream.write(pretty);

Expand All @@ -117,9 +128,12 @@ IEEE.prototype.completeCallback = function(data) {

if (ieee.allresults.length < ieee.hitcount) {
ieee.iter += 1;
remaininghits = ieee.hitcount - ieee.allresults.length;
if(remaininghits<ieee.pagesize) { ieee.residualhits = remaininghits; }
log.debug(ieee.allresults.length);
ieee.pageQuery();
} else {
log.info('Done collecting results');
log.info('Done collecting results. Got ' + ieee.allresults.length);
ieee.handleSearchResults(ieee);
}

Expand Down

0 comments on commit 2d06b39

Please sign in to comment.