<commit_before>'use strict'

const co = require('co-express')
const accepts = require('accepts')
const spotlight = require('node-spotlight')
const sink = require('stream-sink')
const path = require('path')

const fs = require('./fs')
const ui = require('./ui')
const breadcrumb = require('./breadcrumb')



const search = co(function* (req, res, next) {
	if (!req.query || !req.query.q) return next()
	if (!(yield fs.isDir(req.absolute))) return next()
	if (accepts(req).type('html') !== 'html') return next() // todo: support JSON & plain text

	const base = '/Users/j/Documents'
	let results = []
	try {
		results = yield spotlight(req.query.q, base).pipe(sink('object'))

		for (let result of results) {
			const stat = yield fs.stat(result.path)

			result.name = path.basename(result.path)
			result.path = '/' + path.relative(base, result.path)
			result.isDir = stat.isDirectory()
			result.size = stat.size
		}
	} catch (err) {
		return res.status(500).end(err.message)
	}

	if ('function' === typeof req.app.locals.filter)
		results = results.filter(req.app.locals.filter)
	results = results.sort(fs.sortFiles)

	res.status(200).type('html')
	.end(ui({
		  name: req.app.locals.name
		, path: req.relative
		, readonly: req.app.locals.readonly
		, breadcrumb: breadcrumb(req.app.locals.name, req.relative)
		, files: results
	}))
})

module.exports = search
<commit_msg>oops :bug:<commit_after>'use strict'

const co = require('co-express')
const accepts = require('accepts')
const spotlight = require('node-spotlight')
const sink = require('stream-sink')
const path = require('path')

const fs = require('./fs')
const ui = require('./ui')
const breadcrumb = require('./breadcrumb')



const search = co(function* (req, res, next) {
	if (!req.query || !req.query.q) return next()
	if (!(yield fs.isDir(req.absolute))) return next()
	if (accepts(req).type('html') !== 'html') return next() // todo: support JSON & plain text

	let results = []
	try {
		results = yield spotlight(req.query.q, req.absolute).pipe(sink('object'))

		for (let result of results) {
			const stat = yield fs.stat(result.path)

			result.name = path.basename(result.path)
			result.path = '/' + path.relative(req.absolute, result.path)
			result.isDir = stat.isDirectory()
			result.size = stat.size
		}
	} catch (err) {
		return res.status(500).end(err.message)
	}

	if ('function' === typeof req.app.locals.filter)
		results = results.filter(req.app.locals.filter)
	results = results.sort(fs.sortFiles)

	res.status(200).type('html')
	.end(ui({
		  name: req.app.locals.name
		, path: req.relative
		, readonly: req.app.locals.readonly
		, breadcrumb: breadcrumb(req.app.locals.name, req.relative)
		, files: results
	}))
})

module.exports = search

{'fraction_non_alphanumeric': 0.17251461988304093, 'fraction_numerical': 0.0043859649122807015, 'mean_word_length': 4.068518518518519, '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': '1621629', 'n_tokens_mistral': 998, 'n_tokens_neox': 924, 'n_words': 212}