<commit_before>'use strict';

var Model = require('../../models/landsat.js');
var queries = require('./queries.js');

module.exports = function (params, request, cb) {
  // The query object
  var q = {};

  // assemble the query
  if (Object.keys(params).length > 0) {
    q = queries(params, q, request.limit);
  }

  // Legacy support for skip parameter
  if (params.skip) {
    request.page = Math.floor(parseInt(params.skip, 10) / request.limit);
  }

  // Decide from
  var skip = request.limit * (request.page - 1);

  Model.count(q, function (err, count) {
    if (err) {
      return cb(err, null, null);
    }
    Model.find(q, null, {skip: skip, limit: request.limit}).exec(function (err, records) {
      cb(err, records, count);
    });
  });
};<commit_msg>use mongodb native for search<commit_after>'use strict';

var Model = require('../../models/landsat.js');
var queries = require('./queries.js');

module.exports = function (params, request, cb) {
  // The query object
  var q = {};
  var fields = null;

  // assemble the query
  if (Object.keys(params).length > 0) {
    q = queries(params, q, request.limit);
  }

  // Legacy support for skip parameter
  if (params.skip) {
    request.page = Math.floor(parseInt(params.skip, 10) / request.limit);
  }

  // Decide from
  var skip = request.limit * (request.page - 1);

  // Summary fields
  if (params.summary === true) {
    fields = {
      sceneID: 1,
      row: 1,
      path: 1,
      cloudCoverFull: 1,
      sceneStartTime: 1,
      sceneStopTime: 1,
      acquisitionDate: 1,
      browseURL: 1,
      browseAvailable: 1,
      sunAzimuth: 1,
      upperLeftCornerLatitude: 1,
      upperLeftCornerLongitude: 1,
      upperRightCornerLatitude: 1,
      upperRightCornerLongitude: 1,
      lowerLeftCornerLatitude: 1,
      lowerLeftCornerLongitude: 1,
      lowerRightCornerLatitude: 1,
      lowerRightCornerLongitude: 1,
      sceneCenterLatitude: 1,
      sceneCenterLongitude: 1,
      cloudCover: 1,
      boundingBox: 1
    }
  }

  var db = request.server.plugins['hapi-mongodb'].db;
  var collection = db.collection('landsats');
  var query = collection.find(q, {skip: skip, fields: fields, hint: {"boundingBox": "2dsphere"}});
  query.toArray(function (err, records) {
    if (err) return cb(err);
    query.count(function (err, count){
      cb(err, records, count);
    });
  });
};
{'fraction_non_alphanumeric': 0.14707121786767804, 'fraction_numerical': 0.013063632532659082, 'mean_word_length': 2.841423948220065, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 5, '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': '103711', 'n_tokens_mistral': 820, 'n_tokens_neox': 774, 'n_words': 199}