<commit_before>import database from '../../common/database';
import * as _ from 'lodash';
import * as SequelizeStatic from 'sequelize';

import { ListDto } from '../../common/types';

export class SearchService {
async list<T>(options: {
    model: SequelizeStatic.Model<any, any>,
    query?: ListDto,
    where?: SequelizeStatic.WhereOptions,
    include?: SequelizeStatic.IncludeOptions[],
    order?: SequelizeStatic.FindOptions["order"],
    attributes?: string[]
}): Promise<{ rows: T[], count: number}> {
        console.log('**** SEARCH RECIEVED', JSON.stringify(options.query))
    
        options.query = options.query ? options.query : {
            field: undefined,
            order: undefined,
            filter: undefined,
            offset: undefined,
            limit: undefined
        };
    
        options.query.field = options.query.field ? options.query.field : 'createdAt';
        options.query.order = options.query.order ? options.query.order : 'DESC';
        options.query.filter = options.query.filter ? options.query.filter : '';
        options.query.offset = options.query.offset ? options.query.offset : 0;
        options.query.limit = options.query.limit ? options.query.limit : 100;        

        let opts: SequelizeStatic.FindOptions = {            
            offset: options.query.offset,
            limit: options.query.limit            
        }

        if(options.query.field) {
            if(options.query.order != 'DESC') {
                options.query.order = 'ASC';
            }

            opts.order = [ [ options.query.field, options.query.order ] ]
        }

        if(options.where) {
            opts.where = options.where;            
        } else if(options.query.filter) {
            opts.where = {
                name: {
                    $iLike: `%${options.query.filter}%`
                }
            }
        }

        if(options.attributes) {
            opts.attributes = options.attributes
        }

        if(options.include) {
            opts.include = options.include;
        }


        console.log('**** SEARCHING WITH', opts);
        console.log('**** SEARCHING WITH', JSON.stringify(opts));

        let result = await options.model.findAndCountAll(opts);

        return result;
    }
}

export default new SearchService();<commit_msg>Applications list tweak<commit_after>import database from '../../common/database';
import * as _ from 'lodash';
import * as SequelizeStatic from 'sequelize';

import { ListDto } from '../../common/types';

export class SearchService {
async list<T>(options: {
    model: SequelizeStatic.Model<any, any>,
    query?: ListDto,
    where?: SequelizeStatic.WhereOptions,
    include?: SequelizeStatic.IncludeOptions[],
    order?: SequelizeStatic.FindOptions["order"],
    attributes?: string[]
}): Promise<{ rows: T[], count: number}> {
        console.log('**** SEARCH RECIEVED', JSON.stringify(options.query))
    
        options.query = options.query ? options.query : {
            field: undefined,
            order: undefined,
            filter: undefined,
            offset: undefined,
            limit: undefined
        };
    
        options.query.field = options.query.field ? options.query.field : 'createdAt';
        options.query.order = options.query.order ? options.query.order : 'DESC';
        options.query.filter = options.query.filter ? options.query.filter : '';
        options.query.offset = options.query.offset ? options.query.offset : 0;
        options.query.limit = options.query.limit ? options.query.limit : 100;        

        let opts: SequelizeStatic.FindOptions = {            
            offset: options.query.offset,
            limit: options.query.limit            
        }

        if(options.query.field) {
            if(options.query.order != 'DESC') {
                options.query.order = 'ASC';
            }

            opts.order = [ [ options.query.field, options.query.order ] ]
        }

        if(options.where) {
            opts.where = options.where;            
        } else if(options.query.filter) {
            opts.where = {
                name: {
                    $iLike: `%${options.query.filter}%`
                }
            }
        }

        if(options.attributes) {
            opts.attributes = options.attributes
        }

        if(options.include) {
            opts.include = options.include;
        }


        console.log('**** SEARCHING WITH', opts);

        let result = await options.model.findAndCountAll(opts);

        return result;
    }
}

export default new SearchService();
{'fraction_non_alphanumeric': 0.12802768166089964, 'fraction_numerical': 0.0017301038062283738, 'mean_word_length': 1.9033270558694289, 'pattern_counts': {'":': 0, '<': 9, '<?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': '7130961', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1230, 'n_words': 245}