js-search
Advanced tools
Comparing version 1.4.3 to 2.0.0
# Changelog | ||
## 2.0.0 | ||
Added es modules support for bundlers via "module" field and for node via "exports" field. | ||
Commonjs output is no longer provided. Entry point is UMD now. | ||
UMD/ESM are bundled with rollup which reduced minified bundle size twice from 17432 to 7759 bytes! | ||
Flow types are distributed with sources. | ||
## 1.4.3 | ||
@@ -4,0 +11,0 @@ Don't inherit from the default Object for the token dictionary. ([davidlukerice](https://github.com/davidlukerice) - [#73](https://github.com/bvaughn/js-search/pull/73)) |
@@ -1,1123 +0,908 @@ | ||
!function(root, factory) { | ||
"object" == typeof exports && "object" == typeof module ? module.exports = factory() : "function" == typeof define && define.amd ? define([], factory) : "object" == typeof exports ? exports.JsSearch = factory() : root.JsSearch = factory(); | ||
}(this, function() { | ||
/******/ | ||
return function(modules) { | ||
/******/ | ||
// 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] = { | ||
/******/ | ||
i: moduleId, | ||
/******/ | ||
l: !1, | ||
/******/ | ||
exports: {} | ||
}; | ||
/******/ | ||
// Return the exports of the module | ||
/******/ | ||
/******/ | ||
// Execute the module function | ||
/******/ | ||
/******/ | ||
// Flag the module as loaded | ||
/******/ | ||
return modules[moduleId].call(module.exports, module, module.exports, __webpack_require__), | ||
module.l = !0, module.exports; | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.JsSearch = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
/** | ||
* Indexes for all substring searches (e.g. the term "cat" is indexed as "c", "ca", "cat", "a", "at", and "t"). | ||
*/ | ||
var AllSubstringsIndexStrategy = /*#__PURE__*/function () { | ||
function AllSubstringsIndexStrategy() {} | ||
var _proto = AllSubstringsIndexStrategy.prototype; | ||
/** | ||
* @inheritDocs | ||
*/ | ||
_proto.expandToken = function expandToken(token) { | ||
var expandedTokens = []; | ||
var string; | ||
for (var i = 0, length = token.length; i < length; ++i) { | ||
string = ''; | ||
for (var j = i; j < length; ++j) { | ||
string += token.charAt(j); | ||
expandedTokens.push(string); | ||
} | ||
// webpackBootstrap | ||
/******/ | ||
// The module cache | ||
/******/ | ||
var installedModules = {}; | ||
/******/ | ||
// Load entry module and return exports | ||
/******/ | ||
/******/ | ||
// expose the modules object (__webpack_modules__) | ||
/******/ | ||
/******/ | ||
// expose the module cache | ||
/******/ | ||
/******/ | ||
// identity function for calling harmony imports with the correct context | ||
/******/ | ||
/******/ | ||
// define getter function for harmony exports | ||
/******/ | ||
/******/ | ||
// getDefaultExport function for compatibility with non-harmony modules | ||
/******/ | ||
/******/ | ||
// Object.prototype.hasOwnProperty.call | ||
/******/ | ||
/******/ | ||
// __webpack_public_path__ | ||
/******/ | ||
return __webpack_require__.m = modules, __webpack_require__.c = installedModules, | ||
__webpack_require__.i = function(value) { | ||
return value; | ||
}, __webpack_require__.d = function(exports, name, getter) { | ||
/******/ | ||
__webpack_require__.o(exports, name) || /******/ | ||
Object.defineProperty(exports, name, { | ||
/******/ | ||
configurable: !1, | ||
/******/ | ||
enumerable: !0, | ||
/******/ | ||
get: getter | ||
}); | ||
}, __webpack_require__.n = function(module) { | ||
/******/ | ||
var getter = module && module.__esModule ? /******/ | ||
function() { | ||
return module.default; | ||
} : /******/ | ||
function() { | ||
return module; | ||
}; | ||
/******/ | ||
/******/ | ||
return __webpack_require__.d(getter, "a", getter), getter; | ||
}, __webpack_require__.o = function(object, property) { | ||
return Object.prototype.hasOwnProperty.call(object, property); | ||
}, __webpack_require__.p = "", __webpack_require__(__webpack_require__.s = 18); | ||
}([ /* 0 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _AllSubstringsIndexStrategy = __webpack_require__(8); | ||
Object.defineProperty(exports, "AllSubstringsIndexStrategy", { | ||
enumerable: !0, | ||
get: function() { | ||
return _AllSubstringsIndexStrategy.AllSubstringsIndexStrategy; | ||
} | ||
}); | ||
var _ExactWordIndexStrategy = __webpack_require__(9); | ||
Object.defineProperty(exports, "ExactWordIndexStrategy", { | ||
enumerable: !0, | ||
get: function() { | ||
return _ExactWordIndexStrategy.ExactWordIndexStrategy; | ||
} | ||
}); | ||
var _PrefixIndexStrategy = __webpack_require__(10); | ||
Object.defineProperty(exports, "PrefixIndexStrategy", { | ||
enumerable: !0, | ||
get: function() { | ||
return _PrefixIndexStrategy.PrefixIndexStrategy; | ||
} | ||
}); | ||
}, /* 1 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _CaseSensitiveSanitizer = __webpack_require__(11); | ||
Object.defineProperty(exports, "CaseSensitiveSanitizer", { | ||
enumerable: !0, | ||
get: function() { | ||
return _CaseSensitiveSanitizer.CaseSensitiveSanitizer; | ||
} | ||
}); | ||
var _LowerCaseSanitizer = __webpack_require__(12); | ||
Object.defineProperty(exports, "LowerCaseSanitizer", { | ||
enumerable: !0, | ||
get: function() { | ||
return _LowerCaseSanitizer.LowerCaseSanitizer; | ||
} | ||
}); | ||
}, /* 2 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _TfIdfSearchIndex = __webpack_require__(13); | ||
Object.defineProperty(exports, "TfIdfSearchIndex", { | ||
enumerable: !0, | ||
get: function() { | ||
return _TfIdfSearchIndex.TfIdfSearchIndex; | ||
} | ||
}); | ||
var _UnorderedSearchIndex = __webpack_require__(14); | ||
Object.defineProperty(exports, "UnorderedSearchIndex", { | ||
enumerable: !0, | ||
get: function() { | ||
return _UnorderedSearchIndex.UnorderedSearchIndex; | ||
} | ||
}); | ||
}, /* 3 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var StopWordsMap = exports.StopWordsMap = { | ||
a: !0, | ||
able: !0, | ||
about: !0, | ||
across: !0, | ||
after: !0, | ||
all: !0, | ||
almost: !0, | ||
also: !0, | ||
am: !0, | ||
among: !0, | ||
an: !0, | ||
and: !0, | ||
any: !0, | ||
are: !0, | ||
as: !0, | ||
at: !0, | ||
be: !0, | ||
because: !0, | ||
been: !0, | ||
but: !0, | ||
by: !0, | ||
can: !0, | ||
cannot: !0, | ||
could: !0, | ||
dear: !0, | ||
did: !0, | ||
do: !0, | ||
does: !0, | ||
either: !0, | ||
else: !0, | ||
ever: !0, | ||
every: !0, | ||
for: !0, | ||
from: !0, | ||
get: !0, | ||
got: !0, | ||
had: !0, | ||
has: !0, | ||
have: !0, | ||
he: !0, | ||
her: !0, | ||
hers: !0, | ||
him: !0, | ||
his: !0, | ||
how: !0, | ||
however: !0, | ||
i: !0, | ||
if: !0, | ||
in: !0, | ||
into: !0, | ||
is: !0, | ||
it: !0, | ||
its: !0, | ||
just: !0, | ||
least: !0, | ||
let: !0, | ||
like: !0, | ||
likely: !0, | ||
may: !0, | ||
me: !0, | ||
might: !0, | ||
most: !0, | ||
must: !0, | ||
my: !0, | ||
neither: !0, | ||
no: !0, | ||
nor: !0, | ||
not: !0, | ||
of: !0, | ||
off: !0, | ||
often: !0, | ||
on: !0, | ||
only: !0, | ||
or: !0, | ||
other: !0, | ||
our: !0, | ||
own: !0, | ||
rather: !0, | ||
said: !0, | ||
say: !0, | ||
says: !0, | ||
she: !0, | ||
should: !0, | ||
since: !0, | ||
so: !0, | ||
some: !0, | ||
than: !0, | ||
that: !0, | ||
the: !0, | ||
their: !0, | ||
them: !0, | ||
then: !0, | ||
there: !0, | ||
these: !0, | ||
they: !0, | ||
this: !0, | ||
tis: !0, | ||
to: !0, | ||
too: !0, | ||
twas: !0, | ||
us: !0, | ||
wants: !0, | ||
was: !0, | ||
we: !0, | ||
were: !0, | ||
what: !0, | ||
when: !0, | ||
where: !0, | ||
which: !0, | ||
while: !0, | ||
who: !0, | ||
whom: !0, | ||
why: !0, | ||
will: !0, | ||
with: !0, | ||
would: !0, | ||
yet: !0, | ||
you: !0, | ||
your: !0 | ||
}; | ||
// Prevent false positives for inherited properties | ||
StopWordsMap.constructor = !1, StopWordsMap.hasOwnProperty = !1, StopWordsMap.isPrototypeOf = !1, | ||
StopWordsMap.propertyIsEnumerable = !1, StopWordsMap.toLocaleString = !1, StopWordsMap.toString = !1, | ||
StopWordsMap.valueOf = !1; | ||
}, /* 4 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _SimpleTokenizer = __webpack_require__(15); | ||
Object.defineProperty(exports, "SimpleTokenizer", { | ||
enumerable: !0, | ||
get: function() { | ||
return _SimpleTokenizer.SimpleTokenizer; | ||
} | ||
}); | ||
var _StemmingTokenizer = __webpack_require__(16); | ||
Object.defineProperty(exports, "StemmingTokenizer", { | ||
enumerable: !0, | ||
get: function() { | ||
return _StemmingTokenizer.StemmingTokenizer; | ||
} | ||
}); | ||
var _StopWordsTokenizer = __webpack_require__(17); | ||
Object.defineProperty(exports, "StopWordsTokenizer", { | ||
enumerable: !0, | ||
get: function() { | ||
return _StopWordsTokenizer.StopWordsTokenizer; | ||
} | ||
}); | ||
}, /* 5 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
/** | ||
* Find and return a nested object value. | ||
* | ||
* @param object to crawl | ||
* @param path Property path | ||
* @returns {any} | ||
*/ | ||
function getNestedFieldValue(object, path) { | ||
path = path || [], object = object || {}; | ||
// walk down the property path | ||
for (var value = object, i = 0; i < path.length; i++) if (value = value[path[i]], | ||
null == value) return null; | ||
return value; | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}), exports.default = getNestedFieldValue; | ||
}, /* 6 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
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"); | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}), exports.Search = void 0; | ||
var _createClass = function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, | ||
"value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function(Constructor, protoProps, staticProps) { | ||
return protoProps && defineProperties(Constructor.prototype, protoProps), staticProps && defineProperties(Constructor, staticProps), | ||
Constructor; | ||
}; | ||
}(), _getNestedFieldValue = __webpack_require__(5), _getNestedFieldValue2 = _interopRequireDefault(_getNestedFieldValue), _index = __webpack_require__(0), _index2 = __webpack_require__(1), _index3 = __webpack_require__(2), _index4 = __webpack_require__(4); | ||
exports.Search = function() { | ||
/** | ||
* Constructor. | ||
* @param uidFieldName Field containing values that uniquely identify search documents; this field's values are used | ||
* to ensure that a search result set does not contain duplicate objects. | ||
} | ||
return expandedTokens; | ||
}; | ||
return AllSubstringsIndexStrategy; | ||
}(); | ||
/** | ||
* Indexes for exact word matches. | ||
*/ | ||
/** | ||
* Array containing either a property name or a path (list of property names) to a nested value | ||
var ExactWordIndexStrategy = /*#__PURE__*/function () { | ||
function ExactWordIndexStrategy() {} | ||
var _proto = ExactWordIndexStrategy.prototype; | ||
/** | ||
* @inheritDocs | ||
*/ | ||
_proto.expandToken = function expandToken(token) { | ||
return token ? [token] : []; | ||
}; | ||
return ExactWordIndexStrategy; | ||
}(); | ||
/** | ||
* Indexes for prefix searches (e.g. the term "cat" is indexed as "c", "ca", and "cat" allowing prefix search lookups). | ||
*/ | ||
function Search(uidFieldName) { | ||
if (_classCallCheck(this, Search), !uidFieldName) throw Error("js-search requires a uid field name constructor parameter"); | ||
this._uidFieldName = uidFieldName, // Set default/recommended strategies | ||
this._indexStrategy = new _index.PrefixIndexStrategy(), this._searchIndex = new _index3.TfIdfSearchIndex(uidFieldName), | ||
this._sanitizer = new _index2.LowerCaseSanitizer(), this._tokenizer = new _index4.SimpleTokenizer(), | ||
this._documents = [], this._searchableFields = []; | ||
} | ||
/** | ||
* Override the default index strategy. | ||
* @param value Custom index strategy | ||
* @throws Error if documents have already been indexed by this search instance | ||
var PrefixIndexStrategy = /*#__PURE__*/function () { | ||
function PrefixIndexStrategy() {} | ||
var _proto = PrefixIndexStrategy.prototype; | ||
/** | ||
* @inheritDocs | ||
*/ | ||
_proto.expandToken = function expandToken(token) { | ||
var expandedTokens = []; | ||
var string = ''; | ||
for (var i = 0, length = token.length; i < length; ++i) { | ||
string += token.charAt(i); | ||
expandedTokens.push(string); | ||
} | ||
return expandedTokens; | ||
}; | ||
return PrefixIndexStrategy; | ||
}(); | ||
/** | ||
* Enforces case-sensitive text matches. | ||
*/ | ||
return _createClass(Search, [ { | ||
key: "addDocument", | ||
/** | ||
* Add a searchable document to the index. Document will automatically be indexed for search. | ||
* @param document | ||
var CaseSensitiveSanitizer = /*#__PURE__*/function () { | ||
function CaseSensitiveSanitizer() {} | ||
var _proto = CaseSensitiveSanitizer.prototype; | ||
/** | ||
* @inheritDocs | ||
*/ | ||
value: function(document) { | ||
this.addDocuments([ document ]); | ||
} | ||
}, { | ||
key: "addDocuments", | ||
value: function(documents) { | ||
this._documents = this._documents.concat(documents), this.indexDocuments_(documents, this._searchableFields); | ||
} | ||
}, { | ||
key: "addIndex", | ||
value: function(field) { | ||
this._searchableFields.push(field), this.indexDocuments_(this._documents, [ field ]); | ||
} | ||
}, { | ||
key: "search", | ||
value: function(query) { | ||
var tokens = this._tokenizer.tokenize(this._sanitizer.sanitize(query)); | ||
return this._searchIndex.search(tokens, this._documents); | ||
} | ||
}, { | ||
key: "indexDocuments_", | ||
value: function(documents, _searchableFields) { | ||
this._initialized = !0; | ||
for (var indexStrategy = this._indexStrategy, sanitizer = this._sanitizer, searchIndex = this._searchIndex, tokenizer = this._tokenizer, uidFieldName = this._uidFieldName, di = 0, numDocuments = documents.length; di < numDocuments; di++) { | ||
var uid, doc = documents[di]; | ||
uid = uidFieldName instanceof Array ? (0, _getNestedFieldValue2.default)(doc, uidFieldName) : doc[uidFieldName]; | ||
for (var sfi = 0, numSearchableFields = _searchableFields.length; sfi < numSearchableFields; sfi++) { | ||
var fieldValue, searchableField = _searchableFields[sfi]; | ||
if (fieldValue = searchableField instanceof Array ? (0, _getNestedFieldValue2.default)(doc, searchableField) : doc[searchableField], | ||
null != fieldValue && "string" != typeof fieldValue && fieldValue.toString && (fieldValue = fieldValue.toString()), | ||
"string" == typeof fieldValue) for (var fieldTokens = tokenizer.tokenize(sanitizer.sanitize(fieldValue)), fti = 0, numFieldValues = fieldTokens.length; fti < numFieldValues; fti++) for (var fieldToken = fieldTokens[fti], expandedTokens = indexStrategy.expandToken(fieldToken), eti = 0, nummExpandedTokens = expandedTokens.length; eti < nummExpandedTokens; eti++) { | ||
var expandedToken = expandedTokens[eti]; | ||
searchIndex.indexDocument(expandedToken, uid, doc); | ||
} | ||
} | ||
} | ||
} | ||
}, { | ||
key: "indexStrategy", | ||
set: function(value) { | ||
if (this._initialized) throw Error("IIndexStrategy cannot be set after initialization"); | ||
this._indexStrategy = value; | ||
}, | ||
get: function() { | ||
return this._indexStrategy; | ||
} | ||
}, { | ||
key: "sanitizer", | ||
set: function(value) { | ||
if (this._initialized) throw Error("ISanitizer cannot be set after initialization"); | ||
this._sanitizer = value; | ||
}, | ||
get: function() { | ||
return this._sanitizer; | ||
} | ||
}, { | ||
key: "searchIndex", | ||
set: function(value) { | ||
if (this._initialized) throw Error("ISearchIndex cannot be set after initialization"); | ||
this._searchIndex = value; | ||
}, | ||
get: function() { | ||
return this._searchIndex; | ||
} | ||
}, { | ||
key: "tokenizer", | ||
set: function(value) { | ||
if (this._initialized) throw Error("ITokenizer cannot be set after initialization"); | ||
this._tokenizer = value; | ||
}, | ||
get: function() { | ||
return this._tokenizer; | ||
} | ||
} ]), Search; | ||
}(); | ||
}, /* 7 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}), exports.TokenHighlighter = void 0; | ||
var _createClass = function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, | ||
"value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function(Constructor, protoProps, staticProps) { | ||
return protoProps && defineProperties(Constructor.prototype, protoProps), staticProps && defineProperties(Constructor, staticProps), | ||
Constructor; | ||
}; | ||
}(), _index = __webpack_require__(0), _index2 = __webpack_require__(1); | ||
exports.TokenHighlighter = function() { | ||
/** | ||
* Constructor. | ||
* | ||
* @param opt_indexStrategy Index strategy used by Search | ||
* @param opt_sanitizer Sanitizer used by Search | ||
* @param opt_wrapperTagName Optional wrapper tag name; defaults to 'mark' (e.g. <mark>) | ||
_proto.sanitize = function sanitize(text) { | ||
return text ? text.trim() : ''; | ||
}; | ||
return CaseSensitiveSanitizer; | ||
}(); | ||
/** | ||
* Sanitizes text by converting to a locale-friendly lower-case version and triming leading and trailing whitespace. | ||
*/ | ||
function TokenHighlighter(opt_indexStrategy, opt_sanitizer, opt_wrapperTagName) { | ||
_classCallCheck(this, TokenHighlighter), this._indexStrategy = opt_indexStrategy || new _index.PrefixIndexStrategy(), | ||
this._sanitizer = opt_sanitizer || new _index2.LowerCaseSanitizer(), this._wrapperTagName = opt_wrapperTagName || "mark"; | ||
} | ||
/** | ||
* Highlights token occurrences within a string by wrapping them with a DOM element. | ||
var LowerCaseSanitizer = /*#__PURE__*/function () { | ||
function LowerCaseSanitizer() {} | ||
var _proto = LowerCaseSanitizer.prototype; | ||
/** | ||
* @inheritDocs | ||
*/ | ||
_proto.sanitize = function sanitize(text) { | ||
return text ? text.toLocaleLowerCase().trim() : ''; | ||
}; | ||
return LowerCaseSanitizer; | ||
}(); | ||
/** | ||
* Find and return a nested object value. | ||
* | ||
* @param text e.g. "john wayne" | ||
* @param tokens e.g. ["wa"] | ||
* @returns {string} e.g. "john <mark>wa</mark>yne" | ||
* @param object to crawl | ||
* @param path Property path | ||
* @returns {any} | ||
*/ | ||
return _createClass(TokenHighlighter, [ { | ||
key: "highlight", | ||
value: function(text, tokens) { | ||
// Create a token map for easier lookup below. | ||
for (var tagsLength = this._wrapText("").length, tokenDictionary = Object.create(null), i = 0, numTokens = tokens.length; i < numTokens; i++) for (var token = this._sanitizer.sanitize(tokens[i]), expandedTokens = this._indexStrategy.expandToken(token), j = 0, numExpandedTokens = expandedTokens.length; j < numExpandedTokens; j++) { | ||
var expandedToken = expandedTokens[j]; | ||
tokenDictionary[expandedToken] ? tokenDictionary[expandedToken].push(token) : tokenDictionary[expandedToken] = [ token ]; | ||
} | ||
// Note this assumes either prefix or full word matching. | ||
for (var actualCurrentWord = "", sanitizedCurrentWord = "", currentWordStartIndex = 0, i = 0, textLength = text.length; i < textLength; i++) { | ||
var character = text.charAt(i); | ||
" " === character ? (actualCurrentWord = "", sanitizedCurrentWord = "", currentWordStartIndex = i + 1) : (actualCurrentWord += character, | ||
sanitizedCurrentWord += this._sanitizer.sanitize(character)), tokenDictionary[sanitizedCurrentWord] && tokenDictionary[sanitizedCurrentWord].indexOf(sanitizedCurrentWord) >= 0 && (actualCurrentWord = this._wrapText(actualCurrentWord), | ||
text = text.substring(0, currentWordStartIndex) + actualCurrentWord + text.substring(i + 1), | ||
i += tagsLength, textLength += tagsLength); | ||
} | ||
return text; | ||
} | ||
}, { | ||
key: "_wrapText", | ||
value: function(text) { | ||
var tagName = this._wrapperTagName; | ||
return "<" + tagName + ">" + text + "</" + tagName + ">"; | ||
} | ||
} ]), TokenHighlighter; | ||
}(); | ||
}, /* 8 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _createClass = function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, | ||
"value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function(Constructor, protoProps, staticProps) { | ||
return protoProps && defineProperties(Constructor.prototype, protoProps), staticProps && defineProperties(Constructor, staticProps), | ||
Constructor; | ||
}; | ||
}(); | ||
exports.AllSubstringsIndexStrategy = function() { | ||
function AllSubstringsIndexStrategy() { | ||
_classCallCheck(this, AllSubstringsIndexStrategy); | ||
} | ||
return _createClass(AllSubstringsIndexStrategy, [ { | ||
key: "expandToken", | ||
/** | ||
function getNestedFieldValue(object, path) { | ||
path = path || []; | ||
object = object || {}; | ||
var value = object; // walk down the property path | ||
for (var i = 0; i < path.length; i++) { | ||
value = value[path[i]]; | ||
if (value == null) { | ||
return null; | ||
} | ||
} | ||
return value; | ||
} | ||
/** | ||
* Search index capable of returning results matching a set of tokens and ranked according to TF-IDF. | ||
*/ | ||
var TfIdfSearchIndex = /*#__PURE__*/function () { | ||
function TfIdfSearchIndex(uidFieldName) { | ||
this._uidFieldName = uidFieldName; | ||
this._tokenToIdfCache = {}; | ||
this._tokenMap = {}; | ||
} | ||
/** | ||
* @inheritDocs | ||
*/ | ||
value: function(token) { | ||
for (var string, expandedTokens = [], i = 0, length = token.length; i < length; ++i) { | ||
string = ""; | ||
for (var j = i; j < length; ++j) string += token.charAt(j), expandedTokens.push(string); | ||
} | ||
return expandedTokens; | ||
} | ||
} ]), AllSubstringsIndexStrategy; | ||
}(); | ||
}, /* 9 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _createClass = function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, | ||
"value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function(Constructor, protoProps, staticProps) { | ||
return protoProps && defineProperties(Constructor.prototype, protoProps), staticProps && defineProperties(Constructor, staticProps), | ||
Constructor; | ||
}; | ||
}(); | ||
exports.ExactWordIndexStrategy = function() { | ||
function ExactWordIndexStrategy() { | ||
_classCallCheck(this, ExactWordIndexStrategy); | ||
} | ||
return _createClass(ExactWordIndexStrategy, [ { | ||
key: "expandToken", | ||
/** | ||
var _proto = TfIdfSearchIndex.prototype; | ||
_proto.indexDocument = function indexDocument(token, uid, doc) { | ||
this._tokenToIdfCache = {}; // New index invalidates previous IDF caches | ||
var tokenMap = this._tokenMap; | ||
var tokenDatum; | ||
if (typeof tokenMap[token] !== 'object') { | ||
tokenMap[token] = tokenDatum = { | ||
$numDocumentOccurrences: 0, | ||
$totalNumOccurrences: 1, | ||
$uidMap: {} | ||
}; | ||
} else { | ||
tokenDatum = tokenMap[token]; | ||
tokenDatum.$totalNumOccurrences++; | ||
} | ||
var uidMap = tokenDatum.$uidMap; | ||
if (typeof uidMap[uid] !== 'object') { | ||
tokenDatum.$numDocumentOccurrences++; | ||
uidMap[uid] = { | ||
$document: doc, | ||
$numTokenOccurrences: 1 | ||
}; | ||
} else { | ||
uidMap[uid].$numTokenOccurrences++; | ||
} | ||
} | ||
/** | ||
* @inheritDocs | ||
*/ | ||
value: function(token) { | ||
return token ? [ token ] : []; | ||
} | ||
} ]), ExactWordIndexStrategy; | ||
}(); | ||
}, /* 10 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
; | ||
_proto.search = function search(tokens, corpus) { | ||
var uidToDocumentMap = {}; | ||
for (var i = 0, numTokens = tokens.length; i < numTokens; i++) { | ||
var token = tokens[i]; | ||
var tokenMetadata = this._tokenMap[token]; // Short circuit if no matches were found for any given token. | ||
if (!tokenMetadata) { | ||
return []; | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _createClass = function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, | ||
"value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
if (i === 0) { | ||
var keys = Object.keys(tokenMetadata.$uidMap); | ||
for (var j = 0, numKeys = keys.length; j < numKeys; j++) { | ||
var uid = keys[j]; | ||
uidToDocumentMap[uid] = tokenMetadata.$uidMap[uid].$document; | ||
} | ||
} else { | ||
var keys = Object.keys(uidToDocumentMap); | ||
for (var j = 0, numKeys = keys.length; j < numKeys; j++) { | ||
var uid = keys[j]; | ||
if (typeof tokenMetadata.$uidMap[uid] !== 'object') { | ||
delete uidToDocumentMap[uid]; | ||
} | ||
return function(Constructor, protoProps, staticProps) { | ||
return protoProps && defineProperties(Constructor.prototype, protoProps), staticProps && defineProperties(Constructor, staticProps), | ||
Constructor; | ||
}; | ||
}(); | ||
exports.PrefixIndexStrategy = function() { | ||
function PrefixIndexStrategy() { | ||
_classCallCheck(this, PrefixIndexStrategy); | ||
} | ||
return _createClass(PrefixIndexStrategy, [ { | ||
key: "expandToken", | ||
/** | ||
} | ||
} | ||
} | ||
var documents = []; | ||
for (var uid in uidToDocumentMap) { | ||
documents.push(uidToDocumentMap[uid]); | ||
} | ||
var calculateTfIdf = this._createCalculateTfIdf(); // Return documents sorted by TF-IDF | ||
return documents.sort(function (documentA, documentB) { | ||
return calculateTfIdf(tokens, documentB, corpus) - calculateTfIdf(tokens, documentA, corpus); | ||
}); | ||
}; | ||
_proto._createCalculateIdf = function _createCalculateIdf() { | ||
var tokenMap = this._tokenMap; | ||
var tokenToIdfCache = this._tokenToIdfCache; | ||
return function calculateIdf(token, documents) { | ||
if (!tokenToIdfCache[token]) { | ||
var numDocumentsWithToken = typeof tokenMap[token] !== 'undefined' ? tokenMap[token].$numDocumentOccurrences : 0; | ||
tokenToIdfCache[token] = 1 + Math.log(documents.length / (1 + numDocumentsWithToken)); | ||
} | ||
return tokenToIdfCache[token]; | ||
}; | ||
}; | ||
_proto._createCalculateTfIdf = function _createCalculateTfIdf() { | ||
var tokenMap = this._tokenMap; | ||
var uidFieldName = this._uidFieldName; | ||
var calculateIdf = this._createCalculateIdf(); | ||
return function calculateTfIdf(tokens, document, documents) { | ||
var score = 0; | ||
for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) { | ||
var token = tokens[i]; | ||
var inverseDocumentFrequency = calculateIdf(token, documents); | ||
if (inverseDocumentFrequency === Infinity) { | ||
inverseDocumentFrequency = 0; | ||
} | ||
var uid; | ||
if (uidFieldName instanceof Array) { | ||
uid = document && getNestedFieldValue(document, uidFieldName); | ||
} else { | ||
uid = document && document[uidFieldName]; | ||
} | ||
var termFrequency = typeof tokenMap[token] !== 'undefined' && typeof tokenMap[token].$uidMap[uid] !== 'undefined' ? tokenMap[token].$uidMap[uid].$numTokenOccurrences : 0; | ||
score += termFrequency * inverseDocumentFrequency; | ||
} | ||
return score; | ||
}; | ||
}; | ||
return TfIdfSearchIndex; | ||
}(); | ||
/** | ||
* Search index capable of returning results matching a set of tokens but without any meaningful rank or order. | ||
*/ | ||
var UnorderedSearchIndex = /*#__PURE__*/function () { | ||
function UnorderedSearchIndex() { | ||
this._tokenToUidToDocumentMap = {}; | ||
} | ||
/** | ||
* @inheritDocs | ||
*/ | ||
value: function(token) { | ||
for (var expandedTokens = [], string = "", i = 0, length = token.length; i < length; ++i) string += token.charAt(i), | ||
expandedTokens.push(string); | ||
return expandedTokens; | ||
} | ||
} ]), PrefixIndexStrategy; | ||
}(); | ||
}, /* 11 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _createClass = function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, | ||
"value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function(Constructor, protoProps, staticProps) { | ||
return protoProps && defineProperties(Constructor.prototype, protoProps), staticProps && defineProperties(Constructor, staticProps), | ||
Constructor; | ||
}; | ||
}(); | ||
exports.CaseSensitiveSanitizer = function() { | ||
function CaseSensitiveSanitizer() { | ||
_classCallCheck(this, CaseSensitiveSanitizer); | ||
} | ||
return _createClass(CaseSensitiveSanitizer, [ { | ||
key: "sanitize", | ||
/** | ||
var _proto = UnorderedSearchIndex.prototype; | ||
_proto.indexDocument = function indexDocument(token, uid, doc) { | ||
if (typeof this._tokenToUidToDocumentMap[token] !== 'object') { | ||
this._tokenToUidToDocumentMap[token] = {}; | ||
} | ||
this._tokenToUidToDocumentMap[token][uid] = doc; | ||
} | ||
/** | ||
* @inheritDocs | ||
*/ | ||
value: function(text) { | ||
return text ? text.trim() : ""; | ||
} | ||
} ]), CaseSensitiveSanitizer; | ||
}(); | ||
}, /* 12 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
; | ||
_proto.search = function search(tokens, corpus) { | ||
var intersectingDocumentMap = {}; | ||
var tokenToUidToDocumentMap = this._tokenToUidToDocumentMap; | ||
for (var i = 0, numTokens = tokens.length; i < numTokens; i++) { | ||
var token = tokens[i]; | ||
var documentMap = tokenToUidToDocumentMap[token]; // Short circuit if no matches were found for any given token. | ||
if (!documentMap) { | ||
return []; | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _createClass = function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, | ||
"value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
if (i === 0) { | ||
var keys = Object.keys(documentMap); | ||
for (var j = 0, numKeys = keys.length; j < numKeys; j++) { | ||
var uid = keys[j]; | ||
intersectingDocumentMap[uid] = documentMap[uid]; | ||
} | ||
} else { | ||
var keys = Object.keys(intersectingDocumentMap); | ||
for (var j = 0, numKeys = keys.length; j < numKeys; j++) { | ||
var uid = keys[j]; | ||
if (typeof documentMap[uid] !== 'object') { | ||
delete intersectingDocumentMap[uid]; | ||
} | ||
return function(Constructor, protoProps, staticProps) { | ||
return protoProps && defineProperties(Constructor.prototype, protoProps), staticProps && defineProperties(Constructor, staticProps), | ||
Constructor; | ||
}; | ||
}(); | ||
exports.LowerCaseSanitizer = function() { | ||
function LowerCaseSanitizer() { | ||
_classCallCheck(this, LowerCaseSanitizer); | ||
} | ||
return _createClass(LowerCaseSanitizer, [ { | ||
key: "sanitize", | ||
/** | ||
} | ||
} | ||
} | ||
var keys = Object.keys(intersectingDocumentMap); | ||
var documents = []; | ||
for (var i = 0, numKeys = keys.length; i < numKeys; i++) { | ||
var uid = keys[i]; | ||
documents.push(intersectingDocumentMap[uid]); | ||
} | ||
return documents; | ||
}; | ||
return UnorderedSearchIndex; | ||
}(); | ||
var REGEX = /[^a-zа-яё0-9\-']+/i; | ||
/** | ||
* Simple tokenizer that splits strings on whitespace characters and returns an array of all non-empty substrings. | ||
*/ | ||
var SimpleTokenizer = /*#__PURE__*/function () { | ||
function SimpleTokenizer() {} | ||
var _proto = SimpleTokenizer.prototype; | ||
/** | ||
* @inheritDocs | ||
*/ | ||
value: function(text) { | ||
return text ? text.toLocaleLowerCase().trim() : ""; | ||
} | ||
} ]), LowerCaseSanitizer; | ||
}(); | ||
}, /* 13 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
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"); | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}), exports.TfIdfSearchIndex = void 0; | ||
var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) { | ||
return typeof obj; | ||
} : function(obj) { | ||
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}, _createClass = function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, | ||
"value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function(Constructor, protoProps, staticProps) { | ||
return protoProps && defineProperties(Constructor.prototype, protoProps), staticProps && defineProperties(Constructor, staticProps), | ||
Constructor; | ||
}; | ||
}(), _getNestedFieldValue = __webpack_require__(5), _getNestedFieldValue2 = _interopRequireDefault(_getNestedFieldValue); | ||
exports.TfIdfSearchIndex = function() { | ||
function TfIdfSearchIndex(uidFieldName) { | ||
_classCallCheck(this, TfIdfSearchIndex), this._uidFieldName = uidFieldName, this._tokenToIdfCache = {}, | ||
this._tokenMap = {}; | ||
} | ||
/** | ||
* @inheritDocs | ||
_proto.tokenize = function tokenize(text) { | ||
return text.split(REGEX).filter(function (text) { | ||
return text; | ||
} // Filter empty tokens | ||
); | ||
}; | ||
return SimpleTokenizer; | ||
}(); | ||
/** | ||
* Stemming is the process of reducing search tokens to their root (or stem) so that searches for different forms of a | ||
* word will match. For example "search", "searching" and "searched" are all reduced to the stem "search". | ||
* | ||
* <p>This stemming tokenizer converts tokens (words) to their stem forms before returning them. It requires an | ||
* external stemming function to be provided; for this purpose I recommend the NPM 'porter-stemmer' library. | ||
* | ||
* <p>For more information see http : //tartarus.org/~martin/PorterStemmer/ | ||
*/ | ||
return _createClass(TfIdfSearchIndex, [ { | ||
key: "indexDocument", | ||
value: function(token, uid, doc) { | ||
this._tokenToIdfCache = {}; | ||
// New index invalidates previous IDF caches | ||
var tokenDatum, tokenMap = this._tokenMap; | ||
"object" !== _typeof(tokenMap[token]) ? tokenMap[token] = tokenDatum = { | ||
$numDocumentOccurrences: 0, | ||
$totalNumOccurrences: 1, | ||
$uidMap: {} | ||
} : (tokenDatum = tokenMap[token], tokenDatum.$totalNumOccurrences++); | ||
var uidMap = tokenDatum.$uidMap; | ||
"object" !== _typeof(uidMap[uid]) ? (tokenDatum.$numDocumentOccurrences++, uidMap[uid] = { | ||
$document: doc, | ||
$numTokenOccurrences: 1 | ||
}) : uidMap[uid].$numTokenOccurrences++; | ||
} | ||
}, { | ||
key: "search", | ||
value: function(tokens, corpus) { | ||
for (var uidToDocumentMap = {}, i = 0, numTokens = tokens.length; i < numTokens; i++) { | ||
var token = tokens[i], tokenMetadata = this._tokenMap[token]; | ||
// Short circuit if no matches were found for any given token. | ||
if (!tokenMetadata) return []; | ||
if (0 === i) for (var keys = Object.keys(tokenMetadata.$uidMap), j = 0, numKeys = keys.length; j < numKeys; j++) { | ||
var uid = keys[j]; | ||
uidToDocumentMap[uid] = tokenMetadata.$uidMap[uid].$document; | ||
} else for (var keys = Object.keys(uidToDocumentMap), j = 0, numKeys = keys.length; j < numKeys; j++) { | ||
var uid = keys[j]; | ||
"object" !== _typeof(tokenMetadata.$uidMap[uid]) && delete uidToDocumentMap[uid]; | ||
} | ||
} | ||
var documents = []; | ||
for (var uid in uidToDocumentMap) documents.push(uidToDocumentMap[uid]); | ||
var calculateTfIdf = this._createCalculateTfIdf(); | ||
// Return documents sorted by TF-IDF | ||
return documents.sort(function(documentA, documentB) { | ||
return calculateTfIdf(tokens, documentB, corpus) - calculateTfIdf(tokens, documentA, corpus); | ||
}); | ||
} | ||
}, { | ||
key: "_createCalculateIdf", | ||
value: function() { | ||
var tokenMap = this._tokenMap, tokenToIdfCache = this._tokenToIdfCache; | ||
return function(token, documents) { | ||
if (!tokenToIdfCache[token]) { | ||
var numDocumentsWithToken = "undefined" != typeof tokenMap[token] ? tokenMap[token].$numDocumentOccurrences : 0; | ||
tokenToIdfCache[token] = 1 + Math.log(documents.length / (1 + numDocumentsWithToken)); | ||
} | ||
return tokenToIdfCache[token]; | ||
}; | ||
} | ||
}, { | ||
key: "_createCalculateTfIdf", | ||
value: function() { | ||
var tokenMap = this._tokenMap, uidFieldName = this._uidFieldName, calculateIdf = this._createCalculateIdf(); | ||
return function(tokens, document, documents) { | ||
for (var score = 0, i = 0, numTokens = tokens.length; i < numTokens; ++i) { | ||
var token = tokens[i], inverseDocumentFrequency = calculateIdf(token, documents); | ||
inverseDocumentFrequency === 1 / 0 && (inverseDocumentFrequency = 0); | ||
var uid; | ||
uid = uidFieldName instanceof Array ? document && (0, _getNestedFieldValue2.default)(document, uidFieldName) : document && document[uidFieldName]; | ||
var termFrequency = "undefined" != typeof tokenMap[token] && "undefined" != typeof tokenMap[token].$uidMap[uid] ? tokenMap[token].$uidMap[uid].$numTokenOccurrences : 0; | ||
score += termFrequency * inverseDocumentFrequency; | ||
} | ||
return score; | ||
}; | ||
} | ||
} ]), TfIdfSearchIndex; | ||
}(); | ||
}, /* 14 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) { | ||
return typeof obj; | ||
} : function(obj) { | ||
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}, _createClass = function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, | ||
"value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function(Constructor, protoProps, staticProps) { | ||
return protoProps && defineProperties(Constructor.prototype, protoProps), staticProps && defineProperties(Constructor, staticProps), | ||
Constructor; | ||
}; | ||
}(); | ||
exports.UnorderedSearchIndex = function() { | ||
function UnorderedSearchIndex() { | ||
_classCallCheck(this, UnorderedSearchIndex), this._tokenToUidToDocumentMap = {}; | ||
} | ||
/** | ||
* @inheritDocs | ||
var StemmingTokenizer = /*#__PURE__*/function () { | ||
/** | ||
* Constructor. | ||
* | ||
* @param stemmingFunction Function capable of accepting a word and returning its stem. | ||
* @param decoratedIndexStrategy Index strategy to be run after all stop words have been removed. | ||
*/ | ||
function StemmingTokenizer(stemmingFunction, decoratedTokenizer) { | ||
this._stemmingFunction = stemmingFunction; | ||
this._tokenizer = decoratedTokenizer; | ||
} | ||
/** | ||
* @inheritDocs | ||
*/ | ||
var _proto = StemmingTokenizer.prototype; | ||
_proto.tokenize = function tokenize(text) { | ||
return this._tokenizer.tokenize(text).map(this._stemmingFunction); | ||
}; | ||
return StemmingTokenizer; | ||
}(); | ||
/** | ||
* Stop words list copied from Lunr JS. | ||
*/ | ||
return _createClass(UnorderedSearchIndex, [ { | ||
key: "indexDocument", | ||
value: function(token, uid, doc) { | ||
"object" !== _typeof(this._tokenToUidToDocumentMap[token]) && (this._tokenToUidToDocumentMap[token] = {}), | ||
this._tokenToUidToDocumentMap[token][uid] = doc; | ||
} | ||
}, { | ||
key: "search", | ||
value: function(tokens, corpus) { | ||
for (var intersectingDocumentMap = {}, tokenToUidToDocumentMap = this._tokenToUidToDocumentMap, i = 0, numTokens = tokens.length; i < numTokens; i++) { | ||
var token = tokens[i], documentMap = tokenToUidToDocumentMap[token]; | ||
// Short circuit if no matches were found for any given token. | ||
if (!documentMap) return []; | ||
if (0 === i) for (var keys = Object.keys(documentMap), j = 0, numKeys = keys.length; j < numKeys; j++) { | ||
var uid = keys[j]; | ||
intersectingDocumentMap[uid] = documentMap[uid]; | ||
} else for (var keys = Object.keys(intersectingDocumentMap), j = 0, numKeys = keys.length; j < numKeys; j++) { | ||
var uid = keys[j]; | ||
"object" !== _typeof(documentMap[uid]) && delete intersectingDocumentMap[uid]; | ||
} | ||
} | ||
for (var keys = Object.keys(intersectingDocumentMap), documents = [], i = 0, numKeys = keys.length; i < numKeys; i++) { | ||
var uid = keys[i]; | ||
documents.push(intersectingDocumentMap[uid]); | ||
} | ||
return documents; | ||
} | ||
} ]), UnorderedSearchIndex; | ||
}(); | ||
}, /* 15 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _createClass = function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, | ||
"value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function(Constructor, protoProps, staticProps) { | ||
return protoProps && defineProperties(Constructor.prototype, protoProps), staticProps && defineProperties(Constructor, staticProps), | ||
Constructor; | ||
}; | ||
}(), REGEX = /[^a-zа-яё0-9\-']+/i; | ||
exports.SimpleTokenizer = function() { | ||
function SimpleTokenizer() { | ||
_classCallCheck(this, SimpleTokenizer); | ||
} | ||
return _createClass(SimpleTokenizer, [ { | ||
key: "tokenize", | ||
/** | ||
var StopWordsMap = { | ||
a: true, | ||
able: true, | ||
about: true, | ||
across: true, | ||
after: true, | ||
all: true, | ||
almost: true, | ||
also: true, | ||
am: true, | ||
among: true, | ||
an: true, | ||
and: true, | ||
any: true, | ||
are: true, | ||
as: true, | ||
at: true, | ||
be: true, | ||
because: true, | ||
been: true, | ||
but: true, | ||
by: true, | ||
can: true, | ||
cannot: true, | ||
could: true, | ||
dear: true, | ||
did: true, | ||
'do': true, | ||
does: true, | ||
either: true, | ||
'else': true, | ||
ever: true, | ||
every: true, | ||
'for': true, | ||
from: true, | ||
'get': true, | ||
got: true, | ||
had: true, | ||
has: true, | ||
have: true, | ||
he: true, | ||
her: true, | ||
hers: true, | ||
him: true, | ||
his: true, | ||
how: true, | ||
however: true, | ||
i: true, | ||
'if': true, | ||
'in': true, | ||
into: true, | ||
is: true, | ||
it: true, | ||
its: true, | ||
just: true, | ||
least: true, | ||
"let": true, | ||
like: true, | ||
likely: true, | ||
may: true, | ||
me: true, | ||
might: true, | ||
most: true, | ||
must: true, | ||
my: true, | ||
neither: true, | ||
no: true, | ||
nor: true, | ||
not: true, | ||
of: true, | ||
off: true, | ||
often: true, | ||
on: true, | ||
only: true, | ||
or: true, | ||
other: true, | ||
our: true, | ||
own: true, | ||
rather: true, | ||
said: true, | ||
say: true, | ||
says: true, | ||
she: true, | ||
should: true, | ||
since: true, | ||
so: true, | ||
some: true, | ||
than: true, | ||
that: true, | ||
the: true, | ||
their: true, | ||
them: true, | ||
then: true, | ||
there: true, | ||
these: true, | ||
they: true, | ||
'this': true, | ||
tis: true, | ||
to: true, | ||
too: true, | ||
twas: true, | ||
us: true, | ||
wants: true, | ||
was: true, | ||
we: true, | ||
were: true, | ||
what: true, | ||
when: true, | ||
where: true, | ||
which: true, | ||
'while': true, | ||
who: true, | ||
whom: true, | ||
why: true, | ||
will: true, | ||
'with': true, | ||
would: true, | ||
yet: true, | ||
you: true, | ||
your: true | ||
}; // Prevent false positives for inherited properties | ||
StopWordsMap.constructor = false; | ||
StopWordsMap.hasOwnProperty = false; | ||
StopWordsMap.isPrototypeOf = false; | ||
StopWordsMap.propertyIsEnumerable = false; | ||
StopWordsMap.toLocaleString = false; | ||
StopWordsMap.toString = false; | ||
StopWordsMap.valueOf = false; | ||
/** | ||
* Stop words are very common (e.g. "a", "and", "the") and are often not semantically meaningful in the context of a | ||
* search. This tokenizer removes stop words from a set of tokens before passing the remaining tokens along for | ||
* indexing or searching purposes. | ||
*/ | ||
var StopWordsTokenizer = /*#__PURE__*/function () { | ||
/** | ||
* Constructor. | ||
* | ||
* @param decoratedIndexStrategy Index strategy to be run after all stop words have been removed. | ||
*/ | ||
function StopWordsTokenizer(decoratedTokenizer) { | ||
this._tokenizer = decoratedTokenizer; | ||
} | ||
/** | ||
* @inheritDocs | ||
*/ | ||
value: function(text) { | ||
return text.split(REGEX).filter(function(text) { | ||
return text; | ||
}); | ||
} | ||
} ]), SimpleTokenizer; | ||
}(); | ||
}, /* 16 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _createClass = function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, | ||
"value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function(Constructor, protoProps, staticProps) { | ||
return protoProps && defineProperties(Constructor.prototype, protoProps), staticProps && defineProperties(Constructor, staticProps), | ||
Constructor; | ||
}; | ||
}(); | ||
exports.StemmingTokenizer = function() { | ||
/** | ||
* Constructor. | ||
var _proto = StopWordsTokenizer.prototype; | ||
_proto.tokenize = function tokenize(text) { | ||
return this._tokenizer.tokenize(text).filter(function (token) { | ||
return !StopWordsMap[token]; | ||
}); | ||
}; | ||
return StopWordsTokenizer; | ||
}(); | ||
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); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
/** | ||
* Simple client-side searching within a set of documents. | ||
* | ||
* @param stemmingFunction Function capable of accepting a word and returning its stem. | ||
* @param decoratedIndexStrategy Index strategy to be run after all stop words have been removed. | ||
* <p>Documents can be searched by any number of fields. Indexing and search strategies are highly customizable. | ||
*/ | ||
function StemmingTokenizer(stemmingFunction, decoratedTokenizer) { | ||
_classCallCheck(this, StemmingTokenizer), this._stemmingFunction = stemmingFunction, | ||
this._tokenizer = decoratedTokenizer; | ||
var Search = /*#__PURE__*/function () { | ||
/** | ||
* Array containing either a property name or a path (list of property names) to a nested value | ||
*/ | ||
/** | ||
* Constructor. | ||
* @param uidFieldName Field containing values that uniquely identify search documents; this field's values are used | ||
* to ensure that a search result set does not contain duplicate objects. | ||
*/ | ||
function Search(uidFieldName) { | ||
if (!uidFieldName) { | ||
throw Error('js-search requires a uid field name constructor parameter'); | ||
} | ||
this._uidFieldName = uidFieldName; // Set default/recommended strategies | ||
this._indexStrategy = new PrefixIndexStrategy(); | ||
this._searchIndex = new TfIdfSearchIndex(uidFieldName); | ||
this._sanitizer = new LowerCaseSanitizer(); | ||
this._tokenizer = new SimpleTokenizer(); | ||
this._documents = []; | ||
this._searchableFields = []; | ||
} | ||
/** | ||
* Override the default index strategy. | ||
* @param value Custom index strategy | ||
* @throws Error if documents have already been indexed by this search instance | ||
*/ | ||
var _proto = Search.prototype; | ||
/** | ||
* Add a searchable document to the index. Document will automatically be indexed for search. | ||
* @param document | ||
*/ | ||
_proto.addDocument = function addDocument(document) { | ||
this.addDocuments([document]); | ||
} | ||
/** | ||
* Adds searchable documents to the index. Documents will automatically be indexed for search. | ||
* @param document | ||
*/ | ||
; | ||
_proto.addDocuments = function addDocuments(documents) { | ||
this._documents = this._documents.concat(documents); | ||
this.indexDocuments_(documents, this._searchableFields); | ||
} | ||
/** | ||
* Add a new searchable field to the index. Existing documents will automatically be indexed using this new field. | ||
* | ||
* @param field Searchable field or field path. Pass a string to index a top-level field and an array of strings for nested fields. | ||
*/ | ||
; | ||
_proto.addIndex = function addIndex(field) { | ||
this._searchableFields.push(field); | ||
this.indexDocuments_(this._documents, [field]); | ||
} | ||
/** | ||
* Search all documents for ones matching the specified query text. | ||
* @param query | ||
* @returns {Array<Object>} | ||
*/ | ||
; | ||
_proto.search = function search(query) { | ||
var tokens = this._tokenizer.tokenize(this._sanitizer.sanitize(query)); | ||
return this._searchIndex.search(tokens, this._documents); | ||
} | ||
/** | ||
* @param documents | ||
* @param _searchableFields Array containing property names and paths (lists of property names) to nested values | ||
* @private | ||
*/ | ||
; | ||
_proto.indexDocuments_ = function indexDocuments_(documents, _searchableFields) { | ||
this._initialized = true; | ||
var indexStrategy = this._indexStrategy; | ||
var sanitizer = this._sanitizer; | ||
var searchIndex = this._searchIndex; | ||
var tokenizer = this._tokenizer; | ||
var uidFieldName = this._uidFieldName; | ||
for (var di = 0, numDocuments = documents.length; di < numDocuments; di++) { | ||
var doc = documents[di]; | ||
var uid; | ||
if (uidFieldName instanceof Array) { | ||
uid = getNestedFieldValue(doc, uidFieldName); | ||
} else { | ||
uid = doc[uidFieldName]; | ||
} | ||
for (var sfi = 0, numSearchableFields = _searchableFields.length; sfi < numSearchableFields; sfi++) { | ||
var fieldValue; | ||
var searchableField = _searchableFields[sfi]; | ||
if (searchableField instanceof Array) { | ||
fieldValue = getNestedFieldValue(doc, searchableField); | ||
} else { | ||
fieldValue = doc[searchableField]; | ||
} | ||
if (fieldValue != null && typeof fieldValue !== 'string' && fieldValue.toString) { | ||
fieldValue = fieldValue.toString(); | ||
} | ||
if (typeof fieldValue === 'string') { | ||
var fieldTokens = tokenizer.tokenize(sanitizer.sanitize(fieldValue)); | ||
for (var fti = 0, numFieldValues = fieldTokens.length; fti < numFieldValues; fti++) { | ||
var fieldToken = fieldTokens[fti]; | ||
var expandedTokens = indexStrategy.expandToken(fieldToken); | ||
for (var eti = 0, nummExpandedTokens = expandedTokens.length; eti < nummExpandedTokens; eti++) { | ||
var expandedToken = expandedTokens[eti]; | ||
searchIndex.indexDocument(expandedToken, uid, doc); | ||
} | ||
} | ||
/** | ||
* @inheritDocs | ||
*/ | ||
return _createClass(StemmingTokenizer, [ { | ||
key: "tokenize", | ||
value: function(text) { | ||
return this._tokenizer.tokenize(text).map(this._stemmingFunction); | ||
} | ||
} ]), StemmingTokenizer; | ||
}(); | ||
}, /* 17 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}), exports.StopWordsTokenizer = void 0; | ||
var _createClass = function() { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, | ||
"value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function(Constructor, protoProps, staticProps) { | ||
return protoProps && defineProperties(Constructor.prototype, protoProps), staticProps && defineProperties(Constructor, staticProps), | ||
Constructor; | ||
}; | ||
}(), _StopWordsMap = __webpack_require__(3); | ||
exports.StopWordsTokenizer = function() { | ||
/** | ||
* Constructor. | ||
} | ||
}; | ||
_createClass(Search, [{ | ||
key: "indexStrategy", | ||
set: function set(value) { | ||
if (this._initialized) { | ||
throw Error('IIndexStrategy cannot be set after initialization'); | ||
} | ||
this._indexStrategy = value; | ||
}, | ||
get: function get() { | ||
return this._indexStrategy; | ||
} | ||
/** | ||
* Override the default text sanitizing strategy. | ||
* @param value Custom text sanitizing strategy | ||
* @throws Error if documents have already been indexed by this search instance | ||
*/ | ||
}, { | ||
key: "sanitizer", | ||
set: function set(value) { | ||
if (this._initialized) { | ||
throw Error('ISanitizer cannot be set after initialization'); | ||
} | ||
this._sanitizer = value; | ||
}, | ||
get: function get() { | ||
return this._sanitizer; | ||
} | ||
/** | ||
* Override the default search index strategy. | ||
* @param value Custom search index strategy | ||
* @throws Error if documents have already been indexed | ||
*/ | ||
}, { | ||
key: "searchIndex", | ||
set: function set(value) { | ||
if (this._initialized) { | ||
throw Error('ISearchIndex cannot be set after initialization'); | ||
} | ||
this._searchIndex = value; | ||
}, | ||
get: function get() { | ||
return this._searchIndex; | ||
} | ||
/** | ||
* Override the default text tokenizing strategy. | ||
* @param value Custom text tokenizing strategy | ||
* @throws Error if documents have already been indexed by this search instance | ||
*/ | ||
}, { | ||
key: "tokenizer", | ||
set: function set(value) { | ||
if (this._initialized) { | ||
throw Error('ITokenizer cannot be set after initialization'); | ||
} | ||
this._tokenizer = value; | ||
}, | ||
get: function get() { | ||
return this._tokenizer; | ||
} | ||
}]); | ||
return Search; | ||
}(); | ||
/** | ||
* This utility highlights the occurrences of tokens within a string of text. It can be used to give visual indicators | ||
* of match criteria within searchable fields. | ||
* | ||
* @param decoratedIndexStrategy Index strategy to be run after all stop words have been removed. | ||
* <p>For performance purposes this highlighter only works with full-word or prefix token indexes. | ||
*/ | ||
function StopWordsTokenizer(decoratedTokenizer) { | ||
_classCallCheck(this, StopWordsTokenizer), this._tokenizer = decoratedTokenizer; | ||
} | ||
/** | ||
* @inheritDocs | ||
*/ | ||
return _createClass(StopWordsTokenizer, [ { | ||
key: "tokenize", | ||
value: function(text) { | ||
return this._tokenizer.tokenize(text).filter(function(token) { | ||
return !_StopWordsMap.StopWordsMap[token]; | ||
}); | ||
} | ||
} ]), StopWordsTokenizer; | ||
}(); | ||
}, /* 18 */ | ||
/***/ | ||
function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _index = __webpack_require__(0); | ||
Object.defineProperty(exports, "AllSubstringsIndexStrategy", { | ||
enumerable: !0, | ||
get: function() { | ||
return _index.AllSubstringsIndexStrategy; | ||
} | ||
}), Object.defineProperty(exports, "ExactWordIndexStrategy", { | ||
enumerable: !0, | ||
get: function() { | ||
return _index.ExactWordIndexStrategy; | ||
} | ||
}), Object.defineProperty(exports, "PrefixIndexStrategy", { | ||
enumerable: !0, | ||
get: function() { | ||
return _index.PrefixIndexStrategy; | ||
} | ||
}); | ||
var _index2 = __webpack_require__(1); | ||
Object.defineProperty(exports, "CaseSensitiveSanitizer", { | ||
enumerable: !0, | ||
get: function() { | ||
return _index2.CaseSensitiveSanitizer; | ||
} | ||
}), Object.defineProperty(exports, "LowerCaseSanitizer", { | ||
enumerable: !0, | ||
get: function() { | ||
return _index2.LowerCaseSanitizer; | ||
} | ||
}); | ||
var _index3 = __webpack_require__(2); | ||
Object.defineProperty(exports, "TfIdfSearchIndex", { | ||
enumerable: !0, | ||
get: function() { | ||
return _index3.TfIdfSearchIndex; | ||
} | ||
}), Object.defineProperty(exports, "UnorderedSearchIndex", { | ||
enumerable: !0, | ||
get: function() { | ||
return _index3.UnorderedSearchIndex; | ||
} | ||
}); | ||
var _index4 = __webpack_require__(4); | ||
Object.defineProperty(exports, "SimpleTokenizer", { | ||
enumerable: !0, | ||
get: function() { | ||
return _index4.SimpleTokenizer; | ||
} | ||
}), Object.defineProperty(exports, "StemmingTokenizer", { | ||
enumerable: !0, | ||
get: function() { | ||
return _index4.StemmingTokenizer; | ||
} | ||
}), Object.defineProperty(exports, "StopWordsTokenizer", { | ||
enumerable: !0, | ||
get: function() { | ||
return _index4.StopWordsTokenizer; | ||
} | ||
}); | ||
var _Search = __webpack_require__(6); | ||
Object.defineProperty(exports, "Search", { | ||
enumerable: !0, | ||
get: function() { | ||
return _Search.Search; | ||
} | ||
}); | ||
var _StopWordsMap = __webpack_require__(3); | ||
Object.defineProperty(exports, "StopWordsMap", { | ||
enumerable: !0, | ||
get: function() { | ||
return _StopWordsMap.StopWordsMap; | ||
} | ||
}); | ||
var _TokenHighlighter = __webpack_require__(7); | ||
Object.defineProperty(exports, "TokenHighlighter", { | ||
enumerable: !0, | ||
get: function() { | ||
return _TokenHighlighter.TokenHighlighter; | ||
} | ||
}); | ||
} ]); | ||
}); | ||
var TokenHighlighter = /*#__PURE__*/function () { | ||
/** | ||
* Constructor. | ||
* | ||
* @param opt_indexStrategy Index strategy used by Search | ||
* @param opt_sanitizer Sanitizer used by Search | ||
* @param opt_wrapperTagName Optional wrapper tag name; defaults to 'mark' (e.g. <mark>) | ||
*/ | ||
function TokenHighlighter(opt_indexStrategy, opt_sanitizer, opt_wrapperTagName) { | ||
this._indexStrategy = opt_indexStrategy || new PrefixIndexStrategy(); | ||
this._sanitizer = opt_sanitizer || new LowerCaseSanitizer(); | ||
this._wrapperTagName = opt_wrapperTagName || 'mark'; | ||
} | ||
/** | ||
* Highlights token occurrences within a string by wrapping them with a DOM element. | ||
* | ||
* @param text e.g. "john wayne" | ||
* @param tokens e.g. ["wa"] | ||
* @returns {string} e.g. "john <mark>wa</mark>yne" | ||
*/ | ||
var _proto = TokenHighlighter.prototype; | ||
_proto.highlight = function highlight(text, tokens) { | ||
var tagsLength = this._wrapText('').length; | ||
var tokenDictionary = Object.create(null); // Create a token map for easier lookup below. | ||
for (var i = 0, numTokens = tokens.length; i < numTokens; i++) { | ||
var token = this._sanitizer.sanitize(tokens[i]); | ||
var expandedTokens = this._indexStrategy.expandToken(token); | ||
for (var j = 0, numExpandedTokens = expandedTokens.length; j < numExpandedTokens; j++) { | ||
var expandedToken = expandedTokens[j]; | ||
if (!tokenDictionary[expandedToken]) { | ||
tokenDictionary[expandedToken] = [token]; | ||
} else { | ||
tokenDictionary[expandedToken].push(token); | ||
} | ||
} | ||
} // Track actualCurrentWord and sanitizedCurrentWord separately in case we encounter nested tags. | ||
var actualCurrentWord = ''; | ||
var sanitizedCurrentWord = ''; | ||
var currentWordStartIndex = 0; // Note this assumes either prefix or full word matching. | ||
for (var i = 0, textLength = text.length; i < textLength; i++) { | ||
var character = text.charAt(i); | ||
if (character === ' ') { | ||
actualCurrentWord = ''; | ||
sanitizedCurrentWord = ''; | ||
currentWordStartIndex = i + 1; | ||
} else { | ||
actualCurrentWord += character; | ||
sanitizedCurrentWord += this._sanitizer.sanitize(character); | ||
} | ||
if (tokenDictionary[sanitizedCurrentWord] && tokenDictionary[sanitizedCurrentWord].indexOf(sanitizedCurrentWord) >= 0) { | ||
actualCurrentWord = this._wrapText(actualCurrentWord); | ||
text = text.substring(0, currentWordStartIndex) + actualCurrentWord + text.substring(i + 1); | ||
i += tagsLength; | ||
textLength += tagsLength; | ||
} | ||
} | ||
return text; | ||
} | ||
/** | ||
* @param text to wrap | ||
* @returns Text wrapped by wrapper tag (e.g. "foo" becomes "<mark>foo</mark>") | ||
* @private | ||
*/ | ||
; | ||
_proto._wrapText = function _wrapText(text) { | ||
var tagName = this._wrapperTagName; | ||
return "<" + tagName + ">" + text + "</" + tagName + ">"; | ||
}; | ||
return TokenHighlighter; | ||
}(); | ||
exports.AllSubstringsIndexStrategy = AllSubstringsIndexStrategy; | ||
exports.CaseSensitiveSanitizer = CaseSensitiveSanitizer; | ||
exports.ExactWordIndexStrategy = ExactWordIndexStrategy; | ||
exports.LowerCaseSanitizer = LowerCaseSanitizer; | ||
exports.PrefixIndexStrategy = PrefixIndexStrategy; | ||
exports.Search = Search; | ||
exports.SimpleTokenizer = SimpleTokenizer; | ||
exports.StemmingTokenizer = StemmingTokenizer; | ||
exports.StopWordsMap = StopWordsMap; | ||
exports.StopWordsTokenizer = StopWordsTokenizer; | ||
exports.TfIdfSearchIndex = TfIdfSearchIndex; | ||
exports.TokenHighlighter = TokenHighlighter; | ||
exports.UnorderedSearchIndex = UnorderedSearchIndex; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
@@ -1,2 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.JsSearch=t():e.JsSearch=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=18)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(8);Object.defineProperty(t,"AllSubstringsIndexStrategy",{enumerable:!0,get:function(){return r.AllSubstringsIndexStrategy}});var i=n(9);Object.defineProperty(t,"ExactWordIndexStrategy",{enumerable:!0,get:function(){return i.ExactWordIndexStrategy}});var o=n(10);Object.defineProperty(t,"PrefixIndexStrategy",{enumerable:!0,get:function(){return o.PrefixIndexStrategy}})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(11);Object.defineProperty(t,"CaseSensitiveSanitizer",{enumerable:!0,get:function(){return r.CaseSensitiveSanitizer}});var i=n(12);Object.defineProperty(t,"LowerCaseSanitizer",{enumerable:!0,get:function(){return i.LowerCaseSanitizer}})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(13);Object.defineProperty(t,"TfIdfSearchIndex",{enumerable:!0,get:function(){return r.TfIdfSearchIndex}});var i=n(14);Object.defineProperty(t,"UnorderedSearchIndex",{enumerable:!0,get:function(){return i.UnorderedSearchIndex}})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=t.StopWordsMap={a:!0,able:!0,about:!0,across:!0,after:!0,all:!0,almost:!0,also:!0,am:!0,among:!0,an:!0,and:!0,any:!0,are:!0,as:!0,at:!0,be:!0,because:!0,been:!0,but:!0,by:!0,can:!0,cannot:!0,could:!0,dear:!0,did:!0,do:!0,does:!0,either:!0,else:!0,ever:!0,every:!0,for:!0,from:!0,get:!0,got:!0,had:!0,has:!0,have:!0,he:!0,her:!0,hers:!0,him:!0,his:!0,how:!0,however:!0,i:!0,if:!0,in:!0,into:!0,is:!0,it:!0,its:!0,just:!0,least:!0,let:!0,like:!0,likely:!0,may:!0,me:!0,might:!0,most:!0,must:!0,my:!0,neither:!0,no:!0,nor:!0,not:!0,of:!0,off:!0,often:!0,on:!0,only:!0,or:!0,other:!0,our:!0,own:!0,rather:!0,said:!0,say:!0,says:!0,she:!0,should:!0,since:!0,so:!0,some:!0,than:!0,that:!0,the:!0,their:!0,them:!0,then:!0,there:!0,these:!0,they:!0,this:!0,tis:!0,to:!0,too:!0,twas:!0,us:!0,wants:!0,was:!0,we:!0,were:!0,what:!0,when:!0,where:!0,which:!0,while:!0,who:!0,whom:!0,why:!0,will:!0,with:!0,would:!0,yet:!0,you:!0,your:!0};r.constructor=!1,r.hasOwnProperty=!1,r.isPrototypeOf=!1,r.propertyIsEnumerable=!1,r.toLocaleString=!1,r.toString=!1,r.valueOf=!1},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(15);Object.defineProperty(t,"SimpleTokenizer",{enumerable:!0,get:function(){return r.SimpleTokenizer}});var i=n(16);Object.defineProperty(t,"StemmingTokenizer",{enumerable:!0,get:function(){return i.StemmingTokenizer}});var o=n(17);Object.defineProperty(t,"StopWordsTokenizer",{enumerable:!0,get:function(){return o.StopWordsTokenizer}})},function(e,t,n){"use strict";function r(e,t){t=t||[],e=e||{};for(var n=e,r=0;r<t.length;r++)if(n=n[t[r]],null==n)return null;return n}Object.defineProperty(t,"__esModule",{value:!0}),t.default=r},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),t.Search=void 0;var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=n(5),u=r(a),c=n(0),f=n(1),s=n(2),l=n(4);t.Search=function(){function e(t){if(i(this,e),!t)throw Error("js-search requires a uid field name constructor parameter");this._uidFieldName=t,this._indexStrategy=new c.PrefixIndexStrategy,this._searchIndex=new s.TfIdfSearchIndex(t),this._sanitizer=new f.LowerCaseSanitizer,this._tokenizer=new l.SimpleTokenizer,this._documents=[],this._searchableFields=[]}return o(e,[{key:"addDocument",value:function(e){this.addDocuments([e])}},{key:"addDocuments",value:function(e){this._documents=this._documents.concat(e),this.indexDocuments_(e,this._searchableFields)}},{key:"addIndex",value:function(e){this._searchableFields.push(e),this.indexDocuments_(this._documents,[e])}},{key:"search",value:function(e){var t=this._tokenizer.tokenize(this._sanitizer.sanitize(e));return this._searchIndex.search(t,this._documents)}},{key:"indexDocuments_",value:function(e,t){this._initialized=!0;for(var n=this._indexStrategy,r=this._sanitizer,i=this._searchIndex,o=this._tokenizer,a=this._uidFieldName,c=0,f=e.length;c<f;c++){var s,l=e[c];s=a instanceof Array?(0,u.default)(l,a):l[a];for(var d=0,h=t.length;d<h;d++){var y,p=t[d];if(y=p instanceof Array?(0,u.default)(l,p):l[p],null!=y&&"string"!=typeof y&&y.toString&&(y=y.toString()),"string"==typeof y)for(var b=o.tokenize(r.sanitize(y)),v=0,m=b.length;v<m;v++)for(var g=b[v],_=n.expandToken(g),k=0,S=_.length;k<S;k++){var w=_[k];i.indexDocument(w,s,l)}}}}},{key:"indexStrategy",set:function(e){if(this._initialized)throw Error("IIndexStrategy cannot be set after initialization");this._indexStrategy=e},get:function(){return this._indexStrategy}},{key:"sanitizer",set:function(e){if(this._initialized)throw Error("ISanitizer cannot be set after initialization");this._sanitizer=e},get:function(){return this._sanitizer}},{key:"searchIndex",set:function(e){if(this._initialized)throw Error("ISearchIndex cannot be set after initialization");this._searchIndex=e},get:function(){return this._searchIndex}},{key:"tokenizer",set:function(e){if(this._initialized)throw Error("ITokenizer cannot be set after initialization");this._tokenizer=e},get:function(){return this._tokenizer}}]),e}()},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),t.TokenHighlighter=void 0;var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=n(0),a=n(1);t.TokenHighlighter=function(){function e(t,n,i){r(this,e),this._indexStrategy=t||new o.PrefixIndexStrategy,this._sanitizer=n||new a.LowerCaseSanitizer,this._wrapperTagName=i||"mark"}return i(e,[{key:"highlight",value:function(e,t){for(var n=this._wrapText("").length,r=Object.create(null),i=0,o=t.length;i<o;i++)for(var a=this._sanitizer.sanitize(t[i]),u=this._indexStrategy.expandToken(a),c=0,f=u.length;c<f;c++){var s=u[c];r[s]?r[s].push(a):r[s]=[a]}for(var l="",d="",h=0,i=0,y=e.length;i<y;i++){var p=e.charAt(i);" "===p?(l="",d="",h=i+1):(l+=p,d+=this._sanitizer.sanitize(p)),r[d]&&r[d].indexOf(d)>=0&&(l=this._wrapText(l),e=e.substring(0,h)+l+e.substring(i+1),i+=n,y+=n)}return e}},{key:"_wrapText",value:function(e){var t=this._wrapperTagName;return"<"+t+">"+e+"</"+t+">"}}]),e}()},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.AllSubstringsIndexStrategy=function(){function e(){r(this,e)}return i(e,[{key:"expandToken",value:function(e){for(var t,n=[],r=0,i=e.length;r<i;++r){t="";for(var o=r;o<i;++o)t+=e.charAt(o),n.push(t)}return n}}]),e}()},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.ExactWordIndexStrategy=function(){function e(){r(this,e)}return i(e,[{key:"expandToken",value:function(e){return e?[e]:[]}}]),e}()},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.PrefixIndexStrategy=function(){function e(){r(this,e)}return i(e,[{key:"expandToken",value:function(e){for(var t=[],n="",r=0,i=e.length;r<i;++r)n+=e.charAt(r),t.push(n);return t}}]),e}()},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.CaseSensitiveSanitizer=function(){function e(){r(this,e)}return i(e,[{key:"sanitize",value:function(e){return e?e.trim():""}}]),e}()},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.LowerCaseSanitizer=function(){function e(){r(this,e)}return i(e,[{key:"sanitize",value:function(e){return e?e.toLocaleLowerCase().trim():""}}]),e}()},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),t.TfIdfSearchIndex=void 0;var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),u=n(5),c=r(u);t.TfIdfSearchIndex=function(){function e(t){i(this,e),this._uidFieldName=t,this._tokenToIdfCache={},this._tokenMap={}}return a(e,[{key:"indexDocument",value:function(e,t,n){this._tokenToIdfCache={};var r,i=this._tokenMap;"object"!==o(i[e])?i[e]=r={$numDocumentOccurrences:0,$totalNumOccurrences:1,$uidMap:{}}:(r=i[e],r.$totalNumOccurrences++);var a=r.$uidMap;"object"!==o(a[t])?(r.$numDocumentOccurrences++,a[t]={$document:n,$numTokenOccurrences:1}):a[t].$numTokenOccurrences++}},{key:"search",value:function(e,t){for(var n={},r=0,i=e.length;r<i;r++){var a=e[r],u=this._tokenMap[a];if(!u)return[];if(0===r)for(var c=Object.keys(u.$uidMap),f=0,s=c.length;f<s;f++){var l=c[f];n[l]=u.$uidMap[l].$document}else for(var c=Object.keys(n),f=0,s=c.length;f<s;f++){var l=c[f];"object"!==o(u.$uidMap[l])&&delete n[l]}}var d=[];for(var l in n)d.push(n[l]);var h=this._createCalculateTfIdf();return d.sort(function(n,r){return h(e,r,t)-h(e,n,t)})}},{key:"_createCalculateIdf",value:function(){var e=this._tokenMap,t=this._tokenToIdfCache;return function(n,r){if(!t[n]){var i="undefined"!=typeof e[n]?e[n].$numDocumentOccurrences:0;t[n]=1+Math.log(r.length/(1+i))}return t[n]}}},{key:"_createCalculateTfIdf",value:function(){var e=this._tokenMap,t=this._uidFieldName,n=this._createCalculateIdf();return function(r,i,o){for(var a=0,u=0,f=r.length;u<f;++u){var s=r[u],l=n(s,o);l===1/0&&(l=0);var d;d=t instanceof Array?i&&(0,c.default)(i,t):i&&i[t];var h="undefined"!=typeof e[s]&&"undefined"!=typeof e[s].$uidMap[d]?e[s].$uidMap[d].$numTokenOccurrences:0;a+=h*l}return a}}}]),e}()},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.UnorderedSearchIndex=function(){function e(){r(this,e),this._tokenToUidToDocumentMap={}}return o(e,[{key:"indexDocument",value:function(e,t,n){"object"!==i(this._tokenToUidToDocumentMap[e])&&(this._tokenToUidToDocumentMap[e]={}),this._tokenToUidToDocumentMap[e][t]=n}},{key:"search",value:function(e,t){for(var n={},r=this._tokenToUidToDocumentMap,o=0,a=e.length;o<a;o++){var u=e[o],c=r[u];if(!c)return[];if(0===o)for(var f=Object.keys(c),s=0,l=f.length;s<l;s++){var d=f[s];n[d]=c[d]}else for(var f=Object.keys(n),s=0,l=f.length;s<l;s++){var d=f[s];"object"!==i(c[d])&&delete n[d]}}for(var f=Object.keys(n),h=[],o=0,l=f.length;o<l;o++){var d=f[o];h.push(n[d])}return h}}]),e}()},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=/[^a-zа-яё0-9\-']+/i;t.SimpleTokenizer=function(){function e(){r(this,e)}return i(e,[{key:"tokenize",value:function(e){return e.split(o).filter(function(e){return e})}}]),e}()},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.StemmingTokenizer=function(){function e(t,n){r(this,e),this._stemmingFunction=t,this._tokenizer=n}return i(e,[{key:"tokenize",value:function(e){return this._tokenizer.tokenize(e).map(this._stemmingFunction)}}]),e}()},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),t.StopWordsTokenizer=void 0;var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=n(3);t.StopWordsTokenizer=function(){function e(t){r(this,e),this._tokenizer=t}return i(e,[{key:"tokenize",value:function(e){return this._tokenizer.tokenize(e).filter(function(e){return!o.StopWordsMap[e]})}}]),e}()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(0);Object.defineProperty(t,"AllSubstringsIndexStrategy",{enumerable:!0,get:function(){return r.AllSubstringsIndexStrategy}}),Object.defineProperty(t,"ExactWordIndexStrategy",{enumerable:!0,get:function(){return r.ExactWordIndexStrategy}}),Object.defineProperty(t,"PrefixIndexStrategy",{enumerable:!0,get:function(){return r.PrefixIndexStrategy}});var i=n(1);Object.defineProperty(t,"CaseSensitiveSanitizer",{enumerable:!0,get:function(){return i.CaseSensitiveSanitizer}}),Object.defineProperty(t,"LowerCaseSanitizer",{enumerable:!0,get:function(){return i.LowerCaseSanitizer}});var o=n(2);Object.defineProperty(t,"TfIdfSearchIndex",{enumerable:!0,get:function(){return o.TfIdfSearchIndex}}),Object.defineProperty(t,"UnorderedSearchIndex",{enumerable:!0,get:function(){return o.UnorderedSearchIndex}});var a=n(4);Object.defineProperty(t,"SimpleTokenizer",{enumerable:!0,get:function(){return a.SimpleTokenizer}}),Object.defineProperty(t,"StemmingTokenizer",{enumerable:!0,get:function(){return a.StemmingTokenizer}}),Object.defineProperty(t,"StopWordsTokenizer",{enumerable:!0,get:function(){return a.StopWordsTokenizer}});var u=n(6);Object.defineProperty(t,"Search",{enumerable:!0,get:function(){return u.Search}});var c=n(3);Object.defineProperty(t,"StopWordsMap",{enumerable:!0,get:function(){return c.StopWordsMap}});var f=n(7);Object.defineProperty(t,"TokenHighlighter",{enumerable:!0,get:function(){return f.TokenHighlighter}})}])}); | ||
//# sourceMappingURL=dist/umd/js-search.min.js.map | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).JsSearch={})}(this,(function(e){"use strict";var t=function(){function e(){}return e.prototype.expandToken=function(e){for(var t,n=[],i=0,r=e.length;i<r;++i){t="";for(var o=i;o<r;++o)t+=e.charAt(o),n.push(t)}return n},e}(),n=function(){function e(){}return e.prototype.expandToken=function(e){return e?[e]:[]},e}(),i=function(){function e(){}return e.prototype.expandToken=function(e){for(var t=[],n="",i=0,r=e.length;i<r;++i)n+=e.charAt(i),t.push(n);return t},e}(),r=function(){function e(){}return e.prototype.sanitize=function(e){return e?e.trim():""},e}(),o=function(){function e(){}return e.prototype.sanitize=function(e){return e?e.toLocaleLowerCase().trim():""},e}();function a(e,t){t=t||[];for(var n=e=e||{},i=0;i<t.length;i++)if(null==(n=n[t[i]]))return null;return n}var s=function(){function e(e){this._uidFieldName=e,this._tokenToIdfCache={},this._tokenMap={}}var t=e.prototype;return t.indexDocument=function(e,t,n){this._tokenToIdfCache={};var i,r=this._tokenMap;"object"!=typeof r[e]?r[e]=i={$numDocumentOccurrences:0,$totalNumOccurrences:1,$uidMap:{}}:(i=r[e]).$totalNumOccurrences++;var o=i.$uidMap;"object"!=typeof o[t]?(i.$numDocumentOccurrences++,o[t]={$document:n,$numTokenOccurrences:1}):o[t].$numTokenOccurrences++},t.search=function(e,t){for(var n={},i=0,r=e.length;i<r;i++){var o=e[i],a=this._tokenMap[o];if(!a)return[];if(0===i)for(var s=0,u=(c=Object.keys(a.$uidMap)).length;s<u;s++){n[h=c[s]]=a.$uidMap[h].$document}else{var c;for(s=0,u=(c=Object.keys(n)).length;s<u;s++){var h=c[s];"object"!=typeof a.$uidMap[h]&&delete n[h]}}}var f=[];for(var h in n)f.push(n[h]);var d=this._createCalculateTfIdf();return f.sort((function(n,i){return d(e,i,t)-d(e,n,t)}))},t._createCalculateIdf=function(){var e=this._tokenMap,t=this._tokenToIdfCache;return function(n,i){if(!t[n]){var r=void 0!==e[n]?e[n].$numDocumentOccurrences:0;t[n]=1+Math.log(i.length/(1+r))}return t[n]}},t._createCalculateTfIdf=function(){var e=this._tokenMap,t=this._uidFieldName,n=this._createCalculateIdf();return function(i,r,o){for(var s=0,u=0,c=i.length;u<c;++u){var h,f=i[u],d=n(f,o);d===1/0&&(d=0),h=t instanceof Array?r&&a(r,t):r&&r[t],s+=(void 0!==e[f]&&void 0!==e[f].$uidMap[h]?e[f].$uidMap[h].$numTokenOccurrences:0)*d}return s}},e}(),u=function(){function e(){this._tokenToUidToDocumentMap={}}var t=e.prototype;return t.indexDocument=function(e,t,n){"object"!=typeof this._tokenToUidToDocumentMap[e]&&(this._tokenToUidToDocumentMap[e]={}),this._tokenToUidToDocumentMap[e][t]=n},t.search=function(e,t){for(var n={},i=this._tokenToUidToDocumentMap,r=0,o=e.length;r<o;r++){var a=i[e[r]];if(!a)return[];if(0===r)for(var s=0,u=(c=Object.keys(a)).length;s<u;s++){n[f=c[s]]=a[f]}else for(s=0,u=(c=Object.keys(n)).length;s<u;s++){"object"!=typeof a[f=c[s]]&&delete n[f]}}var c,h=[];for(r=0,u=(c=Object.keys(n)).length;r<u;r++){var f=c[r];h.push(n[f])}return h},e}(),c=/[^a-zа-яё0-9\-']+/i,h=function(){function e(){}return e.prototype.tokenize=function(e){return e.split(c).filter((function(e){return e}))},e}(),f=function(){function e(e,t){this._stemmingFunction=e,this._tokenizer=t}return e.prototype.tokenize=function(e){return this._tokenizer.tokenize(e).map(this._stemmingFunction)},e}(),d={a:!0,able:!0,about:!0,across:!0,after:!0,all:!0,almost:!0,also:!0,am:!0,among:!0,an:!0,and:!0,any:!0,are:!0,as:!0,at:!0,be:!0,because:!0,been:!0,but:!0,by:!0,can:!0,cannot:!0,could:!0,dear:!0,did:!0,do:!0,does:!0,either:!0,else:!0,ever:!0,every:!0,for:!0,from:!0,get:!0,got:!0,had:!0,has:!0,have:!0,he:!0,her:!0,hers:!0,him:!0,his:!0,how:!0,however:!0,i:!0,if:!0,in:!0,into:!0,is:!0,it:!0,its:!0,just:!0,least:!0,let:!0,like:!0,likely:!0,may:!0,me:!0,might:!0,most:!0,must:!0,my:!0,neither:!0,no:!0,nor:!0,not:!0,of:!0,off:!0,often:!0,on:!0,only:!0,or:!0,other:!0,our:!0,own:!0,rather:!0,said:!0,say:!0,says:!0,she:!0,should:!0,since:!0,so:!0,some:!0,than:!0,that:!0,the:!0,their:!0,them:!0,then:!0,there:!0,these:!0,they:!0,this:!0,tis:!0,to:!0,too:!0,twas:!0,us:!0,wants:!0,was:!0,we:!0,were:!0,what:!0,when:!0,where:!0,which:!0,while:!0,who:!0,whom:!0,why:!0,will:!0,with:!0,would:!0,yet:!0,you:!0,your:!0,constructor:!1,hasOwnProperty:!1,isPrototypeOf:!1,propertyIsEnumerable:!1,toLocaleString:!1,toString:!1,valueOf:!1},l=function(){function e(e){this._tokenizer=e}return e.prototype.tokenize=function(e){return this._tokenizer.tokenize(e).filter((function(e){return!d[e]}))},e}();function p(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}var _=function(){function e(e){if(!e)throw Error("js-search requires a uid field name constructor parameter");this._uidFieldName=e,this._indexStrategy=new i,this._searchIndex=new s(e),this._sanitizer=new o,this._tokenizer=new h,this._documents=[],this._searchableFields=[]}var t,n,r,u=e.prototype;return u.addDocument=function(e){this.addDocuments([e])},u.addDocuments=function(e){this._documents=this._documents.concat(e),this.indexDocuments_(e,this._searchableFields)},u.addIndex=function(e){this._searchableFields.push(e),this.indexDocuments_(this._documents,[e])},u.search=function(e){var t=this._tokenizer.tokenize(this._sanitizer.sanitize(e));return this._searchIndex.search(t,this._documents)},u.indexDocuments_=function(e,t){this._initialized=!0;for(var n=this._indexStrategy,i=this._sanitizer,r=this._searchIndex,o=this._tokenizer,s=this._uidFieldName,u=0,c=e.length;u<c;u++){var h,f=e[u];h=s instanceof Array?a(f,s):f[s];for(var d=0,l=t.length;d<l;d++){var p,_=t[d];if(null!=(p=_ instanceof Array?a(f,_):f[_])&&"string"!=typeof p&&p.toString&&(p=p.toString()),"string"==typeof p)for(var m=o.tokenize(i.sanitize(p)),y=0,g=m.length;y<g;y++)for(var v=m[y],k=n.expandToken(v),z=0,x=k.length;z<x;z++){var w=k[z];r.indexDocument(w,h,f)}}}},t=e,(n=[{key:"indexStrategy",set:function(e){if(this._initialized)throw Error("IIndexStrategy cannot be set after initialization");this._indexStrategy=e},get:function(){return this._indexStrategy}},{key:"sanitizer",set:function(e){if(this._initialized)throw Error("ISanitizer cannot be set after initialization");this._sanitizer=e},get:function(){return this._sanitizer}},{key:"searchIndex",set:function(e){if(this._initialized)throw Error("ISearchIndex cannot be set after initialization");this._searchIndex=e},get:function(){return this._searchIndex}},{key:"tokenizer",set:function(e){if(this._initialized)throw Error("ITokenizer cannot be set after initialization");this._tokenizer=e},get:function(){return this._tokenizer}}])&&p(t.prototype,n),r&&p(t,r),e}(),m=function(){function e(e,t,n){this._indexStrategy=e||new i,this._sanitizer=t||new o,this._wrapperTagName=n||"mark"}var t=e.prototype;return t.highlight=function(e,t){for(var n=this._wrapText("").length,i=Object.create(null),r=0,o=t.length;r<o;r++)for(var a=this._sanitizer.sanitize(t[r]),s=this._indexStrategy.expandToken(a),u=0,c=s.length;u<c;u++){var h=s[u];i[h]?i[h].push(a):i[h]=[a]}for(var f="",d="",l=0,p=(r=0,e.length);r<p;r++){var _=e.charAt(r);" "===_?(f="",d="",l=r+1):(f+=_,d+=this._sanitizer.sanitize(_)),i[d]&&i[d].indexOf(d)>=0&&(f=this._wrapText(f),e=e.substring(0,l)+f+e.substring(r+1),r+=n,p+=n)}return e},t._wrapText=function(e){var t=this._wrapperTagName;return"<"+t+">"+e+"</"+t+">"},e}();e.AllSubstringsIndexStrategy=t,e.CaseSensitiveSanitizer=r,e.ExactWordIndexStrategy=n,e.LowerCaseSanitizer=o,e.PrefixIndexStrategy=i,e.Search=_,e.SimpleTokenizer=h,e.StemmingTokenizer=f,e.StopWordsMap=d,e.StopWordsTokenizer=l,e.TfIdfSearchIndex=s,e.TokenHighlighter=m,e.UnorderedSearchIndex=u,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "js-search", | ||
"version": "1.4.3", | ||
"version": "2.0.0", | ||
"description": "JS Search is an efficient, client-side search library for JavaScript and JSON objects", | ||
"main": "dist/commonjs/index.js", | ||
"directories": { | ||
"test": "tests" | ||
"main": "./dist/umd/js-search.js", | ||
"module": "./dist/esm/js-search.js", | ||
"exports": { | ||
".": { | ||
"require": "./dist/umd/js-search.js", | ||
"import": "./dist/esm/js-search.js" | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
"dist", | ||
"source" | ||
], | ||
"devDependencies": { | ||
"babel-cli": "^6.22.2", | ||
"babel-loader": "^6.2.10", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
"babel-preset-latest": "^6.22.0", | ||
"cross-env": "^3.1.4", | ||
"flow-bin": "^0.50.0", | ||
"jest": "^20.0.4", | ||
"@babel/core": "^7.8.7", | ||
"@babel/preset-env": "^7.8.7", | ||
"@babel/preset-flow": "^7.8.3", | ||
"babel-jest": "^25.1.0", | ||
"flow-bin": "^0.120.1", | ||
"jest": "^25.1.0", | ||
"prettier": "^1.19.1", | ||
"rimraf": "^2.5.4", | ||
"uglify": "^0.1.5", | ||
"uglify-js": "^2.7.5", | ||
"webpack": "^2.2.1" | ||
"rollup": "^2.0.5", | ||
"rollup-plugin-babel": "^4.4.0", | ||
"rollup-plugin-terser": "^5.3.0" | ||
}, | ||
"scripts": { | ||
"build": "npm run build:commonjs && npm run build:umd", | ||
"build:commonjs": "cross-env NODE_ENV=production babel source --out-dir dist/commonjs --source-maps --ignore test.js", | ||
"build:umd": "cross-env NODE_ENV=production webpack --config webpack.config.js --bail", | ||
"clean": "rimraf dist", | ||
"flow": "flow source", | ||
"prebuild": "flow", | ||
"prebuild:commonjs": "rimraf dist/commonjs", | ||
"prebuild:umd": "rimraf dist/umd", | ||
"postbuild:umd": "uglifyjs dist/umd/js-search.js -o dist/umd/js-search.min.js --source-map dist/umd/js-search.min.js.map -p 5 -c -m", | ||
"pretest": "flow", | ||
"test": "jest", | ||
"tdd": "jest --watch" | ||
"build:flow": "echo \"// @flow\n\nexport * from '../../source'\" > dist/umd/js-search.js.flow", | ||
"build": "rimraf dist && rollup -c && yarn build:flow", | ||
"test": "flow check && jest", | ||
"tdd": "jest --watch", | ||
"prepublishOnly": "yarn build" | ||
}, | ||
@@ -39,0 +37,0 @@ "author": "Brian Vaughn <briandavidvaughn@gmail.com> (https://github.com/bvaughn/)", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
2990
119868
44
2