<commit_before><script src="https://unpkg.com/lunr/lunr.js"></script>
<script>
(function() {
	'use strict';
	/*global lunr*/
	/*eslint no-undef: "error"*/
	/*eslint no-invalid-this: "error"*/

	let _index = lunr(function() {});
	let _debouncer;

	const _courseOfferingSirenHandler = function(href, token, entity) {
		if (entity.class) {
			if (entity.class.indexOf('course-offering') !== -1) {
				return 	_formatResult(
					href,
					token,
					entity.properties.name,
					entity.properties.code,
					'course-offering'
				);
			}
		}
		return null;
	};

	const _userSirenHandler = function(href, token, entity) {
		if (entity.class) {
			if (entity.class.indexOf('user') !== -1 ) {
				const displayName = entity.entities.filter(function(subEntity) {
					return subEntity.class.indexOf('display') !== -1 && subEntity.class.indexOf('name') !== -1;
				});
				if (displayName.length !== 1) {
					return null;
				}
				return 	_formatResult(
					href,
					token,
					displayName[0].properties.name,
					null,
					'user'
				);
			}
		}
		return null;
	};

	const _discussionsSirenHandler = function(href, token, entity) {
		if (entity.class) {
			if (entity.class.indexOf('topic') !== -1) {
				return 	_formatResult(
					href,
					token,
					entity.properties.name,
					entity.properties.description && entity.properties.description.Text || '',
					'topic'
				);
			} else if (entity.class.indexOf('forum') !== -1) {
				return 	_formatResult(
					href,
					token,
					entity.properties.name,
					entity.properties.description && entity.properties.description.Text || '',
					'forum'
				);

			} else if (entity.class.indexOf('thread') !== -1) {
				return 	_formatResult(
					href,
					token,
					entity.properties.subject,
					entity.properties.message,
					'thread'
				);
			}
		}
		return null;
	};
	const SPLITTER = '|';
	const _formatResult = function(href, token, primaryText, secondaryText, type) {
		return 	{
			type: type,
			primaryText: primaryText,
			secondaryText: secondaryText,
			key: `${token}${SPLITTER}${href}${SPLITTER}${type}`
		};
	};
	const _handlers = [
		_userSirenHandler,
		_courseOfferingSirenHandler,
		_discussionsSirenHandler
	];

	const GlobalSearch = {
		update: (store) => {
			_debouncer = Polymer.Debouncer.debounce(
				_debouncer,
				Polymer.Async.timeOut.after(500),
				function() {
					_index = lunr(/* @this */ function() {
						this.ref('key');
						this.field('type');
						this.field('primaryText', { boost: 3 });
						this.field('secondaryText');
						for (const [token, hrefStore] of store.entries()) {
							for (const [href, entity] of hrefStore.entries()) {
								if (entity.status === 'fetching') {
									continue;
								}
								for (const handler of _handlers) {
									const result = handler(href, token, entity.entity);
									if (result) {
										this.add(result);
										break;
									}
								}
							}
						}
					});
				}
			);
		},
		search: (term) => {
			return _index
				.search(term)
				.map(function(result) {
					const parts = result.ref.split(SPLITTER);
					return {
						token: parts[0],
						href: parts[1],
						type: parts[2]<commit_msg>Fix global search indexing errors<commit_after><script src="https://unpkg.com/lunr/lunr.js"></script>
<script>
(function() {
	'use strict';
	/*global lunr*/
	/*eslint no-undef: "error"*/
	/*eslint no-invalid-this: "error"*/

	let _index = lunr(function() {});
	let _debouncer;

	const _courseOfferingSirenHandler = function(href, token, entity) {
		if (entity.class) {
			if (entity.class.indexOf('course-offering') !== -1) {
				return 	_formatResult(
					href,
					token,
					entity.properties.name,
					entity.properties.code,
					'course-offering'
				);
			}
		}
		return null;
	};

	const _userSirenHandler = function(href, token, entity) {
		if (entity.class) {
			if (entity.class.indexOf('user') !== -1 ) {
				const displayName = entity.entities.filter(function(subEntity) {
					return subEntity.class && subEntity.class.indexOf('display') !== -1 && subEntity.class.indexOf('name') !== -1;
				});
				if (displayName.length !== 1) {
					return null;
				}
				return 	_formatResult(
					href,
					token,
					displayName[0].properties.name,
					null,
					'user'
				);
			}
		}
		return null;
	};

	const _discussionsSirenHandler = function(href, token, entity) {
		if (entity.class) {
			if (entity.class.indexOf('topic') !== -1) {
				return 	_formatResult(
					href,
					token,
					entity.properties.name,
					entity.properties.description && entity.properties.description.Text || '',
					'topic'
				);
			} else if (entity.class.indexOf('forum') !== -1) {
				return 	_formatResult(
					href,
					token,
					entity.properties.name,
					entity.properties.description && entity.properties.description.Text || '',
					'forum'
				);

			} else if (entity.class.indexOf('thread') !== -1) {
				return 	_formatResult(
					href,
					token,
					entity.properties.subject,
					entity.properties.message,
					'thread'
				);
			}
		}
		return null;
	};
	const SPLITTER = '|';
	const _formatResult = function(href, token, primaryText, secondaryText, type) {
		return 	{
			type: type,
			primaryText: primaryText,
			secondaryText: secondaryText,
			key: `${token}${SPLITTER}${href}${SPLITTER}${type}`
		};
	};
	const _handlers = [
		_userSirenHandler,
		_courseOfferingSirenHandler,
		_discussionsSirenHandler
	];

	const GlobalSearch = {
		update: (store) => {
			_debouncer = Polymer.Debouncer.debounce(
				_debouncer,
				Polymer.Async.timeOut.after(500),
				function() {
					_index = lunr(/* @this */ function() {
						this.ref('key');
						this.field('type');
						this.field('primaryText', { boost: 3 });
						this.field('secondaryText');
						for (const [token, hrefStore] of store.entries()) {
							for (const [href, entity] of hrefStore.entries()) {
								if (entity.status === 'fetching' || entity.status === 'error') {
									continue;
								}
								for (const handler of _handlers) {
									const result = handler(href, token, entity.entity);
									if (result) {
										this.add(result);
										break;
									}
								}
							}
						}
					});
				}
			);
		},
		search: (term) => {
			return _index
				.search(term)
				.map(function(result) {
					const parts = result.ref.split(SPLITTER);
					return {
						token: parts[0],
						href: parts[1],
						type: parts[2]
{'fraction_non_alphanumeric': 0.15557973267018962, 'fraction_numerical': 0.004973577867578489, 'mean_word_length': 2.6090858104318566, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '4702363', 'n_tokens_mistral': 2910, 'n_tokens_neox': 2132, 'n_words': 408}