Commit 71a49107 by rugbyhead

ES: adding ability to pass a query to the script to further filter the set of documents analyzed

parent 4cde56e9
...@@ -51,7 +51,10 @@ if (db[collection].count() == 0) { ...@@ -51,7 +51,10 @@ if (db[collection].count() == 0) {
"Possible collection options for database specified: " + collNames + "."; "Possible collection options for database specified: " + collNames + ".";
} }
if (typeof limit === "undefined") { var limit = db[collection].count(); } if (typeof query === "undefined") { var query = {}; }
print("Using query of " + query.toSource());
if (typeof limit === "undefined") { var limit = db[collection].find(query).count(); }
print("Using limit of " + limit); print("Using limit of " + limit);
if (typeof maxDepth === "undefined") { var maxDepth = 99; } if (typeof maxDepth === "undefined") { var maxDepth = 99; }
...@@ -182,7 +185,7 @@ var addVarietyResults = function(result) { ...@@ -182,7 +185,7 @@ var addVarietyResults = function(result) {
} }
// main cursor // main cursor
db[collection].find().sort({_id: -1}).limit(limit).forEach(function(obj) { db[collection].find(query).sort({_id: -1}).limit(limit).forEach(function(obj) {
var recordResult = {}; var recordResult = {};
for (var key in obj) { for (var key in obj) {
if(obj.hasOwnProperty(key)) { if(obj.hasOwnProperty(key)) {
...@@ -229,7 +232,7 @@ resultsDB[resultsCollectionName].find({}).forEach(function(key) { ...@@ -229,7 +232,7 @@ resultsDB[resultsCollectionName].find({}).forEach(function(key) {
if(limit < numDocuments) { if(limit < numDocuments) {
var existsQuery = {}; var existsQuery = {};
existsQuery[keyName] = {$exists: true}; existsQuery[keyName] = {$exists: true};
key.totalOccurrences = db[collection].count(existsQuery); key.totalOccurrences = db[collection].find(query).count(existsQuery);
} }
key.percentContaining = (key.totalOccurrences / numDocuments) * 100.0; key.percentContaining = (key.totalOccurrences / numDocuments) * 100.0;
resultsDB[resultsCollectionName].save(key); resultsDB[resultsCollectionName].save(key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment