<commit_before>(function() {

    var searchIco = document.getElementById('search'),
        searchWrap = document.getElementById('search-wrap'),
        keyInput = document.getElementById('key'),
        back = document.getElementById('back'),
        searchPanel = document.getElementById('search-panel'),
        searchResult = document.getElementById('search-result'),
        searchTpl = document.getElementById('search-tpl').innerHTML,
        searchData;

    function loadData(success) {

        if (!searchData) {
            var xhr = new XMLHttpRequest();
            xhr.open('GET', '/content.json', true);

            xhr.onload = function() {
                if (this.status >= 200 && this.status < 300) {
                    searchData = JSON.parse(this.response);
                    success(searchData);
                } else {
                    console.error(this.statusText);
                }
            };

            xhr.onerror = function() {
                console.error(this.statusText);
            };

            xhr.send();

        } else {
            success(searchData);
        }
    }

    function tpl(html, data) {
        return html.replace(/\{\w+\}/g, function(str) {
            var prop = str.replace(/\{|\}/g, '');
            return data[prop] || '';
        });
    }

    var docEl = document[navigator.userAgent.indexOf('Firefox') !== -1 ? 'documentElement' : 'body'],
        noop = function() {};

    var Control = {
        show: function() {
            window.innerWidth < 760 ? docEl.classList.add('lock-size') : noop;
            searchPanel.classList.add('in');
        },
        hide: function() {
            window.innerWidth < 760 ? docEl.classList.remove('lock-size') : noop;
            searchPanel.classList.remove('in');
        }
    };

    function render(data) {
        var html = '';
        if (data.length) {

            html = data.map(function(post) {

                return tpl(searchTpl, {
                    title: post.title,
                    path: post.path,
                    date: new Date(post.date).toLocaleDateString(),
                    tags: post.tags.map(function(tag) {
                        return '<span>#' + tag.name + '</span>';
                    }).join('')
                });

            }).join('');

        } else {
            html = '<li class="tips"><i class="icon icon-coffee icon-3x"></i><p>Results not found!</p></li>';
        }

        searchResult.innerHTML = html;
    }

    function matcher(post, regExp) {
        
        regExp.lastIndex = 0;

        return regExp.test(post.title) || post.tags.some(function(tag) {
            return regExp.test(tag.name);
        }) || regExp.test(post.text);<commit_msg>fix a search bug of regex<commit_after>(function() {

    var searchIco = document.getElementById('search'),
        searchWrap = document.getElementById('search-wrap'),
        keyInput = document.getElementById('key'),
        back = document.getElementById('back'),
        searchPanel = document.getElementById('search-panel'),
        searchResult = document.getElementById('search-result'),
        searchTpl = document.getElementById('search-tpl').innerHTML,
        searchData;

    function loadData(success) {

        if (!searchData) {
            var xhr = new XMLHttpRequest();
            xhr.open('GET', '/content.json', true);

            xhr.onload = function() {
                if (this.status >= 200 && this.status < 300) {
                    searchData = JSON.parse(this.response);
                    success(searchData);
                } else {
                    console.error(this.statusText);
                }
            };

            xhr.onerror = function() {
                console.error(this.statusText);
            };

            xhr.send();

        } else {
            success(searchData);
        }
    }

    function tpl(html, data) {
        return html.replace(/\{\w+\}/g, function(str) {
            var prop = str.replace(/\{|\}/g, '');
            return data[prop] || '';
        });
    }

    var docEl = document[navigator.userAgent.indexOf('Firefox') !== -1 ? 'documentElement' : 'body'],
        noop = function() {};

    var Control = {
        show: function() {
            window.innerWidth < 760 ? docEl.classList.add('lock-size') : noop;
            searchPanel.classList.add('in');
        },
        hide: function() {
            window.innerWidth < 760 ? docEl.classList.remove('lock-size') : noop;
            searchPanel.classList.remove('in');
        }
    };

    function render(data) {
        var html = '';
        if (data.length) {

            html = data.map(function(post) {

                return tpl(searchTpl, {
                    title: post.title,
                    path: post.path,
                    date: new Date(post.date).toLocaleDateString(),
                    tags: post.tags.map(function(tag) {
                        return '<span>#' + tag.name + '</span>';
                    }).join('')
                });

            }).join('');

        } else {
            html = '<li class="tips"><i class="icon icon-coffee icon-3x"></i><p>Results not found!</p></li>';
        }

        searchResult.innerHTML = html;
    }
    function regtest(raw, regExp) {
        regExp.lastIndex = 0;
        return regExp.test(raw);
    }
    function matcher(post, regExp) {
        return regtest(post.title, regExp) || post.tags.some(function(tag) {
            return regtest(tag.name, regExp);
        }) || regtest(post.text, regExp);
{'fraction_non_alphanumeric': 0.1471326164874552, 'fraction_numerical': 0.005376344086021506, 'mean_word_length': 1.6288271314178049, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, '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': '2054452', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1487, 'n_words': 268}