<commit_before>var mongoose = require('mongoose')
const Sound = require('./models').Sound
const settings = require('../.config/settings')
const {
  isValidId, isValidString, andErrorOrResults
} = require('./helpers')


mongoose.Promise = global.Promise
mongoose.connect(settings.database)

const _find = (query, socket) => Sound.find(query, andErrorOrResults(socket))

const add = (obj, socket) => {
  var sound = new Sound(obj)
  sound.save(andErrorOrResults(socket))
}

const remove = (id, socket) => {
  if (isValidId(id, socket)) {
    Sound.remove({ id: id }, andErrorOrResults(socket))
  }
}

const update = (obj, socket) => {
  var sound = new Sound(obj)
  if (isValidId(sound._id, socket)) {
    Sound.findOneAndUpdate(
      { id: sound._id }, sound,
      andErrorOrResults(socket)
    )
  }
}

const search = (searchTerm, socket) => {
  if (isValidString(searchTerm, socket)) {
    _find({$text: {$search: searchTerm.toLowerCase()}}, socket)
  }
}

const lookup = (id, socket) => {
  if (isValidId(id, socket)) {
    _find({ id: id }, socket)
  }
}

const searchbyType = (type, socket) => {
  if (isValidString(type, socket)) {
    _find({type: type}, socket)
  }
}

const searchbyAuthor = (author, socket) => {
  if (isValidString(author, socket)) {
    _find({author: author}, socket)
  }
}

module.exports = {
  add,<commit_msg>Added search limit<commit_after>var mongoose = require('mongoose')
const Sound = require('./models').Sound
const settings = require('../.config/settings')
const {
  isValidId, isValidString, andErrorOrResults
} = require('./helpers')


mongoose.Promise = global.Promise
mongoose.connect(settings.database)

const _find = (query, socket) => {
  Sound
  .find(query)
  .limit(32)
  .exec(andErrorOrResults(socket))
}

const _searchQuery = searchTerm => ({
  $text: { $search: searchTerm.toLowerCase() }
})

const add = (obj, socket) => {
  var sound = new Sound(obj)
  sound.save(andErrorOrResults(socket))
}

const remove = (id, socket) => {
  if (isValidId(id, socket)) {
    Sound.remove({ id: id }, andErrorOrResults(socket))
  }
}

const update = (obj, socket) => {
  var sound = new Sound(obj)
  if (isValidId(sound._id, socket)) {
    Sound.findOneAndUpdate(
      { id: sound._id }, sound,
      andErrorOrResults(socket)
    )
  }
}

const search = (searchTerm, socket) => {
  if (isValidString(searchTerm, socket)) {
    _find(_searchQuery(searchTerm), socket)
  }
}

const lookup = (id, socket) => {
  if (isValidId(id, socket)) {
    _find({ id: id }, socket)
  }
}

const searchbyType = (searchTerm, type, socket) => {
  if (isValidString(type, socket)) {
    var query = _searchQuery(searchTerm)
    query.type = type
    _find(query, socket)
  }
}

const searchbyAuthor = (author, socket) => {
  if (isValidString(author, socket)) {
    var query = _searchQuery(searchTerm)
    query.author = author
    _find(query, socket)
  }
}

module.exports = {
  add,
{'fraction_non_alphanumeric': 0.15899725274725274, 'fraction_numerical': 0.0006868131868131869, 'mean_word_length': 3.895798319327731, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '1719181', 'n_tokens_mistral': 980, 'n_tokens_neox': 1002, 'n_words': 222}