<commit_before>'use strict';

import * as _ from 'lodash';

import { objectUtility } from '../object/object.service';
import { stringUtility } from '../string/string.service';

export interface ISearchUtility {
	search(object: any, search: string, caseSensitive?: boolean): boolean;
	tokenizedSearch(object: any, search: string, caseSensitive?: boolean): boolean;
}

class SearchUtility implements ISearchUtility {
	search(object: any, search: string, caseSensitive?: boolean): boolean {
		if (objectUtility.isNullOrEmpty(search)) {
			return true;
		}

		if (_.isObject(object)) {
			let values: any = _.values(object);
			return _.some(values, (value: any): boolean => { return this.search(value, search, caseSensitive); });
		} else {
			let dataString: string = objectUtility.toString(object);

			if (!caseSensitive) {
				search = search.toLowerCase();
				dataString = dataString.toLowerCase();
			}

			return stringUtility.contains(dataString, search);
		}
	}

	tokenizedSearch(object: any, search: string, caseSensitive?: boolean): boolean {
		return _.every(search.split(' '), (subsearch: string): boolean => {
			return this.search(object, subsearch, caseSensitive);
		});<commit_msg>Null check the search. This fixes a bug where it breaks on `split`<commit_after>'use strict';

import * as _ from 'lodash';

import { objectUtility } from '../object/object.service';
import { stringUtility } from '../string/string.service';

export interface ISearchUtility {
	search(object: any, search: string, caseSensitive?: boolean): boolean;
	tokenizedSearch(object: any, search: string, caseSensitive?: boolean): boolean;
}

class SearchUtility implements ISearchUtility {
	search(object: any, search: string, caseSensitive?: boolean): boolean {
		if (objectUtility.isNullOrEmpty(search)) {
			return true;
		}

		if (_.isObject(object)) {
			let values: any = _.values(object);
			return _.some(values, (value: any): boolean => { return this.search(value, search, caseSensitive); });
		} else {
			let dataString: string = objectUtility.toString(object);

			if (!caseSensitive) {
				search = search.toLowerCase();
				dataString = dataString.toLowerCase();
			}

			return stringUtility.contains(dataString, search);
		}
	}

	tokenizedSearch(object: any, search: string, caseSensitive?: boolean): boolean {
		if (search == null) {
			return true;
		}

		return _.every(search.split(' '), (subsearch: string): boolean => {
			return this.search(object, subsearch, caseSensitive);
		});
{'fraction_non_alphanumeric': 0.13734939759036144, 'fraction_numerical': 0.0, 'mean_word_length': 4.73963133640553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5701803', 'n_tokens_mistral': 787, 'n_tokens_neox': 736, 'n_words': 199}