<commit_before>$(function () {
    "use strict";

    var data = '{{DATA}}';

    var filters = {
        'name': function (val, items) {
            return _.filter(items, function (o) {
                return o['name'].toLowerCase().indexOf(val) > -1;
            });
        },
        'package': function (val, items) {
            return _.filter(items, function (o) {
                return o['packageName'].toLowerCase().indexOf(val) > -1;
            });
        },
        'version': function (val, items) {
            return _.filter(items, function (o) {
                return o['version'].toLowerCase().indexOf(val) > -1;
            });
        },
        'extends': function (val, items) {
            return _.filter(items, function (o) {
                return o['filterExtends'].indexOf(val) > -1;
            });
        },
        'is': function (val, items) {
            return _.filter(items, function (o) {
                return o['filterIs'].indexOf(val) > -1;
            });
        }
    };

    // aliases
    filters['pkg'] = filters['package'];
    filters['from'] = filters['package'];
    filters['in'] = filters['package'];
    filters['since'] = filters['version'];
    filters['sub'] = filters['extends'];

    var parseQuery = function (query) {
        query = query.trim();
        var criteria = [];
        var tokens = query.split(' ');
        var sort = 'alphabetic';

        for (var i = 0; i < tokens.length; i++) {
            var token = tokens[i];
            if (!token) {
                continue;
            }

            var idx = token.indexOf(':');
            if (idx < 0) {
                criteria.push({
                    filter: 'name',
                    value: token
                });
                sort = 'relevance';
                continue;
            }

            var value = token.slice(idx + 1);
            var filter = token.slice(0, idx);
            criteria.push({
                filter: filter,
                value: value
            });
        }

        return {
            criteria: criteria,
            sort: sort
        };
    };

    var source = function (query, process) {
        if (!query) {
            process([]);
        }

        var suggestions = data;
        var parsedQuery = parseQuery(query);

        _.each(parsedQuery.criteria, function (criterion) {
            if (suggestions.length > 0) {
                var filter = filters[criterion.filter];
                var val = criterion.value;
                if (!val) {
                    suggestions = [];
                } else if (filter) {
                    suggestions = filter(val, suggestions);
                }
            }
        });

        if (parsedQuery.sort === 'relevance') {
            suggestions.sort(function (a, b) {
                var name1 = a.name;
                var name2 = b.name;

                if (name1.length < name2.length) {
                    return -1
                }

                if (name1.length > name2.length) {
                    return 1;
                }

                if (name1 < name2) {
                    return -1
                }

                if (name1 > name2) {
                    return 1;
                }

                return 0;
            });
        } else {
            suggestions.sort(function (a, b) {
                var name1 = a.name;
                var name2 = b.name;

                if (name1 < name2) {
                    return -1
                }

                if (name1 === name2) {
                    return 0;
                }

                return 1;
            });
        }

        process(suggestions);
    };


    $('#search-input')
        .typeahead({
            highlight: false,
            minLength: 1
        }, {
            displayKey: 'name',
            source: _.debounce(source, 500),
            templates: {
                suggestion: function (o) {
                    return "<p class='name'>" + o.name + "</p>" +
                        "<p class='type'>" + o.fileType + "</p>" +
                        "<p class='package'>" + o.packageName + "</p>";
                }
            }
        })
        .on('typeahead:selected', function (ev, o, ds) {
            $('#content').attr('src', o.path);
        });
});<commit_msg>Ignore case; add aliases fn + lambda<commit_after>$(function () {
    "use strict";

    var data = '{{DATA}}';

    var filters = {
        'name': function (val, items) {
            return _.filter(items, function (o) {
                return o['name'].toLowerCase().indexOf(val) > -1;
            });
        },
        'package': function (val, items) {
            return _.filter(items, function (o) {
                return o['packageName'].toLowerCase().indexOf(val) > -1;
            });
        },
        'version': function (val, items) {
            return _.filter(items, function (o) {
                return o['version'].toLowerCase().indexOf(val) > -1;
            });
        },
        'extends': function (val, items) {
            return _.filter(items, function (o) {
                return o['filterExtends'].indexOf(val) > -1;
            });
        },
        'is': function (val, items) {
            return _.filter(items, function (o) {
                return o['filterIs'].indexOf(val) > -1;
            });
        }
    };

    // aliases
    filters['pkg'] = filters['package'];
    filters['from'] = filters['package'];
    filters['in'] = filters['package'];
    filters['since'] = filters['version'];
    filters['sub'] = filters['extends'];

    var parseQuery = function (query) {
        query = query.trim();
        var criteria = [];
        var tokens = query.split(' ');
        var sort = 'alphabetic';

        for (var i = 0; i < tokens.length; i++) {
            var token = tokens[i];
            if (!token) {
                continue;
            }

            var idx = token.indexOf(':');
            if (idx < 0) {
                criteria.push({
                    filter: 'name',
                    value: token.toLowerCase()
                });
                sort = 'relevance';
                continue;
            }

            var value = token.slice(idx + 1).toLowerCase();
            var filter = token.slice(0, idx).toLocaleLowerCase();

            // aliases
            if (filter === 'is' && (value === 'fn' || value === 'lambda')) {
                value = 'functional';
            }

            criteria.push({
                filter: filter,
                value: value
            });
        }

        return {
            criteria: criteria,
            sort: sort
        };
    };

    var source = function (query, process) {
        if (!query) {
            process([]);
        }

        var suggestions = data;
        var parsedQuery = parseQuery(query);

        _.each(parsedQuery.criteria, function (criterion) {
            if (suggestions.length > 0) {
                var filter = filters[criterion.filter];
                var val = criterion.value;
                if (!val) {
                    suggestions = [];
                } else if (filter) {
                    suggestions = filter(val, suggestions);
                }
            }
        });

        if (parsedQuery.sort === 'relevance') {
            suggestions.sort(function (a, b) {
                var name1 = a.name;
                var name2 = b.name;

                if (name1.length < name2.length) {
                    return -1
                }

                if (name1.length > name2.length) {
                    return 1;
                }

                if (name1 < name2) {
                    return -1
                }

                if (name1 > name2) {
                    return 1;
                }

                return 0;
            });
        } else {
            suggestions.sort(function (a, b) {
                var name1 = a.name;
                var name2 = b.name;

                if (name1 < name2) {
                    return -1
                }

                if (name1 === name2) {
                    return 0;
                }

                return 1;
            });
        }

        process(suggestions);
    };


    $('#search-input')
        .typeahead({
            highlight: false,
            minLength: 1
        }, {
            displayKey: 'name',
            source: _.debounce(source, 500),
            templates: {
                suggestion: function (o) {
                    return "<p class='name'>" + o.name + "</p>" +
                        "<p class='type'>" + o.fileType + "</p>" +
                        "<p class='package'>" + o.packageName + "</p>";
                }
            }
        })
        .on('typeahead:selected', function (ev, o, ds) {
            $('#content').attr('src', o.path);
        });
});
{'fraction_non_alphanumeric': 0.13822506451250982, 'fraction_numerical': 0.008526870862784697, 'mean_word_length': 1.088076832981963, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, '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': '2947692', 'n_tokens_mistral': 2426, 'n_tokens_neox': 2278, 'n_words': 535}