Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

js-worker-search

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-worker-search - npm Package Compare versions

Comparing version
1.3.0
to
1.4.0
+564
dist/5cafaba60d6eb1f43c8f.worker.js
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var _util = __webpack_require__(1);
/**
* Search entry point to web worker.
* Builds search index and performs searches on separate thread from the ui.
*/
var searchUtility = new _util.SearchUtility();
self.addEventListener("message", function (event) {
var data = event.data;
var method = data.method;
switch (method) {
case "indexDocument":
var uid = data.uid,
text = data.text;
searchUtility.indexDocument(uid, text);
break;
case "search":
var callbackId = data.callbackId,
query = data.query;
var results = searchUtility.search(query);
self.postMessage({ callbackId: callbackId, results: results });
break;
case "setCaseSensitive":
var caseSensitive = data.caseSensitive;
searchUtility.setCaseSensitive(caseSensitive);
break;
case "setIndexMode":
var indexMode = data.indexMode;
searchUtility.setIndexMode(indexMode);
break;
case "setMatchAnyToken":
var matchAnyToken = data.matchAnyToken;
searchUtility.setMatchAnyToken(matchAnyToken);
break;
case "setTokenizePattern":
var tokenizePattern = data.tokenizePattern;
searchUtility.setTokenizePattern(tokenizePattern);
break;
}
}, false);
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SearchUtility = exports.INDEX_MODES = undefined;
var _SearchUtility = __webpack_require__(2);
var _SearchUtility2 = _interopRequireDefault(_SearchUtility);
var _constants = __webpack_require__(3);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = _SearchUtility2.default;
exports.INDEX_MODES = _constants.INDEX_MODES;
exports.SearchUtility = _SearchUtility2.default;
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _constants = __webpack_require__(3);
var _SearchIndex = __webpack_require__(4);
var _SearchIndex2 = _interopRequireDefault(_SearchIndex);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Synchronous client-side full-text search utility.
* Forked from JS search (github.com/bvaughn/js-search).
*/
var SearchUtility = function () {
/**
* Constructor.
*
* @param indexMode See #setIndexMode
* @param tokenizePattern See #setTokenizePattern
* @param caseSensitive See #setCaseSensitive
* @param matchAnyToken See #setMatchAnyToken
*/
function SearchUtility() {
var _this = this;
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$caseSensitive = _ref.caseSensitive,
caseSensitive = _ref$caseSensitive === undefined ? false : _ref$caseSensitive,
_ref$indexMode = _ref.indexMode,
indexMode = _ref$indexMode === undefined ? _constants.INDEX_MODES.ALL_SUBSTRINGS : _ref$indexMode,
_ref$matchAnyToken = _ref.matchAnyToken,
matchAnyToken = _ref$matchAnyToken === undefined ? false : _ref$matchAnyToken,
_ref$tokenizePattern = _ref.tokenizePattern,
tokenizePattern = _ref$tokenizePattern === undefined ? /\s+/ : _ref$tokenizePattern;
_classCallCheck(this, SearchUtility);
this.indexDocument = function (uid, text) {
_this._uids[uid] = true;
var fieldTokens = _this._tokenize(_this._sanitize(text));
fieldTokens.forEach(function (fieldToken) {
var expandedTokens = _this._expandToken(fieldToken);
expandedTokens.forEach(function (expandedToken) {
_this._searchIndex.indexDocument(expandedToken, uid);
});
});
return _this;
};
this.search = function (query) {
if (!query) {
return Object.keys(_this._uids);
} else {
var tokens = _this._tokenize(_this._sanitize(query));
return _this._searchIndex.search(tokens, _this._matchAnyToken);
}
};
this.terminate = function () {};
this._caseSensitive = caseSensitive;
this._indexMode = indexMode;
this._matchAnyToken = matchAnyToken;
this._tokenizePattern = tokenizePattern;
this._searchIndex = new _SearchIndex2.default();
this._uids = {};
}
/**
* Returns a constant representing the current case-sensitive bit.
*/
_createClass(SearchUtility, [{
key: "getCaseSensitive",
value: function getCaseSensitive() {
return this._caseSensitive;
}
/**
* Returns a constant representing the current index mode.
*/
}, {
key: "getIndexMode",
value: function getIndexMode() {
return this._indexMode;
}
/**
* Returns a constant representing the current match-any-token bit.
*/
}, {
key: "getMatchAnyToken",
value: function getMatchAnyToken() {
return this._matchAnyToken;
}
/**
* Returns a constant representing the current tokenize pattern.
*/
}, {
key: "getTokenizePattern",
value: function getTokenizePattern() {
return this._tokenizePattern;
}
/**
* Adds or updates a uid in the search index and associates it with the specified text.
* Note that at this time uids can only be added or updated in the index, not removed.
*
* @param uid Uniquely identifies a searchable object
* @param text Text to associate with uid
*/
/**
* Searches the current index for the specified query text.
* Only uids matching all of the words within the text will be accepted,
* unless matchAny is set to true.
* If an empty query string is provided all indexed uids will be returned.
*
* Document searches are case-insensitive by default (e.g. "search" will match "Search").
* Document searches use substring matching by default (e.g. "na" and "me" will both match "name").
*
* @param query Searchable query text
* @return Array of uids
*/
}, {
key: "setCaseSensitive",
/**
* Sets a new case-sensitive bit
*/
value: function setCaseSensitive(caseSensitive) {
this._caseSensitive = caseSensitive;
}
/**
* Sets a new index mode.
* See util/constants/INDEX_MODES
*/
}, {
key: "setIndexMode",
value: function setIndexMode(indexMode) {
if (Object.keys(this._uids).length > 0) {
throw Error("indexMode cannot be changed once documents have been indexed");
}
this._indexMode = indexMode;
}
/**
* Sets a new match-any-token bit
*/
}, {
key: "setMatchAnyToken",
value: function setMatchAnyToken(matchAnyToken) {
this._matchAnyToken = matchAnyToken;
}
/**
* Sets a new tokenize pattern (regular expression)
*/
}, {
key: "setTokenizePattern",
value: function setTokenizePattern(pattern) {
this._tokenizePattern = pattern;
}
/**
* Added to make class adhere to interface. Add cleanup code as needed.
*/
}, {
key: "_expandToken",
/**
* Index strategy based on 'all-substrings-index-strategy.ts' in github.com/bvaughn/js-search/
*
* @private
*/
value: function _expandToken(token) {
switch (this._indexMode) {
case _constants.INDEX_MODES.EXACT_WORDS:
return [token];
case _constants.INDEX_MODES.PREFIXES:
return this._expandPrefixTokens(token);
case _constants.INDEX_MODES.ALL_SUBSTRINGS:
default:
return this._expandAllSubstringTokens(token);
}
}
}, {
key: "_expandAllSubstringTokens",
value: function _expandAllSubstringTokens(token) {
var expandedTokens = [];
// String.prototype.charAt() may return surrogate halves instead of whole characters.
// When this happens in the context of a web-worker it can cause Chrome to crash.
// Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.
// Resources:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt
// https://mathiasbynens.be/notes/javascript-unicode
try {
for (var i = 0, length = token.length; i < length; ++i) {
var substring = "";
for (var j = i; j < length; ++j) {
substring += token.charAt(j);
expandedTokens.push(substring);
}
}
} catch (error) {
console.error("Unable to parse token \"" + token + "\" " + error);
}
return expandedTokens;
}
}, {
key: "_expandPrefixTokens",
value: function _expandPrefixTokens(token) {
var expandedTokens = [];
// String.prototype.charAt() may return surrogate halves instead of whole characters.
// When this happens in the context of a web-worker it can cause Chrome to crash.
// Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.
// Resources:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt
// https://mathiasbynens.be/notes/javascript-unicode
try {
for (var i = 0, length = token.length; i < length; ++i) {
expandedTokens.push(token.substr(0, i + 1));
}
} catch (error) {
console.error("Unable to parse token \"" + token + "\" " + error);
}
return expandedTokens;
}
/**
* @private
*/
}, {
key: "_sanitize",
value: function _sanitize(string) {
return this._caseSensitive ? string.trim() : string.trim().toLocaleLowerCase();
}
/**
* @private
*/
}, {
key: "_tokenize",
value: function _tokenize(text) {
return text.split(this._tokenizePattern).filter(function (text) {
return text;
}); // Remove empty tokens
}
}]);
return SearchUtility;
}();
exports.default = SearchUtility;
/***/ },
/* 3 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var INDEX_MODES = exports.INDEX_MODES = {
// Indexes for all substring searches (e.g. the term "cat" is indexed as "c", "ca", "cat", "a", "at", and "t").
// Based on 'all-substrings-index-strategy' from js-search;
// github.com/bvaughn/js-search/blob/master/source/index-strategy/all-substrings-index-strategy.ts
ALL_SUBSTRINGS: "ALL_SUBSTRINGS",
// Indexes for exact word matches only.
// Based on 'exact-word-index-strategy' from js-search;
// github.com/bvaughn/js-search/blob/master/source/index-strategy/exact-word-index-strategy.ts
EXACT_WORDS: "EXACT_WORDS",
// Indexes for prefix searches (e.g. the term "cat" is indexed as "c", "ca", and "cat" allowing prefix search lookups).
// Based on 'prefix-index-strategy' from js-search;
// github.com/bvaughn/js-search/blob/master/source/index-strategy/prefix-index-strategy.ts
PREFIXES: "PREFIXES"
};
/***/ },
/* 4 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Maps search tokens to uids using a trie structure.
*/
var SearchIndex = function () {
function SearchIndex() {
_classCallCheck(this, SearchIndex);
this.tokenToUidMap = {};
}
/**
* Maps the specified token to a uid.
*
* @param token Searchable token (e.g. "road")
* @param uid Identifies a document within the searchable corpus
*/
_createClass(SearchIndex, [{
key: "indexDocument",
value: function indexDocument(token, uid) {
if (!this.tokenToUidMap[token]) {
this.tokenToUidMap[token] = {};
}
this.tokenToUidMap[token][uid] = uid;
}
/**
* Finds uids that have been mapped to the set of tokens specified.
* Only uids that have been mapped to all tokens will be returned.
*
* @param tokens Array of searchable tokens (e.g. ["long", "road"])
* @param matchAnyToken Whether to match any token. Default is false.
* @return Array of uids that have been associated with the set of search tokens
*/
}, {
key: "search",
value: function search(tokens, matchAnyToken) {
var _this = this;
var uidMap = {};
var uidMatches = {};
var initialized = false;
tokens.forEach(function (token) {
var currentUidMap = _this.tokenToUidMap[token] || {};
if (!initialized) {
initialized = true;
for (var _uid in currentUidMap) {
uidMap[_uid] = currentUidMap[_uid];
uidMatches[_uid] = 1;
}
} else {
// Delete existing matches if using and AND query (the default)
// Otherwise add new results to the matches
if (!matchAnyToken) {
for (var _uid2 in uidMap) {
if (!currentUidMap[_uid2]) {
delete uidMap[_uid2];
}
}
} else {
for (var _uid3 in currentUidMap) {
uidMap[_uid3] = currentUidMap[_uid3];
uidMatches[_uid3] = (uidMatches[_uid3] || 0) + 1;
}
}
}
});
var uids = [];
for (var _uid4 in uidMap) {
uids.push(uidMap[_uid4]);
}
// Sort according to most matches, if match any token is set.
if (matchAnyToken) {
uids.sort(function (a, b) {
return uidMatches[b] - uidMatches[a];
});
}
return uids;
}
}]);
return SearchIndex;
}();
exports.default = SearchIndex;
/***/ }
/******/ ]);
//# sourceMappingURL=5cafaba60d6eb1f43c8f.worker.js.map
{"version":3,"sources":["webpack:///webpack/bootstrap 5cafaba60d6eb1f43c8f","webpack:///./src/worker/Worker.js","webpack:///./src/util/index.js","webpack:///./src/util/SearchUtility.js","webpack:///./src/util/constants.js","webpack:///./src/util/SearchIndex.js"],"names":["searchUtility","self","addEventListener","data","event","method","uid","text","indexDocument","callbackId","query","results","search","postMessage","caseSensitive","setCaseSensitive","indexMode","setIndexMode","matchAnyToken","setMatchAnyToken","tokenizePattern","setTokenizePattern","INDEX_MODES","SearchUtility","ALL_SUBSTRINGS","_uids","fieldTokens","_tokenize","_sanitize","forEach","expandedTokens","_expandToken","fieldToken","_searchIndex","expandedToken","Object","keys","tokens","_matchAnyToken","terminate","_caseSensitive","_indexMode","_tokenizePattern","length","Error","pattern","token","EXACT_WORDS","PREFIXES","_expandPrefixTokens","_expandAllSubstringTokens","i","substring","j","charAt","push","error","console","substr","string","trim","toLocaleLowerCase","split","filter","SearchIndex","tokenToUidMap","uidMap","uidMatches","initialized","currentUidMap","uids","sort","a","b"],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;ACpCA;;AAEA;;;;;AAKA,KAAMA,gBAAgB,yBAAtB;;AAEAC,MAAKC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;AAED;AACA,WAAIY,aAAJ,EAAmB;AACjBoD,cAAKC,IAAL,CAAU,UAACC,CAAD,EAAIC,CAAJ,EAAU;AAClB,kBAAON,WAAWM,CAAX,IAAgBN,WAAWK,CAAX,CAAvB;AACD,UAFD;AAGD;;AAED,cAAOF,IAAP;AACD;;;;;;mBA3EkBN,W","file":"5cafaba60d6eb1f43c8f.worker.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 5cafaba60d6eb1f43c8f","/** @flow */\n\nimport { SearchUtility } from \"../util\";\n\n/**\n * Search entry point to web worker.\n * Builds search index and performs searches on separate thread from the ui.\n */\n\nconst searchUtility = new SearchUtility();\n\nself.addEventListener(\n \"message\",\n event => {\n const { data } = event;\n const { method } = data;\n\n switch (method) {\n case \"indexDocument\":\n const { uid, text } = data;\n\n searchUtility.indexDocument(uid, text);\n break;\n case \"search\":\n const { callbackId, query } = data;\n\n const results = searchUtility.search(query);\n\n self.postMessage({ callbackId, results });\n break;\n case \"setCaseSensitive\":\n const { caseSensitive } = data;\n\n searchUtility.setCaseSensitive(caseSensitive);\n break;\n case \"setIndexMode\":\n const { indexMode } = data;\n\n searchUtility.setIndexMode(indexMode);\n break;\n case \"setMatchAnyToken\":\n const { matchAnyToken } = data;\n\n searchUtility.setMatchAnyToken(matchAnyToken);\n break;\n case \"setTokenizePattern\":\n const { tokenizePattern } = data;\n\n searchUtility.setTokenizePattern(tokenizePattern);\n break;\n }\n },\n false\n);\n\n\n\n// WEBPACK FOOTER //\n// ./src/worker/Worker.js","/** @flow */\n\nimport SearchUtility from \"./SearchUtility\";\nimport { INDEX_MODES } from \"./constants\";\n\nexport type { IndexMode } from \"./constants\";\n\nexport default SearchUtility;\nexport { INDEX_MODES, SearchUtility };\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/index.js","/** @flow */\n\nimport { INDEX_MODES } from \"./constants\";\nimport SearchIndex from \"./SearchIndex\";\n\nimport type { IndexMode } from \"./constants\";\nimport type { SearchApiIndex } from \"../types\";\n\ntype UidMap = {\n [uid: string]: boolean\n};\n\n/**\n * Synchronous client-side full-text search utility.\n * Forked from JS search (github.com/bvaughn/js-search).\n */\nexport default class SearchUtility implements SearchApiIndex {\n _caseSensitive: boolean;\n _indexMode: IndexMode;\n _matchAnyToken: boolean;\n _searchIndex: SearchIndex;\n _tokenizePattern: RegExp;\n _uids: UidMap;\n\n /**\n * Constructor.\n *\n * @param indexMode See #setIndexMode\n * @param tokenizePattern See #setTokenizePattern\n * @param caseSensitive See #setCaseSensitive\n * @param matchAnyToken See #setMatchAnyToken\n */\n constructor(\n {\n caseSensitive = false,\n indexMode = INDEX_MODES.ALL_SUBSTRINGS,\n matchAnyToken = false,\n tokenizePattern = /\\s+/\n }: {\n caseSensitive?: boolean,\n indexMode?: IndexMode,\n matchAnyToken?: boolean,\n tokenizePattern?: RegExp\n } = {}\n ) {\n this._caseSensitive = caseSensitive;\n this._indexMode = indexMode;\n this._matchAnyToken = matchAnyToken;\n this._tokenizePattern = tokenizePattern;\n\n this._searchIndex = new SearchIndex();\n this._uids = {};\n }\n\n /**\n * Returns a constant representing the current case-sensitive bit.\n */\n getCaseSensitive(): boolean {\n return this._caseSensitive;\n }\n\n /**\n * Returns a constant representing the current index mode.\n */\n getIndexMode(): string {\n return this._indexMode;\n }\n\n /**\n * Returns a constant representing the current match-any-token bit.\n */\n getMatchAnyToken(): boolean {\n return this._matchAnyToken;\n }\n\n /**\n * Returns a constant representing the current tokenize pattern.\n */\n getTokenizePattern(): RegExp {\n return this._tokenizePattern;\n }\n\n /**\n * Adds or updates a uid in the search index and associates it with the specified text.\n * Note that at this time uids can only be added or updated in the index, not removed.\n *\n * @param uid Uniquely identifies a searchable object\n * @param text Text to associate with uid\n */\n indexDocument = (uid: any, text: string): SearchApiIndex => {\n this._uids[uid] = true;\n\n var fieldTokens: Array<string> = this._tokenize(this._sanitize(text));\n\n fieldTokens.forEach(fieldToken => {\n var expandedTokens: Array<string> = this._expandToken(fieldToken);\n\n expandedTokens.forEach(expandedToken => {\n this._searchIndex.indexDocument(expandedToken, uid);\n });\n });\n\n return this;\n };\n\n /**\n * Searches the current index for the specified query text.\n * Only uids matching all of the words within the text will be accepted,\n * unless matchAny is set to true.\n * If an empty query string is provided all indexed uids will be returned.\n *\n * Document searches are case-insensitive by default (e.g. \"search\" will match \"Search\").\n * Document searches use substring matching by default (e.g. \"na\" and \"me\" will both match \"name\").\n *\n * @param query Searchable query text\n * @return Array of uids\n */\n search = (query: string): Array<any> => {\n if (!query) {\n return Object.keys(this._uids);\n } else {\n var tokens: Array<string> = this._tokenize(this._sanitize(query));\n\n return this._searchIndex.search(tokens, this._matchAnyToken);\n }\n };\n\n /**\n * Sets a new case-sensitive bit\n */\n setCaseSensitive(caseSensitive: boolean): void {\n this._caseSensitive = caseSensitive;\n }\n\n /**\n * Sets a new index mode.\n * See util/constants/INDEX_MODES\n */\n setIndexMode(indexMode: IndexMode): void {\n if (Object.keys(this._uids).length > 0) {\n throw Error(\n \"indexMode cannot be changed once documents have been indexed\"\n );\n }\n\n this._indexMode = indexMode;\n }\n\n /**\n * Sets a new match-any-token bit\n */\n setMatchAnyToken(matchAnyToken: boolean): void {\n this._matchAnyToken = matchAnyToken;\n }\n\n /**\n * Sets a new tokenize pattern (regular expression)\n */\n setTokenizePattern(pattern: RegExp): void {\n this._tokenizePattern = pattern;\n }\n\n /**\n * Added to make class adhere to interface. Add cleanup code as needed.\n */\n terminate = () => {};\n\n /**\n * Index strategy based on 'all-substrings-index-strategy.ts' in github.com/bvaughn/js-search/\n *\n * @private\n */\n _expandToken(token: string): Array<string> {\n switch (this._indexMode) {\n case INDEX_MODES.EXACT_WORDS:\n return [token];\n case INDEX_MODES.PREFIXES:\n return this._expandPrefixTokens(token);\n case INDEX_MODES.ALL_SUBSTRINGS:\n default:\n return this._expandAllSubstringTokens(token);\n }\n }\n\n _expandAllSubstringTokens(token: string): Array<string> {\n const expandedTokens = [];\n\n // String.prototype.charAt() may return surrogate halves instead of whole characters.\n // When this happens in the context of a web-worker it can cause Chrome to crash.\n // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\n // Resources:\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\n // https://mathiasbynens.be/notes/javascript-unicode\n try {\n for (let i = 0, length = token.length; i < length; ++i) {\n let substring: string = \"\";\n\n for (let j = i; j < length; ++j) {\n substring += token.charAt(j);\n expandedTokens.push(substring);\n }\n }\n } catch (error) {\n console.error(`Unable to parse token \"${token}\" ${error}`);\n }\n\n return expandedTokens;\n }\n\n _expandPrefixTokens(token: string): Array<string> {\n const expandedTokens = [];\n\n // String.prototype.charAt() may return surrogate halves instead of whole characters.\n // When this happens in the context of a web-worker it can cause Chrome to crash.\n // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\n // Resources:\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\n // https://mathiasbynens.be/notes/javascript-unicode\n try {\n for (let i = 0, length = token.length; i < length; ++i) {\n expandedTokens.push(token.substr(0, i + 1));\n }\n } catch (error) {\n console.error(`Unable to parse token \"${token}\" ${error}`);\n }\n\n return expandedTokens;\n }\n\n /**\n * @private\n */\n _sanitize(string: string): string {\n return this._caseSensitive\n ? string.trim()\n : string.trim().toLocaleLowerCase();\n }\n\n /**\n * @private\n */\n _tokenize(text: string): Array<string> {\n return text.split(this._tokenizePattern).filter(text => text); // Remove empty tokens\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/SearchUtility.js","/** @flow */\n\nexport const INDEX_MODES = {\n // Indexes for all substring searches (e.g. the term \"cat\" is indexed as \"c\", \"ca\", \"cat\", \"a\", \"at\", and \"t\").\n // Based on 'all-substrings-index-strategy' from js-search;\n // github.com/bvaughn/js-search/blob/master/source/index-strategy/all-substrings-index-strategy.ts\n ALL_SUBSTRINGS: \"ALL_SUBSTRINGS\",\n\n // Indexes for exact word matches only.\n // Based on 'exact-word-index-strategy' from js-search;\n // github.com/bvaughn/js-search/blob/master/source/index-strategy/exact-word-index-strategy.ts\n EXACT_WORDS: \"EXACT_WORDS\",\n\n // Indexes for prefix searches (e.g. the term \"cat\" is indexed as \"c\", \"ca\", and \"cat\" allowing prefix search lookups).\n // Based on 'prefix-index-strategy' from js-search;\n // github.com/bvaughn/js-search/blob/master/source/index-strategy/prefix-index-strategy.ts\n PREFIXES: \"PREFIXES\"\n};\n\nexport type IndexMode = $Keys<typeof INDEX_MODES>;\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/constants.js","/** @flow */\n\n/**\n * Maps search tokens to uids using a trie structure.\n */\nexport default class SearchIndex {\n tokenToUidMap: { [token: string]: any };\n\n constructor() {\n this.tokenToUidMap = {};\n }\n\n /**\n * Maps the specified token to a uid.\n *\n * @param token Searchable token (e.g. \"road\")\n * @param uid Identifies a document within the searchable corpus\n */\n indexDocument(token: string, uid: any): void {\n if (!this.tokenToUidMap[token]) {\n this.tokenToUidMap[token] = {};\n }\n\n this.tokenToUidMap[token][uid] = uid;\n }\n\n /**\n * Finds uids that have been mapped to the set of tokens specified.\n * Only uids that have been mapped to all tokens will be returned.\n *\n * @param tokens Array of searchable tokens (e.g. [\"long\", \"road\"])\n * @param matchAnyToken Whether to match any token. Default is false.\n * @return Array of uids that have been associated with the set of search tokens\n */\n search(tokens: Array<string>, matchAnyToken: boolean): Array<any> {\n let uidMap: { [uid: any]: any } = {};\n let uidMatches: { [uid: any]: number } = {};\n let initialized = false;\n\n tokens.forEach(token => {\n let currentUidMap: { [uid: any]: any } = this.tokenToUidMap[token] || {};\n\n if (!initialized) {\n initialized = true;\n\n for (let uid in currentUidMap) {\n uidMap[uid] = currentUidMap[uid];\n uidMatches[uid] = 1;\n }\n } else {\n // Delete existing matches if using and AND query (the default)\n // Otherwise add new results to the matches\n if (!matchAnyToken) {\n for (let uid in uidMap) {\n if (!currentUidMap[uid]) {\n delete uidMap[uid];\n }\n }\n } else {\n for (let uid in currentUidMap) {\n uidMap[uid] = currentUidMap[uid];\n uidMatches[uid] = (uidMatches[uid] || 0) + 1;\n }\n }\n }\n });\n\n let uids: Array<any> = [];\n for (let uid in uidMap) {\n uids.push(uidMap[uid]);\n }\n\n // Sort according to most matches, if match any token is set.\n if (matchAnyToken) {\n uids.sort((a, b) => {\n return uidMatches[b] - uidMatches[a];\n });\n }\n\n return uids;\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/SearchIndex.js"],"sourceRoot":""}
+3
-0
Changelog
-----
#### 1.4.0
* Added support for optional OR searches (documents matching only some of the search tokens) ([@ dlebech](https://github.com/ dlebech) - [#19](https://github.com/bvaughn/js-worker-search/pull/19))
#### 1.3.0

@@ -5,0 +8,0 @@ * Added `terminate` method to enable library users to kill the web worker ([@LrsK](https://github.com/LrsK) - [#15](https://github.com/bvaughn/js-worker-search/pull/15))

+100
-44

@@ -103,5 +103,6 @@ module.exports =

var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
caseSensitive = _ref.caseSensitive,
indexMode = _ref.indexMode,
tokenizePattern = _ref.tokenizePattern,
caseSensitive = _ref.caseSensitive;
matchAnyToken = _ref.matchAnyToken,
tokenizePattern = _ref.tokenizePattern;

@@ -130,2 +131,3 @@ _classCallCheck(this, SearchApi);

indexMode: indexMode,
matchAnyToken: matchAnyToken,
tokenizePattern: tokenizePattern,

@@ -137,2 +139,3 @@ caseSensitive: caseSensitive

indexMode: indexMode,
matchAnyToken: matchAnyToken,
tokenizePattern: tokenizePattern,

@@ -230,2 +233,3 @@ caseSensitive: caseSensitive

* @param caseSensitive See #setCaseSensitive
* @param matchAnyToken See #setMatchAnyToken
*/

@@ -236,8 +240,10 @@ function SearchUtility() {

var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$caseSensitive = _ref.caseSensitive,
caseSensitive = _ref$caseSensitive === undefined ? false : _ref$caseSensitive,
_ref$indexMode = _ref.indexMode,
indexMode = _ref$indexMode === undefined ? _constants.INDEX_MODES.ALL_SUBSTRINGS : _ref$indexMode,
_ref$matchAnyToken = _ref.matchAnyToken,
matchAnyToken = _ref$matchAnyToken === undefined ? false : _ref$matchAnyToken,
_ref$tokenizePattern = _ref.tokenizePattern,
tokenizePattern = _ref$tokenizePattern === undefined ? /\s+/ : _ref$tokenizePattern,
_ref$caseSensitive = _ref.caseSensitive,
caseSensitive = _ref$caseSensitive === undefined ? false : _ref$caseSensitive;
tokenizePattern = _ref$tokenizePattern === undefined ? /\s+/ : _ref$tokenizePattern;

@@ -268,3 +274,3 @@ _classCallCheck(this, SearchUtility);

return _this._searchIndex.search(tokens);
return _this._searchIndex.search(tokens, _this._matchAnyToken);
}

@@ -275,5 +281,6 @@ };

this._caseSensitive = caseSensitive;
this._indexMode = indexMode;
this._matchAnyToken = matchAnyToken;
this._tokenizePattern = tokenizePattern;
this._caseSensitive = caseSensitive;

@@ -285,3 +292,3 @@ this._searchIndex = new _SearchIndex2.default();

/**
* Returns a constant representing the current index mode.
* Returns a constant representing the current case-sensitive bit.
*/

@@ -291,2 +298,12 @@

_createClass(SearchUtility, [{
key: "getCaseSensitive",
value: function getCaseSensitive() {
return this._caseSensitive;
}
/**
* Returns a constant representing the current index mode.
*/
}, {
key: "getIndexMode",

@@ -298,19 +315,19 @@ value: function getIndexMode() {

/**
* Returns a constant representing the current tokenize pattern.
* Returns a constant representing the current match-any-token bit.
*/
}, {
key: "getTokenizePattern",
value: function getTokenizePattern() {
return this._tokenizePattern;
key: "getMatchAnyToken",
value: function getMatchAnyToken() {
return this._matchAnyToken;
}
/**
* Returns a constant representing the current case-sensitive bit.
* Returns a constant representing the current tokenize pattern.
*/
}, {
key: "getCaseSensitive",
value: function getCaseSensitive() {
return this._caseSensitive;
key: "getTokenizePattern",
value: function getTokenizePattern() {
return this._tokenizePattern;
}

@@ -329,7 +346,8 @@

* Searches the current index for the specified query text.
* Only uids matching all of the words within the text will be accepted.
* Only uids matching all of the words within the text will be accepted,
* unless matchAny is set to true.
* If an empty query string is provided all indexed uids will be returned.
*
* Document searches are case-insensitive (e.g. "search" will match "Search").
* Document searches use substring matching (e.g. "na" and "me" will both match "name").
* Document searches are case-insensitive by default (e.g. "search" will match "Search").
* Document searches use substring matching by default (e.g. "na" and "me" will both match "name").
*

@@ -341,9 +359,19 @@ * @param query Searchable query text

}, {
key: "setIndexMode",
key: "setCaseSensitive",
/**
* Sets a new case-sensitive bit
*/
value: function setCaseSensitive(caseSensitive) {
this._caseSensitive = caseSensitive;
}
/**
* Sets a new index mode.
* See util/constants/INDEX_MODES
*/
}, {
key: "setIndexMode",
value: function setIndexMode(indexMode) {

@@ -358,19 +386,19 @@ if (Object.keys(this._uids).length > 0) {

/**
* Sets a new tokenize pattern (regular expression)
* Sets a new match-any-token bit
*/
}, {
key: "setTokenizePattern",
value: function setTokenizePattern(pattern) {
this._tokenizePattern = pattern;
key: "setMatchAnyToken",
value: function setMatchAnyToken(matchAnyToken) {
this._matchAnyToken = matchAnyToken;
}
/**
* Sets a new case-sensitive bit
* Sets a new tokenize pattern (regular expression)
*/
}, {
key: "setCaseSensitive",
value: function setCaseSensitive(caseSensitive) {
this._caseSensitive = caseSensitive;
key: "setTokenizePattern",
value: function setTokenizePattern(pattern) {
this._tokenizePattern = pattern;
}

@@ -551,2 +579,3 @@

* @param tokens Array of searchable tokens (e.g. ["long", "road"])
* @param matchAnyToken Whether to match any token. Default is false.
* @return Array of uids that have been associated with the set of search tokens

@@ -557,6 +586,7 @@ */

key: "search",
value: function search(tokens) {
value: function search(tokens, matchAnyToken) {
var _this = this;
var uidMap = {};
var uidMatches = {};
var initialized = false;

@@ -572,8 +602,18 @@

uidMap[_uid] = currentUidMap[_uid];
uidMatches[_uid] = 1;
}
} else {
for (var _uid2 in uidMap) {
if (!currentUidMap[_uid2]) {
delete uidMap[_uid2];
// Delete existing matches if using and AND query (the default)
// Otherwise add new results to the matches
if (!matchAnyToken) {
for (var _uid2 in uidMap) {
if (!currentUidMap[_uid2]) {
delete uidMap[_uid2];
}
}
} else {
for (var _uid3 in currentUidMap) {
uidMap[_uid3] = currentUidMap[_uid3];
uidMatches[_uid3] = (uidMatches[_uid3] || 0) + 1;
}
}

@@ -584,6 +624,13 @@ }

var uids = [];
for (var _uid3 in uidMap) {
uids.push(uidMap[_uid3]);
for (var _uid4 in uidMap) {
uids.push(uidMap[_uid4]);
}
// Sort according to most matches, if match any token is set.
if (matchAnyToken) {
uids.sort(function (a, b) {
return uidMatches[b] - uidMatches[a];
});
}
return uids;

@@ -651,5 +698,6 @@ }

var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
caseSensitive = _ref.caseSensitive,
indexMode = _ref.indexMode,
matchAnyToken = _ref.matchAnyToken,
tokenizePattern = _ref.tokenizePattern,
caseSensitive = _ref.caseSensitive,
WorkerClass = _ref.WorkerClass;

@@ -726,2 +774,10 @@

// Override default :caseSensitive bit if a specific one has been requested
if (caseSensitive) {
this._worker.postMessage({
method: "setCaseSensitive",
caseSensitive: caseSensitive
});
}
// Override default :indexMode if a specific one has been requested

@@ -735,2 +791,10 @@ if (indexMode) {

// Override default :matchAnyToken bit if a specific one has been requested
if (matchAnyToken) {
this._worker.postMessage({
method: "setMatchAnyToken",
matchAnyToken: matchAnyToken
});
}
// Override default :tokenizePattern if a specific one has been requested

@@ -743,10 +807,2 @@ if (tokenizePattern) {

}
// Override default :caseSensitive bit if a specific one has been requested
if (caseSensitive) {
this._worker.postMessage({
method: "setCaseSensitive",
caseSensitive: caseSensitive
});
}
}

@@ -1058,3 +1114,3 @@

module.exports = function() {
return __webpack_require__(12)("/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t\"use strict\";\n\t\n\tvar _util = __webpack_require__(1);\n\t\n\t/**\n\t * Search entry point to web worker.\n\t * Builds search index and performs searches on separate thread from the ui.\n\t */\n\t\n\tvar searchUtility = new _util.SearchUtility();\n\t\n\tself.addEventListener(\"message\", function (event) {\n\t var data = event.data;\n\t var method = data.method;\n\t\n\t\n\t switch (method) {\n\t case \"indexDocument\":\n\t var uid = data.uid,\n\t text = data.text;\n\t\n\t\n\t searchUtility.indexDocument(uid, text);\n\t break;\n\t case \"search\":\n\t var callbackId = data.callbackId,\n\t query = data.query;\n\t\n\t\n\t var results = searchUtility.search(query);\n\t\n\t self.postMessage({ callbackId: callbackId, results: results });\n\t break;\n\t case \"setIndexMode\":\n\t var indexMode = data.indexMode;\n\t\n\t\n\t searchUtility.setIndexMode(indexMode);\n\t break;\n\t case \"setTokenizePattern\":\n\t var tokenizePattern = data.tokenizePattern;\n\t\n\t\n\t searchUtility.setTokenizePattern(tokenizePattern);\n\t break;\n\t case \"setCaseSensitive\":\n\t var caseSensitive = data.caseSensitive;\n\t\n\t\n\t searchUtility.setCaseSensitive(caseSensitive);\n\t break;\n\t }\n\t}, false);\n\n/***/ },\n/* 1 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t\"use strict\";\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\texports.SearchUtility = exports.INDEX_MODES = undefined;\n\t\n\tvar _SearchUtility = __webpack_require__(2);\n\t\n\tvar _SearchUtility2 = _interopRequireDefault(_SearchUtility);\n\t\n\tvar _constants = __webpack_require__(3);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\texports.default = _SearchUtility2.default;\n\texports.INDEX_MODES = _constants.INDEX_MODES;\n\texports.SearchUtility = _SearchUtility2.default;\n\n/***/ },\n/* 2 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t\"use strict\";\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\t\n\tvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\t\n\tvar _constants = __webpack_require__(3);\n\t\n\tvar _SearchIndex = __webpack_require__(4);\n\t\n\tvar _SearchIndex2 = _interopRequireDefault(_SearchIndex);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\tfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\t\n\t/**\n\t * Synchronous client-side full-text search utility.\n\t * Forked from JS search (github.com/bvaughn/js-search).\n\t */\n\tvar SearchUtility = function () {\n\t\n\t /**\n\t * Constructor.\n\t *\n\t * @param indexMode See #setIndexMode\n\t * @param tokenizePattern See #setTokenizePattern\n\t * @param caseSensitive See #setCaseSensitive\n\t */\n\t function SearchUtility() {\n\t var _this = this;\n\t\n\t var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n\t _ref$indexMode = _ref.indexMode,\n\t indexMode = _ref$indexMode === undefined ? _constants.INDEX_MODES.ALL_SUBSTRINGS : _ref$indexMode,\n\t _ref$tokenizePattern = _ref.tokenizePattern,\n\t tokenizePattern = _ref$tokenizePattern === undefined ? /\\s+/ : _ref$tokenizePattern,\n\t _ref$caseSensitive = _ref.caseSensitive,\n\t caseSensitive = _ref$caseSensitive === undefined ? false : _ref$caseSensitive;\n\t\n\t _classCallCheck(this, SearchUtility);\n\t\n\t this.indexDocument = function (uid, text) {\n\t _this._uids[uid] = true;\n\t\n\t var fieldTokens = _this._tokenize(_this._sanitize(text));\n\t\n\t fieldTokens.forEach(function (fieldToken) {\n\t var expandedTokens = _this._expandToken(fieldToken);\n\t\n\t expandedTokens.forEach(function (expandedToken) {\n\t _this._searchIndex.indexDocument(expandedToken, uid);\n\t });\n\t });\n\t\n\t return _this;\n\t };\n\t\n\t this.search = function (query) {\n\t if (!query) {\n\t return Object.keys(_this._uids);\n\t } else {\n\t var tokens = _this._tokenize(_this._sanitize(query));\n\t\n\t return _this._searchIndex.search(tokens);\n\t }\n\t };\n\t\n\t this.terminate = function () {};\n\t\n\t this._indexMode = indexMode;\n\t this._tokenizePattern = tokenizePattern;\n\t this._caseSensitive = caseSensitive;\n\t\n\t this._searchIndex = new _SearchIndex2.default();\n\t this._uids = {};\n\t }\n\t\n\t /**\n\t * Returns a constant representing the current index mode.\n\t */\n\t\n\t\n\t _createClass(SearchUtility, [{\n\t key: \"getIndexMode\",\n\t value: function getIndexMode() {\n\t return this._indexMode;\n\t }\n\t\n\t /**\n\t * Returns a constant representing the current tokenize pattern.\n\t */\n\t\n\t }, {\n\t key: \"getTokenizePattern\",\n\t value: function getTokenizePattern() {\n\t return this._tokenizePattern;\n\t }\n\t\n\t /**\n\t * Returns a constant representing the current case-sensitive bit.\n\t */\n\t\n\t }, {\n\t key: \"getCaseSensitive\",\n\t value: function getCaseSensitive() {\n\t return this._caseSensitive;\n\t }\n\t\n\t /**\n\t * Adds or updates a uid in the search index and associates it with the specified text.\n\t * Note that at this time uids can only be added or updated in the index, not removed.\n\t *\n\t * @param uid Uniquely identifies a searchable object\n\t * @param text Text to associate with uid\n\t */\n\t\n\t\n\t /**\n\t * Searches the current index for the specified query text.\n\t * Only uids matching all of the words within the text will be accepted.\n\t * If an empty query string is provided all indexed uids will be returned.\n\t *\n\t * Document searches are case-insensitive (e.g. \"search\" will match \"Search\").\n\t * Document searches use substring matching (e.g. \"na\" and \"me\" will both match \"name\").\n\t *\n\t * @param query Searchable query text\n\t * @return Array of uids\n\t */\n\t\n\t }, {\n\t key: \"setIndexMode\",\n\t\n\t\n\t /**\n\t * Sets a new index mode.\n\t * See util/constants/INDEX_MODES\n\t */\n\t value: function setIndexMode(indexMode) {\n\t if (Object.keys(this._uids).length > 0) {\n\t throw Error(\"indexMode cannot be changed once documents have been indexed\");\n\t }\n\t\n\t this._indexMode = indexMode;\n\t }\n\t\n\t /**\n\t * Sets a new tokenize pattern (regular expression)\n\t */\n\t\n\t }, {\n\t key: \"setTokenizePattern\",\n\t value: function setTokenizePattern(pattern) {\n\t this._tokenizePattern = pattern;\n\t }\n\t\n\t /**\n\t * Sets a new case-sensitive bit\n\t */\n\t\n\t }, {\n\t key: \"setCaseSensitive\",\n\t value: function setCaseSensitive(caseSensitive) {\n\t this._caseSensitive = caseSensitive;\n\t }\n\t\n\t /**\n\t * Added to make class adhere to interface. Add cleanup code as needed.\n\t */\n\t\n\t }, {\n\t key: \"_expandToken\",\n\t\n\t\n\t /**\n\t * Index strategy based on 'all-substrings-index-strategy.ts' in github.com/bvaughn/js-search/\n\t *\n\t * @private\n\t */\n\t value: function _expandToken(token) {\n\t switch (this._indexMode) {\n\t case _constants.INDEX_MODES.EXACT_WORDS:\n\t return [token];\n\t case _constants.INDEX_MODES.PREFIXES:\n\t return this._expandPrefixTokens(token);\n\t case _constants.INDEX_MODES.ALL_SUBSTRINGS:\n\t default:\n\t return this._expandAllSubstringTokens(token);\n\t }\n\t }\n\t }, {\n\t key: \"_expandAllSubstringTokens\",\n\t value: function _expandAllSubstringTokens(token) {\n\t var expandedTokens = [];\n\t\n\t // String.prototype.charAt() may return surrogate halves instead of whole characters.\n\t // When this happens in the context of a web-worker it can cause Chrome to crash.\n\t // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\n\t // Resources:\n\t // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\n\t // https://mathiasbynens.be/notes/javascript-unicode\n\t try {\n\t for (var i = 0, length = token.length; i < length; ++i) {\n\t var substring = \"\";\n\t\n\t for (var j = i; j < length; ++j) {\n\t substring += token.charAt(j);\n\t expandedTokens.push(substring);\n\t }\n\t }\n\t } catch (error) {\n\t console.error(\"Unable to parse token \\\"\" + token + \"\\\" \" + error);\n\t }\n\t\n\t return expandedTokens;\n\t }\n\t }, {\n\t key: \"_expandPrefixTokens\",\n\t value: function _expandPrefixTokens(token) {\n\t var expandedTokens = [];\n\t\n\t // String.prototype.charAt() may return surrogate halves instead of whole characters.\n\t // When this happens in the context of a web-worker it can cause Chrome to crash.\n\t // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\n\t // Resources:\n\t // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\n\t // https://mathiasbynens.be/notes/javascript-unicode\n\t try {\n\t for (var i = 0, length = token.length; i < length; ++i) {\n\t expandedTokens.push(token.substr(0, i + 1));\n\t }\n\t } catch (error) {\n\t console.error(\"Unable to parse token \\\"\" + token + \"\\\" \" + error);\n\t }\n\t\n\t return expandedTokens;\n\t }\n\t\n\t /**\n\t * @private\n\t */\n\t\n\t }, {\n\t key: \"_sanitize\",\n\t value: function _sanitize(string) {\n\t return this._caseSensitive ? string.trim() : string.trim().toLocaleLowerCase();\n\t }\n\t\n\t /**\n\t * @private\n\t */\n\t\n\t }, {\n\t key: \"_tokenize\",\n\t value: function _tokenize(text) {\n\t return text.split(this._tokenizePattern).filter(function (text) {\n\t return text;\n\t }); // Remove empty tokens\n\t }\n\t }]);\n\t\n\t return SearchUtility;\n\t}();\n\t\n\texports.default = SearchUtility;\n\n/***/ },\n/* 3 */\n/***/ function(module, exports) {\n\n\t\"use strict\";\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\tvar INDEX_MODES = exports.INDEX_MODES = {\n\t // Indexes for all substring searches (e.g. the term \"cat\" is indexed as \"c\", \"ca\", \"cat\", \"a\", \"at\", and \"t\").\n\t // Based on 'all-substrings-index-strategy' from js-search;\n\t // github.com/bvaughn/js-search/blob/master/source/index-strategy/all-substrings-index-strategy.ts\n\t ALL_SUBSTRINGS: \"ALL_SUBSTRINGS\",\n\t\n\t // Indexes for exact word matches only.\n\t // Based on 'exact-word-index-strategy' from js-search;\n\t // github.com/bvaughn/js-search/blob/master/source/index-strategy/exact-word-index-strategy.ts\n\t EXACT_WORDS: \"EXACT_WORDS\",\n\t\n\t // Indexes for prefix searches (e.g. the term \"cat\" is indexed as \"c\", \"ca\", and \"cat\" allowing prefix search lookups).\n\t // Based on 'prefix-index-strategy' from js-search;\n\t // github.com/bvaughn/js-search/blob/master/source/index-strategy/prefix-index-strategy.ts\n\t PREFIXES: \"PREFIXES\"\n\t};\n\n/***/ },\n/* 4 */\n/***/ function(module, exports) {\n\n\t\"use strict\";\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\t\n\tvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\t\n\tfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\t\n\t/**\n\t * Maps search tokens to uids using a trie structure.\n\t */\n\tvar SearchIndex = function () {\n\t function SearchIndex() {\n\t _classCallCheck(this, SearchIndex);\n\t\n\t this.tokenToUidMap = {};\n\t }\n\t\n\t /**\n\t * Maps the specified token to a uid.\n\t *\n\t * @param token Searchable token (e.g. \"road\")\n\t * @param uid Identifies a document within the searchable corpus\n\t */\n\t\n\t\n\t _createClass(SearchIndex, [{\n\t key: \"indexDocument\",\n\t value: function indexDocument(token, uid) {\n\t if (!this.tokenToUidMap[token]) {\n\t this.tokenToUidMap[token] = {};\n\t }\n\t\n\t this.tokenToUidMap[token][uid] = uid;\n\t }\n\t\n\t /**\n\t * Finds uids that have been mapped to the set of tokens specified.\n\t * Only uids that have been mapped to all tokens will be returned.\n\t *\n\t * @param tokens Array of searchable tokens (e.g. [\"long\", \"road\"])\n\t * @return Array of uids that have been associated with the set of search tokens\n\t */\n\t\n\t }, {\n\t key: \"search\",\n\t value: function search(tokens) {\n\t var _this = this;\n\t\n\t var uidMap = {};\n\t var initialized = false;\n\t\n\t tokens.forEach(function (token) {\n\t var currentUidMap = _this.tokenToUidMap[token] || {};\n\t\n\t if (!initialized) {\n\t initialized = true;\n\t\n\t for (var _uid in currentUidMap) {\n\t uidMap[_uid] = currentUidMap[_uid];\n\t }\n\t } else {\n\t for (var _uid2 in uidMap) {\n\t if (!currentUidMap[_uid2]) {\n\t delete uidMap[_uid2];\n\t }\n\t }\n\t }\n\t });\n\t\n\t var uids = [];\n\t for (var _uid3 in uidMap) {\n\t uids.push(uidMap[_uid3]);\n\t }\n\t\n\t return uids;\n\t }\n\t }]);\n\t\n\t return SearchIndex;\n\t}();\n\t\n\texports.default = SearchIndex;\n\n/***/ }\n/******/ ]);\n//# sourceMappingURL=2ef0afcacb6f46b34be5.worker.js.map", __webpack_require__.p + "2ef0afcacb6f46b34be5.worker.js");
return __webpack_require__(12)("/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t\"use strict\";\n\t\n\tvar _util = __webpack_require__(1);\n\t\n\t/**\n\t * Search entry point to web worker.\n\t * Builds search index and performs searches on separate thread from the ui.\n\t */\n\t\n\tvar searchUtility = new _util.SearchUtility();\n\t\n\tself.addEventListener(\"message\", function (event) {\n\t var data = event.data;\n\t var method = data.method;\n\t\n\t\n\t switch (method) {\n\t case \"indexDocument\":\n\t var uid = data.uid,\n\t text = data.text;\n\t\n\t\n\t searchUtility.indexDocument(uid, text);\n\t break;\n\t case \"search\":\n\t var callbackId = data.callbackId,\n\t query = data.query;\n\t\n\t\n\t var results = searchUtility.search(query);\n\t\n\t self.postMessage({ callbackId: callbackId, results: results });\n\t break;\n\t case \"setCaseSensitive\":\n\t var caseSensitive = data.caseSensitive;\n\t\n\t\n\t searchUtility.setCaseSensitive(caseSensitive);\n\t break;\n\t case \"setIndexMode\":\n\t var indexMode = data.indexMode;\n\t\n\t\n\t searchUtility.setIndexMode(indexMode);\n\t break;\n\t case \"setMatchAnyToken\":\n\t var matchAnyToken = data.matchAnyToken;\n\t\n\t\n\t searchUtility.setMatchAnyToken(matchAnyToken);\n\t break;\n\t case \"setTokenizePattern\":\n\t var tokenizePattern = data.tokenizePattern;\n\t\n\t\n\t searchUtility.setTokenizePattern(tokenizePattern);\n\t break;\n\t }\n\t}, false);\n\n/***/ },\n/* 1 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t\"use strict\";\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\texports.SearchUtility = exports.INDEX_MODES = undefined;\n\t\n\tvar _SearchUtility = __webpack_require__(2);\n\t\n\tvar _SearchUtility2 = _interopRequireDefault(_SearchUtility);\n\t\n\tvar _constants = __webpack_require__(3);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\texports.default = _SearchUtility2.default;\n\texports.INDEX_MODES = _constants.INDEX_MODES;\n\texports.SearchUtility = _SearchUtility2.default;\n\n/***/ },\n/* 2 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t\"use strict\";\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\t\n\tvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\t\n\tvar _constants = __webpack_require__(3);\n\t\n\tvar _SearchIndex = __webpack_require__(4);\n\t\n\tvar _SearchIndex2 = _interopRequireDefault(_SearchIndex);\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\t\n\tfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\t\n\t/**\n\t * Synchronous client-side full-text search utility.\n\t * Forked from JS search (github.com/bvaughn/js-search).\n\t */\n\tvar SearchUtility = function () {\n\t\n\t /**\n\t * Constructor.\n\t *\n\t * @param indexMode See #setIndexMode\n\t * @param tokenizePattern See #setTokenizePattern\n\t * @param caseSensitive See #setCaseSensitive\n\t * @param matchAnyToken See #setMatchAnyToken\n\t */\n\t function SearchUtility() {\n\t var _this = this;\n\t\n\t var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n\t _ref$caseSensitive = _ref.caseSensitive,\n\t caseSensitive = _ref$caseSensitive === undefined ? false : _ref$caseSensitive,\n\t _ref$indexMode = _ref.indexMode,\n\t indexMode = _ref$indexMode === undefined ? _constants.INDEX_MODES.ALL_SUBSTRINGS : _ref$indexMode,\n\t _ref$matchAnyToken = _ref.matchAnyToken,\n\t matchAnyToken = _ref$matchAnyToken === undefined ? false : _ref$matchAnyToken,\n\t _ref$tokenizePattern = _ref.tokenizePattern,\n\t tokenizePattern = _ref$tokenizePattern === undefined ? /\\s+/ : _ref$tokenizePattern;\n\t\n\t _classCallCheck(this, SearchUtility);\n\t\n\t this.indexDocument = function (uid, text) {\n\t _this._uids[uid] = true;\n\t\n\t var fieldTokens = _this._tokenize(_this._sanitize(text));\n\t\n\t fieldTokens.forEach(function (fieldToken) {\n\t var expandedTokens = _this._expandToken(fieldToken);\n\t\n\t expandedTokens.forEach(function (expandedToken) {\n\t _this._searchIndex.indexDocument(expandedToken, uid);\n\t });\n\t });\n\t\n\t return _this;\n\t };\n\t\n\t this.search = function (query) {\n\t if (!query) {\n\t return Object.keys(_this._uids);\n\t } else {\n\t var tokens = _this._tokenize(_this._sanitize(query));\n\t\n\t return _this._searchIndex.search(tokens, _this._matchAnyToken);\n\t }\n\t };\n\t\n\t this.terminate = function () {};\n\t\n\t this._caseSensitive = caseSensitive;\n\t this._indexMode = indexMode;\n\t this._matchAnyToken = matchAnyToken;\n\t this._tokenizePattern = tokenizePattern;\n\t\n\t this._searchIndex = new _SearchIndex2.default();\n\t this._uids = {};\n\t }\n\t\n\t /**\n\t * Returns a constant representing the current case-sensitive bit.\n\t */\n\t\n\t\n\t _createClass(SearchUtility, [{\n\t key: \"getCaseSensitive\",\n\t value: function getCaseSensitive() {\n\t return this._caseSensitive;\n\t }\n\t\n\t /**\n\t * Returns a constant representing the current index mode.\n\t */\n\t\n\t }, {\n\t key: \"getIndexMode\",\n\t value: function getIndexMode() {\n\t return this._indexMode;\n\t }\n\t\n\t /**\n\t * Returns a constant representing the current match-any-token bit.\n\t */\n\t\n\t }, {\n\t key: \"getMatchAnyToken\",\n\t value: function getMatchAnyToken() {\n\t return this._matchAnyToken;\n\t }\n\t\n\t /**\n\t * Returns a constant representing the current tokenize pattern.\n\t */\n\t\n\t }, {\n\t key: \"getTokenizePattern\",\n\t value: function getTokenizePattern() {\n\t return this._tokenizePattern;\n\t }\n\t\n\t /**\n\t * Adds or updates a uid in the search index and associates it with the specified text.\n\t * Note that at this time uids can only be added or updated in the index, not removed.\n\t *\n\t * @param uid Uniquely identifies a searchable object\n\t * @param text Text to associate with uid\n\t */\n\t\n\t\n\t /**\n\t * Searches the current index for the specified query text.\n\t * Only uids matching all of the words within the text will be accepted,\n\t * unless matchAny is set to true.\n\t * If an empty query string is provided all indexed uids will be returned.\n\t *\n\t * Document searches are case-insensitive by default (e.g. \"search\" will match \"Search\").\n\t * Document searches use substring matching by default (e.g. \"na\" and \"me\" will both match \"name\").\n\t *\n\t * @param query Searchable query text\n\t * @return Array of uids\n\t */\n\t\n\t }, {\n\t key: \"setCaseSensitive\",\n\t\n\t\n\t /**\n\t * Sets a new case-sensitive bit\n\t */\n\t value: function setCaseSensitive(caseSensitive) {\n\t this._caseSensitive = caseSensitive;\n\t }\n\t\n\t /**\n\t * Sets a new index mode.\n\t * See util/constants/INDEX_MODES\n\t */\n\t\n\t }, {\n\t key: \"setIndexMode\",\n\t value: function setIndexMode(indexMode) {\n\t if (Object.keys(this._uids).length > 0) {\n\t throw Error(\"indexMode cannot be changed once documents have been indexed\");\n\t }\n\t\n\t this._indexMode = indexMode;\n\t }\n\t\n\t /**\n\t * Sets a new match-any-token bit\n\t */\n\t\n\t }, {\n\t key: \"setMatchAnyToken\",\n\t value: function setMatchAnyToken(matchAnyToken) {\n\t this._matchAnyToken = matchAnyToken;\n\t }\n\t\n\t /**\n\t * Sets a new tokenize pattern (regular expression)\n\t */\n\t\n\t }, {\n\t key: \"setTokenizePattern\",\n\t value: function setTokenizePattern(pattern) {\n\t this._tokenizePattern = pattern;\n\t }\n\t\n\t /**\n\t * Added to make class adhere to interface. Add cleanup code as needed.\n\t */\n\t\n\t }, {\n\t key: \"_expandToken\",\n\t\n\t\n\t /**\n\t * Index strategy based on 'all-substrings-index-strategy.ts' in github.com/bvaughn/js-search/\n\t *\n\t * @private\n\t */\n\t value: function _expandToken(token) {\n\t switch (this._indexMode) {\n\t case _constants.INDEX_MODES.EXACT_WORDS:\n\t return [token];\n\t case _constants.INDEX_MODES.PREFIXES:\n\t return this._expandPrefixTokens(token);\n\t case _constants.INDEX_MODES.ALL_SUBSTRINGS:\n\t default:\n\t return this._expandAllSubstringTokens(token);\n\t }\n\t }\n\t }, {\n\t key: \"_expandAllSubstringTokens\",\n\t value: function _expandAllSubstringTokens(token) {\n\t var expandedTokens = [];\n\t\n\t // String.prototype.charAt() may return surrogate halves instead of whole characters.\n\t // When this happens in the context of a web-worker it can cause Chrome to crash.\n\t // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\n\t // Resources:\n\t // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\n\t // https://mathiasbynens.be/notes/javascript-unicode\n\t try {\n\t for (var i = 0, length = token.length; i < length; ++i) {\n\t var substring = \"\";\n\t\n\t for (var j = i; j < length; ++j) {\n\t substring += token.charAt(j);\n\t expandedTokens.push(substring);\n\t }\n\t }\n\t } catch (error) {\n\t console.error(\"Unable to parse token \\\"\" + token + \"\\\" \" + error);\n\t }\n\t\n\t return expandedTokens;\n\t }\n\t }, {\n\t key: \"_expandPrefixTokens\",\n\t value: function _expandPrefixTokens(token) {\n\t var expandedTokens = [];\n\t\n\t // String.prototype.charAt() may return surrogate halves instead of whole characters.\n\t // When this happens in the context of a web-worker it can cause Chrome to crash.\n\t // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\n\t // Resources:\n\t // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\n\t // https://mathiasbynens.be/notes/javascript-unicode\n\t try {\n\t for (var i = 0, length = token.length; i < length; ++i) {\n\t expandedTokens.push(token.substr(0, i + 1));\n\t }\n\t } catch (error) {\n\t console.error(\"Unable to parse token \\\"\" + token + \"\\\" \" + error);\n\t }\n\t\n\t return expandedTokens;\n\t }\n\t\n\t /**\n\t * @private\n\t */\n\t\n\t }, {\n\t key: \"_sanitize\",\n\t value: function _sanitize(string) {\n\t return this._caseSensitive ? string.trim() : string.trim().toLocaleLowerCase();\n\t }\n\t\n\t /**\n\t * @private\n\t */\n\t\n\t }, {\n\t key: \"_tokenize\",\n\t value: function _tokenize(text) {\n\t return text.split(this._tokenizePattern).filter(function (text) {\n\t return text;\n\t }); // Remove empty tokens\n\t }\n\t }]);\n\t\n\t return SearchUtility;\n\t}();\n\t\n\texports.default = SearchUtility;\n\n/***/ },\n/* 3 */\n/***/ function(module, exports) {\n\n\t\"use strict\";\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\tvar INDEX_MODES = exports.INDEX_MODES = {\n\t // Indexes for all substring searches (e.g. the term \"cat\" is indexed as \"c\", \"ca\", \"cat\", \"a\", \"at\", and \"t\").\n\t // Based on 'all-substrings-index-strategy' from js-search;\n\t // github.com/bvaughn/js-search/blob/master/source/index-strategy/all-substrings-index-strategy.ts\n\t ALL_SUBSTRINGS: \"ALL_SUBSTRINGS\",\n\t\n\t // Indexes for exact word matches only.\n\t // Based on 'exact-word-index-strategy' from js-search;\n\t // github.com/bvaughn/js-search/blob/master/source/index-strategy/exact-word-index-strategy.ts\n\t EXACT_WORDS: \"EXACT_WORDS\",\n\t\n\t // Indexes for prefix searches (e.g. the term \"cat\" is indexed as \"c\", \"ca\", and \"cat\" allowing prefix search lookups).\n\t // Based on 'prefix-index-strategy' from js-search;\n\t // github.com/bvaughn/js-search/blob/master/source/index-strategy/prefix-index-strategy.ts\n\t PREFIXES: \"PREFIXES\"\n\t};\n\n/***/ },\n/* 4 */\n/***/ function(module, exports) {\n\n\t\"use strict\";\n\t\n\tObject.defineProperty(exports, \"__esModule\", {\n\t value: true\n\t});\n\t\n\tvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\t\n\tfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\t\n\t/**\n\t * Maps search tokens to uids using a trie structure.\n\t */\n\tvar SearchIndex = function () {\n\t function SearchIndex() {\n\t _classCallCheck(this, SearchIndex);\n\t\n\t this.tokenToUidMap = {};\n\t }\n\t\n\t /**\n\t * Maps the specified token to a uid.\n\t *\n\t * @param token Searchable token (e.g. \"road\")\n\t * @param uid Identifies a document within the searchable corpus\n\t */\n\t\n\t\n\t _createClass(SearchIndex, [{\n\t key: \"indexDocument\",\n\t value: function indexDocument(token, uid) {\n\t if (!this.tokenToUidMap[token]) {\n\t this.tokenToUidMap[token] = {};\n\t }\n\t\n\t this.tokenToUidMap[token][uid] = uid;\n\t }\n\t\n\t /**\n\t * Finds uids that have been mapped to the set of tokens specified.\n\t * Only uids that have been mapped to all tokens will be returned.\n\t *\n\t * @param tokens Array of searchable tokens (e.g. [\"long\", \"road\"])\n\t * @param matchAnyToken Whether to match any token. Default is false.\n\t * @return Array of uids that have been associated with the set of search tokens\n\t */\n\t\n\t }, {\n\t key: \"search\",\n\t value: function search(tokens, matchAnyToken) {\n\t var _this = this;\n\t\n\t var uidMap = {};\n\t var uidMatches = {};\n\t var initialized = false;\n\t\n\t tokens.forEach(function (token) {\n\t var currentUidMap = _this.tokenToUidMap[token] || {};\n\t\n\t if (!initialized) {\n\t initialized = true;\n\t\n\t for (var _uid in currentUidMap) {\n\t uidMap[_uid] = currentUidMap[_uid];\n\t uidMatches[_uid] = 1;\n\t }\n\t } else {\n\t // Delete existing matches if using and AND query (the default)\n\t // Otherwise add new results to the matches\n\t if (!matchAnyToken) {\n\t for (var _uid2 in uidMap) {\n\t if (!currentUidMap[_uid2]) {\n\t delete uidMap[_uid2];\n\t }\n\t }\n\t } else {\n\t for (var _uid3 in currentUidMap) {\n\t uidMap[_uid3] = currentUidMap[_uid3];\n\t uidMatches[_uid3] = (uidMatches[_uid3] || 0) + 1;\n\t }\n\t }\n\t }\n\t });\n\t\n\t var uids = [];\n\t for (var _uid4 in uidMap) {\n\t uids.push(uidMap[_uid4]);\n\t }\n\t\n\t // Sort according to most matches, if match any token is set.\n\t if (matchAnyToken) {\n\t uids.sort(function (a, b) {\n\t return uidMatches[b] - uidMatches[a];\n\t });\n\t }\n\t\n\t return uids;\n\t }\n\t }]);\n\t\n\t return SearchIndex;\n\t}();\n\t\n\texports.default = SearchIndex;\n\n/***/ }\n/******/ ]);\n//# sourceMappingURL=5cafaba60d6eb1f43c8f.worker.js.map", __webpack_require__.p + "5cafaba60d6eb1f43c8f.worker.js");
};

@@ -1061,0 +1117,0 @@

@@ -1,1 +0,1 @@

{"version":3,"sources":["webpack:///webpack/bootstrap 50bfbe92ee51eb38a4e6","webpack:///./src/index.js","webpack:///./src/SearchApi.js","webpack:///./src/util/index.js","webpack:///./src/util/SearchUtility.js","webpack:///./src/util/constants.js","webpack:///./src/util/SearchIndex.js","webpack:///./src/worker/index.js","webpack:///./src/worker/SearchWorkerLoader.js","webpack:///./~/uuid/uuid.js","webpack:///./~/uuid/rng-browser.js","webpack:///./src/worker/Worker.js","webpack:///./~/worker-loader/createInlineWorker.js"],"names":["INDEX_MODES","SearchApi","indexMode","tokenizePattern","caseSensitive","indexDocument","uid","text","_search","search","query","terminate","window","Worker","SearchUtility","ALL_SUBSTRINGS","_uids","fieldTokens","_tokenize","_sanitize","forEach","expandedTokens","_expandToken","fieldToken","_searchIndex","expandedToken","Object","keys","tokens","_indexMode","_tokenizePattern","_caseSensitive","length","Error","pattern","token","EXACT_WORDS","PREFIXES","_expandPrefixTokens","_expandAllSubstringTokens","i","substring","j","charAt","push","error","console","substr","string","trim","toLocaleLowerCase","split","filter","SearchIndex","tokenToUidMap","uidMap","initialized","currentUidMap","uids","SearchWorkerLoader","WorkerClass","_worker","postMessage","method","Promise","resolve","reject","callbackId","v4","data","complete","results","_callbackQueue","_callbackIdMap","require","onerror","event","_updateQueue","onmessage","target","shift"],"mappings":";;AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;;;;;;;;;;;;;ACpCA;;;;AACA;;;;;SAGSA,W;;;;;;;;;;;;ACJT;;AACA;;;;;;;;AAIA;;;;KAIqBC,S,GACL;;AAEd,sBAUE;AAAA;;AAAA,kFADI,EACJ;AAAA,OAREC,SAQF,QAREA,SAQF;AAAA,OAPEC,eAOF,QAPEA,eAOF;AAAA,OANEC,aAMF,QANEA,aAMF;;AAAA;;AAAA,QAyBFC,aAzBE,GAyBc,UAACC,GAAD,EAAWC,IAAX,EAAuC;AACrD,WAAKC,OAAL,CAAaH,aAAb,CAA2BC,GAA3B,EAAgCC,IAAhC;;AAEA;AACD,IA7BC;;AAAA,QA0CFE,MA1CE,GA0CO,UAACC,KAAD,EAAwC;AAC/C;AACA,YAAO,MAAKF,OAAL,CAAaC,MAAb,CAAoBC,KAApB,CAAP;AACD,IA7CC;;AAAA,QAkDFC,SAlDE,GAkDU,YAAM;AAChB,WAAKH,OAAL,CAAaG,SAAb;AACD,IApDC;;AACA;AACA;AACA,OAAI,OAAOC,MAAP,KAAkB,WAAlB,IAAiCA,OAAOC,MAA5C,EAAoD;AAClD,UAAKL,OAAL,GAAe,qBAAuB;AACpCN,2BADoC;AAEpCC,uCAFoC;AAGpCC;AAHoC,MAAvB,CAAf;AAKD,IAND,MAMO;AACL,UAAKI,OAAL,GAAe,wBAAkB;AAC/BN,2BAD+B;AAE/BC,uC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,KAApB;;AAEA,gBAAO,KAAKP,cAAL,CAAoBJ,KAAKF,UAAzB,CAAP;;AAEA,aAAIE,KAAKxB,KAAT,EAAgB;AACdwB,gBAAKH,MAAL,CAAYG,KAAKxB,KAAjB;AACD,UAFD,MAEO;AACL;AACA;AACAwB,gBAAKJ,OAAL,CAAcI,KAAKE,OAAnB;AACD;AACF;AACF;;;;;;mBApKkBZ,kB;;;;;;AC3BrB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,gBAAe,SAAS;AACxB;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,qCAAoC,EAAE;AACtC,mBAAkB;AAClB;AACA;AACA,IAAG;;AAEH;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,oCAAmC;AACnC;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA,kBAAiB,OAAO;AACxB;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,qBAAoB,SAAS;AAC7B;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;;;;;;;ACrLA;;AAEA,+CAA8C;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;A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e,aAAa,WAAW,EAAE,4BAA4B,qCAAqC,qCAAqC,WAAW,0BAA0B,SAAS,OAAO,GAAG,6BAA6B,KAAK,GAAG,sCAAsC,WAAW,cAAc;AAC31gB,G;;;;;;ACFA;;AAEA;AACA;AACA;AACA;AACA;AACA,YAAW;AACX;AACA;AACA;AACA;AACA,QAAO,WAAW;AAClB;AACA;AACA;AACA,MAAK;AACL;AACA;AACA,IAAG;AACH;AACA;AACA;AACA;AACA;AACA","file":"js-worker-search.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 50bfbe92ee51eb38a4e6","/** @flow */\n\nimport SearchApi from \"./SearchApi\";\nimport { INDEX_MODES } from \"./util\";\n\nexport default SearchApi;\nexport { INDEX_MODES };\n\n\n\n// WEBPACK FOOTER //\n// ./src/index.js","/** @flow */\n\nimport { SearchUtility } from \"./util\";\nimport SearchWorkerLoader from \"./worker\";\n\nimport type { IndexMode } from \"./util\";\n\n/**\n * Search API that uses web workers when available.\n * Indexing and searching is performed in the UI thread as a fallback when web workers aren't supported.\n */\nexport default class SearchApi {\n _search: any; // TODO\n\n constructor(\n {\n indexMode,\n tokenizePattern,\n caseSensitive\n }: {\n indexMode?: IndexMode,\n tokenizePattern?: RegExp,\n caseSensitive?: boolean\n } = {}\n ) {\n // Based on https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers\n // But with added check for Node environment\n if (typeof window !== \"undefined\" && window.Worker) {\n this._search = new SearchWorkerLoader({\n indexMode,\n tokenizePattern,\n caseSensitive\n });\n } else {\n this._search = new SearchUtility({\n indexMode,\n tokenizePattern,\n caseSensitive\n });\n }\n }\n\n /**\n * Adds or updates a uid in the search index and associates it with the specified text.\n * Note that at this time uids can only be added or updated in the index, not removed.\n *\n * @param uid Uniquely identifies a searchable object\n * @param text Text to associate with uid\n */\n indexDocument = (uid: any, text: string): SearchApi => {\n this._search.indexDocument(uid, text);\n\n return this;\n };\n\n /**\n * Searches the current index for the specified query text.\n * Only uids matching all of the words within the text will be accepted.\n * If an empty query string is provided all indexed uids will be returned.\n *\n * Document searches are case-insensitive (e.g. \"search\" will match \"Search\").\n * Document searches use substring matching (e.g. \"na\" and \"me\" will both match \"name\").\n *\n * @param query Searchable query text\n * @return Promise to be resolved with an Array of matching uids\n */\n search = (query: string): Promise<Array<any>> => {\n // Promise.resolve handles both synchronous and web-worker Search utilities\n return this._search.search(query);\n };\n\n /**\n * Stops and retires the worker in the search API. Used for cleanup.\n */\n terminate = () => {\n this._search.terminate();\n };\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/SearchApi.js","/** @flow */\n\nimport SearchUtility from \"./SearchUtility\";\nimport { INDEX_MODES } from \"./constants\";\n\nexport type { IndexMode } from \"./constants\";\n\nexport default SearchUtility;\nexport { INDEX_MODES, SearchUtility };\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/index.js","/** @flow */\n\nimport { INDEX_MODES } from \"./constants\";\nimport SearchIndex from \"./SearchIndex\";\n\nimport type { IndexMode } from \"./constants\";\nimport type { SearchApiIndex } from \"../types\";\n\ntype UidMap = {\n [uid: string]: boolean\n};\n\n/**\n * Synchronous client-side full-text search utility.\n * Forked from JS search (github.com/bvaughn/js-search).\n */\nexport default class SearchUtility implements SearchApiIndex {\n _indexMode: IndexMode;\n _tokenizePattern: RegExp;\n _caseSensitive: boolean;\n _searchIndex: SearchIndex;\n _uids: UidMap;\n\n /**\n * Constructor.\n *\n * @param indexMode See #setIndexMode\n * @param tokenizePattern See #setTokenizePattern\n * @param caseSensitive See #setCaseSensitive\n */\n constructor(\n {\n indexMode = INDEX_MODES.ALL_SUBSTRINGS,\n tokenizePattern = /\\s+/,\n caseSensitive = false\n }: {\n indexMode?: IndexMode,\n tokenizePattern?: RegExp,\n caseSensitive?: boolean\n } = {}\n ) {\n this._indexMode = indexMode;\n this._tokenizePattern = tokenizePattern;\n this._caseSensitive = caseSensitive;\n\n this._searchIndex = new SearchIndex();\n this._uids = {};\n }\n\n /**\n * Returns a constant representing the current index mode.\n */\n getIndexMode(): string {\n return this._indexMode;\n }\n\n /**\n * Returns a constant representing the current tokenize pattern.\n */\n getTokenizePattern(): RegExp {\n return this._tokenizePattern;\n }\n\n /**\n * Returns a constant representing the current case-sensitive bit.\n */\n getCaseSensitive(): boolean {\n return this._caseSensitive;\n }\n\n /**\n * Adds or updates a uid in the search index and associates it with the specified text.\n * Note that at this time uids can only be added or updated in the index, not removed.\n *\n * @param uid Uniquely identifies a searchable object\n * @param text Text to associate with uid\n */\n indexDocument = (uid: any, text: string): SearchApiIndex => {\n this._uids[uid] = true;\n\n var fieldTokens: Array<string> = this._tokenize(this._sanitize(text));\n\n fieldTokens.forEach(fieldToken => {\n var expandedTokens: Array<string> = this._expandToken(fieldToken);\n\n expandedTokens.forEach(expandedToken => {\n this._searchIndex.indexDocument(expandedToken, uid);\n });\n });\n\n return this;\n };\n\n /**\n * Searches the current index for the specified query text.\n * Only uids matching all of the words within the text will be accepted.\n * If an empty query string is provided all indexed uids will be returned.\n *\n * Document searches are case-insensitive (e.g. \"search\" will match \"Search\").\n * Document searches use substring matching (e.g. \"na\" and \"me\" will both match \"name\").\n *\n * @param query Searchable query text\n * @return Array of uids\n */\n search = (query: string): Array<any> => {\n if (!query) {\n return Object.keys(this._uids);\n } else {\n var tokens: Array<string> = this._tokenize(this._sanitize(query));\n\n return this._searchIndex.search(tokens);\n }\n };\n\n /**\n * Sets a new index mode.\n * See util/constants/INDEX_MODES\n */\n setIndexMode(indexMode: IndexMode): void {\n if (Object.keys(this._uids).length > 0) {\n throw Error(\n \"indexMode cannot be changed once documents have been indexed\"\n );\n }\n\n this._indexMode = indexMode;\n }\n\n /**\n * Sets a new tokenize pattern (regular expression)\n */\n setTokenizePattern(pattern: RegExp): void {\n this._tokenizePattern = pattern;\n }\n\n /**\n * Sets a new case-sensitive bit\n */\n setCaseSensitive(caseSensitive: boolean): void {\n this._caseSensitive = caseSensitive;\n }\n\n /**\n * Added to make class adhere to interface. Add cleanup code as needed.\n */\n terminate = () => {};\n\n /**\n * Index strategy based on 'all-substrings-index-strategy.ts' in github.com/bvaughn/js-search/\n *\n * @private\n */\n _expandToken(token: string): Array<string> {\n switch (this._indexMode) {\n case INDEX_MODES.EXACT_WORDS:\n return [token];\n case INDEX_MODES.PREFIXES:\n return this._expandPrefixTokens(token);\n case INDEX_MODES.ALL_SUBSTRINGS:\n default:\n return this._expandAllSubstringTokens(token);\n }\n }\n\n _expandAllSubstringTokens(token: string): Array<string> {\n const expandedTokens = [];\n\n // String.prototype.charAt() may return surrogate halves instead of whole characters.\n // When this happens in the context of a web-worker it can cause Chrome to crash.\n // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\n // Resources:\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\n // https://mathiasbynens.be/notes/javascript-unicode\n try {\n for (let i = 0, length = token.length; i < length; ++i) {\n let substring: string = \"\";\n\n for (let j = i; j < length; ++j) {\n substring += token.charAt(j);\n expandedTokens.push(substring);\n }\n }\n } catch (error) {\n console.error(`Unable to parse token \"${token}\" ${error}`);\n }\n\n return expandedTokens;\n }\n\n _expandPrefixTokens(token: string): Array<string> {\n const expandedTokens = [];\n\n // String.prototype.charAt() may return surrogate halves instead of whole characters.\n // When this happens in the context of a web-worker it can cause Chrome to crash.\n // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\n // Resources:\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\n // https://mathiasbynens.be/notes/javascript-unicode\n try {\n for (let i = 0, length = token.length; i < length; ++i) {\n expandedTokens.push(token.substr(0, i + 1));\n }\n } catch (error) {\n console.error(`Unable to parse token \"${token}\" ${error}`);\n }\n\n return expandedTokens;\n }\n\n /**\n * @private\n */\n _sanitize(string: string): string {\n return this._caseSensitive\n ? string.trim()\n : string.trim().toLocaleLowerCase();\n }\n\n /**\n * @private\n */\n _tokenize(text: string): Array<string> {\n return text.split(this._tokenizePattern).filter(text => text); // Remove empty tokens\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/SearchUtility.js","/** @flow */\n\nexport const INDEX_MODES = {\n // Indexes for all substring searches (e.g. the term \"cat\" is indexed as \"c\", \"ca\", \"cat\", \"a\", \"at\", and \"t\").\n // Based on 'all-substrings-index-strategy' from js-search;\n // github.com/bvaughn/js-search/blob/master/source/index-strategy/all-substrings-index-strategy.ts\n ALL_SUBSTRINGS: \"ALL_SUBSTRINGS\",\n\n // Indexes for exact word matches only.\n // Based on 'exact-word-index-strategy' from js-search;\n // github.com/bvaughn/js-search/blob/master/source/index-strategy/exact-word-index-strategy.ts\n EXACT_WORDS: \"EXACT_WORDS\",\n\n // Indexes for prefix searches (e.g. the term \"cat\" is indexed as \"c\", \"ca\", and \"cat\" allowing prefix search lookups).\n // Based on 'prefix-index-strategy' from js-search;\n // github.com/bvaughn/js-search/blob/master/source/index-strategy/prefix-index-strategy.ts\n PREFIXES: \"PREFIXES\"\n};\n\nexport type IndexMode = $Keys<typeof INDEX_MODES>;\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/constants.js","/** @flow */\n\n/**\n * Maps search tokens to uids using a trie structure.\n */\nexport default class SearchIndex {\n tokenToUidMap: { [token: string]: any };\n\n constructor() {\n this.tokenToUidMap = {};\n }\n\n /**\n * Maps the specified token to a uid.\n *\n * @param token Searchable token (e.g. \"road\")\n * @param uid Identifies a document within the searchable corpus\n */\n indexDocument(token: string, uid: any): void {\n if (!this.tokenToUidMap[token]) {\n this.tokenToUidMap[token] = {};\n }\n\n this.tokenToUidMap[token][uid] = uid;\n }\n\n /**\n * Finds uids that have been mapped to the set of tokens specified.\n * Only uids that have been mapped to all tokens will be returned.\n *\n * @param tokens Array of searchable tokens (e.g. [\"long\", \"road\"])\n * @return Array of uids that have been associated with the set of search tokens\n */\n search(tokens: Array<string>): Array<any> {\n let uidMap: { [uid: any]: any } = {};\n let initialized = false;\n\n tokens.forEach(token => {\n let currentUidMap: { [uid: any]: any } = this.tokenToUidMap[token] || {};\n\n if (!initialized) {\n initialized = true;\n\n for (let uid in currentUidMap) {\n uidMap[uid] = currentUidMap[uid];\n }\n } else {\n for (let uid in uidMap) {\n if (!currentUidMap[uid]) {\n delete uidMap[uid];\n }\n }\n }\n });\n\n let uids: Array<any> = [];\n for (let uid in uidMap) {\n uids.push(uidMap[uid]);\n }\n\n return uids;\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/SearchIndex.js","/** @flow */\n\nimport SearchWorkerLoader from \"./SearchWorkerLoader\";\n\nexport default SearchWorkerLoader;\n\n\n\n// WEBPACK FOOTER //\n// ./src/worker/index.js","/** @flow */\n\nimport uuid from \"uuid\";\n\nimport type { IndexMode } from \"../util\";\nimport type { SearchApiIndex } from \"../types\";\n\ntype Results = Array<any>;\ntype RejectFn = (error: Error) => void;\ntype ResolveFn = (results: Results) => void;\nexport type CallbackData = {\n callbackId: string,\n complete: boolean,\n error: ?Error,\n reject: RejectFn,\n resolve: ResolveFn,\n results: ?Results\n};\ntype CallbackIdMap = { [callbackId: string]: CallbackData };\ntype CallbackQueue = Array<CallbackData>;\n\ntype Worker = any; // TODO\n\n/**\n * Client side, full text search utility.\n * This interface exposes web worker search capabilities to the UI thread.\n */\nexport default class SearchWorkerLoader implements SearchApiIndex {\n _callbackIdMap: CallbackIdMap;\n _callbackQueue: CallbackQueue;\n _worker: Worker;\n\n /**\n * Constructor.\n */\n constructor(\n {\n indexMode,\n tokenizePattern,\n caseSensitive,\n WorkerClass\n }: {\n indexMode?: IndexMode,\n tokenizePattern?: RegExp,\n caseSensitive?: boolean,\n WorkerClass?: Class<Worker>\n } = {}\n ) {\n // Defer worker import until construction to avoid testing error:\n // Error: Cannot find module 'worker!./[workername]'\n if (!WorkerClass) {\n // $FlowFixMe eslint-disable-next-line\n WorkerClass = require(\"worker?inline=true!./Worker\");\n }\n\n this._callbackQueue = [];\n this._callbackIdMap = {};\n\n this._worker = new WorkerClass();\n this._worker.onerror = event => {\n if (event.data) {\n const { callbackId, error } = event.data;\n this._updateQueue({ callbackId, error });\n } else {\n console.error(event);\n }\n };\n this._worker.onmessage = event => {\n const { callbackId, results } = event.data;\n this._updateQueue({ callbackId, results });\n };\n\n // Override default :indexMode if a specific one has been requested\n if (indexMode) {\n this._worker.postMessage({\n method: \"setIndexMode\",\n indexMode\n });\n }\n\n // Override default :tokenizePattern if a specific one has been requested\n if (tokenizePattern) {\n this._worker.postMessage({\n method: \"setTokenizePattern\",\n tokenizePattern\n });\n }\n\n // Override default :caseSensitive bit if a specific one has been requested\n if (caseSensitive) {\n this._worker.postMessage({\n method: \"setCaseSensitive\",\n caseSensitive\n });\n }\n }\n\n /**\n * Adds or updates a uid in the search index and associates it with the specified text.\n * Note that at this time uids can only be added or updated in the index, not removed.\n *\n * @param uid Uniquely identifies a searchable object\n * @param text Text to associate with uid\n */\n indexDocument = (uid: any, text: string): SearchApiIndex => {\n this._worker.postMessage({\n method: \"indexDocument\",\n text,\n uid\n });\n\n return this;\n };\n\n /**\n * Searches the current index for the specified query text.\n * Only uids matching all of the words within the text will be accepted.\n * If an empty query string is provided all indexed uids will be returned.\n *\n * Document searches are case-insensitive (e.g. \"search\" will match \"Search\").\n * Document searches use substring matching (e.g. \"na\" and \"me\" will both match \"name\").\n *\n * @param query Searchable query text\n * @return Promise to be resolved with an array of uids\n */\n search = (query: string): Promise<Array<any>> => {\n return new Promise((resolve: ResolveFn, reject: RejectFn) => {\n const callbackId = uuid.v4();\n const data = {\n callbackId,\n complete: false,\n error: null,\n reject,\n resolve,\n results: null\n };\n\n this._worker.postMessage({\n method: \"search\",\n query,\n callbackId\n });\n\n this._callbackQueue.push(data);\n this._callbackIdMap[callbackId] = data;\n });\n };\n\n /**\n * Stops and retires the worker. Used for cleanup.\n */\n terminate = () => {\n this._worker.terminate();\n };\n\n /**\n * Updates the queue and flushes any completed promises that are ready.\n */\n _updateQueue({\n callbackId,\n error,\n results\n }: {\n callbackId: string,\n error?: Error,\n results?: Results\n }) {\n const target = this._callbackIdMap[callbackId];\n target.complete = true;\n target.error = error;\n target.results = results;\n\n while (this._callbackQueue.length) {\n let data = this._callbackQueue[0];\n\n if (!data.complete) {\n break;\n }\n\n this._callbackQueue.shift();\n\n delete this._callbackIdMap[data.callbackId];\n\n if (data.error) {\n data.reject(data.error);\n } else {\n // This type will always be defined in this case;\n // This casting lets Flow know it's safe.\n data.resolve((data.results: any));\n }\n }\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/worker/SearchWorkerLoader.js","// uuid.js\n//\n// Copyright (c) 2010-2012 Robert Kieffer\n// MIT License - http://opensource.org/licenses/mit-license.php\n\n// Unique ID creation requires a high quality random # generator. We feature\n// detect to determine the best RNG source, normalizing to a function that\n// returns 128-bits of randomness, since that's what's usually required\nvar _rng = require('./rng');\n\n// Maps for number <-> hex string conversion\nvar _byteToHex = [];\nvar _hexToByte = {};\nfor (var i = 0; i < 256; i++) {\n _byteToHex[i] = (i + 0x100).toString(16).substr(1);\n _hexToByte[_byteToHex[i]] = i;\n}\n\n// **`parse()` - Parse a UUID into it's component bytes**\nfunction parse(s, buf, offset) {\n var i = (buf && offset) || 0, ii = 0;\n\n buf = buf || [];\n s.toLowerCase().replace(/[0-9a-f]{2}/g, function(oct) {\n if (ii < 16) { // Don't overflow!\n buf[i + ii++] = _hexToByte[oct];\n }\n });\n\n // Zero out remaining bytes if string was short\n while (ii < 16) {\n buf[i + ii++] = 0;\n }\n\n return buf;\n}\n\n// **`unparse()` - Convert UUID byte array (ala parse()) into a string**\nfunction unparse(buf, offset) {\n var i = offset || 0, bth = _byteToHex;\n return bth[buf[i++]] + bth[buf[i++]] +\n bth[buf[i++]] + bth[buf[i++]] + '-' +\n bth[buf[i++]] + bth[buf[i++]] + '-' +\n bth[buf[i++]] + bth[buf[i++]] + '-' +\n bth[buf[i++]] + bth[buf[i++]] + '-' +\n bth[buf[i++]] + bth[buf[i++]] +\n bth[buf[i++]] + bth[buf[i++]] +\n bth[buf[i++]] + bth[buf[i++]];\n}\n\n// **`v1()` - Generate time-based UUID**\n//\n// Inspired by https://github.com/LiosK/UUID.js\n// and http://docs.python.org/library/uuid.html\n\n// random #'s we need to init node and clockseq\nvar _seedBytes = _rng();\n\n// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)\nvar _nodeId = [\n _seedBytes[0] | 0x01,\n _seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5]\n];\n\n// Per 4.2.2, randomize (14 bit) clockseq\nvar _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff;\n\n// Previous uuid creation time\nvar _lastMSecs = 0, _lastNSecs = 0;\n\n// See https://github.com/broofa/node-uuid for API details\nfunction v1(options, buf, offset) {\n var i = buf && offset || 0;\n var b = buf || [];\n\n options = options || {};\n\n var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;\n\n // UUID timestamps are 100 nano-second units since the Gregorian epoch,\n // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so\n // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'\n // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.\n var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime();\n\n // Per 4.2.1.2, use count of uuid's generated during the current clock\n // cycle to simulate higher resolution clock\n var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;\n\n // Time since last uuid creation (in msecs)\n var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;\n\n // Per 4.2.1.2, Bump clockseq on clock regression\n if (dt < 0 && options.clockseq === undefined) {\n clockseq = clockseq + 1 & 0x3fff;\n }\n\n // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new\n // time interval\n if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {\n nsecs = 0;\n }\n\n // Per 4.2.1.2 Throw error if too many uuids are requested\n if (nsecs >= 10000) {\n throw new Error('uuid.v1(): Can\\'t create more than 10M uuids/sec');\n }\n\n _lastMSecs = msecs;\n _lastNSecs = nsecs;\n _clockseq = clockseq;\n\n // Per 4.1.4 - Convert from unix epoch to Gregorian epoch\n msecs += 12219292800000;\n\n // `time_low`\n var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;\n b[i++] = tl >>> 24 & 0xff;\n b[i++] = tl >>> 16 & 0xff;\n b[i++] = tl >>> 8 & 0xff;\n b[i++] = tl & 0xff;\n\n // `time_mid`\n var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;\n b[i++] = tmh >>> 8 & 0xff;\n b[i++] = tmh & 0xff;\n\n // `time_high_and_version`\n b[i++] = tmh >>> 24 & 0xf | 0x10; // include version\n b[i++] = tmh >>> 16 & 0xff;\n\n // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)\n b[i++] = clockseq >>> 8 | 0x80;\n\n // `clock_seq_low`\n b[i++] = clockseq & 0xff;\n\n // `node`\n var node = options.node || _nodeId;\n for (var n = 0; n < 6; n++) {\n b[i + n] = node[n];\n }\n\n return buf ? buf : unparse(b);\n}\n\n// **`v4()` - Generate random UUID**\n\n// See https://github.com/broofa/node-uuid for API details\nfunction v4(options, buf, offset) {\n // Deprecated - 'format' argument, as supported in v1.2\n var i = buf && offset || 0;\n\n if (typeof(options) == 'string') {\n buf = options == 'binary' ? new Array(16) : null;\n options = null;\n }\n options = options || {};\n\n var rnds = options.random || (options.rng || _rng)();\n\n // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n\n // Copy bytes to buffer, if provided\n if (buf) {\n for (var ii = 0; ii < 16; ii++) {\n buf[i + ii] = rnds[ii];\n }\n }\n\n return buf || unparse(rnds);\n}\n\n// Export public API\nvar uuid = v4;\nuuid.v1 = v1;\nuuid.v4 = v4;\nuuid.parse = parse;\nuuid.unparse = unparse;\n\nmodule.exports = uuid;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/uuid/uuid.js\n// module id = 9\n// module chunks = 0","\nvar rng;\n\nvar crypto = global.crypto || global.msCrypto; // for IE 11\nif (crypto && crypto.getRandomValues) {\n // WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto\n // Moderately fast, high quality\n var _rnds8 = new Uint8Array(16);\n rng = function whatwgRNG() {\n crypto.getRandomValues(_rnds8);\n return _rnds8;\n };\n}\n\nif (!rng) {\n // Math.random()-based (RNG)\n //\n // If all else fails, use Math.random(). It's fast, but is of unspecified\n // quality.\n var _rnds = new Array(16);\n rng = function() {\n for (var i = 0, r; i < 16; i++) {\n if ((i & 0x03) === 0) r = Math.random() * 0x100000000;\n _rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;\n }\n\n return _rnds;\n };\n}\n\nmodule.exports = rng;\n\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/uuid/rng-browser.js\n// module id = 10\n// module chunks = 0","module.exports = function() {\n\treturn require(\"!!/Users/bvaughn/Documents/git/js-worker-search/node_modules/worker-loader/createInlineWorker.js\")(\"/******/ (function(modules) { // webpackBootstrap\\n/******/ \\t// The module cache\\n/******/ \\tvar installedModules = {};\\n/******/\\n/******/ \\t// The require function\\n/******/ \\tfunction __webpack_require__(moduleId) {\\n/******/\\n/******/ \\t\\t// Check if module is in cache\\n/******/ \\t\\tif(installedModules[moduleId])\\n/******/ \\t\\t\\treturn installedModules[moduleId].exports;\\n/******/\\n/******/ \\t\\t// Create a new module (and put it into the cache)\\n/******/ \\t\\tvar module = installedModules[moduleId] = {\\n/******/ \\t\\t\\texports: {},\\n/******/ \\t\\t\\tid: moduleId,\\n/******/ \\t\\t\\tloaded: false\\n/******/ \\t\\t};\\n/******/\\n/******/ \\t\\t// Execute the module function\\n/******/ \\t\\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\\n/******/\\n/******/ \\t\\t// Flag the module as loaded\\n/******/ \\t\\tmodule.loaded = true;\\n/******/\\n/******/ \\t\\t// Return the exports of the module\\n/******/ \\t\\treturn module.exports;\\n/******/ \\t}\\n/******/\\n/******/\\n/******/ \\t// expose the modules object (__webpack_modules__)\\n/******/ \\t__webpack_require__.m = modules;\\n/******/\\n/******/ \\t// expose the module cache\\n/******/ \\t__webpack_require__.c = installedModules;\\n/******/\\n/******/ \\t// __webpack_public_path__\\n/******/ \\t__webpack_require__.p = \\\"\\\";\\n/******/\\n/******/ \\t// Load entry module and return exports\\n/******/ \\treturn __webpack_require__(0);\\n/******/ })\\n/************************************************************************/\\n/******/ ([\\n/* 0 */\\n/***/ function(module, exports, __webpack_require__) {\\n\\n\\t\\\"use strict\\\";\\n\\t\\n\\tvar _util = __webpack_require__(1);\\n\\t\\n\\t/**\\n\\t * Search entry point to web worker.\\n\\t * Builds search index and performs searches on separate thread from the ui.\\n\\t */\\n\\t\\n\\tvar searchUtility = new _util.SearchUtility();\\n\\t\\n\\tself.addEventListener(\\\"message\\\", function (event) {\\n\\t var data = event.data;\\n\\t var method = data.method;\\n\\t\\n\\t\\n\\t switch (method) {\\n\\t case \\\"indexDocument\\\":\\n\\t var uid = data.uid,\\n\\t text = data.text;\\n\\t\\n\\t\\n\\t searchUtility.indexDocument(uid, text);\\n\\t break;\\n\\t case \\\"search\\\":\\n\\t var callbackId = data.callbackId,\\n\\t query = data.query;\\n\\t\\n\\t\\n\\t var results = searchUtility.search(query);\\n\\t\\n\\t self.postMessage({ callbackId: callbackId, results: results });\\n\\t break;\\n\\t case \\\"setIndexMode\\\":\\n\\t var indexMode = data.indexMode;\\n\\t\\n\\t\\n\\t searchUtility.setIndexMode(indexMode);\\n\\t break;\\n\\t case \\\"setTokenizePattern\\\":\\n\\t var tokenizePattern = data.tokenizePattern;\\n\\t\\n\\t\\n\\t searchUtility.setTokenizePattern(tokenizePattern);\\n\\t break;\\n\\t case \\\"setCaseSensitive\\\":\\n\\t var caseSensitive = data.caseSensitive;\\n\\t\\n\\t\\n\\t searchUtility.setCaseSensitive(caseSensitive);\\n\\t break;\\n\\t }\\n\\t}, false);\\n\\n/***/ },\\n/* 1 */\\n/***/ function(module, exports, __webpack_require__) {\\n\\n\\t\\\"use strict\\\";\\n\\t\\n\\tObject.defineProperty(exports, \\\"__esModule\\\", {\\n\\t value: true\\n\\t});\\n\\texports.SearchUtility = exports.INDEX_MODES = undefined;\\n\\t\\n\\tvar _SearchUtility = __webpack_require__(2);\\n\\t\\n\\tvar _SearchUtility2 = _interopRequireDefault(_SearchUtility);\\n\\t\\n\\tvar _constants = __webpack_require__(3);\\n\\t\\n\\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\\n\\t\\n\\texports.default = _SearchUtility2.default;\\n\\texports.INDEX_MODES = _constants.INDEX_MODES;\\n\\texports.SearchUtility = _SearchUtility2.default;\\n\\n/***/ },\\n/* 2 */\\n/***/ function(module, exports, __webpack_require__) {\\n\\n\\t\\\"use strict\\\";\\n\\t\\n\\tObject.defineProperty(exports, \\\"__esModule\\\", {\\n\\t value: true\\n\\t});\\n\\t\\n\\tvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\\\"value\\\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\\n\\t\\n\\tvar _constants = __webpack_require__(3);\\n\\t\\n\\tvar _SearchIndex = __webpack_require__(4);\\n\\t\\n\\tvar _SearchIndex2 = _interopRequireDefault(_SearchIndex);\\n\\t\\n\\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\\n\\t\\n\\tfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\\\"Cannot call a class as a function\\\"); } }\\n\\t\\n\\t/**\\n\\t * Synchronous client-side full-text search utility.\\n\\t * Forked from JS search (github.com/bvaughn/js-search).\\n\\t */\\n\\tvar SearchUtility = function () {\\n\\t\\n\\t /**\\n\\t * Constructor.\\n\\t *\\n\\t * @param indexMode See #setIndexMode\\n\\t * @param tokenizePattern See #setTokenizePattern\\n\\t * @param caseSensitive See #setCaseSensitive\\n\\t */\\n\\t function SearchUtility() {\\n\\t var _this = this;\\n\\t\\n\\t var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\\n\\t _ref$indexMode = _ref.indexMode,\\n\\t indexMode = _ref$indexMode === undefined ? _constants.INDEX_MODES.ALL_SUBSTRINGS : _ref$indexMode,\\n\\t _ref$tokenizePattern = _ref.tokenizePattern,\\n\\t tokenizePattern = _ref$tokenizePattern === undefined ? /\\\\s+/ : _ref$tokenizePattern,\\n\\t _ref$caseSensitive = _ref.caseSensitive,\\n\\t caseSensitive = _ref$caseSensitive === undefined ? false : _ref$caseSensitive;\\n\\t\\n\\t _classCallCheck(this, SearchUtility);\\n\\t\\n\\t this.indexDocument = function (uid, text) {\\n\\t _this._uids[uid] = true;\\n\\t\\n\\t var fieldTokens = _this._tokenize(_this._sanitize(text));\\n\\t\\n\\t fieldTokens.forEach(function (fieldToken) {\\n\\t var expandedTokens = _this._expandToken(fieldToken);\\n\\t\\n\\t expandedTokens.forEach(function (expandedToken) {\\n\\t _this._searchIndex.indexDocument(expandedToken, uid);\\n\\t });\\n\\t });\\n\\t\\n\\t return _this;\\n\\t };\\n\\t\\n\\t this.search = function (query) {\\n\\t if (!query) {\\n\\t return Object.keys(_this._uids);\\n\\t } else {\\n\\t var tokens = _this._tokenize(_this._sanitize(query));\\n\\t\\n\\t return _this._searchIndex.search(tokens);\\n\\t }\\n\\t };\\n\\t\\n\\t this.terminate = function () {};\\n\\t\\n\\t this._indexMode = indexMode;\\n\\t this._tokenizePattern = tokenizePattern;\\n\\t this._caseSensitive = caseSensitive;\\n\\t\\n\\t this._searchIndex = new _SearchIndex2.default();\\n\\t this._uids = {};\\n\\t }\\n\\t\\n\\t /**\\n\\t * Returns a constant representing the current index mode.\\n\\t */\\n\\t\\n\\t\\n\\t _createClass(SearchUtility, [{\\n\\t key: \\\"getIndexMode\\\",\\n\\t value: function getIndexMode() {\\n\\t return this._indexMode;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Returns a constant representing the current tokenize pattern.\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"getTokenizePattern\\\",\\n\\t value: function getTokenizePattern() {\\n\\t return this._tokenizePattern;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Returns a constant representing the current case-sensitive bit.\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"getCaseSensitive\\\",\\n\\t value: function getCaseSensitive() {\\n\\t return this._caseSensitive;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Adds or updates a uid in the search index and associates it with the specified text.\\n\\t * Note that at this time uids can only be added or updated in the index, not removed.\\n\\t *\\n\\t * @param uid Uniquely identifies a searchable object\\n\\t * @param text Text to associate with uid\\n\\t */\\n\\t\\n\\t\\n\\t /**\\n\\t * Searches the current index for the specified query text.\\n\\t * Only uids matching all of the words within the text will be accepted.\\n\\t * If an empty query string is provided all indexed uids will be returned.\\n\\t *\\n\\t * Document searches are case-insensitive (e.g. \\\"search\\\" will match \\\"Search\\\").\\n\\t * Document searches use substring matching (e.g. \\\"na\\\" and \\\"me\\\" will both match \\\"name\\\").\\n\\t *\\n\\t * @param query Searchable query text\\n\\t * @return Array of uids\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"setIndexMode\\\",\\n\\t\\n\\t\\n\\t /**\\n\\t * Sets a new index mode.\\n\\t * See util/constants/INDEX_MODES\\n\\t */\\n\\t value: function setIndexMode(indexMode) {\\n\\t if (Object.keys(this._uids).length > 0) {\\n\\t throw Error(\\\"indexMode cannot be changed once documents have been indexed\\\");\\n\\t }\\n\\t\\n\\t this._indexMode = indexMode;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Sets a new tokenize pattern (regular expression)\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"setTokenizePattern\\\",\\n\\t value: function setTokenizePattern(pattern) {\\n\\t this._tokenizePattern = pattern;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Sets a new case-sensitive bit\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"setCaseSensitive\\\",\\n\\t value: function setCaseSensitive(caseSensitive) {\\n\\t this._caseSensitive = caseSensitive;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Added to make class adhere to interface. Add cleanup code as needed.\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"_expandToken\\\",\\n\\t\\n\\t\\n\\t /**\\n\\t * Index strategy based on 'all-substrings-index-strategy.ts' in github.com/bvaughn/js-search/\\n\\t *\\n\\t * @private\\n\\t */\\n\\t value: function _expandToken(token) {\\n\\t switch (this._indexMode) {\\n\\t case _constants.INDEX_MODES.EXACT_WORDS:\\n\\t return [token];\\n\\t case _constants.INDEX_MODES.PREFIXES:\\n\\t return this._expandPrefixTokens(token);\\n\\t case _constants.INDEX_MODES.ALL_SUBSTRINGS:\\n\\t default:\\n\\t return this._expandAllSubstringTokens(token);\\n\\t }\\n\\t }\\n\\t }, {\\n\\t key: \\\"_expandAllSubstringTokens\\\",\\n\\t value: function _expandAllSubstringTokens(token) {\\n\\t var expandedTokens = [];\\n\\t\\n\\t // String.prototype.charAt() may return surrogate halves instead of whole characters.\\n\\t // When this happens in the context of a web-worker it can cause Chrome to crash.\\n\\t // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\\n\\t // Resources:\\n\\t // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\\n\\t // https://mathiasbynens.be/notes/javascript-unicode\\n\\t try {\\n\\t for (var i = 0, length = token.length; i < length; ++i) {\\n\\t var substring = \\\"\\\";\\n\\t\\n\\t for (var j = i; j < length; ++j) {\\n\\t substring += token.charAt(j);\\n\\t expandedTokens.push(substring);\\n\\t }\\n\\t }\\n\\t } catch (error) {\\n\\t console.error(\\\"Unable to parse token \\\\\\\"\\\" + token + \\\"\\\\\\\" \\\" + error);\\n\\t }\\n\\t\\n\\t return expandedTokens;\\n\\t }\\n\\t }, {\\n\\t key: \\\"_expandPrefixTokens\\\",\\n\\t value: function _expandPrefixTokens(token) {\\n\\t var expandedTokens = [];\\n\\t\\n\\t // String.prototype.charAt() may return surrogate halves instead of whole characters.\\n\\t // When this happens in the context of a web-worker it can cause Chrome to crash.\\n\\t // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\\n\\t // Resources:\\n\\t // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\\n\\t // https://mathiasbynens.be/notes/javascript-unicode\\n\\t try {\\n\\t for (var i = 0, length = token.length; i < length; ++i) {\\n\\t expandedTokens.push(token.substr(0, i + 1));\\n\\t }\\n\\t } catch (error) {\\n\\t console.error(\\\"Unable to parse token \\\\\\\"\\\" + token + \\\"\\\\\\\" \\\" + error);\\n\\t }\\n\\t\\n\\t return expandedTokens;\\n\\t }\\n\\t\\n\\t /**\\n\\t * @private\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"_sanitize\\\",\\n\\t value: function _sanitize(string) {\\n\\t return this._caseSensitive ? string.trim() : string.trim().toLocaleLowerCase();\\n\\t }\\n\\t\\n\\t /**\\n\\t * @private\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"_tokenize\\\",\\n\\t value: function _tokenize(text) {\\n\\t return text.split(this._tokenizePattern).filter(function (text) {\\n\\t return text;\\n\\t }); // Remove empty tokens\\n\\t }\\n\\t }]);\\n\\t\\n\\t return SearchUtility;\\n\\t}();\\n\\t\\n\\texports.default = SearchUtility;\\n\\n/***/ },\\n/* 3 */\\n/***/ function(module, exports) {\\n\\n\\t\\\"use strict\\\";\\n\\t\\n\\tObject.defineProperty(exports, \\\"__esModule\\\", {\\n\\t value: true\\n\\t});\\n\\tvar INDEX_MODES = exports.INDEX_MODES = {\\n\\t // Indexes for all substring searches (e.g. the term \\\"cat\\\" is indexed as \\\"c\\\", \\\"ca\\\", \\\"cat\\\", \\\"a\\\", \\\"at\\\", and \\\"t\\\").\\n\\t // Based on 'all-substrings-index-strategy' from js-search;\\n\\t // github.com/bvaughn/js-search/blob/master/source/index-strategy/all-substrings-index-strategy.ts\\n\\t ALL_SUBSTRINGS: \\\"ALL_SUBSTRINGS\\\",\\n\\t\\n\\t // Indexes for exact word matches only.\\n\\t // Based on 'exact-word-index-strategy' from js-search;\\n\\t // github.com/bvaughn/js-search/blob/master/source/index-strategy/exact-word-index-strategy.ts\\n\\t EXACT_WORDS: \\\"EXACT_WORDS\\\",\\n\\t\\n\\t // Indexes for prefix searches (e.g. the term \\\"cat\\\" is indexed as \\\"c\\\", \\\"ca\\\", and \\\"cat\\\" allowing prefix search lookups).\\n\\t // Based on 'prefix-index-strategy' from js-search;\\n\\t // github.com/bvaughn/js-search/blob/master/source/index-strategy/prefix-index-strategy.ts\\n\\t PREFIXES: \\\"PREFIXES\\\"\\n\\t};\\n\\n/***/ },\\n/* 4 */\\n/***/ function(module, exports) {\\n\\n\\t\\\"use strict\\\";\\n\\t\\n\\tObject.defineProperty(exports, \\\"__esModule\\\", {\\n\\t value: true\\n\\t});\\n\\t\\n\\tvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\\\"value\\\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\\n\\t\\n\\tfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\\\"Cannot call a class as a function\\\"); } }\\n\\t\\n\\t/**\\n\\t * Maps search tokens to uids using a trie structure.\\n\\t */\\n\\tvar SearchIndex = function () {\\n\\t function SearchIndex() {\\n\\t _classCallCheck(this, SearchIndex);\\n\\t\\n\\t this.tokenToUidMap = {};\\n\\t }\\n\\t\\n\\t /**\\n\\t * Maps the specified token to a uid.\\n\\t *\\n\\t * @param token Searchable token (e.g. \\\"road\\\")\\n\\t * @param uid Identifies a document within the searchable corpus\\n\\t */\\n\\t\\n\\t\\n\\t _createClass(SearchIndex, [{\\n\\t key: \\\"indexDocument\\\",\\n\\t value: function indexDocument(token, uid) {\\n\\t if (!this.tokenToUidMap[token]) {\\n\\t this.tokenToUidMap[token] = {};\\n\\t }\\n\\t\\n\\t this.tokenToUidMap[token][uid] = uid;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Finds uids that have been mapped to the set of tokens specified.\\n\\t * Only uids that have been mapped to all tokens will be returned.\\n\\t *\\n\\t * @param tokens Array of searchable tokens (e.g. [\\\"long\\\", \\\"road\\\"])\\n\\t * @return Array of uids that have been associated with the set of search tokens\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"search\\\",\\n\\t value: function search(tokens) {\\n\\t var _this = this;\\n\\t\\n\\t var uidMap = {};\\n\\t var initialized = false;\\n\\t\\n\\t tokens.forEach(function (token) {\\n\\t var currentUidMap = _this.tokenToUidMap[token] || {};\\n\\t\\n\\t if (!initialized) {\\n\\t initialized = true;\\n\\t\\n\\t for (var _uid in currentUidMap) {\\n\\t uidMap[_uid] = currentUidMap[_uid];\\n\\t }\\n\\t } else {\\n\\t for (var _uid2 in uidMap) {\\n\\t if (!currentUidMap[_uid2]) {\\n\\t delete uidMap[_uid2];\\n\\t }\\n\\t }\\n\\t }\\n\\t });\\n\\t\\n\\t var uids = [];\\n\\t for (var _uid3 in uidMap) {\\n\\t uids.push(uidMap[_uid3]);\\n\\t }\\n\\t\\n\\t return uids;\\n\\t }\\n\\t }]);\\n\\t\\n\\t return SearchIndex;\\n\\t}();\\n\\t\\n\\texports.default = SearchIndex;\\n\\n/***/ }\\n/******/ ]);\\n//# sourceMappingURL=2ef0afcacb6f46b34be5.worker.js.map\", __webpack_public_path__ + \"2ef0afcacb6f46b34be5.worker.js\");\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/worker-loader?inline=true!./src/worker/Worker.js\n// module id = 11\n// module chunks = 0","// http://stackoverflow.com/questions/10343913/how-to-create-a-web-worker-from-a-string\r\n\r\nvar URL = window.URL || window.webkitURL;\r\nmodule.exports = function(content, url) {\r\n try {\r\n try {\r\n var blob;\r\n try { // BlobBuilder = Deprecated, but widely implemented\r\n var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;\r\n blob = new BlobBuilder();\r\n blob.append(content);\r\n blob = blob.getBlob();\r\n } catch(e) { // The proposed API\r\n blob = new Blob([content]);\r\n }\r\n return new Worker(URL.createObjectURL(blob));\r\n } catch(e) {\r\n return new Worker('data:application/javascript,' + encodeURIComponent(content));\r\n }\r\n } catch(e) {\r\n if (!url) {\r\n throw Error('Inline worker is not supported');\r\n }\r\n return new Worker(url);\r\n }\r\n}\r\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/worker-loader/createInlineWorker.js\n// module id = 12\n// module chunks = 0"],"sourceRoot":""}
{"version":3,"sources":["webpack:///webpack/bootstrap 0612b6c518c2ad138c3b","webpack:///./src/index.js","webpack:///./src/SearchApi.js","webpack:///./src/util/index.js","webpack:///./src/util/SearchUtility.js","webpack:///./src/util/constants.js","webpack:///./src/util/SearchIndex.js","webpack:///./src/worker/index.js","webpack:///./src/worker/SearchWorkerLoader.js","webpack:///./~/uuid/uuid.js","webpack:///./~/uuid/rng-browser.js","webpack:///./src/worker/Worker.js","webpack:///./~/worker-loader/createInlineWorker.js"],"names":["INDEX_MODES","SearchApi","caseSensitive","indexMode","matchAnyToken","tokenizePattern","indexDocument","uid","text","_search","search","query","terminate","window","Worker","SearchUtility","ALL_SUBSTRINGS","_uids","fieldTokens","_tokenize","_sanitize","forEach","expandedTokens","_expandToken","fieldToken","_searchIndex","expandedToken","Object","keys","tokens","_matchAnyToken","_caseSensitive","_indexMode","_tokenizePattern","length","Error","pattern","token","EXACT_WORDS","PREFIXES","_expandPrefixTokens","_expandAllSubstringTokens","i","substring","j","charAt","push","error","console","substr","string","trim","toLocaleLowerCase","split","filter","SearchIndex","tokenToUidMap","uidMap","uidMatches","initialized","currentUidMap","uids","sort","a","b","SearchWorkerLoader","WorkerClass","_worker","postMessage","method","Promise","resolve","reject","callbackId","v4","data","complete","results","_callbackQueue","_callbackIdMap","require","onerror","event","_updateQueue","onmessage","target","shift"],"mappings":";;AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;;;;;;;;;;;;;ACpCA;;;;AACA;;;;;SAGSA,W;;;;;;;;;;;;ACJT;;AACA;;;;;;;;AAIA;;;;KAIqBC,S,GACL;;AAEd,sBAYE;AAAA;;AAAA,kFADI,EACJ;AAAA,OAVEC,aAUF,QAVEA,aAUF;AAAA,OATEC,SASF,QATEA,SASF;AAAA,O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A6C,qBAAqB,wDAAwD,sBAAsB,EAAE,wCAAwC,2CAA2C,gBAAgB,kBAAkB,OAAO,2BAA2B,wDAAwD,gCAAgC,yDAAyD,2DAA2D,EAAE,EAAE,yDAAyD,qEAAqE,6DAA6D,oBAAoB,GAAG,EAAE,GAAG,yDAAyD,0CAA0C,4DAA4D,EAAE,EAAE,8GAA8G,8BAA8B,2CAA2C,oCAAoC,OAAO,+OAA+O,kFAAkF,2CAA2C,2CAA2C,WAAW,mDAAmD,SAAS,wbAAwb,GAAG,+EAA+E,2BAA2B,8BAA8B,8BAA8B,kCAAkC,+CAA+C,iEAAiE,mCAAmC,iCAAiC,mDAAmD,mDAAmD,qCAAqC,eAAe,aAAa,OAAO,yKAAyK,2CAA2C,8CAA8C,yCAAyC,mBAAmB,iBAAiB,eAAe,OAAO,kDAAkD,uDAAuD,mEAAmE,iBAAiB,eAAe,aAAa,WAAW,EAAE,4BAA4B,qCAAqC,qCAAqC,WAAW,yGAAyG,uCAAuC,mDAAmD,aAAa,EAAE,WAAW,0BAA0B,SAAS,OAAO,GAAG,6BAA6B,KAAK,GAAG,sCAAsC,WAAW,cAAc;AACpikB,G;;;;;;ACFA;;AAEA;AACA;AACA;AACA;AACA;AACA,YAAW;AACX;AACA;AACA;AACA;AACA,QAAO,WAAW;AAClB;AACA;AACA;AACA,MAAK;AACL;AACA;AACA,IAAG;AACH;AACA;AACA;AACA;AACA;AACA","file":"js-worker-search.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 0612b6c518c2ad138c3b","/** @flow */\n\nimport SearchApi from \"./SearchApi\";\nimport { INDEX_MODES } from \"./util\";\n\nexport default SearchApi;\nexport { INDEX_MODES };\n\n\n\n// WEBPACK FOOTER //\n// ./src/index.js","/** @flow */\n\nimport { SearchUtility } from \"./util\";\nimport SearchWorkerLoader from \"./worker\";\n\nimport type { IndexMode } from \"./util\";\n\n/**\n * Search API that uses web workers when available.\n * Indexing and searching is performed in the UI thread as a fallback when web workers aren't supported.\n */\nexport default class SearchApi {\n _search: any; // TODO\n\n constructor(\n {\n caseSensitive,\n indexMode,\n matchAnyToken,\n tokenizePattern\n }: {\n caseSensitive?: boolean,\n indexMode?: IndexMode,\n matchAnyToken?: boolean,\n tokenizePattern?: RegExp\n } = {}\n ) {\n // Based on https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers\n // But with added check for Node environment\n if (typeof window !== \"undefined\" && window.Worker) {\n this._search = new SearchWorkerLoader({\n indexMode,\n matchAnyToken,\n tokenizePattern,\n caseSensitive\n });\n } else {\n this._search = new SearchUtility({\n indexMode,\n matchAnyToken,\n tokenizePattern,\n caseSensitive\n });\n }\n }\n\n /**\n * Adds or updates a uid in the search index and associates it with the specified text.\n * Note that at this time uids can only be added or updated in the index, not removed.\n *\n * @param uid Uniquely identifies a searchable object\n * @param text Text to associate with uid\n */\n indexDocument = (uid: any, text: string): SearchApi => {\n this._search.indexDocument(uid, text);\n\n return this;\n };\n\n /**\n * Searches the current index for the specified query text.\n * Only uids matching all of the words within the text will be accepted.\n * If an empty query string is provided all indexed uids will be returned.\n *\n * Document searches are case-insensitive (e.g. \"search\" will match \"Search\").\n * Document searches use substring matching (e.g. \"na\" and \"me\" will both match \"name\").\n *\n * @param query Searchable query text\n * @return Promise to be resolved with an Array of matching uids\n */\n search = (query: string): Promise<Array<any>> => {\n // Promise.resolve handles both synchronous and web-worker Search utilities\n return this._search.search(query);\n };\n\n /**\n * Stops and retires the worker in the search API. Used for cleanup.\n */\n terminate = () => {\n this._search.terminate();\n };\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/SearchApi.js","/** @flow */\n\nimport SearchUtility from \"./SearchUtility\";\nimport { INDEX_MODES } from \"./constants\";\n\nexport type { IndexMode } from \"./constants\";\n\nexport default SearchUtility;\nexport { INDEX_MODES, SearchUtility };\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/index.js","/** @flow */\n\nimport { INDEX_MODES } from \"./constants\";\nimport SearchIndex from \"./SearchIndex\";\n\nimport type { IndexMode } from \"./constants\";\nimport type { SearchApiIndex } from \"../types\";\n\ntype UidMap = {\n [uid: string]: boolean\n};\n\n/**\n * Synchronous client-side full-text search utility.\n * Forked from JS search (github.com/bvaughn/js-search).\n */\nexport default class SearchUtility implements SearchApiIndex {\n _caseSensitive: boolean;\n _indexMode: IndexMode;\n _matchAnyToken: boolean;\n _searchIndex: SearchIndex;\n _tokenizePattern: RegExp;\n _uids: UidMap;\n\n /**\n * Constructor.\n *\n * @param indexMode See #setIndexMode\n * @param tokenizePattern See #setTokenizePattern\n * @param caseSensitive See #setCaseSensitive\n * @param matchAnyToken See #setMatchAnyToken\n */\n constructor(\n {\n caseSensitive = false,\n indexMode = INDEX_MODES.ALL_SUBSTRINGS,\n matchAnyToken = false,\n tokenizePattern = /\\s+/\n }: {\n caseSensitive?: boolean,\n indexMode?: IndexMode,\n matchAnyToken?: boolean,\n tokenizePattern?: RegExp\n } = {}\n ) {\n this._caseSensitive = caseSensitive;\n this._indexMode = indexMode;\n this._matchAnyToken = matchAnyToken;\n this._tokenizePattern = tokenizePattern;\n\n this._searchIndex = new SearchIndex();\n this._uids = {};\n }\n\n /**\n * Returns a constant representing the current case-sensitive bit.\n */\n getCaseSensitive(): boolean {\n return this._caseSensitive;\n }\n\n /**\n * Returns a constant representing the current index mode.\n */\n getIndexMode(): string {\n return this._indexMode;\n }\n\n /**\n * Returns a constant representing the current match-any-token bit.\n */\n getMatchAnyToken(): boolean {\n return this._matchAnyToken;\n }\n\n /**\n * Returns a constant representing the current tokenize pattern.\n */\n getTokenizePattern(): RegExp {\n return this._tokenizePattern;\n }\n\n /**\n * Adds or updates a uid in the search index and associates it with the specified text.\n * Note that at this time uids can only be added or updated in the index, not removed.\n *\n * @param uid Uniquely identifies a searchable object\n * @param text Text to associate with uid\n */\n indexDocument = (uid: any, text: string): SearchApiIndex => {\n this._uids[uid] = true;\n\n var fieldTokens: Array<string> = this._tokenize(this._sanitize(text));\n\n fieldTokens.forEach(fieldToken => {\n var expandedTokens: Array<string> = this._expandToken(fieldToken);\n\n expandedTokens.forEach(expandedToken => {\n this._searchIndex.indexDocument(expandedToken, uid);\n });\n });\n\n return this;\n };\n\n /**\n * Searches the current index for the specified query text.\n * Only uids matching all of the words within the text will be accepted,\n * unless matchAny is set to true.\n * If an empty query string is provided all indexed uids will be returned.\n *\n * Document searches are case-insensitive by default (e.g. \"search\" will match \"Search\").\n * Document searches use substring matching by default (e.g. \"na\" and \"me\" will both match \"name\").\n *\n * @param query Searchable query text\n * @return Array of uids\n */\n search = (query: string): Array<any> => {\n if (!query) {\n return Object.keys(this._uids);\n } else {\n var tokens: Array<string> = this._tokenize(this._sanitize(query));\n\n return this._searchIndex.search(tokens, this._matchAnyToken);\n }\n };\n\n /**\n * Sets a new case-sensitive bit\n */\n setCaseSensitive(caseSensitive: boolean): void {\n this._caseSensitive = caseSensitive;\n }\n\n /**\n * Sets a new index mode.\n * See util/constants/INDEX_MODES\n */\n setIndexMode(indexMode: IndexMode): void {\n if (Object.keys(this._uids).length > 0) {\n throw Error(\n \"indexMode cannot be changed once documents have been indexed\"\n );\n }\n\n this._indexMode = indexMode;\n }\n\n /**\n * Sets a new match-any-token bit\n */\n setMatchAnyToken(matchAnyToken: boolean): void {\n this._matchAnyToken = matchAnyToken;\n }\n\n /**\n * Sets a new tokenize pattern (regular expression)\n */\n setTokenizePattern(pattern: RegExp): void {\n this._tokenizePattern = pattern;\n }\n\n /**\n * Added to make class adhere to interface. Add cleanup code as needed.\n */\n terminate = () => {};\n\n /**\n * Index strategy based on 'all-substrings-index-strategy.ts' in github.com/bvaughn/js-search/\n *\n * @private\n */\n _expandToken(token: string): Array<string> {\n switch (this._indexMode) {\n case INDEX_MODES.EXACT_WORDS:\n return [token];\n case INDEX_MODES.PREFIXES:\n return this._expandPrefixTokens(token);\n case INDEX_MODES.ALL_SUBSTRINGS:\n default:\n return this._expandAllSubstringTokens(token);\n }\n }\n\n _expandAllSubstringTokens(token: string): Array<string> {\n const expandedTokens = [];\n\n // String.prototype.charAt() may return surrogate halves instead of whole characters.\n // When this happens in the context of a web-worker it can cause Chrome to crash.\n // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\n // Resources:\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\n // https://mathiasbynens.be/notes/javascript-unicode\n try {\n for (let i = 0, length = token.length; i < length; ++i) {\n let substring: string = \"\";\n\n for (let j = i; j < length; ++j) {\n substring += token.charAt(j);\n expandedTokens.push(substring);\n }\n }\n } catch (error) {\n console.error(`Unable to parse token \"${token}\" ${error}`);\n }\n\n return expandedTokens;\n }\n\n _expandPrefixTokens(token: string): Array<string> {\n const expandedTokens = [];\n\n // String.prototype.charAt() may return surrogate halves instead of whole characters.\n // When this happens in the context of a web-worker it can cause Chrome to crash.\n // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\n // Resources:\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\n // https://mathiasbynens.be/notes/javascript-unicode\n try {\n for (let i = 0, length = token.length; i < length; ++i) {\n expandedTokens.push(token.substr(0, i + 1));\n }\n } catch (error) {\n console.error(`Unable to parse token \"${token}\" ${error}`);\n }\n\n return expandedTokens;\n }\n\n /**\n * @private\n */\n _sanitize(string: string): string {\n return this._caseSensitive\n ? string.trim()\n : string.trim().toLocaleLowerCase();\n }\n\n /**\n * @private\n */\n _tokenize(text: string): Array<string> {\n return text.split(this._tokenizePattern).filter(text => text); // Remove empty tokens\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/SearchUtility.js","/** @flow */\n\nexport const INDEX_MODES = {\n // Indexes for all substring searches (e.g. the term \"cat\" is indexed as \"c\", \"ca\", \"cat\", \"a\", \"at\", and \"t\").\n // Based on 'all-substrings-index-strategy' from js-search;\n // github.com/bvaughn/js-search/blob/master/source/index-strategy/all-substrings-index-strategy.ts\n ALL_SUBSTRINGS: \"ALL_SUBSTRINGS\",\n\n // Indexes for exact word matches only.\n // Based on 'exact-word-index-strategy' from js-search;\n // github.com/bvaughn/js-search/blob/master/source/index-strategy/exact-word-index-strategy.ts\n EXACT_WORDS: \"EXACT_WORDS\",\n\n // Indexes for prefix searches (e.g. the term \"cat\" is indexed as \"c\", \"ca\", and \"cat\" allowing prefix search lookups).\n // Based on 'prefix-index-strategy' from js-search;\n // github.com/bvaughn/js-search/blob/master/source/index-strategy/prefix-index-strategy.ts\n PREFIXES: \"PREFIXES\"\n};\n\nexport type IndexMode = $Keys<typeof INDEX_MODES>;\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/constants.js","/** @flow */\n\n/**\n * Maps search tokens to uids using a trie structure.\n */\nexport default class SearchIndex {\n tokenToUidMap: { [token: string]: any };\n\n constructor() {\n this.tokenToUidMap = {};\n }\n\n /**\n * Maps the specified token to a uid.\n *\n * @param token Searchable token (e.g. \"road\")\n * @param uid Identifies a document within the searchable corpus\n */\n indexDocument(token: string, uid: any): void {\n if (!this.tokenToUidMap[token]) {\n this.tokenToUidMap[token] = {};\n }\n\n this.tokenToUidMap[token][uid] = uid;\n }\n\n /**\n * Finds uids that have been mapped to the set of tokens specified.\n * Only uids that have been mapped to all tokens will be returned.\n *\n * @param tokens Array of searchable tokens (e.g. [\"long\", \"road\"])\n * @param matchAnyToken Whether to match any token. Default is false.\n * @return Array of uids that have been associated with the set of search tokens\n */\n search(tokens: Array<string>, matchAnyToken: boolean): Array<any> {\n let uidMap: { [uid: any]: any } = {};\n let uidMatches: { [uid: any]: number } = {};\n let initialized = false;\n\n tokens.forEach(token => {\n let currentUidMap: { [uid: any]: any } = this.tokenToUidMap[token] || {};\n\n if (!initialized) {\n initialized = true;\n\n for (let uid in currentUidMap) {\n uidMap[uid] = currentUidMap[uid];\n uidMatches[uid] = 1;\n }\n } else {\n // Delete existing matches if using and AND query (the default)\n // Otherwise add new results to the matches\n if (!matchAnyToken) {\n for (let uid in uidMap) {\n if (!currentUidMap[uid]) {\n delete uidMap[uid];\n }\n }\n } else {\n for (let uid in currentUidMap) {\n uidMap[uid] = currentUidMap[uid];\n uidMatches[uid] = (uidMatches[uid] || 0) + 1;\n }\n }\n }\n });\n\n let uids: Array<any> = [];\n for (let uid in uidMap) {\n uids.push(uidMap[uid]);\n }\n\n // Sort according to most matches, if match any token is set.\n if (matchAnyToken) {\n uids.sort((a, b) => {\n return uidMatches[b] - uidMatches[a];\n });\n }\n\n return uids;\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/SearchIndex.js","/** @flow */\n\nimport SearchWorkerLoader from \"./SearchWorkerLoader\";\n\nexport default SearchWorkerLoader;\n\n\n\n// WEBPACK FOOTER //\n// ./src/worker/index.js","/** @flow */\n\nimport uuid from \"uuid\";\n\nimport type { IndexMode } from \"../util\";\nimport type { SearchApiIndex } from \"../types\";\n\ntype Results = Array<any>;\ntype RejectFn = (error: Error) => void;\ntype ResolveFn = (results: Results) => void;\nexport type CallbackData = {\n callbackId: string,\n complete: boolean,\n error: ?Error,\n reject: RejectFn,\n resolve: ResolveFn,\n results: ?Results\n};\ntype CallbackIdMap = { [callbackId: string]: CallbackData };\ntype CallbackQueue = Array<CallbackData>;\n\ntype Worker = any; // TODO\n\n/**\n * Client side, full text search utility.\n * This interface exposes web worker search capabilities to the UI thread.\n */\nexport default class SearchWorkerLoader implements SearchApiIndex {\n _callbackIdMap: CallbackIdMap;\n _callbackQueue: CallbackQueue;\n _worker: Worker;\n\n /**\n * Constructor.\n */\n constructor(\n {\n caseSensitive,\n indexMode,\n matchAnyToken,\n tokenizePattern,\n WorkerClass\n }: {\n caseSensitive?: boolean,\n indexMode?: IndexMode,\n matchAnyToken?: boolean,\n tokenizePattern?: RegExp,\n WorkerClass?: Class<Worker>\n } = {}\n ) {\n // Defer worker import until construction to avoid testing error:\n // Error: Cannot find module 'worker!./[workername]'\n if (!WorkerClass) {\n // $FlowFixMe eslint-disable-next-line\n WorkerClass = require(\"worker?inline=true!./Worker\");\n }\n\n this._callbackQueue = [];\n this._callbackIdMap = {};\n\n this._worker = new WorkerClass();\n this._worker.onerror = event => {\n if (event.data) {\n const { callbackId, error } = event.data;\n this._updateQueue({ callbackId, error });\n } else {\n console.error(event);\n }\n };\n this._worker.onmessage = event => {\n const { callbackId, results } = event.data;\n this._updateQueue({ callbackId, results });\n };\n\n // Override default :caseSensitive bit if a specific one has been requested\n if (caseSensitive) {\n this._worker.postMessage({\n method: \"setCaseSensitive\",\n caseSensitive\n });\n }\n\n // Override default :indexMode if a specific one has been requested\n if (indexMode) {\n this._worker.postMessage({\n method: \"setIndexMode\",\n indexMode\n });\n }\n\n // Override default :matchAnyToken bit if a specific one has been requested\n if (matchAnyToken) {\n this._worker.postMessage({\n method: \"setMatchAnyToken\",\n matchAnyToken\n });\n }\n\n // Override default :tokenizePattern if a specific one has been requested\n if (tokenizePattern) {\n this._worker.postMessage({\n method: \"setTokenizePattern\",\n tokenizePattern\n });\n }\n }\n\n /**\n * Adds or updates a uid in the search index and associates it with the specified text.\n * Note that at this time uids can only be added or updated in the index, not removed.\n *\n * @param uid Uniquely identifies a searchable object\n * @param text Text to associate with uid\n */\n indexDocument = (uid: any, text: string): SearchApiIndex => {\n this._worker.postMessage({\n method: \"indexDocument\",\n text,\n uid\n });\n\n return this;\n };\n\n /**\n * Searches the current index for the specified query text.\n * Only uids matching all of the words within the text will be accepted.\n * If an empty query string is provided all indexed uids will be returned.\n *\n * Document searches are case-insensitive (e.g. \"search\" will match \"Search\").\n * Document searches use substring matching (e.g. \"na\" and \"me\" will both match \"name\").\n *\n * @param query Searchable query text\n * @return Promise to be resolved with an array of uids\n */\n search = (query: string): Promise<Array<any>> => {\n return new Promise((resolve: ResolveFn, reject: RejectFn) => {\n const callbackId = uuid.v4();\n const data = {\n callbackId,\n complete: false,\n error: null,\n reject,\n resolve,\n results: null\n };\n\n this._worker.postMessage({\n method: \"search\",\n query,\n callbackId\n });\n\n this._callbackQueue.push(data);\n this._callbackIdMap[callbackId] = data;\n });\n };\n\n /**\n * Stops and retires the worker. Used for cleanup.\n */\n terminate = () => {\n this._worker.terminate();\n };\n\n /**\n * Updates the queue and flushes any completed promises that are ready.\n */\n _updateQueue({\n callbackId,\n error,\n results\n }: {\n callbackId: string,\n error?: Error,\n results?: Results\n }) {\n const target = this._callbackIdMap[callbackId];\n target.complete = true;\n target.error = error;\n target.results = results;\n\n while (this._callbackQueue.length) {\n let data = this._callbackQueue[0];\n\n if (!data.complete) {\n break;\n }\n\n this._callbackQueue.shift();\n\n delete this._callbackIdMap[data.callbackId];\n\n if (data.error) {\n data.reject(data.error);\n } else {\n // This type will always be defined in this case;\n // This casting lets Flow know it's safe.\n data.resolve((data.results: any));\n }\n }\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/worker/SearchWorkerLoader.js","// uuid.js\n//\n// Copyright (c) 2010-2012 Robert Kieffer\n// MIT License - http://opensource.org/licenses/mit-license.php\n\n// Unique ID creation requires a high quality random # generator. We feature\n// detect to determine the best RNG source, normalizing to a function that\n// returns 128-bits of randomness, since that's what's usually required\nvar _rng = require('./rng');\n\n// Maps for number <-> hex string conversion\nvar _byteToHex = [];\nvar _hexToByte = {};\nfor (var i = 0; i < 256; i++) {\n _byteToHex[i] = (i + 0x100).toString(16).substr(1);\n _hexToByte[_byteToHex[i]] = i;\n}\n\n// **`parse()` - Parse a UUID into it's component bytes**\nfunction parse(s, buf, offset) {\n var i = (buf && offset) || 0, ii = 0;\n\n buf = buf || [];\n s.toLowerCase().replace(/[0-9a-f]{2}/g, function(oct) {\n if (ii < 16) { // Don't overflow!\n buf[i + ii++] = _hexToByte[oct];\n }\n });\n\n // Zero out remaining bytes if string was short\n while (ii < 16) {\n buf[i + ii++] = 0;\n }\n\n return buf;\n}\n\n// **`unparse()` - Convert UUID byte array (ala parse()) into a string**\nfunction unparse(buf, offset) {\n var i = offset || 0, bth = _byteToHex;\n return bth[buf[i++]] + bth[buf[i++]] +\n bth[buf[i++]] + bth[buf[i++]] + '-' +\n bth[buf[i++]] + bth[buf[i++]] + '-' +\n bth[buf[i++]] + bth[buf[i++]] + '-' +\n bth[buf[i++]] + bth[buf[i++]] + '-' +\n bth[buf[i++]] + bth[buf[i++]] +\n bth[buf[i++]] + bth[buf[i++]] +\n bth[buf[i++]] + bth[buf[i++]];\n}\n\n// **`v1()` - Generate time-based UUID**\n//\n// Inspired by https://github.com/LiosK/UUID.js\n// and http://docs.python.org/library/uuid.html\n\n// random #'s we need to init node and clockseq\nvar _seedBytes = _rng();\n\n// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)\nvar _nodeId = [\n _seedBytes[0] | 0x01,\n _seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5]\n];\n\n// Per 4.2.2, randomize (14 bit) clockseq\nvar _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff;\n\n// Previous uuid creation time\nvar _lastMSecs = 0, _lastNSecs = 0;\n\n// See https://github.com/broofa/node-uuid for API details\nfunction v1(options, buf, offset) {\n var i = buf && offset || 0;\n var b = buf || [];\n\n options = options || {};\n\n var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;\n\n // UUID timestamps are 100 nano-second units since the Gregorian epoch,\n // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so\n // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'\n // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.\n var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime();\n\n // Per 4.2.1.2, use count of uuid's generated during the current clock\n // cycle to simulate higher resolution clock\n var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;\n\n // Time since last uuid creation (in msecs)\n var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;\n\n // Per 4.2.1.2, Bump clockseq on clock regression\n if (dt < 0 && options.clockseq === undefined) {\n clockseq = clockseq + 1 & 0x3fff;\n }\n\n // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new\n // time interval\n if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {\n nsecs = 0;\n }\n\n // Per 4.2.1.2 Throw error if too many uuids are requested\n if (nsecs >= 10000) {\n throw new Error('uuid.v1(): Can\\'t create more than 10M uuids/sec');\n }\n\n _lastMSecs = msecs;\n _lastNSecs = nsecs;\n _clockseq = clockseq;\n\n // Per 4.1.4 - Convert from unix epoch to Gregorian epoch\n msecs += 12219292800000;\n\n // `time_low`\n var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;\n b[i++] = tl >>> 24 & 0xff;\n b[i++] = tl >>> 16 & 0xff;\n b[i++] = tl >>> 8 & 0xff;\n b[i++] = tl & 0xff;\n\n // `time_mid`\n var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;\n b[i++] = tmh >>> 8 & 0xff;\n b[i++] = tmh & 0xff;\n\n // `time_high_and_version`\n b[i++] = tmh >>> 24 & 0xf | 0x10; // include version\n b[i++] = tmh >>> 16 & 0xff;\n\n // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)\n b[i++] = clockseq >>> 8 | 0x80;\n\n // `clock_seq_low`\n b[i++] = clockseq & 0xff;\n\n // `node`\n var node = options.node || _nodeId;\n for (var n = 0; n < 6; n++) {\n b[i + n] = node[n];\n }\n\n return buf ? buf : unparse(b);\n}\n\n// **`v4()` - Generate random UUID**\n\n// See https://github.com/broofa/node-uuid for API details\nfunction v4(options, buf, offset) {\n // Deprecated - 'format' argument, as supported in v1.2\n var i = buf && offset || 0;\n\n if (typeof(options) == 'string') {\n buf = options == 'binary' ? new Array(16) : null;\n options = null;\n }\n options = options || {};\n\n var rnds = options.random || (options.rng || _rng)();\n\n // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n\n // Copy bytes to buffer, if provided\n if (buf) {\n for (var ii = 0; ii < 16; ii++) {\n buf[i + ii] = rnds[ii];\n }\n }\n\n return buf || unparse(rnds);\n}\n\n// Export public API\nvar uuid = v4;\nuuid.v1 = v1;\nuuid.v4 = v4;\nuuid.parse = parse;\nuuid.unparse = unparse;\n\nmodule.exports = uuid;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/uuid/uuid.js\n// module id = 9\n// module chunks = 0","\nvar rng;\n\nvar crypto = global.crypto || global.msCrypto; // for IE 11\nif (crypto && crypto.getRandomValues) {\n // WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto\n // Moderately fast, high quality\n var _rnds8 = new Uint8Array(16);\n rng = function whatwgRNG() {\n crypto.getRandomValues(_rnds8);\n return _rnds8;\n };\n}\n\nif (!rng) {\n // Math.random()-based (RNG)\n //\n // If all else fails, use Math.random(). It's fast, but is of unspecified\n // quality.\n var _rnds = new Array(16);\n rng = function() {\n for (var i = 0, r; i < 16; i++) {\n if ((i & 0x03) === 0) r = Math.random() * 0x100000000;\n _rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;\n }\n\n return _rnds;\n };\n}\n\nmodule.exports = rng;\n\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/uuid/rng-browser.js\n// module id = 10\n// module chunks = 0","module.exports = function() {\n\treturn require(\"!!/Users/bvaughn/Documents/git/js-worker-search/node_modules/worker-loader/createInlineWorker.js\")(\"/******/ (function(modules) { // webpackBootstrap\\n/******/ \\t// The module cache\\n/******/ \\tvar installedModules = {};\\n/******/\\n/******/ \\t// The require function\\n/******/ \\tfunction __webpack_require__(moduleId) {\\n/******/\\n/******/ \\t\\t// Check if module is in cache\\n/******/ \\t\\tif(installedModules[moduleId])\\n/******/ \\t\\t\\treturn installedModules[moduleId].exports;\\n/******/\\n/******/ \\t\\t// Create a new module (and put it into the cache)\\n/******/ \\t\\tvar module = installedModules[moduleId] = {\\n/******/ \\t\\t\\texports: {},\\n/******/ \\t\\t\\tid: moduleId,\\n/******/ \\t\\t\\tloaded: false\\n/******/ \\t\\t};\\n/******/\\n/******/ \\t\\t// Execute the module function\\n/******/ \\t\\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\\n/******/\\n/******/ \\t\\t// Flag the module as loaded\\n/******/ \\t\\tmodule.loaded = true;\\n/******/\\n/******/ \\t\\t// Return the exports of the module\\n/******/ \\t\\treturn module.exports;\\n/******/ \\t}\\n/******/\\n/******/\\n/******/ \\t// expose the modules object (__webpack_modules__)\\n/******/ \\t__webpack_require__.m = modules;\\n/******/\\n/******/ \\t// expose the module cache\\n/******/ \\t__webpack_require__.c = installedModules;\\n/******/\\n/******/ \\t// __webpack_public_path__\\n/******/ \\t__webpack_require__.p = \\\"\\\";\\n/******/\\n/******/ \\t// Load entry module and return exports\\n/******/ \\treturn __webpack_require__(0);\\n/******/ })\\n/************************************************************************/\\n/******/ ([\\n/* 0 */\\n/***/ function(module, exports, __webpack_require__) {\\n\\n\\t\\\"use strict\\\";\\n\\t\\n\\tvar _util = __webpack_require__(1);\\n\\t\\n\\t/**\\n\\t * Search entry point to web worker.\\n\\t * Builds search index and performs searches on separate thread from the ui.\\n\\t */\\n\\t\\n\\tvar searchUtility = new _util.SearchUtility();\\n\\t\\n\\tself.addEventListener(\\\"message\\\", function (event) {\\n\\t var data = event.data;\\n\\t var method = data.method;\\n\\t\\n\\t\\n\\t switch (method) {\\n\\t case \\\"indexDocument\\\":\\n\\t var uid = data.uid,\\n\\t text = data.text;\\n\\t\\n\\t\\n\\t searchUtility.indexDocument(uid, text);\\n\\t break;\\n\\t case \\\"search\\\":\\n\\t var callbackId = data.callbackId,\\n\\t query = data.query;\\n\\t\\n\\t\\n\\t var results = searchUtility.search(query);\\n\\t\\n\\t self.postMessage({ callbackId: callbackId, results: results });\\n\\t break;\\n\\t case \\\"setCaseSensitive\\\":\\n\\t var caseSensitive = data.caseSensitive;\\n\\t\\n\\t\\n\\t searchUtility.setCaseSensitive(caseSensitive);\\n\\t break;\\n\\t case \\\"setIndexMode\\\":\\n\\t var indexMode = data.indexMode;\\n\\t\\n\\t\\n\\t searchUtility.setIndexMode(indexMode);\\n\\t break;\\n\\t case \\\"setMatchAnyToken\\\":\\n\\t var matchAnyToken = data.matchAnyToken;\\n\\t\\n\\t\\n\\t searchUtility.setMatchAnyToken(matchAnyToken);\\n\\t break;\\n\\t case \\\"setTokenizePattern\\\":\\n\\t var tokenizePattern = data.tokenizePattern;\\n\\t\\n\\t\\n\\t searchUtility.setTokenizePattern(tokenizePattern);\\n\\t break;\\n\\t }\\n\\t}, false);\\n\\n/***/ },\\n/* 1 */\\n/***/ function(module, exports, __webpack_require__) {\\n\\n\\t\\\"use strict\\\";\\n\\t\\n\\tObject.defineProperty(exports, \\\"__esModule\\\", {\\n\\t value: true\\n\\t});\\n\\texports.SearchUtility = exports.INDEX_MODES = undefined;\\n\\t\\n\\tvar _SearchUtility = __webpack_require__(2);\\n\\t\\n\\tvar _SearchUtility2 = _interopRequireDefault(_SearchUtility);\\n\\t\\n\\tvar _constants = __webpack_require__(3);\\n\\t\\n\\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\\n\\t\\n\\texports.default = _SearchUtility2.default;\\n\\texports.INDEX_MODES = _constants.INDEX_MODES;\\n\\texports.SearchUtility = _SearchUtility2.default;\\n\\n/***/ },\\n/* 2 */\\n/***/ function(module, exports, __webpack_require__) {\\n\\n\\t\\\"use strict\\\";\\n\\t\\n\\tObject.defineProperty(exports, \\\"__esModule\\\", {\\n\\t value: true\\n\\t});\\n\\t\\n\\tvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\\\"value\\\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\\n\\t\\n\\tvar _constants = __webpack_require__(3);\\n\\t\\n\\tvar _SearchIndex = __webpack_require__(4);\\n\\t\\n\\tvar _SearchIndex2 = _interopRequireDefault(_SearchIndex);\\n\\t\\n\\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\\n\\t\\n\\tfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\\\"Cannot call a class as a function\\\"); } }\\n\\t\\n\\t/**\\n\\t * Synchronous client-side full-text search utility.\\n\\t * Forked from JS search (github.com/bvaughn/js-search).\\n\\t */\\n\\tvar SearchUtility = function () {\\n\\t\\n\\t /**\\n\\t * Constructor.\\n\\t *\\n\\t * @param indexMode See #setIndexMode\\n\\t * @param tokenizePattern See #setTokenizePattern\\n\\t * @param caseSensitive See #setCaseSensitive\\n\\t * @param matchAnyToken See #setMatchAnyToken\\n\\t */\\n\\t function SearchUtility() {\\n\\t var _this = this;\\n\\t\\n\\t var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\\n\\t _ref$caseSensitive = _ref.caseSensitive,\\n\\t caseSensitive = _ref$caseSensitive === undefined ? false : _ref$caseSensitive,\\n\\t _ref$indexMode = _ref.indexMode,\\n\\t indexMode = _ref$indexMode === undefined ? _constants.INDEX_MODES.ALL_SUBSTRINGS : _ref$indexMode,\\n\\t _ref$matchAnyToken = _ref.matchAnyToken,\\n\\t matchAnyToken = _ref$matchAnyToken === undefined ? false : _ref$matchAnyToken,\\n\\t _ref$tokenizePattern = _ref.tokenizePattern,\\n\\t tokenizePattern = _ref$tokenizePattern === undefined ? /\\\\s+/ : _ref$tokenizePattern;\\n\\t\\n\\t _classCallCheck(this, SearchUtility);\\n\\t\\n\\t this.indexDocument = function (uid, text) {\\n\\t _this._uids[uid] = true;\\n\\t\\n\\t var fieldTokens = _this._tokenize(_this._sanitize(text));\\n\\t\\n\\t fieldTokens.forEach(function (fieldToken) {\\n\\t var expandedTokens = _this._expandToken(fieldToken);\\n\\t\\n\\t expandedTokens.forEach(function (expandedToken) {\\n\\t _this._searchIndex.indexDocument(expandedToken, uid);\\n\\t });\\n\\t });\\n\\t\\n\\t return _this;\\n\\t };\\n\\t\\n\\t this.search = function (query) {\\n\\t if (!query) {\\n\\t return Object.keys(_this._uids);\\n\\t } else {\\n\\t var tokens = _this._tokenize(_this._sanitize(query));\\n\\t\\n\\t return _this._searchIndex.search(tokens, _this._matchAnyToken);\\n\\t }\\n\\t };\\n\\t\\n\\t this.terminate = function () {};\\n\\t\\n\\t this._caseSensitive = caseSensitive;\\n\\t this._indexMode = indexMode;\\n\\t this._matchAnyToken = matchAnyToken;\\n\\t this._tokenizePattern = tokenizePattern;\\n\\t\\n\\t this._searchIndex = new _SearchIndex2.default();\\n\\t this._uids = {};\\n\\t }\\n\\t\\n\\t /**\\n\\t * Returns a constant representing the current case-sensitive bit.\\n\\t */\\n\\t\\n\\t\\n\\t _createClass(SearchUtility, [{\\n\\t key: \\\"getCaseSensitive\\\",\\n\\t value: function getCaseSensitive() {\\n\\t return this._caseSensitive;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Returns a constant representing the current index mode.\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"getIndexMode\\\",\\n\\t value: function getIndexMode() {\\n\\t return this._indexMode;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Returns a constant representing the current match-any-token bit.\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"getMatchAnyToken\\\",\\n\\t value: function getMatchAnyToken() {\\n\\t return this._matchAnyToken;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Returns a constant representing the current tokenize pattern.\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"getTokenizePattern\\\",\\n\\t value: function getTokenizePattern() {\\n\\t return this._tokenizePattern;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Adds or updates a uid in the search index and associates it with the specified text.\\n\\t * Note that at this time uids can only be added or updated in the index, not removed.\\n\\t *\\n\\t * @param uid Uniquely identifies a searchable object\\n\\t * @param text Text to associate with uid\\n\\t */\\n\\t\\n\\t\\n\\t /**\\n\\t * Searches the current index for the specified query text.\\n\\t * Only uids matching all of the words within the text will be accepted,\\n\\t * unless matchAny is set to true.\\n\\t * If an empty query string is provided all indexed uids will be returned.\\n\\t *\\n\\t * Document searches are case-insensitive by default (e.g. \\\"search\\\" will match \\\"Search\\\").\\n\\t * Document searches use substring matching by default (e.g. \\\"na\\\" and \\\"me\\\" will both match \\\"name\\\").\\n\\t *\\n\\t * @param query Searchable query text\\n\\t * @return Array of uids\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"setCaseSensitive\\\",\\n\\t\\n\\t\\n\\t /**\\n\\t * Sets a new case-sensitive bit\\n\\t */\\n\\t value: function setCaseSensitive(caseSensitive) {\\n\\t this._caseSensitive = caseSensitive;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Sets a new index mode.\\n\\t * See util/constants/INDEX_MODES\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"setIndexMode\\\",\\n\\t value: function setIndexMode(indexMode) {\\n\\t if (Object.keys(this._uids).length > 0) {\\n\\t throw Error(\\\"indexMode cannot be changed once documents have been indexed\\\");\\n\\t }\\n\\t\\n\\t this._indexMode = indexMode;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Sets a new match-any-token bit\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"setMatchAnyToken\\\",\\n\\t value: function setMatchAnyToken(matchAnyToken) {\\n\\t this._matchAnyToken = matchAnyToken;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Sets a new tokenize pattern (regular expression)\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"setTokenizePattern\\\",\\n\\t value: function setTokenizePattern(pattern) {\\n\\t this._tokenizePattern = pattern;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Added to make class adhere to interface. Add cleanup code as needed.\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"_expandToken\\\",\\n\\t\\n\\t\\n\\t /**\\n\\t * Index strategy based on 'all-substrings-index-strategy.ts' in github.com/bvaughn/js-search/\\n\\t *\\n\\t * @private\\n\\t */\\n\\t value: function _expandToken(token) {\\n\\t switch (this._indexMode) {\\n\\t case _constants.INDEX_MODES.EXACT_WORDS:\\n\\t return [token];\\n\\t case _constants.INDEX_MODES.PREFIXES:\\n\\t return this._expandPrefixTokens(token);\\n\\t case _constants.INDEX_MODES.ALL_SUBSTRINGS:\\n\\t default:\\n\\t return this._expandAllSubstringTokens(token);\\n\\t }\\n\\t }\\n\\t }, {\\n\\t key: \\\"_expandAllSubstringTokens\\\",\\n\\t value: function _expandAllSubstringTokens(token) {\\n\\t var expandedTokens = [];\\n\\t\\n\\t // String.prototype.charAt() may return surrogate halves instead of whole characters.\\n\\t // When this happens in the context of a web-worker it can cause Chrome to crash.\\n\\t // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\\n\\t // Resources:\\n\\t // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\\n\\t // https://mathiasbynens.be/notes/javascript-unicode\\n\\t try {\\n\\t for (var i = 0, length = token.length; i < length; ++i) {\\n\\t var substring = \\\"\\\";\\n\\t\\n\\t for (var j = i; j < length; ++j) {\\n\\t substring += token.charAt(j);\\n\\t expandedTokens.push(substring);\\n\\t }\\n\\t }\\n\\t } catch (error) {\\n\\t console.error(\\\"Unable to parse token \\\\\\\"\\\" + token + \\\"\\\\\\\" \\\" + error);\\n\\t }\\n\\t\\n\\t return expandedTokens;\\n\\t }\\n\\t }, {\\n\\t key: \\\"_expandPrefixTokens\\\",\\n\\t value: function _expandPrefixTokens(token) {\\n\\t var expandedTokens = [];\\n\\t\\n\\t // String.prototype.charAt() may return surrogate halves instead of whole characters.\\n\\t // When this happens in the context of a web-worker it can cause Chrome to crash.\\n\\t // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\\n\\t // Resources:\\n\\t // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\\n\\t // https://mathiasbynens.be/notes/javascript-unicode\\n\\t try {\\n\\t for (var i = 0, length = token.length; i < length; ++i) {\\n\\t expandedTokens.push(token.substr(0, i + 1));\\n\\t }\\n\\t } catch (error) {\\n\\t console.error(\\\"Unable to parse token \\\\\\\"\\\" + token + \\\"\\\\\\\" \\\" + error);\\n\\t }\\n\\t\\n\\t return expandedTokens;\\n\\t }\\n\\t\\n\\t /**\\n\\t * @private\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"_sanitize\\\",\\n\\t value: function _sanitize(string) {\\n\\t return this._caseSensitive ? string.trim() : string.trim().toLocaleLowerCase();\\n\\t }\\n\\t\\n\\t /**\\n\\t * @private\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"_tokenize\\\",\\n\\t value: function _tokenize(text) {\\n\\t return text.split(this._tokenizePattern).filter(function (text) {\\n\\t return text;\\n\\t }); // Remove empty tokens\\n\\t }\\n\\t }]);\\n\\t\\n\\t return SearchUtility;\\n\\t}();\\n\\t\\n\\texports.default = SearchUtility;\\n\\n/***/ },\\n/* 3 */\\n/***/ function(module, exports) {\\n\\n\\t\\\"use strict\\\";\\n\\t\\n\\tObject.defineProperty(exports, \\\"__esModule\\\", {\\n\\t value: true\\n\\t});\\n\\tvar INDEX_MODES = exports.INDEX_MODES = {\\n\\t // Indexes for all substring searches (e.g. the term \\\"cat\\\" is indexed as \\\"c\\\", \\\"ca\\\", \\\"cat\\\", \\\"a\\\", \\\"at\\\", and \\\"t\\\").\\n\\t // Based on 'all-substrings-index-strategy' from js-search;\\n\\t // github.com/bvaughn/js-search/blob/master/source/index-strategy/all-substrings-index-strategy.ts\\n\\t ALL_SUBSTRINGS: \\\"ALL_SUBSTRINGS\\\",\\n\\t\\n\\t // Indexes for exact word matches only.\\n\\t // Based on 'exact-word-index-strategy' from js-search;\\n\\t // github.com/bvaughn/js-search/blob/master/source/index-strategy/exact-word-index-strategy.ts\\n\\t EXACT_WORDS: \\\"EXACT_WORDS\\\",\\n\\t\\n\\t // Indexes for prefix searches (e.g. the term \\\"cat\\\" is indexed as \\\"c\\\", \\\"ca\\\", and \\\"cat\\\" allowing prefix search lookups).\\n\\t // Based on 'prefix-index-strategy' from js-search;\\n\\t // github.com/bvaughn/js-search/blob/master/source/index-strategy/prefix-index-strategy.ts\\n\\t PREFIXES: \\\"PREFIXES\\\"\\n\\t};\\n\\n/***/ },\\n/* 4 */\\n/***/ function(module, exports) {\\n\\n\\t\\\"use strict\\\";\\n\\t\\n\\tObject.defineProperty(exports, \\\"__esModule\\\", {\\n\\t value: true\\n\\t});\\n\\t\\n\\tvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\\\"value\\\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\\n\\t\\n\\tfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\\\"Cannot call a class as a function\\\"); } }\\n\\t\\n\\t/**\\n\\t * Maps search tokens to uids using a trie structure.\\n\\t */\\n\\tvar SearchIndex = function () {\\n\\t function SearchIndex() {\\n\\t _classCallCheck(this, SearchIndex);\\n\\t\\n\\t this.tokenToUidMap = {};\\n\\t }\\n\\t\\n\\t /**\\n\\t * Maps the specified token to a uid.\\n\\t *\\n\\t * @param token Searchable token (e.g. \\\"road\\\")\\n\\t * @param uid Identifies a document within the searchable corpus\\n\\t */\\n\\t\\n\\t\\n\\t _createClass(SearchIndex, [{\\n\\t key: \\\"indexDocument\\\",\\n\\t value: function indexDocument(token, uid) {\\n\\t if (!this.tokenToUidMap[token]) {\\n\\t this.tokenToUidMap[token] = {};\\n\\t }\\n\\t\\n\\t this.tokenToUidMap[token][uid] = uid;\\n\\t }\\n\\t\\n\\t /**\\n\\t * Finds uids that have been mapped to the set of tokens specified.\\n\\t * Only uids that have been mapped to all tokens will be returned.\\n\\t *\\n\\t * @param tokens Array of searchable tokens (e.g. [\\\"long\\\", \\\"road\\\"])\\n\\t * @param matchAnyToken Whether to match any token. Default is false.\\n\\t * @return Array of uids that have been associated with the set of search tokens\\n\\t */\\n\\t\\n\\t }, {\\n\\t key: \\\"search\\\",\\n\\t value: function search(tokens, matchAnyToken) {\\n\\t var _this = this;\\n\\t\\n\\t var uidMap = {};\\n\\t var uidMatches = {};\\n\\t var initialized = false;\\n\\t\\n\\t tokens.forEach(function (token) {\\n\\t var currentUidMap = _this.tokenToUidMap[token] || {};\\n\\t\\n\\t if (!initialized) {\\n\\t initialized = true;\\n\\t\\n\\t for (var _uid in currentUidMap) {\\n\\t uidMap[_uid] = currentUidMap[_uid];\\n\\t uidMatches[_uid] = 1;\\n\\t }\\n\\t } else {\\n\\t // Delete existing matches if using and AND query (the default)\\n\\t // Otherwise add new results to the matches\\n\\t if (!matchAnyToken) {\\n\\t for (var _uid2 in uidMap) {\\n\\t if (!currentUidMap[_uid2]) {\\n\\t delete uidMap[_uid2];\\n\\t }\\n\\t }\\n\\t } else {\\n\\t for (var _uid3 in currentUidMap) {\\n\\t uidMap[_uid3] = currentUidMap[_uid3];\\n\\t uidMatches[_uid3] = (uidMatches[_uid3] || 0) + 1;\\n\\t }\\n\\t }\\n\\t }\\n\\t });\\n\\t\\n\\t var uids = [];\\n\\t for (var _uid4 in uidMap) {\\n\\t uids.push(uidMap[_uid4]);\\n\\t }\\n\\t\\n\\t // Sort according to most matches, if match any token is set.\\n\\t if (matchAnyToken) {\\n\\t uids.sort(function (a, b) {\\n\\t return uidMatches[b] - uidMatches[a];\\n\\t });\\n\\t }\\n\\t\\n\\t return uids;\\n\\t }\\n\\t }]);\\n\\t\\n\\t return SearchIndex;\\n\\t}();\\n\\t\\n\\texports.default = SearchIndex;\\n\\n/***/ }\\n/******/ ]);\\n//# sourceMappingURL=5cafaba60d6eb1f43c8f.worker.js.map\", __webpack_public_path__ + \"5cafaba60d6eb1f43c8f.worker.js\");\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/worker-loader?inline=true!./src/worker/Worker.js\n// module id = 11\n// module chunks = 0","// http://stackoverflow.com/questions/10343913/how-to-create-a-web-worker-from-a-string\r\n\r\nvar URL = window.URL || window.webkitURL;\r\nmodule.exports = function(content, url) {\r\n try {\r\n try {\r\n var blob;\r\n try { // BlobBuilder = Deprecated, but widely implemented\r\n var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;\r\n blob = new BlobBuilder();\r\n blob.append(content);\r\n blob = blob.getBlob();\r\n } catch(e) { // The proposed API\r\n blob = new Blob([content]);\r\n }\r\n return new Worker(URL.createObjectURL(blob));\r\n } catch(e) {\r\n return new Worker('data:application/javascript,' + encodeURIComponent(content));\r\n }\r\n } catch(e) {\r\n if (!url) {\r\n throw Error('Inline worker is not supported');\r\n }\r\n return new Worker(url);\r\n }\r\n}\r\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/worker-loader/createInlineWorker.js\n// module id = 12\n// module chunks = 0"],"sourceRoot":""}
{
"name": "js-worker-search",
"version": "1.3.0",
"version": "1.4.0",
"description": "JavaScript client-side search API with web-worker support",

@@ -5,0 +5,0 @@ "author": "Brian Vaughn (brian.david.vaughn@gmail.com)",

@@ -50,2 +50,5 @@ js-worker-search

##### `terminate()`
If search is running in a web worker, this will terminate the worker to allow for garbage collection.
Example Usage

@@ -120,2 +123,13 @@ ------

### Partial matches
By default, the search utility only returns documents containing every search token.
It can be configured to return documents containing any search token.
```js
// Change search behavior from AND to OR
const searchApi = new SearchApi({
matchAnyToken: true
})
```
Changelog

@@ -122,0 +136,0 @@ ---------

/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var _util = __webpack_require__(1);
/**
* Search entry point to web worker.
* Builds search index and performs searches on separate thread from the ui.
*/
var searchUtility = new _util.SearchUtility();
self.addEventListener("message", function (event) {
var data = event.data;
var method = data.method;
switch (method) {
case "indexDocument":
var uid = data.uid,
text = data.text;
searchUtility.indexDocument(uid, text);
break;
case "search":
var callbackId = data.callbackId,
query = data.query;
var results = searchUtility.search(query);
self.postMessage({ callbackId: callbackId, results: results });
break;
case "setIndexMode":
var indexMode = data.indexMode;
searchUtility.setIndexMode(indexMode);
break;
case "setTokenizePattern":
var tokenizePattern = data.tokenizePattern;
searchUtility.setTokenizePattern(tokenizePattern);
break;
case "setCaseSensitive":
var caseSensitive = data.caseSensitive;
searchUtility.setCaseSensitive(caseSensitive);
break;
}
}, false);
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SearchUtility = exports.INDEX_MODES = undefined;
var _SearchUtility = __webpack_require__(2);
var _SearchUtility2 = _interopRequireDefault(_SearchUtility);
var _constants = __webpack_require__(3);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = _SearchUtility2.default;
exports.INDEX_MODES = _constants.INDEX_MODES;
exports.SearchUtility = _SearchUtility2.default;
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _constants = __webpack_require__(3);
var _SearchIndex = __webpack_require__(4);
var _SearchIndex2 = _interopRequireDefault(_SearchIndex);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Synchronous client-side full-text search utility.
* Forked from JS search (github.com/bvaughn/js-search).
*/
var SearchUtility = function () {
/**
* Constructor.
*
* @param indexMode See #setIndexMode
* @param tokenizePattern See #setTokenizePattern
* @param caseSensitive See #setCaseSensitive
*/
function SearchUtility() {
var _this = this;
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$indexMode = _ref.indexMode,
indexMode = _ref$indexMode === undefined ? _constants.INDEX_MODES.ALL_SUBSTRINGS : _ref$indexMode,
_ref$tokenizePattern = _ref.tokenizePattern,
tokenizePattern = _ref$tokenizePattern === undefined ? /\s+/ : _ref$tokenizePattern,
_ref$caseSensitive = _ref.caseSensitive,
caseSensitive = _ref$caseSensitive === undefined ? false : _ref$caseSensitive;
_classCallCheck(this, SearchUtility);
this.indexDocument = function (uid, text) {
_this._uids[uid] = true;
var fieldTokens = _this._tokenize(_this._sanitize(text));
fieldTokens.forEach(function (fieldToken) {
var expandedTokens = _this._expandToken(fieldToken);
expandedTokens.forEach(function (expandedToken) {
_this._searchIndex.indexDocument(expandedToken, uid);
});
});
return _this;
};
this.search = function (query) {
if (!query) {
return Object.keys(_this._uids);
} else {
var tokens = _this._tokenize(_this._sanitize(query));
return _this._searchIndex.search(tokens);
}
};
this.terminate = function () {};
this._indexMode = indexMode;
this._tokenizePattern = tokenizePattern;
this._caseSensitive = caseSensitive;
this._searchIndex = new _SearchIndex2.default();
this._uids = {};
}
/**
* Returns a constant representing the current index mode.
*/
_createClass(SearchUtility, [{
key: "getIndexMode",
value: function getIndexMode() {
return this._indexMode;
}
/**
* Returns a constant representing the current tokenize pattern.
*/
}, {
key: "getTokenizePattern",
value: function getTokenizePattern() {
return this._tokenizePattern;
}
/**
* Returns a constant representing the current case-sensitive bit.
*/
}, {
key: "getCaseSensitive",
value: function getCaseSensitive() {
return this._caseSensitive;
}
/**
* Adds or updates a uid in the search index and associates it with the specified text.
* Note that at this time uids can only be added or updated in the index, not removed.
*
* @param uid Uniquely identifies a searchable object
* @param text Text to associate with uid
*/
/**
* Searches the current index for the specified query text.
* Only uids matching all of the words within the text will be accepted.
* If an empty query string is provided all indexed uids will be returned.
*
* Document searches are case-insensitive (e.g. "search" will match "Search").
* Document searches use substring matching (e.g. "na" and "me" will both match "name").
*
* @param query Searchable query text
* @return Array of uids
*/
}, {
key: "setIndexMode",
/**
* Sets a new index mode.
* See util/constants/INDEX_MODES
*/
value: function setIndexMode(indexMode) {
if (Object.keys(this._uids).length > 0) {
throw Error("indexMode cannot be changed once documents have been indexed");
}
this._indexMode = indexMode;
}
/**
* Sets a new tokenize pattern (regular expression)
*/
}, {
key: "setTokenizePattern",
value: function setTokenizePattern(pattern) {
this._tokenizePattern = pattern;
}
/**
* Sets a new case-sensitive bit
*/
}, {
key: "setCaseSensitive",
value: function setCaseSensitive(caseSensitive) {
this._caseSensitive = caseSensitive;
}
/**
* Added to make class adhere to interface. Add cleanup code as needed.
*/
}, {
key: "_expandToken",
/**
* Index strategy based on 'all-substrings-index-strategy.ts' in github.com/bvaughn/js-search/
*
* @private
*/
value: function _expandToken(token) {
switch (this._indexMode) {
case _constants.INDEX_MODES.EXACT_WORDS:
return [token];
case _constants.INDEX_MODES.PREFIXES:
return this._expandPrefixTokens(token);
case _constants.INDEX_MODES.ALL_SUBSTRINGS:
default:
return this._expandAllSubstringTokens(token);
}
}
}, {
key: "_expandAllSubstringTokens",
value: function _expandAllSubstringTokens(token) {
var expandedTokens = [];
// String.prototype.charAt() may return surrogate halves instead of whole characters.
// When this happens in the context of a web-worker it can cause Chrome to crash.
// Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.
// Resources:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt
// https://mathiasbynens.be/notes/javascript-unicode
try {
for (var i = 0, length = token.length; i < length; ++i) {
var substring = "";
for (var j = i; j < length; ++j) {
substring += token.charAt(j);
expandedTokens.push(substring);
}
}
} catch (error) {
console.error("Unable to parse token \"" + token + "\" " + error);
}
return expandedTokens;
}
}, {
key: "_expandPrefixTokens",
value: function _expandPrefixTokens(token) {
var expandedTokens = [];
// String.prototype.charAt() may return surrogate halves instead of whole characters.
// When this happens in the context of a web-worker it can cause Chrome to crash.
// Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.
// Resources:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt
// https://mathiasbynens.be/notes/javascript-unicode
try {
for (var i = 0, length = token.length; i < length; ++i) {
expandedTokens.push(token.substr(0, i + 1));
}
} catch (error) {
console.error("Unable to parse token \"" + token + "\" " + error);
}
return expandedTokens;
}
/**
* @private
*/
}, {
key: "_sanitize",
value: function _sanitize(string) {
return this._caseSensitive ? string.trim() : string.trim().toLocaleLowerCase();
}
/**
* @private
*/
}, {
key: "_tokenize",
value: function _tokenize(text) {
return text.split(this._tokenizePattern).filter(function (text) {
return text;
}); // Remove empty tokens
}
}]);
return SearchUtility;
}();
exports.default = SearchUtility;
/***/ },
/* 3 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var INDEX_MODES = exports.INDEX_MODES = {
// Indexes for all substring searches (e.g. the term "cat" is indexed as "c", "ca", "cat", "a", "at", and "t").
// Based on 'all-substrings-index-strategy' from js-search;
// github.com/bvaughn/js-search/blob/master/source/index-strategy/all-substrings-index-strategy.ts
ALL_SUBSTRINGS: "ALL_SUBSTRINGS",
// Indexes for exact word matches only.
// Based on 'exact-word-index-strategy' from js-search;
// github.com/bvaughn/js-search/blob/master/source/index-strategy/exact-word-index-strategy.ts
EXACT_WORDS: "EXACT_WORDS",
// Indexes for prefix searches (e.g. the term "cat" is indexed as "c", "ca", and "cat" allowing prefix search lookups).
// Based on 'prefix-index-strategy' from js-search;
// github.com/bvaughn/js-search/blob/master/source/index-strategy/prefix-index-strategy.ts
PREFIXES: "PREFIXES"
};
/***/ },
/* 4 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Maps search tokens to uids using a trie structure.
*/
var SearchIndex = function () {
function SearchIndex() {
_classCallCheck(this, SearchIndex);
this.tokenToUidMap = {};
}
/**
* Maps the specified token to a uid.
*
* @param token Searchable token (e.g. "road")
* @param uid Identifies a document within the searchable corpus
*/
_createClass(SearchIndex, [{
key: "indexDocument",
value: function indexDocument(token, uid) {
if (!this.tokenToUidMap[token]) {
this.tokenToUidMap[token] = {};
}
this.tokenToUidMap[token][uid] = uid;
}
/**
* Finds uids that have been mapped to the set of tokens specified.
* Only uids that have been mapped to all tokens will be returned.
*
* @param tokens Array of searchable tokens (e.g. ["long", "road"])
* @return Array of uids that have been associated with the set of search tokens
*/
}, {
key: "search",
value: function search(tokens) {
var _this = this;
var uidMap = {};
var initialized = false;
tokens.forEach(function (token) {
var currentUidMap = _this.tokenToUidMap[token] || {};
if (!initialized) {
initialized = true;
for (var _uid in currentUidMap) {
uidMap[_uid] = currentUidMap[_uid];
}
} else {
for (var _uid2 in uidMap) {
if (!currentUidMap[_uid2]) {
delete uidMap[_uid2];
}
}
}
});
var uids = [];
for (var _uid3 in uidMap) {
uids.push(uidMap[_uid3]);
}
return uids;
}
}]);
return SearchIndex;
}();
exports.default = SearchIndex;
/***/ }
/******/ ]);
//# sourceMappingURL=2ef0afcacb6f46b34be5.worker.js.map
{"version":3,"sources":["webpack:///webpack/bootstrap 2ef0afcacb6f46b34be5","webpack:///./src/worker/Worker.js","webpack:///./src/util/index.js","webpack:///./src/util/SearchUtility.js","webpack:///./src/util/constants.js","webpack:///./src/util/SearchIndex.js"],"names":["searchUtility","self","addEventListener","data","event","method","uid","text","indexDocument","callbackId","query","results","search","postMessage","indexMode","setIndexMode","tokenizePattern","setTokenizePattern","caseSensitive","setCaseSensitive","INDEX_MODES","SearchUtility","ALL_SUBSTRINGS","_uids","fieldTokens","_tokenize","_sanitize","forEach","expandedTokens","_expandToken","fieldToken","_searchIndex","expandedToken","Object","keys","tokens","terminate","_indexMode","_tokenizePattern","_caseSensitive","length","Error","pattern","token","EXACT_WORDS","PREFIXES","_expandPrefixTokens","_expandAllSubstringTokens","i","substring","j","charAt","push","error","console","substr","string","trim","toLocaleLowerCase","split","filter","SearchIndex","tokenToUidMap","uidMap","initialized","currentUidMap","uids"],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;ACpCA;;AAEA;;;;;AAKA,KAAMA,gBAAgB,yBAAtB;;AAEAC,MAAKC,gBAAL,CACE,SADF,EAEE,iBAAS;AAAA,OACCC,IADD,GACUC,KADV,CACCD,IADD;AAAA,OAECE,MAFD,GAEYF,IAFZ,CAECE,MAFD;;;AAIP,WAAQA,MAAR;AACE,UAAK,eAAL;AAAA,WACUC,GADV,GACwBH,IADxB,CACUG,GADV;AAAA,WACeC,IADf,GACwBJ,IADxB,CACeI,IADf;;;AAGEP,qBAAcQ,aAAd,CAA4BF,GAA5B,EAAiCC,IAAjC;AACA;AACF,UAAK,QAAL;AAAA,WACUE,UADV,GACgCN,IADhC,CACUM,UADV;AAAA,WACsBC,KADtB,GACgCP,IADhC,CACsBO,KADtB;;;AAGE,WAAMC,UAAUX,cAAcY,MAAd,CAAqBF,KAArB,CAAhB;;AAEAT,YAAKY,WAAL,CAAiB,EAAEJ,sBAAF,EAAcE,gBAAd,EAAjB;AACA;AACF,UAAK,cAAL;AAAA,WACUG,SADV,GACwBX,IADxB,CACUW,SADV;;;AAGEd,qBAAce,YAAd,CAA2BD,SAA3B;AACA;AACF,UAAK,oBAAL;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{};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 2ef0afcacb6f46b34be5","/** @flow */\n\nimport { SearchUtility } from \"../util\";\n\n/**\n * Search entry point to web worker.\n * Builds search index and performs searches on separate thread from the ui.\n */\n\nconst searchUtility = new SearchUtility();\n\nself.addEventListener(\n \"message\",\n event => {\n const { data } = event;\n const { method } = data;\n\n switch (method) {\n case \"indexDocument\":\n const { uid, text } = data;\n\n searchUtility.indexDocument(uid, text);\n break;\n case \"search\":\n const { callbackId, query } = data;\n\n const results = searchUtility.search(query);\n\n self.postMessage({ callbackId, results });\n break;\n case \"setIndexMode\":\n const { indexMode } = data;\n\n searchUtility.setIndexMode(indexMode);\n break;\n case \"setTokenizePattern\":\n const { tokenizePattern } = data;\n\n searchUtility.setTokenizePattern(tokenizePattern);\n break;\n case \"setCaseSensitive\":\n const { caseSensitive } = data;\n\n searchUtility.setCaseSensitive(caseSensitive);\n break;\n }\n },\n false\n);\n\n\n\n// WEBPACK FOOTER //\n// ./src/worker/Worker.js","/** @flow */\n\nimport SearchUtility from \"./SearchUtility\";\nimport { INDEX_MODES } from \"./constants\";\n\nexport type { IndexMode } from \"./constants\";\n\nexport default SearchUtility;\nexport { INDEX_MODES, SearchUtility };\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/index.js","/** @flow */\n\nimport { INDEX_MODES } from \"./constants\";\nimport SearchIndex from \"./SearchIndex\";\n\nimport type { IndexMode } from \"./constants\";\nimport type { SearchApiIndex } from \"../types\";\n\ntype UidMap = {\n [uid: string]: boolean\n};\n\n/**\n * Synchronous client-side full-text search utility.\n * Forked from JS search (github.com/bvaughn/js-search).\n */\nexport default class SearchUtility implements SearchApiIndex {\n _indexMode: IndexMode;\n _tokenizePattern: RegExp;\n _caseSensitive: boolean;\n _searchIndex: SearchIndex;\n _uids: UidMap;\n\n /**\n * Constructor.\n *\n * @param indexMode See #setIndexMode\n * @param tokenizePattern See #setTokenizePattern\n * @param caseSensitive See #setCaseSensitive\n */\n constructor(\n {\n indexMode = INDEX_MODES.ALL_SUBSTRINGS,\n tokenizePattern = /\\s+/,\n caseSensitive = false\n }: {\n indexMode?: IndexMode,\n tokenizePattern?: RegExp,\n caseSensitive?: boolean\n } = {}\n ) {\n this._indexMode = indexMode;\n this._tokenizePattern = tokenizePattern;\n this._caseSensitive = caseSensitive;\n\n this._searchIndex = new SearchIndex();\n this._uids = {};\n }\n\n /**\n * Returns a constant representing the current index mode.\n */\n getIndexMode(): string {\n return this._indexMode;\n }\n\n /**\n * Returns a constant representing the current tokenize pattern.\n */\n getTokenizePattern(): RegExp {\n return this._tokenizePattern;\n }\n\n /**\n * Returns a constant representing the current case-sensitive bit.\n */\n getCaseSensitive(): boolean {\n return this._caseSensitive;\n }\n\n /**\n * Adds or updates a uid in the search index and associates it with the specified text.\n * Note that at this time uids can only be added or updated in the index, not removed.\n *\n * @param uid Uniquely identifies a searchable object\n * @param text Text to associate with uid\n */\n indexDocument = (uid: any, text: string): SearchApiIndex => {\n this._uids[uid] = true;\n\n var fieldTokens: Array<string> = this._tokenize(this._sanitize(text));\n\n fieldTokens.forEach(fieldToken => {\n var expandedTokens: Array<string> = this._expandToken(fieldToken);\n\n expandedTokens.forEach(expandedToken => {\n this._searchIndex.indexDocument(expandedToken, uid);\n });\n });\n\n return this;\n };\n\n /**\n * Searches the current index for the specified query text.\n * Only uids matching all of the words within the text will be accepted.\n * If an empty query string is provided all indexed uids will be returned.\n *\n * Document searches are case-insensitive (e.g. \"search\" will match \"Search\").\n * Document searches use substring matching (e.g. \"na\" and \"me\" will both match \"name\").\n *\n * @param query Searchable query text\n * @return Array of uids\n */\n search = (query: string): Array<any> => {\n if (!query) {\n return Object.keys(this._uids);\n } else {\n var tokens: Array<string> = this._tokenize(this._sanitize(query));\n\n return this._searchIndex.search(tokens);\n }\n };\n\n /**\n * Sets a new index mode.\n * See util/constants/INDEX_MODES\n */\n setIndexMode(indexMode: IndexMode): void {\n if (Object.keys(this._uids).length > 0) {\n throw Error(\n \"indexMode cannot be changed once documents have been indexed\"\n );\n }\n\n this._indexMode = indexMode;\n }\n\n /**\n * Sets a new tokenize pattern (regular expression)\n */\n setTokenizePattern(pattern: RegExp): void {\n this._tokenizePattern = pattern;\n }\n\n /**\n * Sets a new case-sensitive bit\n */\n setCaseSensitive(caseSensitive: boolean): void {\n this._caseSensitive = caseSensitive;\n }\n\n /**\n * Added to make class adhere to interface. Add cleanup code as needed.\n */\n terminate = () => {};\n\n /**\n * Index strategy based on 'all-substrings-index-strategy.ts' in github.com/bvaughn/js-search/\n *\n * @private\n */\n _expandToken(token: string): Array<string> {\n switch (this._indexMode) {\n case INDEX_MODES.EXACT_WORDS:\n return [token];\n case INDEX_MODES.PREFIXES:\n return this._expandPrefixTokens(token);\n case INDEX_MODES.ALL_SUBSTRINGS:\n default:\n return this._expandAllSubstringTokens(token);\n }\n }\n\n _expandAllSubstringTokens(token: string): Array<string> {\n const expandedTokens = [];\n\n // String.prototype.charAt() may return surrogate halves instead of whole characters.\n // When this happens in the context of a web-worker it can cause Chrome to crash.\n // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\n // Resources:\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\n // https://mathiasbynens.be/notes/javascript-unicode\n try {\n for (let i = 0, length = token.length; i < length; ++i) {\n let substring: string = \"\";\n\n for (let j = i; j < length; ++j) {\n substring += token.charAt(j);\n expandedTokens.push(substring);\n }\n }\n } catch (error) {\n console.error(`Unable to parse token \"${token}\" ${error}`);\n }\n\n return expandedTokens;\n }\n\n _expandPrefixTokens(token: string): Array<string> {\n const expandedTokens = [];\n\n // String.prototype.charAt() may return surrogate halves instead of whole characters.\n // When this happens in the context of a web-worker it can cause Chrome to crash.\n // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters.\n // Resources:\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt\n // https://mathiasbynens.be/notes/javascript-unicode\n try {\n for (let i = 0, length = token.length; i < length; ++i) {\n expandedTokens.push(token.substr(0, i + 1));\n }\n } catch (error) {\n console.error(`Unable to parse token \"${token}\" ${error}`);\n }\n\n return expandedTokens;\n }\n\n /**\n * @private\n */\n _sanitize(string: string): string {\n return this._caseSensitive\n ? string.trim()\n : string.trim().toLocaleLowerCase();\n }\n\n /**\n * @private\n */\n _tokenize(text: string): Array<string> {\n return text.split(this._tokenizePattern).filter(text => text); // Remove empty tokens\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/SearchUtility.js","/** @flow */\n\nexport const INDEX_MODES = {\n // Indexes for all substring searches (e.g. the term \"cat\" is indexed as \"c\", \"ca\", \"cat\", \"a\", \"at\", and \"t\").\n // Based on 'all-substrings-index-strategy' from js-search;\n // github.com/bvaughn/js-search/blob/master/source/index-strategy/all-substrings-index-strategy.ts\n ALL_SUBSTRINGS: \"ALL_SUBSTRINGS\",\n\n // Indexes for exact word matches only.\n // Based on 'exact-word-index-strategy' from js-search;\n // github.com/bvaughn/js-search/blob/master/source/index-strategy/exact-word-index-strategy.ts\n EXACT_WORDS: \"EXACT_WORDS\",\n\n // Indexes for prefix searches (e.g. the term \"cat\" is indexed as \"c\", \"ca\", and \"cat\" allowing prefix search lookups).\n // Based on 'prefix-index-strategy' from js-search;\n // github.com/bvaughn/js-search/blob/master/source/index-strategy/prefix-index-strategy.ts\n PREFIXES: \"PREFIXES\"\n};\n\nexport type IndexMode = $Keys<typeof INDEX_MODES>;\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/constants.js","/** @flow */\n\n/**\n * Maps search tokens to uids using a trie structure.\n */\nexport default class SearchIndex {\n tokenToUidMap: { [token: string]: any };\n\n constructor() {\n this.tokenToUidMap = {};\n }\n\n /**\n * Maps the specified token to a uid.\n *\n * @param token Searchable token (e.g. \"road\")\n * @param uid Identifies a document within the searchable corpus\n */\n indexDocument(token: string, uid: any): void {\n if (!this.tokenToUidMap[token]) {\n this.tokenToUidMap[token] = {};\n }\n\n this.tokenToUidMap[token][uid] = uid;\n }\n\n /**\n * Finds uids that have been mapped to the set of tokens specified.\n * Only uids that have been mapped to all tokens will be returned.\n *\n * @param tokens Array of searchable tokens (e.g. [\"long\", \"road\"])\n * @return Array of uids that have been associated with the set of search tokens\n */\n search(tokens: Array<string>): Array<any> {\n let uidMap: { [uid: any]: any } = {};\n let initialized = false;\n\n tokens.forEach(token => {\n let currentUidMap: { [uid: any]: any } = this.tokenToUidMap[token] || {};\n\n if (!initialized) {\n initialized = true;\n\n for (let uid in currentUidMap) {\n uidMap[uid] = currentUidMap[uid];\n }\n } else {\n for (let uid in uidMap) {\n if (!currentUidMap[uid]) {\n delete uidMap[uid];\n }\n }\n }\n });\n\n let uids: Array<any> = [];\n for (let uid in uidMap) {\n uids.push(uidMap[uid]);\n }\n\n return uids;\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/util/SearchIndex.js"],"sourceRoot":""}