<commit_before>"use strict";

//Load dependencies
var async = require("async");
var applicationStorage = process.require("core/applicationStorage.js");
var guildModel = process.require("guilds/guildModel.js");
var guildCriteria = process.require("guilds/utilities/mongo/guildCriteria.js");
var guildProjection = process.require("guilds/utilities/mongo/guildProjection.js");
var numberLimit = process.require("core/utilities/mongo/numberLimit.js");
var guildSort = process.require("guilds/utilities/mongo/guildSort.js");
var guildService = process.require("guilds/guildService.js");
var updateModel = process.require("updates/updateModel.js");

/**
 * Return guilds
 * @param req
 * @param res
 */
module.exports.getGuilds = function (req, res) {
    var logger = applicationStorage.logger;
    logger.verbose("%s %s %s", req.method, req.path, JSON.stringify(req.query));

    async.waterfall([
            function (callback) {
                guildCriteria.get(req.query, function (error, criteria) {
                    callback(error, criteria);
                });
            },
            function (criteria, callback) {
                callback(null, criteria, guildProjection.get(req.query));
            },
            function (criteria, projection, callback) {
                callback(null, criteria, projection, numberLimit.get(req.query));
            },
            function (criteria, projection, limit, callback) {
                callback(null, criteria, projection, limit, guildSort.get(req.query));
            },
            function (criteria, projection, limit, sort, callback) {
                logger.debug("guilds - criteria:%s projection:%s limit:%s sort:%s", JSON.stringify(criteria), JSON.stringify(projection), JSON.stringify(limit), JSON.stringify(sort));
                //TODO Improve hint selection
                if (query.lfg == "true") {
                    guildModel.find(criteria, projection, sort, limit, {"ad.lfg": 1}, function (error, guilds) {
                        callback(error, guilds);
                    });
                }
                else if (query.rank =="true"){
                    guildModel.find(criteria, projection, sort, limit, {"rank.Hellfire Citadel.world": 1}, function (error, guilds) {
                        callback(error, guilds);
                    });
                } else {
                    guildModel.find(criteria, projection, sort, limit, function (error, guilds) {
                        callback(error, guilds);
                    });
                }
            }

        ],
        function (error, guilds) {
            if (error) {
                logger.error(error.message);
                res.status(500).send(error.message);
            }
            res.json(guilds);
        }
    )
    ;
}<commit_msg>Progress rank criterion change for best performance.<commit_after>"use strict";

//Load dependencies
var async = require("async");
var applicationStorage = process.require("core/applicationStorage.js");
var guildModel = process.require("guilds/guildModel.js");
var guildCriteria = process.require("guilds/utilities/mongo/guildCriteria.js");
var guildProjection = process.require("guilds/utilities/mongo/guildProjection.js");
var numberLimit = process.require("core/utilities/mongo/numberLimit.js");
var guildSort = process.require("guilds/utilities/mongo/guildSort.js");
var guildService = process.require("guilds/guildService.js");
var updateModel = process.require("updates/updateModel.js");

/**
 * Return guilds
 * @param req
 * @param res
 */
module.exports.getGuilds = function (req, res) {
    var logger = applicationStorage.logger;
    logger.verbose("%s %s %s", req.method, req.path, JSON.stringify(req.query));

    async.waterfall([
            function (callback) {
                guildCriteria.get(req.query, function (error, criteria) {
                    callback(error, criteria);
                });
            },
            function (criteria, callback) {
                callback(null, criteria, guildProjection.get(req.query));
            },
            function (criteria, projection, callback) {
                callback(null, criteria, projection, numberLimit.get(req.query));
            },
            function (criteria, projection, limit, callback) {
                callback(null, criteria, projection, limit, guildSort.get(req.query));
            },
            function (criteria, projection, limit, sort, callback) {
                logger.debug("guilds - criteria:%s projection:%s limit:%s sort:%s", JSON.stringify(criteria), JSON.stringify(projection), JSON.stringify(limit), JSON.stringify(sort));
                //TODO Improve hint selection
                if (req.query.lfg == "true") {
                    guildModel.find(criteria, projection, sort, limit, {"ad.lfg": 1}, function (error, guilds) {
                        callback(error, guilds);
                    });
                }
                else if (req.query.rank =="true"){
                    guildModel.find(criteria, projection, sort, limit, {"rank.Hellfire Citadel.world": 1}, function (error, guilds) {
                        callback(error, guilds);
                    });
                } else {
                    guildModel.find(criteria, projection, sort, limit, function (error, guilds) {
                        callback(error, guilds);
                    });
                }
            }

        ],
        function (error, guilds) {
            if (error) {
                logger.error(error.message);
                res.status(500).send(error.message);
            }
            res.json(guilds);
        }
    )
    ;
}
{'fraction_non_alphanumeric': 0.12890142831952037, 'fraction_numerical': 0.0017633574325515782, 'mean_word_length': 2.0725893824485375, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1992804', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1469, 'n_words': 306}