<commit_before><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Search - ScrapBook</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" type="text/css" href="tree/index.css" media="all">
<link rel="stylesheet" type="text/css" href="tree/custom.css" media="all">
<script>
var searchEngine = {

	_cache: null,
	_scrapbook: null,
	config: {
		'default_search': '',
		'default_field': 'tcc',
		'list_bullet': '◉'
	},

	init: function () {
		var that = this;
		if (location.protocol.match(/https?/)) {
			if (!confirm('Running this search engine could cause large network flow, are you sure to continue?')) {
				return;
			}
		}
		try {
			that.loadXMLDoc('cache.rdf', function(xml){
				var data = [];
				// some mobile browsers (e.g. Dolphin) do not support xmlDoc.getElementsByTagName
				var items = xml.documentElement.childNodes;
				for (var i = 0, len = items.length; i < len; i++) {
					var item = items[i];
					if (item.nodeName != 'RDF:Description') continue;
					var id_path = item.getAttribute('RDF:about').match(/^urn:scrapbook:item(\d{14})#(.*?)$/);
					// var folder = item.getAttribute('NS1:folder').match(/^urn:scrapbook:item(\d{14})$/);
					data.push({
						'id': id_path[1],
						'path': id_path[2],
						// 'folder': folder ? folder[1] : null,
						'content': item.getAttribute('NS1:content')
					});
				}
				that._cache = data;
				checkLoad();
			});
			that.loadXMLDoc('scrapbook.rdf', function(xml){
				var data = [];
				var items = xml.documentElement.childNodes;
				for (var i = 0, len = items.length; i < len; i++) {
					var item = items[i];
					if (item.nodeName != 'RDF:Description') continue;
					var id = item.getAttribute('NS1:id');
					data[id] = {
						'id': id,
						'type': item.getAttribute('NS1:type'),
						'title': item.getAttribute('NS1:title'),
						'source': item.getAttribute('NS1:source'),
						'comment': item.getAttribute('NS1:comment'),
						'create': item.getAttribute('NS1:create'),
						'modify': item.getAttribute('NS1:modify')
					};
				}
				that._scrapbook = data;
				checkLoad();
			});
		} catch(ex) {
			alert("Your browser doesn't support AJAX connection: \n" + ex.name + ': ' + ex.message);
			return;
		}

		function checkLoad() {
			if (that._cache && that._scrapbook) {
				document.getElementById('search').removeAttribute('disabled');
			}
		}
	},

	loadXMLDoc: function(url, callback) {
		var that = this;
		var xmlhttp;
		if (window.XMLHttpRequest) {  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
		}
		else {  // code for IE6, IE5
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200 || xmlhttp.status == 0) {
					callback.call(that, xmlhttp.responseXML);
				}
			}
		}
		xmlhttp.open("GET", url, true);
		xmlhttp.send();
		return xmlhttp;
	},

	search: function() {
		this.clearResult();
		try {
			// parse key
			var keyStr = document.getElementById('keyword').value;
			if (this.config['default_search']) keyStr = this.config['default_search'] + ' ' + keyStr;
			var key = this.parseQuery(keyStr);
			if (key.error.length) {
				for (var i = 0, len = key.error.length; i < len; i++) {
					this.addMsg(key.error[i]);
				}
				return;
			}
			// get result
			var result = [];
			for (var i = 0, len = this._cache.length; i < len; i++) {
				var item = this._cache[i];
				var data = {
					'cache': item,
					'item': this._scrapbook[item.id]
				};
				if (this.matchResult(data, key)) {
					result.push(data);
				}
			}
			// sort result
			for (var i = 0, len = key.sort.length; i < len; i++) {
				var sort = key.sort[i];
				result.sort(function(a, b){
					if (a[sort[0]][sort[1]] > b[sort[0]][sort[1]]) return sort[2];
					if (a[sort[0]][sort[1]] < b[sort[0]][sort[1]]) return -sort[2];
					return 0;
				});
			}
			// display result
			this.addMsg('Found ' + result.length + ' results:');
			for (var i = 0, len = result.length; i < len; i++) {
				this.addResult(result[i]);
			}
		}
		catch (ex) {
			alert("Script error: \n" + ex.name + ': ' + ex.message);
			throw ex;<commit_msg>Optimize the code.<commit_after><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Search - ScrapBook</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" type="text/css" href="tree/index.css" media="all">
<link rel="stylesheet" type="text/css" href="tree/custom.css" media="all">
<script>
var searchEngine = {

	_cache: null,
	_scrapbook: null,
	config: {
		'default_search': '',
		'default_field': 'tcc',
		'list_bullet': '◉'
	},

	init: function () {
		var that = this;
		if (location.protocol.match(/https?/)) {
			if (!confirm('Running this search engine could cause large network flow, are you sure to continue?')) {
				return;
			}
		}
		try {
			that.loadXMLDoc('cache.rdf', function(xml){
				var data = [];
				// some mobile browsers (e.g. Dolphin) do not support xmlDoc.getElementsByTagName
				var items = xml.documentElement.childNodes;
				for (var i = 0, len = items.length; i < len; i++) {
					var item = items[i];
					if (item.nodeName != 'RDF:Description') continue;
					var id_path = item.getAttribute('RDF:about').match(/^urn:scrapbook:item(\d{14})#(.*?)$/);
					// var folder = item.getAttribute('NS1:folder').match(/^urn:scrapbook:item(\d{14})$/);
					data.push({
						'id': id_path[1],
						'path': id_path[2],
						// 'folder': folder ? folder[1] : null,
						'content': item.getAttribute('NS1:content')
					});
				}
				that._cache = data;
				checkLoad();
			});
			that.loadXMLDoc('scrapbook.rdf', function(xml){
				var data = [];
				var items = xml.documentElement.childNodes;
				for (var i = 0, len = items.length; i < len; i++) {
					var item = items[i];
					if (item.nodeName != 'RDF:Description') continue;
					var id = item.getAttribute('NS1:id');
					data[id] = {
						'id': id,
						'type': item.getAttribute('NS1:type'),
						'title': item.getAttribute('NS1:title'),
						'source': item.getAttribute('NS1:source'),
						'comment': item.getAttribute('NS1:comment'),
						'create': item.getAttribute('NS1:create'),
						'modify': item.getAttribute('NS1:modify')
					};
				}
				that._scrapbook = data;
				checkLoad();
			});
		} catch(ex) {
			alert("Your browser doesn't support AJAX connection: \n" + ex.name + ': ' + ex.message);
			return;
		}

		function checkLoad() {
			if (that._cache && that._scrapbook) {
				document.getElementById('search').removeAttribute('disabled');
			}
		}
	},

	loadXMLDoc: function(url, callback) {
		var that = this;
		var xmlhttp;
		if (window.XMLHttpRequest) {  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
		}
		else {  // code for IE6, IE5
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200 || xmlhttp.status == 0) {
					callback.call(that, xmlhttp.responseXML);
				}
			}
		}
		xmlhttp.open("GET", url, true);
		xmlhttp.send();
		return xmlhttp;
	},

	search: function() {
		this.clearResult();
		try {
			// parse key
			var keyStr = document.getElementById('keyword').value;
			if (this.config['default_search']) keyStr = this.config['default_search'] + ' ' + keyStr;
			var key = this.parseQuery(keyStr);
			if (key.error.length) {
				for (var i = 0, len = key.error.length; i < len; i++) {
					this.addMsg(key.error[i]);
				}
				return;
			}
			// get result
			var result = [];
			for (var i = 0, len = this._cache.length; i < len; i++) {
				var item = this._cache[i];
				var data = {
					'cache': item,
					'item': this._scrapbook[item.id]
				};
				if (this.matchResult(data, key)) {
					result.push(data);
				}
			}
			// sort result
			for (var i = 0, len = key.sort.length; i < len; i++) {
				var sortKey = key.sort[i];
				result.sort(function(a, b){
					a = a[sortKey[0]][sortKey[1]];
					b = b[sortKey[0]][sortKey[1]];
					if (a > b) return sortKey[2];
					if (a < b) return -sortKey[2];
					return 0;
				});
			}
			// display result
			this.addMsg('Found ' + result.length + ' results:');
			for (var i = 0, len = result.length; i < len; i++) {
				this.addResult(result[i]);
			}
		}
		catch (ex) {
			alert("Script error: \n" + ex.name + ': ' + ex.message);
			throw ex;
{'fraction_non_alphanumeric': 0.18535714285714286, 'fraction_numerical': 0.009523809523809525, 'mean_word_length': 3.0350624399615755, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 32}, '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': '2347401', 'n_tokens_mistral': 3636, 'n_tokens_neox': 2963, 'n_words': 655}