Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var tweetsPerSect = 5
for (var sect in tweetsBySect){
//Select the tweets within the sect
var sectTweets = tweetsBySect[sect];
// Setup a hastable and list for heap
var hashtable = new HashTable();
var scoresList = []
for (var i = 0; i < sectTweets.length; i++) {
var tweet = sectTweets[i];
var score = evaluate(tweet);
scoresList.push(score);
hashtable.put(score, tweet);
}
//Get the largest few scores in the scoresList
var largeScores = Heap.nlargest(unique(scoresList), tweetsPerSect);
//Push those tweets into the final list
for (var i=0; i < tweetsPerSect; i++){
if (largeScores[i]) {
finalList.push(hashtable.get(largeScores[i]))
}
}
}
return finalList;
}
module.exports = function(arr, n=10) {
// Subset the reverse index so that both the largest elements
// and the indices where they occur are returned.
return _.pick(_.invertBy(arr),
Heap.nlargest(arr, n)
);
};
}
if (isArray) idx = parseInt(c);
else idx = c;
if (result > options.cutoff) results.push([choices[c], result, idx]);
}
if (isArray && c < choices.length - 1) {
setImmediate(function () { searchLoop(c + 1) })
}
else if (i < keys.length - 1) {
setImmediate(function () { searchLoop(keys[i + 1], i + 1) });
}
else {
if (anyblank) console.log("One or more choices were empty. (post-processing if applied)")
if (options.limit && typeof options.limit === "number" && options.limit > 0 && options.limit < numchoices && !options.unsorted) {
var cmp = function (a, b) { return a[1] - b[1]; }
results = Heap.nlargest(results, options.limit, cmp);
}
else if (!options.unsorted) {
results = results.sort(function (a, b) { return b[1] - a[1]; });
}
callback(null, results);
}
}
}
}
else {
mychoice = pre_processor(options.processor(value), options);
if (typeof mychoice !== "string" || mychoice.length === 0) anyblank = true;
if (normalize && typeof mychoice === "string") mychoice = mychoice.normalize();
result = options.scorer(query, mychoice, options);
}
if (result > options.cutoff) {
if (options.returnObjects) results.push({choice: value, score: result, key: key});
else results.push([value, result, key]);
}
});
if (anyblank) if (typeof console !== undefined) console.log("One or more choices were empty. (post-processing if applied)")
if (options.limit && typeof options.limit === "number" && options.limit > 0 && options.limit < numchoices && !options.unsorted) {
results = Heap.nlargest(results, options.limit, cmpHeap);
}
else if (!options.unsorted) {
results = results.sort(cmpSort);
}
return results;
}
if (choices[c].tokens) options.tokens = [query_tokens, choices[c].tokens];
else options.tokens = [query_tokens, tokenize(mychoice)]
//query and mychoice only used for validation here
var result = options.scorer(query, mychoice, options);
}
else {
var mychoice = pre_processor(options.processor(choices[c]), options.force_ascii).valueOf();
if (typeof mychoice !== "string" || (typeof mychoice === "string" && mychoice.length === 0)) anyblank = true;
var result = options.scorer(query, mychoice, options);
}
if (result > options.cutoff) results.push([choices[c],result]);
}
if(anyblank) console.log("One or more choices were empty. (post-processing if applied)")
if (options.limit && typeof options.limit === "number" && options.limit > 0 && options.limit < choices.length) {
var cmp = function(a, b) { return a[1] - b[1]; }
results = Heap.nlargest(results, options.limit, cmp);
}
else {
results = results.sort(function(a,b){return b[1]-a[1];});
}
return results;
}
callback(new Error("canceled"));
return;
}
if (isArray && c < choices.length - 1) {
if (c % loopOffset === 0) { setImmediate(function () { searchLoop(c + 1); }); }
else searchLoop(c + 1);
}
else if (i < keys.length - 1) {
if (i % loopOffset === 0) { setImmediate(function () { searchLoop(keys[i + 1], i + 1); }); }
else { searchLoop(keys[i + 1], i + 1); }
}
else {
if (anyblank) if (typeof console !== undefined) console.log("One or more choices were empty. (post-processing if applied)")
if (options.limit && typeof options.limit === "number" && options.limit > 0 && options.limit < numchoices && !options.unsorted) {
results = Heap.nlargest(results, options.limit, cmpHeap);
}
else if (!options.unsorted) {
results = results.sort(cmpSort);
}
callback(null, results);
}
}
}
callback(new Error("canceled"));
return;
}
if (isArray && c < choices.length - 1) {
if (c % loopOffset === 0) { setImmediate(function () { searchLoop(c + 1) }); }
else { searchLoop(c + 1); }
}
else if (i < keys.length - 1) {
if (i % loopOffset === 0) {setImmediate(function () { searchLoop(keys[i + 1], i + 1); }); }
else { searchLoop(keys[i + 1], i + 1); }
}
else {
if (anyblank) if (typeof console !== undefined) console.log("One or more choices were empty. (post-processing if applied)")
if (options.limit && typeof options.limit === "number" && options.limit > 0 && options.limit < numchoices && !options.unsorted) {
results = Heap.nlargest(results, options.limit, cmpHeap);
}
else if (!options.unsorted) {
results = results.sort(cmpSort);
}
callback(null, results);
}
}
}
mychoice = pre_processor(options.processor(choices[c]), options);
if (typeof mychoice !== "string" || mychoice.length === 0) anyblank = true;
if (normalize && typeof mychoice === "string") mychoice = mychoice.normalize();
result = options.scorer(query, mychoice, options);
}
if (isArray) idx = parseInt(c);
else idx = c;
if (result > options.cutoff) {
if (options.returnObjects) results.push({ choice: choices[c], score: result, key: idx });
else results.push([choices[c], result, idx]);;
}
}
}
if (anyblank) if (typeof console !== undefined) console.log("One or more choices were empty. (post-processing if applied)")
if (options.limit && typeof options.limit === "number" && options.limit > 0 && options.limit < numchoices && !options.unsorted) {
results = Heap.nlargest(results, options.limit, cmpHeap);
}
else if (!options.unsorted) {
results = results.sort(cmpSort);
}
return results;
}
}
else {
mychoice = pre_processor(options.processor(choices[c]), options.force_ascii);
if (typeof mychoice !== "string" || mychoice.length === 0) anyblank = true;
if (normalize && typeof mychoice === "string") mychoice = mychoice.normalize();
result = options.scorer(query, mychoice, options);
}
if (isArray) idx = parseInt(c);
else idx = c;
if (result > options.cutoff) results.push([choices[c], result, idx]);
}
}
if(anyblank) console.log("One or more choices were empty. (post-processing if applied)")
if (options.limit && typeof options.limit === "number" && options.limit > 0 && options.limit < numchoices && !options.unsorted) {
var cmp = function(a, b) { return a[1] - b[1]; }
results = Heap.nlargest(results, options.limit, cmp);
}
else if (!options.unsorted) {
results = results.sort(function(a,b){return b[1]-a[1];});
}
return results;
}