<commit_before>/*jslint node: true */
/*global require */

module.exports = function (Gearman, elasticManager, settings) {
    "use strict";

    var gearmanSettings = settings.gearman;

    var gearman = new Gearman(gearmanSettings.hostname, gearmanSettings.port);

    console.info(
        "Listening to gearman on %s:%d (%s)",
        settings.gearman.hostname, settings.gearman.port, settings.env
    );

    gearman.registerWorker("searchDelete", function (payload, worker) {
        var data;

        if (! payload) {
            console.log("Payload not found for the searchDelete job");
            worker.error();
            return;
        }

        var input = payload.toString("utf-8");

        try {
            data = JSON.parse(input);

            if (! data.index || ! data.type || ! data.id) {
                console.error("Missing parameters from the JSON response");
                worker.error();
                return;
            }

            if (! (
                typeof data.index === "string" &&
                    typeof data.type === "string" &&
                    typeof data.id === "string"
                )) {
                console.error("Wrong parameter(s) type(s) from the JSON response");
                worker.error();
                return;
            }
        } catch (e) {
            console.error("Error parsing the expected JSON response (searchDelete job)");
            worker.error();
            return;
        }

        elasticManager.deleteDocument("post", document.type, document.id, function (isSuccess) {
            if (isSuccess) {
                worker.end();
            } else {
                worker.error();
            }
        });
    });

    gearman.registerWorker("searchIndex", function (payload, worker) {
        var data;

        if (! payload) {
            console.log("Payload not found for the searchIndex job");
            worker.error();
            return;
        }

        var input = payload.toString("utf-8");

        try {
            data = JSON.parse(input);

            if (! data.index || ! data.type || ! data.id || ! data.document) {
                console.error("Missing parameters from the JSON response");
                worker.error();
                return;
            }

            if (! (
                typeof data.index === "string" &&
                typeof data.type === "string" &&
                typeof data.id === "string"
                )) {
                console.error("Wrong parameter(s) type(s) from the JSON response");
                worker.error();
                return;
            }
        } catch (e) {
            console.error("Error parsing the expected JSON response (searchIndex job)");
            worker.error();
            return;
        }

        elasticManager.storeDocument(data.index, data.type, data.id, data.document, function (isSuccess) {
            if (isSuccess) {
                worker.end();
            } else {
                worker.error();
            }
        });
    });
};
<commit_msg>add missing change in the refactory of searchIndexPost and searchDeletePost to make them into searchIndex and searchDelete, now able to cope with general types of contents<commit_after>/*jslint node: true */
/*global require */

module.exports = function (Gearman, elasticManager, settings) {
    "use strict";

    var gearmanSettings = settings.gearman;

    var gearman = new Gearman(gearmanSettings.hostname, gearmanSettings.port);

    console.info(
        "Listening to gearman on %s:%d (%s)",
        settings.gearman.hostname, settings.gearman.port, settings.env
    );

    gearman.registerWorker("searchDelete", function (payload, worker) {
        var data;

        if (! payload) {
            console.log("Payload not found for the searchDelete job");
            worker.error();
            return;
        }

        var input = payload.toString("utf-8");

        try {
            data = JSON.parse(input);

            if (! data.index || ! data.type || ! data.id) {
                console.error("Missing parameters from the JSON response");
                worker.error();
                return;
            }

            if (! (
                typeof data.index === "string" &&
                    typeof data.type === "string" &&
                    typeof data.id === "string"
                )) {
                console.error("Wrong parameter(s) type(s) from the JSON response");
                worker.error();
                return;
            }
        } catch (e) {
            console.error("Error parsing the expected JSON response (searchDelete job)");
            worker.error();
            return;
        }

        elasticManager.deleteDocument(data.index, data.type, data.id, function (isSuccess) {
            if (isSuccess) {
                worker.end();
            } else {
                worker.error();
            }
        });
    });

    gearman.registerWorker("searchIndex", function (payload, worker) {
        var data;

        if (! payload) {
            console.log("Payload not found for the searchIndex job");
            worker.error();
            return;
        }

        var input = payload.toString("utf-8");

        try {
            data = JSON.parse(input);

            if (! data.index || ! data.type || ! data.id || ! data.document) {
                console.error("Missing parameters from the JSON response");
                worker.error();
                return;
            }

            if (! (
                typeof data.index === "string" &&
                typeof data.type === "string" &&
                typeof data.id === "string"
                )) {
                console.error("Wrong parameter(s) type(s) from the JSON response");
                worker.error();
                return;
            }
        } catch (e) {
            console.error("Error parsing the expected JSON response (searchIndex job)");
            worker.error();
            return;
        }

        elasticManager.storeDocument(data.index, data.type, data.id, data.document, function (isSuccess) {
            if (isSuccess) {
                worker.end();
            } else {
                worker.error();
            }
        });
    });
};

{'fraction_non_alphanumeric': 0.1197205462051445, 'fraction_numerical': 0.0006351222610352493, 'mean_word_length': 1.4595860991800078, 'pattern_counts': {'":': 0, '<': 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': '4136023', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1521, 'n_words': 393}