<commit_before>define(
[
  'underscore'
],
function(_) { "use strict";

/*
* Boolean search engine.
*/
var BooleanSearchEngine = function () {

    var exTree;
    var searchTextForExTree;

    var andExpression = 'AND';
    var orExpression = 'OR';
    var nonePattern = 'NONE';

    var patterns = ['TAG:', 'URL:', 'TITLE:'];

    // Trims defined characters from begining and ending of the string. Defaults to whitespace characters.
    var trim = function(input, characters){
        if (!_.isString(input)) return input;

        if (!characters) characters = '\\s';

        return String(input).replace(new RegExp('^' + characters + '+|' + characters + '+$', 'g'), '');
    };

    // Checks if string is blank or not.
    var isBlank = function(str){
        if (_.isNull(str)) str = '';
        return (/^\s*$/).test(str);
    };

    // Check that tag collection contains search.
    var containsTag = function(tags, patternText){

        var tag = _.find(tags, function(item){
            return item.text.toUpperCase().indexOf(patternText) != -1;
        });

        return !_.isUndefined(tag);
    };

    // Check that title contains search.
    var containsTitle = function(title, patternText){

        return title.toUpperCase().indexOf(trim(patternText)) != -1;
    };

    // Check that url contains search.
    var containsUrl = function(url, patternText){

        return url.toUpperCase().indexOf(trim(patternText)) != -1;
    };

    // Check that bookmark fields contain search.
    var containsField = function(bookmark, patternText){

        var filteredValue = _.find(_.values(_.pick(bookmark, 'title', 'url')), function(propertyValue){
            return propertyValue.toString().toUpperCase().indexOf(trim(patternText)) != -1;
        });
        return !_.isUndefined(filteredValue);
    };

    // Check that bookmark could be reached by following expression.
    var evaluateExpression = function(bookmark, node){

        if(node.pattern === nonePattern && node.literals.length === 1){
            var literal = node.literals[0];
            return containsField(bookmark, literal.text);
        }

        var evaluateFunc = function(word){ return containsField(bookmark, word); };
        if(node.pattern === 'TAG:'){
            evaluateFunc = function(word){ return containsTag(bookmark.tag, word); };
        }
        else if(node.pattern === 'TITLE:'){
            evaluateFunc = function(word){ return containsTitle(bookmark.title, word); };
        }
        else if(node.pattern === 'URL:'){<commit_msg>make simple search only in title and url fields.<commit_after>define(
[
  'underscore'
],
function(_) { "use strict";

/*
* Boolean search engine.
*/
var BooleanSearchEngine = function () {

    var exTree;
    var searchTextForExTree;

    var andExpression = 'AND';
    var orExpression = 'OR';
    var nonePattern = 'NONE';

    var patterns = ['TAG:', 'URL:', 'TITLE:'];

    // Trims defined characters from begining and ending of the string. Defaults to whitespace characters.
    var trim = function(input, characters){
        if (!_.isString(input)) return input;

        if (!characters) characters = '\\s';

        return String(input).replace(new RegExp('^' + characters + '+|' + characters + '+$', 'g'), '');
    };

    // Checks if string is blank or not.
    var isBlank = function(str){
        if (_.isNull(str)) str = '';
        return (/^\s*$/).test(str);
    };

    // Check that tag collection contains search.
    var containsTag = function(tags, patternText){

        var tag = _.find(tags, function(item){
            return item.text.toUpperCase().indexOf(patternText) != -1;
        });

        return !_.isUndefined(tag);
    };

    // Check that title contains search.
    var containsTitle = function(title, patternText){

        return title.toUpperCase().indexOf(trim(patternText)) != -1;
    };

    // Check that url contains search.
    var containsUrl = function(url, patternText){

        return url.toUpperCase().indexOf(trim(patternText)) != -1;
    };

    // Check that bookmark fields contain search.
    var containsField = function(bookmark, patternText){

        // var filteredValue = _.find(_.values(_.pick(bookmark, 'title', 'url')), function(propertyValue){
        var filteredValue = _.find([bookmark.title, bookmark.url], function(propertyValue){
            return propertyValue.toString().toUpperCase().indexOf(trim(patternText)) != -1;
        });
        return !_.isUndefined(filteredValue);
    };

    // Check that bookmark could be reached by following expression.
    var evaluateExpression = function(bookmark, node){

        if(node.pattern === nonePattern && node.literals.length === 1){
            var literal = node.literals[0];
            return containsField(bookmark, literal.text);
        }

        var evaluateFunc = function(word){ return containsField(bookmark, word); };
        if(node.pattern === 'TAG:'){
            evaluateFunc = function(word){ return containsTag(bookmark.tag, word); };
        }
        else if(node.pattern === 'TITLE:'){
            evaluateFunc = function(word){ return containsTitle(bookmark.title, word); };
        }
        else if(node.pattern === 'URL:'){
{'fraction_non_alphanumeric': 0.14403213465952563, 'fraction_numerical': 0.0022953328232593728, 'mean_word_length': 2.745702005730659, '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': '4649729', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1429, 'n_words': 386}