<commit_before>var request = require('request');
var url = require('url');
var locker = require('../../../../Common/node/locker.js');

exports.map = function(type) { };

exports.index = function(id, type, body, callback) {
    console.log('not implemented');
    callback(null, {result: 'ok'});
};

exports.search = function(type, term, offset, limit, callback) {
    
    locker.providers('search', function(error, providers) {
        if (!providers || providers.length === 0) {
            return callback('No Locker search providers found', null);
        }
        
        // lame regex replacement of the incoming bad encoding from the form handling.  Ugly but effective
        term = term.replace(/&lt;/g, '<');
        term = term.replace(/&gt;/g, '>');
        term = term.replace(/&quot;/g, '"');

        var fetchURL = providers[0].uri + 'query?q='+encodeURIComponent(term);
        if (type !== '') {
          fetchURL += '&type=' + type;
        }

        request.get({url:fetchURL}, function(error, res, body) {
            var results = {};
            if (error || !res) {
                results.error = 'Failed calling provider GET at ' + fetchURL;
                return callback(results.error, results);
            }
            
            else if (res.statusCode >= 300) {
                results.error = 'That\'s an invalid query term, try again!';<commit_msg>Print the statusCode for a search failure, rather than assuming it's caused by an invalid query term<commit_after>var request = require('request');
var url = require('url');
var locker = require('../../../../Common/node/locker.js');

exports.map = function(type) { };

exports.index = function(id, type, body, callback) {
    console.log('not implemented');
    callback(null, {result: 'ok'});
};

exports.search = function(type, term, offset, limit, callback) {
    
    locker.providers('search', function(error, providers) {
        if (!providers || providers.length === 0) {
            return callback('No Locker search providers found', null);
        }
        
        // lame regex replacement of the incoming bad encoding from the form handling.  Ugly but effective
        term = term.replace(/&lt;/g, '<');
        term = term.replace(/&gt;/g, '>');
        term = term.replace(/&quot;/g, '"');

        var fetchURL = providers[0].uri + 'query?q='+encodeURIComponent(term);
        if (type !== '') {
          fetchURL += '&type=' + type;
        }

        request.get({url:fetchURL}, function(error, res, body) {
            var results = {};
            if (error || !res) {
                results.error = 'Failed calling provider GET at ' + fetchURL;
                return callback(results.error, results);
            }
            
            else if (res.statusCode >= 300) {
                results.error = 'Search failed: ' + res.statusCode;
{'fraction_non_alphanumeric': 0.15640307907627712, 'fraction_numerical': 0.0034989503149055285, 'mean_word_length': 2.289988492520138, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5984808', 'n_tokens_mistral': 799, 'n_tokens_neox': 779, 'n_words': 215}