<commit_before>const Wreck = require('wreck');
const Schema = require('./schema.js');
const ResponseMessages = require('../responseMessages');

const config = require('config');
// const authors = config.get('data.authors');
// const keywords = config.get('data.keywords');
// const taxa = config.get('data.taxa');
// const families = config.get('data.families');

const Database = require('better-sqlite3');
const db = new Database(config.get('data.facets'));

// const data = {
//     authors: require(authors),
//     keywords: require(keywords),
//     taxa: require(taxa),
//     families: require(families)
// };

const facets = {
    authors: 'author',
    families: 'family',
    keywords: 'keyword',
    taxa: 'taxon'
};



module.exports = {
    // findjs: function(pattern, source) {
    //     const re = new RegExp(`^${pattern}`, 'i');
    //     const res = data[source].filter(function(element) {
    //         return (element.search(re) > -1)
    //     });
    
    //     return(res);
    // },

    find: function(pattern, source) {
        console.log(`looking for ${pattern} in ${source}`)
        return db.prepare(`SELECT ${facets[source]} FROM ${source} WHERE ${facets[source]} LIKE ?`)
            .raw()
            .all(`%${pattern}%`)
            .map(r => r[0]);
    },
    
    getImages: async function(treatmentId) {
    
        const _getRecords = async (query) => {
    
            let recordId = '';<commit_msg>fixed Utils.find<commit_after>const Wreck = require('wreck');
const Schema = require('./schema.js');
const ResponseMessages = require('../responseMessages');

const config = require('config');
// const authors = config.get('data.authors');
// const keywords = config.get('data.keywords');
// const taxa = config.get('data.taxa');
// const families = config.get('data.families');

const Database = require('better-sqlite3');
const db = new Database(config.get('data.facets'));

// const data = {
//     authors: require(authors),
//     keywords: require(keywords),
//     taxa: require(taxa),
//     families: require(families)
// };

const facets = {
    authors: 'author',
    families: 'family',
    keywords: 'keyword',
    taxa: 'taxon'
};



module.exports = {
    // findjs: function(pattern, source) {
    //     const re = new RegExp(`^${pattern}`, 'i');
    //     const res = data[source].filter(function(element) {
    //         return (element.search(re) > -1)
    //     });
    
    //     return(res);
    // },

    find: function(pattern, source) {
        //console.log(`looking for ${pattern} in ${source}`)
        return db.prepare(`SELECT ${facets[source]} FROM ${source} WHERE ${facets[source]} LIKE ?`)
            .raw()
            .all(`%${pattern}%`)
            .map(r => r[0]);
    },
    
    getImages: async function(treatmentId) {
    
        const _getRecords = async (query) => {
    
            let recordId = '';
{'fraction_non_alphanumeric': 0.18704788150189458, 'fraction_numerical': 0.0020668274199104374, 'mean_word_length': 2.5807644882860665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2829480', 'n_tokens_mistral': 900, 'n_tokens_neox': 863, 'n_words': 193}