<commit_before>'use strict'
var util = require('../util')
var ltgt = require('ltgt')

var LO = null
var HI = undefined

module.exports = function (db, query) {
  //choose the most indexable parameter
  //use eq instead of a range.
  var index = db.indexes.filter(function (e) {
    if(!e) return
    var str = ''+e.path
    return util.find(query, function (q) {
      return q.path == str
    })
  }).shift()

  if(!index) return

  var q = util.find(query, function (e) {
    return e.path == ''+index.path
  })

  var opts

  if(q.eq)
    opts = {index: [q.path], gte: [q.eq], lte: [q.eq]}
  else {
    opts = ltgt.toLtgt(q, {}, function (value) { return [value] })
//    if(q.gte) opts.gte = [q.gte]
//    if(q.gt)  opts.gt  = [q.gt]
//    if(q.lte) opts.lte = [q.lte]
//    if(q.lt)  opts.lt  = [q.lt]
  }

  opts.values = false

  return {
    opts: opts,
    query: query,
    exec: function () {
      return db.readIndex(opts, util.createFilter(query))
    }
  }
}
<commit_msg>tidy up filtered index query<commit_after>'use strict'
var util = require('../util')
var ltgt = require('ltgt')

var LO = null
var HI = undefined

module.exports = function (db, query) {
  //choose the most indexable parameter
  //use eq instead of a range.
  var index = db.indexes.filter(function (e) {
    if(!e) return
    var str = ''+e.path
    return util.find(query, function (q) {
      return q.path == str
    })
  }).shift()

  if(!index) return

  var q = util.find(query, function (e) {
    return e.path == ''+index.path
  })

  var opts

  if(q.eq)
    opts = {index: [q.path], gte: [q.eq], lte: [q.eq]}
  else {
    opts = ltgt.toLtgt(q, {index: [q.path]}, function (value) { return [value] })
  }

  opts.values = false

  return {
    opts: opts,
    query: query,
    exec: function () {
      return db.readIndex(opts, util.createFilter(query))
    }
  }
}

{'fraction_non_alphanumeric': 0.17167381974248927, 'fraction_numerical': 0.0, 'mean_word_length': 2.5255198487712667, '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': '2607837', 'n_tokens_mistral': 719, 'n_tokens_neox': 701, 'n_words': 188}