"use strict";
var search = require('../lib/search');

module.exports = function (input, callback) {
    if (typeof input.query.plan !== 'undefined' && typeof input.query.plan.esquery !== 'undefined') {
        input.query.plan.esquery.from = input.query.offset || 0;
        if (input.query.plan.esonly) {
            input.query.plan.esquery.size = input.query.perpage;
        } else {
            input.query.plan.esquery.size = input.query.perpage * 4;
        }
    }
    search(input.query, function (results) {
        if (results.records) {
            callback({
                records: results.records,
                count: results.count,
                summary: 'Search: ' + input.query.canonical
            });
        } else if (results.pipe) {
            var records = results.pipe.range(input.query.offset, input.query.offset + input.query.size).toJSON();
            var count = input.query.offset + records.length;
            if (records.length > input.query.size) {
                records.pop();
            }
            callback({
                records: records,
                count: count,
                summary: 'Search: ' + input.query.canonical
            });
        }
    });
};

module.exports.message = 'search';


"use strict";
var search = require('../lib/search');

module.exports = function (input, callback) {
    if (typeof input.query.plan !== 'undefined' && typeof input.query.plan.esquery !== 'undefined') {
        input.query.plan.esquery.from = input.query.offset || 0;
        if (input.query.plan.esonly) {
            input.query.plan.esquery.size = input.query.perpage;
        } else {
            input.query.plan.esquery.size = Math.max(1000, input.query.perpage * 4);
        }
    }
    search(input.query, function (results) {
        if (results.records) {
            callback({
                records: results.records,
                count: results.count,
                summary: 'Search: ' + input.query.canonical
            });
        } else if (results.pipe) {
            var records = results.pipe.range(input.query.offset, input.query.offset + input.query.size).toJSON();
            var count = input.query.offset + records.length;
            if (records.length > input.query.size) {
                records.pop();
            }
            callback({
                records: records,
                count: count,
                summary: 'Search: ' + input.query.canonical
            });
        }
    });
};

module.exports.message = 'search';


Use top thousand results when faceting
Use top thousand results when faceting
