From: Vincent Vanwaelscappel Date: Tue, 22 Feb 2022 17:21:32 +0000 (+0100) Subject: wip #5120 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=6ba9a395d7ccf8318f3a46a90c9ad499b038424d;p=cubist_minisearch.git wip #5120 @1 --- diff --git a/composer.json b/composer.json index da353ee..90423c0 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ "php": ">=8.0", "laravel/framework": "^v8.64.0", "ext-json": "*", - "cubist/pdf": "dev-master" + "cubist/pdf": "dev-master", + "cubist/util": "dev-master" }, "suggest": { "cubist/pdf": "Allows to support PDF indexation" diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json new file mode 100644 index 0000000..3c9b5b2 --- /dev/null +++ b/node_modules/.package-lock.json @@ -0,0 +1,17 @@ +{ + "name": "cubist_minisearch", + "lockfileVersion": 2, + "requires": true, + "packages": { + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=" + }, + "node_modules/minisearch": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/minisearch/-/minisearch-4.0.3.tgz", + "integrity": "sha512-yEbNeb41Qk0g9IMJAgmp/kEaW2Ub2cs9MAKphTel24O8mymLheFU7esyfiumeUsvs2f4O0boO0zrp4bc9Po2cA==" + } + } +} diff --git a/node_modules/fs/README.md b/node_modules/fs/README.md new file mode 100644 index 0000000..5e9a74c --- /dev/null +++ b/node_modules/fs/README.md @@ -0,0 +1,9 @@ +# Security holding package + +This package name is not currently in use, but was formerly occupied +by another package. To avoid malicious use, npm is hanging on to the +package name, but loosely, and we'll probably give it to you if you +want it. + +You may adopt this package by contacting support@npmjs.com and +requesting the name. diff --git a/node_modules/fs/package.json b/node_modules/fs/package.json new file mode 100644 index 0000000..11661b0 --- /dev/null +++ b/node_modules/fs/package.json @@ -0,0 +1,20 @@ +{ + "name": "fs", + "version": "0.0.1-security", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/npm/security-holder.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/npm/security-holder/issues" + }, + "homepage": "https://github.com/npm/security-holder#readme" +} diff --git a/node_modules/minisearch/CHANGELOG.md b/node_modules/minisearch/CHANGELOG.md new file mode 100644 index 0000000..e6a708f --- /dev/null +++ b/node_modules/minisearch/CHANGELOG.md @@ -0,0 +1,308 @@ +# Changelog + +`MiniSearch` follows [semantic versioning](https://semver.org/spec/v2.0.0.html). + +# v4.0.3 + + - [fix] Fix regression causing stored fields not being saved in some + situations. + +# v4.0.2 + + - [fix] Fix match data on mixed prefix and fuzzy search + +# v4.0.1 + + - [fix] Fix an issue with scoring, causing a result matching both fuzzy and + prefix search to be scored higher than an exact match. + + - [breaking change] `SearchableMap` method `fuzzyGet` now returns a `Map` + instead of an object. This is a breaking change only if you directly use + `SearchableMap`, not if you use `MiniSearch`, and is considered part of + version 4. + +# v4.0.0 + + - [breaking change] The serialization format was changed, to abstract away the + internal implementation details of the index data structure. This allows for + present and future optimizations without breaking backward compatibility + again. Moreover, the new format is simpler, facilitating the job of tools + that create a serialized MiniSearch index in other languages. + + - [performance] Large performance improvements on indexing (at least 4 time + faster in the official benchmark) and search, due to changes to the internal + data structures and the code. + + - [peformance] The fuzzy search algorythm has been updated to work like + outlined in [this blog post by Steve + Hanov](http://stevehanov.ca/blog/?id=114), improving its performance by + several times, especially on large maximum edit distances. + + - [fix] The `weights` search option did not have an effect due to a bug. Now + it works as documented. Note that, due to this, the relative scoring of + fuzzy vs. prefix search matches might change compared to previous versions. + This change also brings a further performance improvement of both fuzzy and + prefix search. + +**Migration notes:** + +If you have an index serialized with a previous version of MiniSearch, you will +need to re-create it when you upgrade to MiniSearch `v4`. + +Also note that loading a pre-serialized index is _slower_ in `v4` than in +previous versions, but there are much larger performance gains on indexing and +search speed. If you serialized an index on the server-side, it is worth +checking if it is now fast enough for your use case to index on the client side: +it would save you from having to re-serialize the index every time something +changes. + +**Acknowledgements:** + +Many thanks to [rolftimmermans](https://github.com/rolftimmermans) for +contributing the fixes and outstanding performance improvements that are part of +this release. + + +# v3.3.0 + + - Add `maxFuzzy` search option, to limit the maximum edit distance for fuzzy + search when using fractional fuzziness + +# v3.2.0 + + - Add AND_NOT combinator to subtract results of a subquery from another (for + example to find documents that match one term and not another) + +# v3.1.0 + + - Add possibility for advanced combination of subqueries as query expression + trees + +# v3.0.4 + + - [fix] Keep radix tree property (no node with a single child) after removal + of an entry + +# v3.0.3 + + - [fix] Adjust data about field lengths upon document removal + +# v3.0.2 + + - [fix] `addAllAsync` now allows events to be processed between chunks, avoid + blocking the UI (by [@grimmen](https://github.com/grimmen)) + +# v3.0.1 + + - [fix] Fix type signature of `removeAll` to allow calling it with no + arguments. Also, throw a more informative error if called with a falsey + value. Thanks to [https://github.com/nilclass](@nilclass). + +# v3.0.0 + + This major version ports the source code to TypeScript. That made it possible + to improve types and documentation, making sure that both are in sync with the + actual code. It is mostly backward compatible: JavaScript users should + experience no breaking change, while TypeScript users _might_ have toadapt + some types. + + - Port source to [TypeScript](https://www.typescriptlang.org), adding type + safety + - Improved types and documentation (now generated with [TypeDoc](http://typedoc.org)) + - [breaking change, fix] TypeScript `SearchOptions` type is not generic + anymore + - [breaking change] `SearchableMap` is not a static field of `MiniSearch` + anymore: it can instead be imported separately as `minisearch/SearchableMap` + +# v2.6.2 + + - [fix] Improve TypeScript types: default generic document type is `any`, not `object` + +# v2.6.1 + + - No change from 2.6.0 + +# v2.6.0 + + - Better TypeScript typings using generics, letting the user (optionally) + specify the document type. + +# v2.5.1 + + - [fix] Fix document removal when using a custom `extractField` function + (thanks [@ahri](https://github.com/ahri) for reporting and reproducting) + +# v2.5.0 + + - Make `idField` extraction customizeable and consistent with other fields, + using `extractField` + +# v2.4.1 + + - [fix] Fix issue with the term `constructor` (reported by + [@scambier](https://github.com/scambier)) + + - [fix] Fix issues when a field is named like a default property of JavaScript + objects + +# v2.4.0 + + - Convert field value to string before tokenization and indexing. This makes + a custom field extractor unnecessary for basic cases like integers or simple + arrays. + +# v2.3.1 + + - Version `v2.3.1` mistakenly did not contain the commit adding `removeAll`, + this patch release fixes it. + +# v2.3.0 + + - Add `removeAll` method, to remove many documents, or all documents, at once. + +# v2.2.2 + + - Avoid destructuring variables named with an underscore prefix. This plays + nicer to some common minifier and builder configurations. + + - Performance improvement in `getDefault` (by + [stalniy](https://github.com/stalniy)) + + - Fix the linter setup, to ensure code style consistency + +## v2.2.1 + + - Add `"sideEffects": false` to `package.json` to allow bundlers to perform + tree shaking + +## v2.2.0 + + - [fix] Fix documentation of `SearchableMap.prototype.atPrefix` (by + [@graphman65](https://github.com/graphman65)) + - Switch to Rollup for bundling (by [stalniy](https://github.com/stalniy)), + reducing size of build and providing ES6 and ES5 module versions too. + +## v2.1.4 + + - [fix] Fix document removal in presence of custom per field tokenizer, field + extractor, or term processor (thanks [@CaptainChaos](https://github.com/CaptainChaos)) + +## v2.1.3 + + - [fix] Fix TypeScript definition for `storeFields` option (by + [@ryan-codingintrigue](https://github.com/ryan-codingintrigue)) + +## v2.1.2 + + - [fix] Fix TypeScript definition for `fuzzy` option (by + [@alessandrobardini](https://github.com/alessandrobardini)) + +## v2.1.1 + + - [fix] Fix TypeScript definitions adding `filter` and `storeFields` options + (by [@emilianox](https://github.com/emilianox)) + +## v2.1.0 + + - [feature] Add support for stored fields + + - [feature] Add filtering of search results and auto suggestions + +## v2.0.6 + + - Better TypeScript definitions (by [@samuelmeuli](https://github.com/samuelmeuli)) + +## v2.0.5 + + - Add TypeScript definitions for ease of use in TypeScript projects + +## v2.0.4 + + - [fix] tokenizer behavior with newline characters (by [@samuelmeuli](https://github.com/samuelmeuli)) + +## v2.0.3 + + - Fix small imprecision in documentation + +## v2.0.2 + + - Add `addAllAsync` method, adding many documents asynchronously and in chunks + to avoid blocking the main thread + +## v2.0.1 + + - Throw a more descriptive error when `loadJSON` is called without options + +## v2.0.0 + +This release introduces better defaults. It is considered a major release, as +the default options are slightly different, but the API is not changed. + + - *Breaking change*: default tokenizer splits by Unicode space or punctuation + (before it was splitting by space, punctuation, or _symbol_). The difference + is that currency symbols and other non-punctuation symbols will not be + discarded: "it's 100€" is now tokenized as `["it", "s", "100€"]` instead of + `["it", "s", "100"]`. + + - *Breaking change*: default term processing does not discard 1-character + words. + + - *Breaking change*: auto suggestions by default perform prefix search only on + the last term in the query. So "super cond" will suggest "super + conductivity", but not "superposition condition". + +## v1.3.1 + + - Better and more compact regular expression in the default tokenizer, + separating on Unicode spaces, punctuation, and symbols + +## v1.3.0 + + - Support for non-latin scripts + +## v1.2.1 + + - Improve fuzzy search performance (common cases are now ~4x faster, as shown + by the benchmark) + +## v1.2.0 + + - Add possibility to configure a custom field extraction function by setting + the `extractField` option (to support cases like nested fields, non-string + fields, getter methods, field pre-processing, etc.) + +## v1.1.2 + + - Add `getDefault` static method to get the default value of configuration options + +## v1.1.1 + + - Do not minify library when published as NPM package. Run `yarn + build-minified` (or `npm run build-minified`) to produce a minified build + with source maps. + - **Bugfix**: as per specification, `processTerm` is called with only one + argument upon search (see [#5](https://github.com/lucaong/minisearch/issues/5)) + +## v1.1.0 + + - Add possibility to configure separate index-time and search-time + tokenization and term processing functions + - The `processTerm` function can now reject a term by returning a falsy value + - Upon indexing, the `tokenize` and `processTerm` functions receive the field + name as the second argument. This makes it possible to process or tokenize + each field differently. + +## v1.0.1 + + - Reduce bundle size by optimizing babel preset env options + +## v1.0.0 + +Production-ready release. + +Features: + + - Space-optimized index + - Exact match, prefix match, fuzzy search + - Auto suggestions + - Add/remove documents at any time diff --git a/node_modules/minisearch/LICENSE.txt b/node_modules/minisearch/LICENSE.txt new file mode 100644 index 0000000..8cffd9e --- /dev/null +++ b/node_modules/minisearch/LICENSE.txt @@ -0,0 +1,7 @@ +Copyright 2018 Luca Ongaro + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/minisearch/README.md b/node_modules/minisearch/README.md new file mode 100644 index 0000000..250c677 --- /dev/null +++ b/node_modules/minisearch/README.md @@ -0,0 +1,340 @@ +# MiniSearch + +[![CI Build](https://github.com/lucaong/minisearch/workflows/CI%20Build/badge.svg)](https://github.com/lucaong/minisearch/actions) +[![Coverage Status](https://coveralls.io/repos/github/lucaong/minisearch/badge.svg?branch=master)](https://coveralls.io/github/lucaong/minisearch?branch=master) +[![Minzipped Size](https://badgen.net/bundlephobia/minzip/minisearch)](https://bundlephobia.com/result?p=minisearch) +[![npm](https://img.shields.io/npm/v/minisearch?color=%23ff00dd)](https://www.npmjs.com/package/minisearch) +[![npm downloads](https://img.shields.io/npm/dw/minisearch)](https://www.npmjs.com/package/minisearch) +[![types](https://img.shields.io/npm/types/minisearch)](https://lucaong.github.io/minisearch/classes/_minisearch_.minisearch.html) + +`MiniSearch` is a tiny but powerful in-memory fulltext search engine written in +JavaScript. It is respectful of resources, and it can comfortably run both in +Node and in the browser. + +Try out the [demo application](https://lucaong.github.io/minisearch/examples/). + +Find the complete [documentation and API reference +here](https://lucaong.github.io/minisearch/classes/_minisearch_.minisearch.html), +and more background about `MiniSearch`, including a comparison with other +similar libraries, in [this blog +post](https://lucaongaro.eu/blog/2019/01/30/minisearch-client-side-fulltext-search-engine.html). + + +## Use case + +`MiniSearch` addresses use cases where full-text search features are needed +(e.g. prefix search, fuzzy search, ranking, boosting of fields…), but the data +to be indexed can fit locally in the process memory. While you won't index the +whole Internet with it, there are surprisingly many use cases that are served +well by `MiniSearch`. By storing the index in local memory, `MiniSearch` can +work offline, and can process queries quickly, without network latency. + +A prominent use-case is real time search "as you type" in web and mobile +applications, where keeping the index on the client enables fast and reactive +UIs, removing the need to make requests to a search server. + + +## Features + + * Memory-efficient index, designed to support memory-constrained use cases + like mobile browsers. + + * Exact match, prefix search, fuzzy match, field boosting + + * Auto-suggestion engine, for auto-completion of search queries + + * Documents can be added and removed from the index at any time + + * Zero external dependencies + +`MiniSearch` strives to expose a simple API that provides the building blocks to +build custom solutions, while keeping a small and well tested codebase. + + +## Installation + +With `npm`: + +``` +npm install --save minisearch +``` + +With `yarn`: + +``` +yarn add minisearch +``` + +Then `require` or `import` it in your project: + +```javascript +// If you are using import: +import MiniSearch from 'minisearch' + +// If you are using require: +const MiniSearch = require('minisearch') +``` + +Alternatively, if you prefer to use a ` +``` + +In this case, `MiniSearch` will appear as a global variable in your project. + +Finally, if you want to manually build the library, clone the repository and run +`yarn build` (or `yarn build-minified` for a minified version + source maps). +The compiled source will be created in the `dist` folder (UMD, ES6 and ES2015 +module versions are provided). + + +## Usage + +### Basic usage + +```javascript +// A collection of documents for our examples +const documents = [ + { + id: 1, + title: 'Moby Dick', + text: 'Call me Ishmael. Some years ago...', + category: 'fiction' + }, + { + id: 2, + title: 'Zen and the Art of Motorcycle Maintenance', + text: 'I can see by my watch...', + category: 'fiction' + }, + { + id: 3, + title: 'Neuromancer', + text: 'The sky above the port was...', + category: 'fiction' + }, + { + id: 4, + title: 'Zen and the Art of Archery', + text: 'At first sight it must seem...', + category: 'non-fiction' + }, + // ...and more +] + +let miniSearch = new MiniSearch({ + fields: ['title', 'text'], // fields to index for full-text search + storeFields: ['title', 'category'] // fields to return with search results +}) + +// Index all documents +miniSearch.addAll(documents) + +// Search with default options +let results = miniSearch.search('zen art motorcycle') +// => [ +// { id: 2, title: 'Zen and the Art of Motorcycle Maintenance', category: 'fiction', score: 2.77258, match: { ... } }, +// { id: 4, title: 'Zen and the Art of Archery', category: 'non-fiction', score: 1.38629, match: { ... } } +// ] +``` + +### Search options + +`MiniSearch` supports several options for more advanced search behavior: + +```javascript +// Search only specific fields +miniSearch.search('zen', { fields: ['title'] }) + +// Boost some fields (here "title") +miniSearch.search('zen', { boost: { title: 2 } }) + +// Prefix search (so that 'moto' will match 'motorcycle') +miniSearch.search('moto', { prefix: true }) + +// Search within a specific category +miniSearch.search('zen', { + filter: (result) => result.category === 'fiction' +}) + +// Fuzzy search, in this example, with a max edit distance of 0.2 * term length, +// rounded to nearest integer. The mispelled 'ismael' will match 'ishmael'. +miniSearch.search('ismael', { fuzzy: 0.2 }) + +// You can set the default search options upon initialization +miniSearch = new MiniSearch({ + fields: ['title', 'text'], + searchOptions: { + boost: { title: 2 }, + fuzzy: 0.2 + } +}) +miniSearch.addAll(documents) + +// It will now by default perform fuzzy search and boost "title": +miniSearch.search('zen and motorcycles') +``` + +### Auto suggestions + +`MiniSearch` can suggest search queries given an incomplete query: + +```javascript +miniSearch.autoSuggest('zen ar') +// => [ { suggestion: 'zen archery art', terms: [ 'zen', 'archery', 'art' ], score: 1.73332 }, +// { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 } ] +``` + +The `autoSuggest` method takes the same options as the `search` method, so you +can get suggestions for misspelled words using fuzzy search: + +```javascript +miniSearch.autoSuggest('neromancer', { fuzzy: 0.2 }) +// => [ { suggestion: 'neuromancer', terms: [ 'neuromancer' ], score: 1.03998 } ] +``` + +Suggestions are ranked by the relevance of the documents that would be returned +by that search. + +Sometimes, you might need to filter auto suggestions to, say, only a specific +category. You can do so by providing a `filter` option: + +```javascript +miniSearch.autoSuggest('zen ar', { + filter: (result) => result.category === 'fiction' +}) +// => [ { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 } ] +``` + +### Field extraction + +By default, documents are assumed to be plain key-value objects with field names +as keys and field values as simple values. In order to support custom field +extraction logic (for example for nested fields, or non-string field values that +need processing before tokenization), a custom field extractor function can be +passed as the `extractField` option: + +```javascript +// Assuming that our documents look like: +const documents = [ + { id: 1, title: 'Moby Dick', author: { name: 'Herman Melville' }, pubDate: new Date(1851, 9, 18) }, + { id: 2, title: 'Zen and the Art of Motorcycle Maintenance', author: { name: 'Robert Pirsig' }, pubDate: new Date(1974, 3, 1) }, + { id: 3, title: 'Neuromancer', author: { name: 'William Gibson' }, pubDate: new Date(1984, 6, 1) }, + { id: 4, title: 'Zen in the Art of Archery', author: { name: 'Eugen Herrigel' }, pubDate: new Date(1948, 0, 1) }, + // ...and more +] + +// We can support nested fields (author.name) and date fields (pubDate) with a +// custom `extractField` function: + +let miniSearch = new MiniSearch({ + fields: ['title', 'author.name', 'pubYear'], + extractField: (document, fieldName) => { + // If field name is 'pubYear', extract just the year from 'pubDate' + if (fieldName === 'pubYear') { + const pubDate = document['pubDate'] + return pubDate && pubDate.getFullYear().toString() + } + + // Access nested fields + return fieldName.split('.').reduce((doc, key) => doc && doc[key], document) + } +}) +``` + +The default field extractor can be obtained by calling +`MiniSearch.getDefault('extractField')`. + +### Tokenization + +By default, documents are tokenized by splitting on Unicode space or punctuation +characters. The tokenization logic can be easily changed by passing a custom +tokenizer function as the `tokenize` option: + +```javascript +// Tokenize splitting by hyphen +let miniSearch = new MiniSearch({ + fields: ['title', 'text'], + tokenize: (string, _fieldName) => string.split('-') +}) +``` + +Upon search, the same tokenization is used by default, but it is possible to +pass a `tokenize` search option in case a different search-time tokenization is +necessary: + +```javascript +// Tokenize splitting by hyphen +let miniSearch = new MiniSearch({ + fields: ['title', 'text'], + tokenize: (string) => string.split('-'), // indexing tokenizer + searchOptions: { + tokenize: (string) => string.split(/[\s-]+/) // search query tokenizer + } +}) +``` + +The default tokenizer can be obtained by calling +`MiniSearch.getDefault('tokenize')`. + +### Term processing + +Terms are downcased by default. No stemming is performed, and no stop-word list +is applied. To customize how the terms are processed upon indexing, for example +to normalize them, filter them, or to apply stemming, the `processTerm` option +can be used. The `processTerm` function should return the processed term as a +string, or a falsy value if the term should be discarded: + +```javascript +let stopWords = new Set(['and', 'or', 'to', 'in', 'a', 'the', /* ...and more */ ]) + +// Perform custom term processing (here discarding stop words and downcasing) +let miniSearch = new MiniSearch({ + fields: ['title', 'text'], + processTerm: (term, _fieldName) => + stopWords.has(term) ? null : term.toLowerCase() +}) +``` + +By default, the same processing is applied to search queries. In order to apply +a different processing to search queries, supply a `processTerm` search option: + +```javascript +let miniSearch = new MiniSearch({ + fields: ['title', 'text'], + processTerm: (term) => + stopWords.has(term) ? null : term.toLowerCase(), // index term processing + searchOptions: { + processTerm: (term) => term.toLowerCase() // search query processing + } +}) +``` + +The default term processor can be obtained by calling +`MiniSearch.getDefault('processTerm')`. + +### API Documentation + +Refer to the [API +documentation](https://lucaong.github.io/minisearch/classes/_minisearch_.minisearch.html) +for details about configuration options and methods. + + +## Browser compatibility + +`MiniSearch` natively supports all modern browsers implementing JavaScript +standards, but requires a polyfill when used in Internet Explorer, as it makes +use functions like `Object.entries`, `Array.includes`, and `Array.from`, which +are standard but not available on older browsers. The package +[`core-js`](https://github.com/zloirock/core-js) is one such polyfill that can +be used to provide those functions. + +## Contributing + +Contributions to `MiniSearch` are welcome! Please read the [contributions +guidelines](https://github.com/lucaong/minisearch/blob/master/CONTRIBUTING.md). +Reading the [design +document](https://github.com/lucaong/minisearch/blob/master/DESIGN_DOCUMENT.md) is +also useful to understand the project goals and the technical implementation. diff --git a/node_modules/minisearch/dist/es/SearchableMap.js b/node_modules/minisearch/dist/es/SearchableMap.js new file mode 100644 index 0000000..6364fa9 --- /dev/null +++ b/node_modules/minisearch/dist/es/SearchableMap.js @@ -0,0 +1,672 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ + +function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +} + +function __read(o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +} + +/** @ignore */ +var ENTRIES = 'ENTRIES'; +/** @ignore */ +var KEYS = 'KEYS'; +/** @ignore */ +var VALUES = 'VALUES'; +/** @ignore */ +var LEAF = ''; +/** + * @private + */ +var TreeIterator = /** @class */ (function () { + function TreeIterator(set, type) { + var node = set._tree; + var keys = Array.from(node.keys()); + this.set = set; + this._type = type; + this._path = keys.length > 0 ? [{ node: node, keys: keys }] : []; + } + TreeIterator.prototype.next = function () { + var value = this.dive(); + this.backtrack(); + return value; + }; + TreeIterator.prototype.dive = function () { + if (this._path.length === 0) { + return { done: true, value: undefined }; + } + var _a = last$1(this._path), node = _a.node, keys = _a.keys; + if (last$1(keys) === LEAF) { + return { done: false, value: this.result() }; + } + this._path.push({ node: node.get(last$1(keys)), keys: Array.from(node.get(last$1(keys)).keys()) }); + return this.dive(); + }; + TreeIterator.prototype.backtrack = function () { + if (this._path.length === 0) { + return; + } + last$1(this._path).keys.pop(); + if (last$1(this._path).keys.length > 0) { + return; + } + this._path.pop(); + this.backtrack(); + }; + TreeIterator.prototype.key = function () { + return this.set._prefix + this._path + .map(function (_a) { + var keys = _a.keys; + return last$1(keys); + }) + .filter(function (key) { return key !== LEAF; }) + .join(''); + }; + TreeIterator.prototype.value = function () { + return last$1(this._path).node.get(LEAF); + }; + TreeIterator.prototype.result = function () { + if (this._type === VALUES) { + return this.value(); + } + if (this._type === KEYS) { + return this.key(); + } + return [this.key(), this.value()]; + }; + TreeIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return TreeIterator; +}()); +var last$1 = function (array) { + return array[array.length - 1]; +}; + +/** + * @ignore + */ +var fuzzySearch = function (node, query, maxDistance) { + var results = new Map(); + if (query === undefined) + return results; + // Number of columns in the Levenshtein matrix. + var n = query.length + 1; + // Matching terms can never be longer than N + maxDistance. + var maxLength = n + maxDistance; + // Fill first matrix row with consecutive numbers 0 1 2 3 ... (n - 1) + var matrix = new Uint8Array(maxLength * n); + for (var i = 0; i < n; i++) + matrix[i] = i; + recurse(node, query, maxDistance, results, matrix, n, n, ''); + return results; +}; +// Modified version of http://stevehanov.ca/blog/?id=114 +// This builds a Levenshtein matrix for a given query and continuously updates +// it for nodes in the radix tree that fall within the given maximum edit +// distance. Keeping the same matrix around is beneficial especially for larger +// edit distances. +// +// k a t e <-- query +// 0 1 2 3 4 +// c 1 1 2 3 4 +// a 2 2 1 2 3 +// t 3 3 2 1 [2] <-- edit distance +// ^ +// ^ term in radix tree, rows are added and removed as needed +var recurse = function (node, query, maxDistance, results, matrix, offset, n, prefix) { + var e_1, _a; + try { + key: for (var _b = __values(node.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var key = _c.value; + if (key === LEAF) { + // We've reached a leaf node. Check if the edit distance acceptable and + // store the result if it is. + var distance = matrix[offset - 1]; + if (distance <= maxDistance) { + results.set(prefix, [node.get(key), distance]); + } + } + else { + // Iterate over all characters in the key. Update the Levenshtein matrix + // and check if the minimum distance in the last row is still within the + // maximum edit distance. If it is, we can recurse over all child nodes. + for (var i = 0; i < key.length; i++) { + var char = key[i]; + var thisRowOffset = offset + n * i; + var prevRowOffset = thisRowOffset - n; + // Set the first column based on the previous row, and initialize the + // minimum distance in the current row. + var minDistance = matrix[thisRowOffset] = matrix[prevRowOffset] + 1; + // Iterate over remaining columns (characters in the query). + for (var j = 0; j < n - 1; j++) { + var different = char !== query[j]; + // It might make sense to only read the matrix positions used for + // deletion/insertion if the characters are different. But we want to + // avoid conditional reads for performance reasons. + var rpl = matrix[prevRowOffset + j] + +different; + var del = matrix[prevRowOffset + j + 1] + 1; + var ins = matrix[thisRowOffset + j] + 1; + var dist = matrix[thisRowOffset + j + 1] = Math.min(rpl, del, ins); + if (dist < minDistance) + minDistance = dist; + } + // Because distance will never decrease, we can stop. There will be no + // matching child nodes. + if (minDistance > maxDistance) { + continue key; + } + } + recurse(node.get(key), query, maxDistance, results, matrix, offset + n * key.length, n, prefix + key); + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_1) throw e_1.error; } + } +}; + +/** + * A class implementing the same interface as a standard JavaScript + * [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) + * with string keys, but adding support for efficiently searching entries with + * prefix or fuzzy search. This class is used internally by [[MiniSearch]] as + * the inverted index data structure. The implementation is a radix tree + * (compressed prefix tree). + * + * Since this class can be of general utility beyond _MiniSearch_, it is + * exported by the `minisearch` package and can be imported (or required) as + * `minisearch/SearchableMap`. + * + * @typeParam T The type of the values stored in the map. + */ +var SearchableMap = /** @class */ (function () { + /** + * The constructor is normally called without arguments, creating an empty + * map. In order to create a [[SearchableMap]] from an iterable or from an + * object, check [[SearchableMap.from]] and [[SearchableMap.fromObject]]. + * + * The constructor arguments are for internal use, when creating derived + * mutable views of a map at a prefix. + */ + function SearchableMap(tree, prefix) { + if (tree === void 0) { tree = new Map(); } + if (prefix === void 0) { prefix = ''; } + this._size = undefined; + this._tree = tree; + this._prefix = prefix; + } + /** + * Creates and returns a mutable view of this [[SearchableMap]], containing only + * entries that share the given prefix. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set("unicorn", 1) + * map.set("universe", 2) + * map.set("university", 3) + * map.set("unique", 4) + * map.set("hello", 5) + * + * let uni = map.atPrefix("uni") + * uni.get("unique") // => 4 + * uni.get("unicorn") // => 1 + * uni.get("hello") // => undefined + * + * let univer = map.atPrefix("univer") + * univer.get("unique") // => undefined + * univer.get("universe") // => 2 + * univer.get("university") // => 3 + * ``` + * + * @param prefix The prefix + * @return A [[SearchableMap]] representing a mutable view of the original Map at the given prefix + */ + SearchableMap.prototype.atPrefix = function (prefix) { + var e_1, _a; + if (!prefix.startsWith(this._prefix)) { + throw new Error('Mismatched prefix'); + } + var _b = __read(trackDown(this._tree, prefix.slice(this._prefix.length)), 2), node = _b[0], path = _b[1]; + if (node === undefined) { + var _c = __read(last(path), 2), parentNode = _c[0], key = _c[1]; + try { + for (var _d = __values(parentNode.keys()), _e = _d.next(); !_e.done; _e = _d.next()) { + var k = _e.value; + if (k !== LEAF && k.startsWith(key)) { + var node_1 = new Map(); + node_1.set(k.slice(key.length), parentNode.get(k)); + return new SearchableMap(node_1, prefix); + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (_e && !_e.done && (_a = _d.return)) _a.call(_d); + } + finally { if (e_1) throw e_1.error; } + } + } + return new SearchableMap(node, prefix); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear + */ + SearchableMap.prototype.clear = function () { + this._size = undefined; + this._tree.clear(); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete + * @param key Key to delete + */ + SearchableMap.prototype.delete = function (key) { + this._size = undefined; + return remove(this._tree, key); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries + * @return An iterator iterating through `[key, value]` entries. + */ + SearchableMap.prototype.entries = function () { + return new TreeIterator(this, ENTRIES); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach + * @param fn Iteration function + */ + SearchableMap.prototype.forEach = function (fn) { + var e_2, _a; + try { + for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) { + var _d = __read(_c.value, 2), key = _d[0], value = _d[1]; + fn(key, value, this); + } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_2) throw e_2.error; } + } + }; + /** + * Returns a Map of all the entries that have a key within the given edit + * distance from the search key. The keys of the returned Map are the matching + * keys, while the values are two-element arrays where the first element is + * the value associated to the key, and the second is the edit distance of the + * key to the search key. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set('hello', 'world') + * map.set('hell', 'yeah') + * map.set('ciao', 'mondo') + * + * // Get all entries that match the key 'hallo' with a maximum edit distance of 2 + * map.fuzzyGet('hallo', 2) + * // => Map(2) { 'hello' => ['world', 1], 'hell' => ['yeah', 2] } + * + * // In the example, the "hello" key has value "world" and edit distance of 1 + * // (change "e" to "a"), the key "hell" has value "yeah" and edit distance of 2 + * // (change "e" to "a", delete "o") + * ``` + * + * @param key The search key + * @param maxEditDistance The maximum edit distance (Levenshtein) + * @return A Map of the matching keys to their value and edit distance + */ + SearchableMap.prototype.fuzzyGet = function (key, maxEditDistance) { + return fuzzySearch(this._tree, key, maxEditDistance); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get + * @param key Key to get + * @return Value associated to the key, or `undefined` if the key is not + * found. + */ + SearchableMap.prototype.get = function (key) { + var node = lookup(this._tree, key); + return node !== undefined ? node.get(LEAF) : undefined; + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has + * @param key Key + * @return True if the key is in the map, false otherwise + */ + SearchableMap.prototype.has = function (key) { + var node = lookup(this._tree, key); + return node !== undefined && node.has(LEAF); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys + * @return An `Iterable` iterating through keys + */ + SearchableMap.prototype.keys = function () { + return new TreeIterator(this, KEYS); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set + * @param key Key to set + * @param value Value to associate to the key + * @return The [[SearchableMap]] itself, to allow chaining + */ + SearchableMap.prototype.set = function (key, value) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + node.set(LEAF, value); + return this; + }; + Object.defineProperty(SearchableMap.prototype, "size", { + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size + */ + get: function () { + if (this._size) { + return this._size; + } + /** @ignore */ + this._size = 0; + var iter = this.entries(); + while (!iter.next().done) + this._size += 1; + return this._size; + }, + enumerable: false, + configurable: true + }); + /** + * Updates the value at the given key using the provided function. The function + * is called with the current value at the key, and its return value is used as + * the new value to be set. + * + * ### Example: + * + * ```javascript + * // Increment the current value by one + * searchableMap.update('somekey', (currentValue) => currentValue == null ? 0 : currentValue + 1) + * ``` + * + * If the value at the given key is or will be an object, it might not require + * re-assignment. In that case it is better to use `fetch()`, because it is + * faster. + * + * @param key The key to update + * @param fn The function used to compute the new value from the current one + * @return The [[SearchableMap]] itself, to allow chaining + */ + SearchableMap.prototype.update = function (key, fn) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + node.set(LEAF, fn(node.get(LEAF))); + return this; + }; + /** + * Fetches the value of the given key. If the value does not exist, calls the + * given function to create a new value, which is inserted at the given key + * and subsequently returned. + * + * ### Example: + * + * ```javascript + * const map = searchableMap.fetch('somekey', () => new Map()) + * map.set('foo', 'bar') + * ``` + * + * @param key The key to update + * @param defaultValue A function that creates a new value if the key does not exist + * @return The existing or new value at the given key + */ + SearchableMap.prototype.fetch = function (key, initial) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + var value = node.get(LEAF); + if (value === undefined) { + node.set(LEAF, value = initial()); + } + return value; + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values + * @return An `Iterable` iterating through values. + */ + SearchableMap.prototype.values = function () { + return new TreeIterator(this, VALUES); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/@@iterator + */ + SearchableMap.prototype[Symbol.iterator] = function () { + return this.entries(); + }; + /** + * Creates a [[SearchableMap]] from an `Iterable` of entries + * + * @param entries Entries to be inserted in the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + SearchableMap.from = function (entries) { + var e_3, _a; + var tree = new SearchableMap(); + try { + for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) { + var _b = __read(entries_1_1.value, 2), key = _b[0], value = _b[1]; + tree.set(key, value); + } + } + catch (e_3_1) { e_3 = { error: e_3_1 }; } + finally { + try { + if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1); + } + finally { if (e_3) throw e_3.error; } + } + return tree; + }; + /** + * Creates a [[SearchableMap]] from the iterable properties of a JavaScript object + * + * @param object Object of entries for the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + SearchableMap.fromObject = function (object) { + return SearchableMap.from(Object.entries(object)); + }; + return SearchableMap; +}()); +var trackDown = function (tree, key, path) { + var e_4, _a; + if (path === void 0) { path = []; } + if (key.length === 0 || tree == null) { + return [tree, path]; + } + try { + for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var k = _c.value; + if (k !== LEAF && key.startsWith(k)) { + path.push([tree, k]); // performance: update in place + return trackDown(tree.get(k), key.slice(k.length), path); + } + } + } + catch (e_4_1) { e_4 = { error: e_4_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_4) throw e_4.error; } + } + path.push([tree, key]); // performance: update in place + return trackDown(undefined, '', path); +}; +var lookup = function (tree, key) { + var e_5, _a; + if (key.length === 0 || tree == null) { + return tree; + } + try { + for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var k = _c.value; + if (k !== LEAF && key.startsWith(k)) { + return lookup(tree.get(k), key.slice(k.length)); + } + } + } + catch (e_5_1) { e_5 = { error: e_5_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_5) throw e_5.error; } + } +}; +var createPath = function (tree, key) { + var e_6, _a, e_7, _b; + if (key.length === 0 || tree == null) { + return tree; + } + try { + for (var _c = __values(tree.keys()), _d = _c.next(); !_d.done; _d = _c.next()) { + var k = _d.value; + if (k !== LEAF && key.startsWith(k)) { + return createPath(tree.get(k), key.slice(k.length)); + } + } + } + catch (e_6_1) { e_6 = { error: e_6_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_6) throw e_6.error; } + } + try { + for (var _e = __values(tree.keys()), _f = _e.next(); !_f.done; _f = _e.next()) { + var k = _f.value; + if (k !== LEAF && k.startsWith(key[0])) { + var offset = commonPrefixOffset(key, k); + var node_2 = new Map(); + node_2.set(k.slice(offset), tree.get(k)); + tree.set(key.slice(0, offset), node_2); + tree.delete(k); + return createPath(node_2, key.slice(offset)); + } + } + } + catch (e_7_1) { e_7 = { error: e_7_1 }; } + finally { + try { + if (_f && !_f.done && (_b = _e.return)) _b.call(_e); + } + finally { if (e_7) throw e_7.error; } + } + var node = new Map(); + tree.set(key, node); + return node; +}; +var commonPrefixOffset = function (a, b) { + var length = Math.min(a.length, b.length); + for (var i = 0; i < length; i++) { + if (a[i] !== b[i]) + return i; + } + return length; +}; +var remove = function (tree, key) { + var _a = __read(trackDown(tree, key), 2), node = _a[0], path = _a[1]; + if (node === undefined) { + return; + } + node.delete(LEAF); + if (node.size === 0) { + cleanup(path); + } + else if (node.size === 1) { + var _b = __read(node.entries().next().value, 2), key_1 = _b[0], value = _b[1]; + merge(path, key_1, value); + } +}; +var cleanup = function (path) { + if (path.length === 0) { + return; + } + var _a = __read(last(path), 2), node = _a[0], key = _a[1]; + node.delete(key); + if (node.size === 0) { + cleanup(path.slice(0, -1)); + } + else if (node.size === 1) { + var _b = __read(node.entries().next().value, 2), key_2 = _b[0], value = _b[1]; + if (key_2 !== LEAF) { + merge(path.slice(0, -1), key_2, value); + } + } +}; +var merge = function (path, key, value) { + if (path.length === 0) { + return; + } + var _a = __read(last(path), 2), node = _a[0], nodeKey = _a[1]; + node.set(nodeKey + key, value); + node.delete(nodeKey); +}; +var last = function (array) { + return array[array.length - 1]; +}; + +export { SearchableMap as default }; +//# sourceMappingURL=SearchableMap.js.map diff --git a/node_modules/minisearch/dist/es/SearchableMap.js.map b/node_modules/minisearch/dist/es/SearchableMap.js.map new file mode 100644 index 0000000..cec0f7a --- /dev/null +++ b/node_modules/minisearch/dist/es/SearchableMap.js.map @@ -0,0 +1 @@ +{"version":3,"file":"SearchableMap.js","sources":["../../node_modules/tslib/tslib.es6.js","../../src/SearchableMap/TreeIterator.ts","../../src/SearchableMap/fuzzySearch.ts","../../src/SearchableMap/SearchableMap.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n",null,null,null],"names":["last"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAyGA;AACO,SAAS,QAAQ,CAAC,CAAC,EAAE;AAC5B,IAAI,IAAI,CAAC,GAAG,OAAO,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;AAClF,IAAI,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC5B,IAAI,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,EAAE,OAAO;AAClD,QAAQ,IAAI,EAAE,YAAY;AAC1B,YAAY,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC;AAC/C,YAAY,OAAO,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,IAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AACvB,CAAC,CAAA;AAED,IAAM,IAAI,GAAG,UAAU,KAAU;IAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AAChC,CAAC;;;;"} \ No newline at end of file diff --git a/node_modules/minisearch/dist/es/index.js b/node_modules/minisearch/dist/es/index.js new file mode 100644 index 0000000..65b9bd3 --- /dev/null +++ b/node_modules/minisearch/dist/es/index.js @@ -0,0 +1,1956 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ + +var __assign = function() { + __assign = Object.assign || function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; + +function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +} + +function __read(o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +} + +function __spreadArray(to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +} + +/** @ignore */ +var ENTRIES = 'ENTRIES'; +/** @ignore */ +var KEYS = 'KEYS'; +/** @ignore */ +var VALUES = 'VALUES'; +/** @ignore */ +var LEAF = ''; +/** + * @private + */ +var TreeIterator = /** @class */ (function () { + function TreeIterator(set, type) { + var node = set._tree; + var keys = Array.from(node.keys()); + this.set = set; + this._type = type; + this._path = keys.length > 0 ? [{ node: node, keys: keys }] : []; + } + TreeIterator.prototype.next = function () { + var value = this.dive(); + this.backtrack(); + return value; + }; + TreeIterator.prototype.dive = function () { + if (this._path.length === 0) { + return { done: true, value: undefined }; + } + var _a = last$1(this._path), node = _a.node, keys = _a.keys; + if (last$1(keys) === LEAF) { + return { done: false, value: this.result() }; + } + this._path.push({ node: node.get(last$1(keys)), keys: Array.from(node.get(last$1(keys)).keys()) }); + return this.dive(); + }; + TreeIterator.prototype.backtrack = function () { + if (this._path.length === 0) { + return; + } + last$1(this._path).keys.pop(); + if (last$1(this._path).keys.length > 0) { + return; + } + this._path.pop(); + this.backtrack(); + }; + TreeIterator.prototype.key = function () { + return this.set._prefix + this._path + .map(function (_a) { + var keys = _a.keys; + return last$1(keys); + }) + .filter(function (key) { return key !== LEAF; }) + .join(''); + }; + TreeIterator.prototype.value = function () { + return last$1(this._path).node.get(LEAF); + }; + TreeIterator.prototype.result = function () { + if (this._type === VALUES) { + return this.value(); + } + if (this._type === KEYS) { + return this.key(); + } + return [this.key(), this.value()]; + }; + TreeIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return TreeIterator; +}()); +var last$1 = function (array) { + return array[array.length - 1]; +}; + +/** + * @ignore + */ +var fuzzySearch = function (node, query, maxDistance) { + var results = new Map(); + if (query === undefined) + return results; + // Number of columns in the Levenshtein matrix. + var n = query.length + 1; + // Matching terms can never be longer than N + maxDistance. + var maxLength = n + maxDistance; + // Fill first matrix row with consecutive numbers 0 1 2 3 ... (n - 1) + var matrix = new Uint8Array(maxLength * n); + for (var i = 0; i < n; i++) + matrix[i] = i; + recurse(node, query, maxDistance, results, matrix, n, n, ''); + return results; +}; +// Modified version of http://stevehanov.ca/blog/?id=114 +// This builds a Levenshtein matrix for a given query and continuously updates +// it for nodes in the radix tree that fall within the given maximum edit +// distance. Keeping the same matrix around is beneficial especially for larger +// edit distances. +// +// k a t e <-- query +// 0 1 2 3 4 +// c 1 1 2 3 4 +// a 2 2 1 2 3 +// t 3 3 2 1 [2] <-- edit distance +// ^ +// ^ term in radix tree, rows are added and removed as needed +var recurse = function (node, query, maxDistance, results, matrix, offset, n, prefix) { + var e_1, _a; + try { + key: for (var _b = __values(node.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var key = _c.value; + if (key === LEAF) { + // We've reached a leaf node. Check if the edit distance acceptable and + // store the result if it is. + var distance = matrix[offset - 1]; + if (distance <= maxDistance) { + results.set(prefix, [node.get(key), distance]); + } + } + else { + // Iterate over all characters in the key. Update the Levenshtein matrix + // and check if the minimum distance in the last row is still within the + // maximum edit distance. If it is, we can recurse over all child nodes. + for (var i = 0; i < key.length; i++) { + var char = key[i]; + var thisRowOffset = offset + n * i; + var prevRowOffset = thisRowOffset - n; + // Set the first column based on the previous row, and initialize the + // minimum distance in the current row. + var minDistance = matrix[thisRowOffset] = matrix[prevRowOffset] + 1; + // Iterate over remaining columns (characters in the query). + for (var j = 0; j < n - 1; j++) { + var different = char !== query[j]; + // It might make sense to only read the matrix positions used for + // deletion/insertion if the characters are different. But we want to + // avoid conditional reads for performance reasons. + var rpl = matrix[prevRowOffset + j] + +different; + var del = matrix[prevRowOffset + j + 1] + 1; + var ins = matrix[thisRowOffset + j] + 1; + var dist = matrix[thisRowOffset + j + 1] = Math.min(rpl, del, ins); + if (dist < minDistance) + minDistance = dist; + } + // Because distance will never decrease, we can stop. There will be no + // matching child nodes. + if (minDistance > maxDistance) { + continue key; + } + } + recurse(node.get(key), query, maxDistance, results, matrix, offset + n * key.length, n, prefix + key); + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_1) throw e_1.error; } + } +}; + +/** + * A class implementing the same interface as a standard JavaScript + * [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) + * with string keys, but adding support for efficiently searching entries with + * prefix or fuzzy search. This class is used internally by [[MiniSearch]] as + * the inverted index data structure. The implementation is a radix tree + * (compressed prefix tree). + * + * Since this class can be of general utility beyond _MiniSearch_, it is + * exported by the `minisearch` package and can be imported (or required) as + * `minisearch/SearchableMap`. + * + * @typeParam T The type of the values stored in the map. + */ +var SearchableMap = /** @class */ (function () { + /** + * The constructor is normally called without arguments, creating an empty + * map. In order to create a [[SearchableMap]] from an iterable or from an + * object, check [[SearchableMap.from]] and [[SearchableMap.fromObject]]. + * + * The constructor arguments are for internal use, when creating derived + * mutable views of a map at a prefix. + */ + function SearchableMap(tree, prefix) { + if (tree === void 0) { tree = new Map(); } + if (prefix === void 0) { prefix = ''; } + this._size = undefined; + this._tree = tree; + this._prefix = prefix; + } + /** + * Creates and returns a mutable view of this [[SearchableMap]], containing only + * entries that share the given prefix. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set("unicorn", 1) + * map.set("universe", 2) + * map.set("university", 3) + * map.set("unique", 4) + * map.set("hello", 5) + * + * let uni = map.atPrefix("uni") + * uni.get("unique") // => 4 + * uni.get("unicorn") // => 1 + * uni.get("hello") // => undefined + * + * let univer = map.atPrefix("univer") + * univer.get("unique") // => undefined + * univer.get("universe") // => 2 + * univer.get("university") // => 3 + * ``` + * + * @param prefix The prefix + * @return A [[SearchableMap]] representing a mutable view of the original Map at the given prefix + */ + SearchableMap.prototype.atPrefix = function (prefix) { + var e_1, _a; + if (!prefix.startsWith(this._prefix)) { + throw new Error('Mismatched prefix'); + } + var _b = __read(trackDown(this._tree, prefix.slice(this._prefix.length)), 2), node = _b[0], path = _b[1]; + if (node === undefined) { + var _c = __read(last(path), 2), parentNode = _c[0], key = _c[1]; + try { + for (var _d = __values(parentNode.keys()), _e = _d.next(); !_e.done; _e = _d.next()) { + var k = _e.value; + if (k !== LEAF && k.startsWith(key)) { + var node_1 = new Map(); + node_1.set(k.slice(key.length), parentNode.get(k)); + return new SearchableMap(node_1, prefix); + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (_e && !_e.done && (_a = _d.return)) _a.call(_d); + } + finally { if (e_1) throw e_1.error; } + } + } + return new SearchableMap(node, prefix); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear + */ + SearchableMap.prototype.clear = function () { + this._size = undefined; + this._tree.clear(); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete + * @param key Key to delete + */ + SearchableMap.prototype.delete = function (key) { + this._size = undefined; + return remove(this._tree, key); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries + * @return An iterator iterating through `[key, value]` entries. + */ + SearchableMap.prototype.entries = function () { + return new TreeIterator(this, ENTRIES); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach + * @param fn Iteration function + */ + SearchableMap.prototype.forEach = function (fn) { + var e_2, _a; + try { + for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) { + var _d = __read(_c.value, 2), key = _d[0], value = _d[1]; + fn(key, value, this); + } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_2) throw e_2.error; } + } + }; + /** + * Returns a Map of all the entries that have a key within the given edit + * distance from the search key. The keys of the returned Map are the matching + * keys, while the values are two-element arrays where the first element is + * the value associated to the key, and the second is the edit distance of the + * key to the search key. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set('hello', 'world') + * map.set('hell', 'yeah') + * map.set('ciao', 'mondo') + * + * // Get all entries that match the key 'hallo' with a maximum edit distance of 2 + * map.fuzzyGet('hallo', 2) + * // => Map(2) { 'hello' => ['world', 1], 'hell' => ['yeah', 2] } + * + * // In the example, the "hello" key has value "world" and edit distance of 1 + * // (change "e" to "a"), the key "hell" has value "yeah" and edit distance of 2 + * // (change "e" to "a", delete "o") + * ``` + * + * @param key The search key + * @param maxEditDistance The maximum edit distance (Levenshtein) + * @return A Map of the matching keys to their value and edit distance + */ + SearchableMap.prototype.fuzzyGet = function (key, maxEditDistance) { + return fuzzySearch(this._tree, key, maxEditDistance); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get + * @param key Key to get + * @return Value associated to the key, or `undefined` if the key is not + * found. + */ + SearchableMap.prototype.get = function (key) { + var node = lookup(this._tree, key); + return node !== undefined ? node.get(LEAF) : undefined; + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has + * @param key Key + * @return True if the key is in the map, false otherwise + */ + SearchableMap.prototype.has = function (key) { + var node = lookup(this._tree, key); + return node !== undefined && node.has(LEAF); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys + * @return An `Iterable` iterating through keys + */ + SearchableMap.prototype.keys = function () { + return new TreeIterator(this, KEYS); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set + * @param key Key to set + * @param value Value to associate to the key + * @return The [[SearchableMap]] itself, to allow chaining + */ + SearchableMap.prototype.set = function (key, value) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + node.set(LEAF, value); + return this; + }; + Object.defineProperty(SearchableMap.prototype, "size", { + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size + */ + get: function () { + if (this._size) { + return this._size; + } + /** @ignore */ + this._size = 0; + var iter = this.entries(); + while (!iter.next().done) + this._size += 1; + return this._size; + }, + enumerable: false, + configurable: true + }); + /** + * Updates the value at the given key using the provided function. The function + * is called with the current value at the key, and its return value is used as + * the new value to be set. + * + * ### Example: + * + * ```javascript + * // Increment the current value by one + * searchableMap.update('somekey', (currentValue) => currentValue == null ? 0 : currentValue + 1) + * ``` + * + * If the value at the given key is or will be an object, it might not require + * re-assignment. In that case it is better to use `fetch()`, because it is + * faster. + * + * @param key The key to update + * @param fn The function used to compute the new value from the current one + * @return The [[SearchableMap]] itself, to allow chaining + */ + SearchableMap.prototype.update = function (key, fn) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + node.set(LEAF, fn(node.get(LEAF))); + return this; + }; + /** + * Fetches the value of the given key. If the value does not exist, calls the + * given function to create a new value, which is inserted at the given key + * and subsequently returned. + * + * ### Example: + * + * ```javascript + * const map = searchableMap.fetch('somekey', () => new Map()) + * map.set('foo', 'bar') + * ``` + * + * @param key The key to update + * @param defaultValue A function that creates a new value if the key does not exist + * @return The existing or new value at the given key + */ + SearchableMap.prototype.fetch = function (key, initial) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + var value = node.get(LEAF); + if (value === undefined) { + node.set(LEAF, value = initial()); + } + return value; + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values + * @return An `Iterable` iterating through values. + */ + SearchableMap.prototype.values = function () { + return new TreeIterator(this, VALUES); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/@@iterator + */ + SearchableMap.prototype[Symbol.iterator] = function () { + return this.entries(); + }; + /** + * Creates a [[SearchableMap]] from an `Iterable` of entries + * + * @param entries Entries to be inserted in the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + SearchableMap.from = function (entries) { + var e_3, _a; + var tree = new SearchableMap(); + try { + for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) { + var _b = __read(entries_1_1.value, 2), key = _b[0], value = _b[1]; + tree.set(key, value); + } + } + catch (e_3_1) { e_3 = { error: e_3_1 }; } + finally { + try { + if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1); + } + finally { if (e_3) throw e_3.error; } + } + return tree; + }; + /** + * Creates a [[SearchableMap]] from the iterable properties of a JavaScript object + * + * @param object Object of entries for the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + SearchableMap.fromObject = function (object) { + return SearchableMap.from(Object.entries(object)); + }; + return SearchableMap; +}()); +var trackDown = function (tree, key, path) { + var e_4, _a; + if (path === void 0) { path = []; } + if (key.length === 0 || tree == null) { + return [tree, path]; + } + try { + for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var k = _c.value; + if (k !== LEAF && key.startsWith(k)) { + path.push([tree, k]); // performance: update in place + return trackDown(tree.get(k), key.slice(k.length), path); + } + } + } + catch (e_4_1) { e_4 = { error: e_4_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_4) throw e_4.error; } + } + path.push([tree, key]); // performance: update in place + return trackDown(undefined, '', path); +}; +var lookup = function (tree, key) { + var e_5, _a; + if (key.length === 0 || tree == null) { + return tree; + } + try { + for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var k = _c.value; + if (k !== LEAF && key.startsWith(k)) { + return lookup(tree.get(k), key.slice(k.length)); + } + } + } + catch (e_5_1) { e_5 = { error: e_5_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_5) throw e_5.error; } + } +}; +var createPath = function (tree, key) { + var e_6, _a, e_7, _b; + if (key.length === 0 || tree == null) { + return tree; + } + try { + for (var _c = __values(tree.keys()), _d = _c.next(); !_d.done; _d = _c.next()) { + var k = _d.value; + if (k !== LEAF && key.startsWith(k)) { + return createPath(tree.get(k), key.slice(k.length)); + } + } + } + catch (e_6_1) { e_6 = { error: e_6_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_6) throw e_6.error; } + } + try { + for (var _e = __values(tree.keys()), _f = _e.next(); !_f.done; _f = _e.next()) { + var k = _f.value; + if (k !== LEAF && k.startsWith(key[0])) { + var offset = commonPrefixOffset(key, k); + var node_2 = new Map(); + node_2.set(k.slice(offset), tree.get(k)); + tree.set(key.slice(0, offset), node_2); + tree.delete(k); + return createPath(node_2, key.slice(offset)); + } + } + } + catch (e_7_1) { e_7 = { error: e_7_1 }; } + finally { + try { + if (_f && !_f.done && (_b = _e.return)) _b.call(_e); + } + finally { if (e_7) throw e_7.error; } + } + var node = new Map(); + tree.set(key, node); + return node; +}; +var commonPrefixOffset = function (a, b) { + var length = Math.min(a.length, b.length); + for (var i = 0; i < length; i++) { + if (a[i] !== b[i]) + return i; + } + return length; +}; +var remove = function (tree, key) { + var _a = __read(trackDown(tree, key), 2), node = _a[0], path = _a[1]; + if (node === undefined) { + return; + } + node.delete(LEAF); + if (node.size === 0) { + cleanup(path); + } + else if (node.size === 1) { + var _b = __read(node.entries().next().value, 2), key_1 = _b[0], value = _b[1]; + merge(path, key_1, value); + } +}; +var cleanup = function (path) { + if (path.length === 0) { + return; + } + var _a = __read(last(path), 2), node = _a[0], key = _a[1]; + node.delete(key); + if (node.size === 0) { + cleanup(path.slice(0, -1)); + } + else if (node.size === 1) { + var _b = __read(node.entries().next().value, 2), key_2 = _b[0], value = _b[1]; + if (key_2 !== LEAF) { + merge(path.slice(0, -1), key_2, value); + } + } +}; +var merge = function (path, key, value) { + if (path.length === 0) { + return; + } + var _a = __read(last(path), 2), node = _a[0], nodeKey = _a[1]; + node.set(nodeKey + key, value); + node.delete(nodeKey); +}; +var last = function (array) { + return array[array.length - 1]; +}; + +var _a; +var OR = 'or'; +var AND = 'and'; +var AND_NOT = 'and_not'; +/** + * [[MiniSearch]] is the main entrypoint class, implementing a full-text search + * engine in memory. + * + * @typeParam T The type of the documents being indexed. + * + * ### Basic example: + * + * ```javascript + * const documents = [ + * { + * id: 1, + * title: 'Moby Dick', + * text: 'Call me Ishmael. Some years ago...', + * category: 'fiction' + * }, + * { + * id: 2, + * title: 'Zen and the Art of Motorcycle Maintenance', + * text: 'I can see by my watch...', + * category: 'fiction' + * }, + * { + * id: 3, + * title: 'Neuromancer', + * text: 'The sky above the port was...', + * category: 'fiction' + * }, + * { + * id: 4, + * title: 'Zen and the Art of Archery', + * text: 'At first sight it must seem...', + * category: 'non-fiction' + * }, + * // ...and more + * ] + * + * // Create a search engine that indexes the 'title' and 'text' fields for + * // full-text search. Search results will include 'title' and 'category' (plus the + * // id field, that is always stored and returned) + * const miniSearch = new MiniSearch({ + * fields: ['title', 'text'], + * storeFields: ['title', 'category'] + * }) + * + * // Add documents to the index + * miniSearch.addAll(documents) + * + * // Search for documents: + * let results = miniSearch.search('zen art motorcycle') + * // => [ + * // { id: 2, title: 'Zen and the Art of Motorcycle Maintenance', category: 'fiction', score: 2.77258 }, + * // { id: 4, title: 'Zen and the Art of Archery', category: 'non-fiction', score: 1.38629 } + * // ] + * ``` + */ +var MiniSearch = /** @class */ (function () { + /** + * @param options Configuration options + * + * ### Examples: + * + * ```javascript + * // Create a search engine that indexes the 'title' and 'text' fields of your + * // documents: + * const miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * ``` + * + * ### ID Field: + * + * ```javascript + * // Your documents are assumed to include a unique 'id' field, but if you want + * // to use a different field for document identification, you can set the + * // 'idField' option: + * const miniSearch = new MiniSearch({ idField: 'key', fields: ['title', 'text'] }) + * ``` + * + * ### Options and defaults: + * + * ```javascript + * // The full set of options (here with their default value) is: + * const miniSearch = new MiniSearch({ + * // idField: field that uniquely identifies a document + * idField: 'id', + * + * // extractField: function used to get the value of a field in a document. + * // By default, it assumes the document is a flat object with field names as + * // property keys and field values as string property values, but custom logic + * // can be implemented by setting this option to a custom extractor function. + * extractField: (document, fieldName) => document[fieldName], + * + * // tokenize: function used to split fields into individual terms. By + * // default, it is also used to tokenize search queries, unless a specific + * // `tokenize` search option is supplied. When tokenizing an indexed field, + * // the field name is passed as the second argument. + * tokenize: (string, _fieldName) => string.split(SPACE_OR_PUNCTUATION), + * + * // processTerm: function used to process each tokenized term before + * // indexing. It can be used for stemming and normalization. Return a falsy + * // value in order to discard a term. By default, it is also used to process + * // search queries, unless a specific `processTerm` option is supplied as a + * // search option. When processing a term from a indexed field, the field + * // name is passed as the second argument. + * processTerm: (term, _fieldName) => term.toLowerCase(), + * + * // searchOptions: default search options, see the `search` method for + * // details + * searchOptions: undefined, + * + * // fields: document fields to be indexed. Mandatory, but not set by default + * fields: undefined + * + * // storeFields: document fields to be stored and returned as part of the + * // search results. + * storeFields: [] + * }) + * ``` + */ + function MiniSearch(options) { + if ((options === null || options === void 0 ? void 0 : options.fields) == null) { + throw new Error('MiniSearch: option "fields" must be provided'); + } + this._options = __assign(__assign(__assign({}, defaultOptions), options), { searchOptions: __assign(__assign({}, defaultSearchOptions), (options.searchOptions || {})) }); + this._index = new SearchableMap(); + this._documentCount = 0; + this._documentIds = new Map(); + // Fields are defined during initialization, don't change, are few in + // number, rarely need iterating over, and have string keys. Therefore in + // this case an object is a better candidate than a Map to store the mapping + // from field key to ID. + this._fieldIds = {}; + this._fieldLength = new Map(); + this._averageFieldLength = []; + this._nextId = 0; + this._storedFields = new Map(); + this.addFields(this._options.fields); + } + /** + * Adds a document to the index + * + * @param document The document to be indexed + */ + MiniSearch.prototype.add = function (document) { + var e_1, _a, e_2, _b; + var _c = this._options, extractField = _c.extractField, tokenize = _c.tokenize, processTerm = _c.processTerm, fields = _c.fields, idField = _c.idField; + var id = extractField(document, idField); + if (id == null) { + throw new Error("MiniSearch: document does not have ID field \"".concat(idField, "\"")); + } + var shortDocumentId = this.addDocumentId(id); + this.saveStoredFields(shortDocumentId, document); + try { + for (var fields_1 = __values(fields), fields_1_1 = fields_1.next(); !fields_1_1.done; fields_1_1 = fields_1.next()) { + var field = fields_1_1.value; + var fieldValue = extractField(document, field); + if (fieldValue == null) + continue; + var tokens = tokenize(fieldValue.toString(), field); + var fieldId = this._fieldIds[field]; + this.addFieldLength(shortDocumentId, fieldId, this.documentCount - 1, tokens.length); + try { + for (var tokens_1 = (e_2 = void 0, __values(tokens)), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) { + var term = tokens_1_1.value; + var processedTerm = processTerm(term, field); + if (processedTerm) { + this.addTerm(fieldId, shortDocumentId, processedTerm); + } + } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { + if (tokens_1_1 && !tokens_1_1.done && (_b = tokens_1.return)) _b.call(tokens_1); + } + finally { if (e_2) throw e_2.error; } + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (fields_1_1 && !fields_1_1.done && (_a = fields_1.return)) _a.call(fields_1); + } + finally { if (e_1) throw e_1.error; } + } + }; + /** + * Adds all the given documents to the index + * + * @param documents An array of documents to be indexed + */ + MiniSearch.prototype.addAll = function (documents) { + var e_3, _a; + try { + for (var documents_1 = __values(documents), documents_1_1 = documents_1.next(); !documents_1_1.done; documents_1_1 = documents_1.next()) { + var document_1 = documents_1_1.value; + this.add(document_1); + } + } + catch (e_3_1) { e_3 = { error: e_3_1 }; } + finally { + try { + if (documents_1_1 && !documents_1_1.done && (_a = documents_1.return)) _a.call(documents_1); + } + finally { if (e_3) throw e_3.error; } + } + }; + /** + * Adds all the given documents to the index asynchronously. + * + * Returns a promise that resolves (to `undefined`) when the indexing is done. + * This method is useful when index many documents, to avoid blocking the main + * thread. The indexing is performed asynchronously and in chunks. + * + * @param documents An array of documents to be indexed + * @param options Configuration options + * @return A promise resolving to `undefined` when the indexing is done + */ + MiniSearch.prototype.addAllAsync = function (documents, options) { + var _this = this; + if (options === void 0) { options = {}; } + var _a = options.chunkSize, chunkSize = _a === void 0 ? 10 : _a; + var acc = { chunk: [], promise: Promise.resolve() }; + var _b = documents.reduce(function (_a, document, i) { + var chunk = _a.chunk, promise = _a.promise; + chunk.push(document); + if ((i + 1) % chunkSize === 0) { + return { + chunk: [], + promise: promise + .then(function () { return new Promise(function (resolve) { return setTimeout(resolve, 0); }); }) + .then(function () { return _this.addAll(chunk); }) + }; + } + else { + return { chunk: chunk, promise: promise }; + } + }, acc), chunk = _b.chunk, promise = _b.promise; + return promise.then(function () { return _this.addAll(chunk); }); + }; + /** + * Removes the given document from the index. + * + * The document to delete must NOT have changed between indexing and deletion, + * otherwise the index will be corrupted. Therefore, when reindexing a document + * after a change, the correct order of operations is: + * + * 1. remove old version + * 2. apply changes + * 3. index new version + * + * @param document The document to be removed + */ + MiniSearch.prototype.remove = function (document) { + var e_4, _a, e_5, _b, e_6, _c; + var _d = this._options, tokenize = _d.tokenize, processTerm = _d.processTerm, extractField = _d.extractField, fields = _d.fields, idField = _d.idField; + var id = extractField(document, idField); + if (id == null) { + throw new Error("MiniSearch: document does not have ID field \"".concat(idField, "\"")); + } + try { + for (var _e = __values(this._documentIds), _f = _e.next(); !_f.done; _f = _e.next()) { + var _g = __read(_f.value, 2), shortId = _g[0], longId = _g[1]; + if (id === longId) { + try { + for (var fields_2 = (e_5 = void 0, __values(fields)), fields_2_1 = fields_2.next(); !fields_2_1.done; fields_2_1 = fields_2.next()) { + var field = fields_2_1.value; + var fieldValue = extractField(document, field); + if (fieldValue == null) + continue; + var tokens = tokenize(fieldValue.toString(), field); + var fieldId = this._fieldIds[field]; + try { + for (var tokens_2 = (e_6 = void 0, __values(tokens)), tokens_2_1 = tokens_2.next(); !tokens_2_1.done; tokens_2_1 = tokens_2.next()) { + var term = tokens_2_1.value; + var processedTerm = processTerm(term, field); + if (processedTerm) { + this.removeTerm(fieldId, shortId, processedTerm); + } + } + } + catch (e_6_1) { e_6 = { error: e_6_1 }; } + finally { + try { + if (tokens_2_1 && !tokens_2_1.done && (_c = tokens_2.return)) _c.call(tokens_2); + } + finally { if (e_6) throw e_6.error; } + } + this.removeFieldLength(shortId, fieldId, this.documentCount, tokens.length); + } + } + catch (e_5_1) { e_5 = { error: e_5_1 }; } + finally { + try { + if (fields_2_1 && !fields_2_1.done && (_b = fields_2.return)) _b.call(fields_2); + } + finally { if (e_5) throw e_5.error; } + } + this._storedFields.delete(shortId); + this._documentIds.delete(shortId); + this._fieldLength.delete(shortId); + this._documentCount -= 1; + return; + } + } + } + catch (e_4_1) { e_4 = { error: e_4_1 }; } + finally { + try { + if (_f && !_f.done && (_a = _e.return)) _a.call(_e); + } + finally { if (e_4) throw e_4.error; } + } + throw new Error("MiniSearch: cannot remove document with ID ".concat(id, ": it is not in the index")); + }; + /** + * Removes all the given documents from the index. If called with no arguments, + * it removes _all_ documents from the index. + * + * @param documents The documents to be removed. If this argument is omitted, + * all documents are removed. Note that, for removing all documents, it is + * more efficient to call this method with no arguments than to pass all + * documents. + */ + MiniSearch.prototype.removeAll = function (documents) { + var e_7, _a; + if (documents) { + try { + for (var documents_2 = __values(documents), documents_2_1 = documents_2.next(); !documents_2_1.done; documents_2_1 = documents_2.next()) { + var document_2 = documents_2_1.value; + this.remove(document_2); + } + } + catch (e_7_1) { e_7 = { error: e_7_1 }; } + finally { + try { + if (documents_2_1 && !documents_2_1.done && (_a = documents_2.return)) _a.call(documents_2); + } + finally { if (e_7) throw e_7.error; } + } + } + else if (arguments.length > 0) { + throw new Error('Expected documents to be present. Omit the argument to remove all documents.'); + } + else { + this._index = new SearchableMap(); + this._documentCount = 0; + this._documentIds = new Map(); + this._fieldLength = new Map(); + this._averageFieldLength = []; + this._storedFields = new Map(); + this._nextId = 0; + } + }; + /** + * Search for documents matching the given search query. + * + * The result is a list of scored document IDs matching the query, sorted by + * descending score, and each including data about which terms were matched and + * in which fields. + * + * ### Basic usage: + * + * ```javascript + * // Search for "zen art motorcycle" with default options: terms have to match + * // exactly, and individual terms are joined with OR + * miniSearch.search('zen art motorcycle') + * // => [ { id: 2, score: 2.77258, match: { ... } }, { id: 4, score: 1.38629, match: { ... } } ] + * ``` + * + * ### Restrict search to specific fields: + * + * ```javascript + * // Search only in the 'title' field + * miniSearch.search('zen', { fields: ['title'] }) + * ``` + * + * ### Field boosting: + * + * ```javascript + * // Boost a field + * miniSearch.search('zen', { boost: { title: 2 } }) + * ``` + * + * ### Prefix search: + * + * ```javascript + * // Search for "moto" with prefix search (it will match documents + * // containing terms that start with "moto" or "neuro") + * miniSearch.search('moto neuro', { prefix: true }) + * ``` + * + * ### Fuzzy search: + * + * ```javascript + * // Search for "ismael" with fuzzy search (it will match documents containing + * // terms similar to "ismael", with a maximum edit distance of 0.2 term.length + * // (rounded to nearest integer) + * miniSearch.search('ismael', { fuzzy: 0.2 }) + * ``` + * + * ### Combining strategies: + * + * ```javascript + * // Mix of exact match, prefix search, and fuzzy search + * miniSearch.search('ismael mob', { + * prefix: true, + * fuzzy: 0.2 + * }) + * ``` + * + * ### Advanced prefix and fuzzy search: + * + * ```javascript + * // Perform fuzzy and prefix search depending on the search term. Here + * // performing prefix and fuzzy search only on terms longer than 3 characters + * miniSearch.search('ismael mob', { + * prefix: term => term.length > 3 + * fuzzy: term => term.length > 3 ? 0.2 : null + * }) + * ``` + * + * ### Combine with AND: + * + * ```javascript + * // Combine search terms with AND (to match only documents that contain both + * // "motorcycle" and "art") + * miniSearch.search('motorcycle art', { combineWith: 'AND' }) + * ``` + * + * ### Combine with AND_NOT: + * + * There is also an AND_NOT combinator, that finds documents that match the + * first term, but do not match any of the other terms. This combinator is + * rarely useful with simple queries, and is meant to be used with advanced + * query combinations (see later for more details). + * + * ### Filtering results: + * + * ```javascript + * // Filter only results in the 'fiction' category (assuming that 'category' + * // is a stored field) + * miniSearch.search('motorcycle art', { + * filter: (result) => result.category === 'fiction' + * }) + * ``` + * + * ### Advanced combination of queries: + * + * It is possible to combine different subqueries with OR, AND, and AND_NOT, + * and even with different search options, by passing a query expression + * tree object as the first argument, instead of a string. + * + * ```javascript + * // Search for documents that contain "zen" and ("motorcycle" or "archery") + * miniSearch.search({ + * combineWith: 'AND', + * queries: [ + * 'zen', + * { + * combineWith: 'OR', + * queries: ['motorcycle', 'archery'] + * } + * ] + * }) + * + * // Search for documents that contain ("apple" or "pear") but not "juice" and + * // not "tree" + * miniSearch.search({ + * combineWith: 'AND_NOT', + * queries: [ + * { + * combineWith: 'OR', + * queries: ['apple', 'pear'] + * }, + * 'juice', + * 'tree' + * ] + * }) + * ``` + * + * Each node in the expression tree can be either a string, or an object that + * supports all `SearchOptions` fields, plus a `queries` array field for + * subqueries. + * + * Note that, while this can become complicated to do by hand for complex or + * deeply nested queries, it provides a formalized expression tree API for + * external libraries that implement a parser for custom query languages. + * + * @param query Search query + * @param options Search options. Each option, if not given, defaults to the corresponding value of `searchOptions` given to the constructor, or to the library default. + */ + MiniSearch.prototype.search = function (query, searchOptions) { + var e_8, _a; + if (searchOptions === void 0) { searchOptions = {}; } + var combinedResults = this.executeQuery(query, searchOptions); + var results = []; + try { + for (var combinedResults_1 = __values(combinedResults), combinedResults_1_1 = combinedResults_1.next(); !combinedResults_1_1.done; combinedResults_1_1 = combinedResults_1.next()) { + var _b = __read(combinedResults_1_1.value, 2), docId = _b[0], _c = _b[1], score = _c.score, match = _c.match, terms = _c.terms; + var result = { + id: this._documentIds.get(docId), + terms: uniq(terms), + score: score, + match: match + }; + Object.assign(result, this._storedFields.get(docId)); + if (searchOptions.filter == null || searchOptions.filter(result)) { + results.push(result); + } + } + } + catch (e_8_1) { e_8 = { error: e_8_1 }; } + finally { + try { + if (combinedResults_1_1 && !combinedResults_1_1.done && (_a = combinedResults_1.return)) _a.call(combinedResults_1); + } + finally { if (e_8) throw e_8.error; } + } + results.sort(function (_a, _b) { + var a = _a.score; + var b = _b.score; + return a < b ? 1 : -1; + }); + return results; + }; + /** + * Provide suggestions for the given search query + * + * The result is a list of suggested modified search queries, derived from the + * given search query, each with a relevance score, sorted by descending score. + * + * ### Basic usage: + * + * ```javascript + * // Get suggestions for 'neuro': + * miniSearch.autoSuggest('neuro') + * // => [ { suggestion: 'neuromancer', terms: [ 'neuromancer' ], score: 0.46240 } ] + * ``` + * + * ### Multiple words: + * + * ```javascript + * // Get suggestions for 'zen ar': + * miniSearch.autoSuggest('zen ar') + * // => [ + * // { suggestion: 'zen archery art', terms: [ 'zen', 'archery', 'art' ], score: 1.73332 }, + * // { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 } + * // ] + * ``` + * + * ### Fuzzy suggestions: + * + * ```javascript + * // Correct spelling mistakes using fuzzy search: + * miniSearch.autoSuggest('neromancer', { fuzzy: 0.2 }) + * // => [ { suggestion: 'neuromancer', terms: [ 'neuromancer' ], score: 1.03998 } ] + * ``` + * + * ### Filtering: + * + * ```javascript + * // Get suggestions for 'zen ar', but only within the 'fiction' category + * // (assuming that 'category' is a stored field): + * miniSearch.autoSuggest('zen ar', { + * filter: (result) => result.category === 'fiction' + * }) + * // => [ + * // { suggestion: 'zen archery art', terms: [ 'zen', 'archery', 'art' ], score: 1.73332 }, + * // { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 } + * // ] + * ``` + * + * @param queryString Query string to be expanded into suggestions + * @param options Search options. The supported options and default values + * are the same as for the `search` method, except that by default prefix + * search is performed on the last term in the query. + * @return A sorted array of suggestions sorted by relevance score. + */ + MiniSearch.prototype.autoSuggest = function (queryString, options) { + var e_9, _a, e_10, _b; + if (options === void 0) { options = {}; } + options = __assign(__assign({}, defaultAutoSuggestOptions), options); + var suggestions = new Map(); + try { + for (var _c = __values(this.search(queryString, options)), _d = _c.next(); !_d.done; _d = _c.next()) { + var _e = _d.value, score = _e.score, terms = _e.terms; + var phrase = terms.join(' '); + var suggestion = suggestions.get(phrase); + if (suggestion != null) { + suggestion.score += score; + suggestion.count += 1; + } + else { + suggestions.set(phrase, { score: score, terms: terms, count: 1 }); + } + } + } + catch (e_9_1) { e_9 = { error: e_9_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_9) throw e_9.error; } + } + var results = []; + try { + for (var suggestions_1 = __values(suggestions), suggestions_1_1 = suggestions_1.next(); !suggestions_1_1.done; suggestions_1_1 = suggestions_1.next()) { + var _f = __read(suggestions_1_1.value, 2), suggestion = _f[0], _g = _f[1], score = _g.score, terms = _g.terms, count = _g.count; + results.push({ suggestion: suggestion, terms: terms, score: score / count }); + } + } + catch (e_10_1) { e_10 = { error: e_10_1 }; } + finally { + try { + if (suggestions_1_1 && !suggestions_1_1.done && (_b = suggestions_1.return)) _b.call(suggestions_1); + } + finally { if (e_10) throw e_10.error; } + } + results.sort(function (_a, _b) { + var a = _a.score; + var b = _b.score; + return a < b ? 1 : -1; + }); + return results; + }; + Object.defineProperty(MiniSearch.prototype, "documentCount", { + /** + * Number of documents in the index + */ + get: function () { + return this._documentCount; + }, + enumerable: false, + configurable: true + }); + /** + * Deserializes a JSON index (serialized with `JSON.stringify(miniSearch)`) + * and instantiates a MiniSearch instance. It should be given the same options + * originally used when serializing the index. + * + * ### Usage: + * + * ```javascript + * // If the index was serialized with: + * let miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * miniSearch.addAll(documents) + * + * const json = JSON.stringify(miniSearch) + * // It can later be deserialized like this: + * miniSearch = MiniSearch.loadJSON(json, { fields: ['title', 'text'] }) + * ``` + * + * @param json JSON-serialized index + * @param options configuration options, same as the constructor + * @return An instance of MiniSearch deserialized from the given JSON. + */ + MiniSearch.loadJSON = function (json, options) { + if (options == null) { + throw new Error('MiniSearch: loadJSON should be given the same options used when serializing the index'); + } + return MiniSearch.loadJS(JSON.parse(json), options); + }; + /** + * Returns the default value of an option. It will throw an error if no option + * with the given name exists. + * + * @param optionName Name of the option + * @return The default value of the given option + * + * ### Usage: + * + * ```javascript + * // Get default tokenizer + * MiniSearch.getDefault('tokenize') + * + * // Get default term processor + * MiniSearch.getDefault('processTerm') + * + * // Unknown options will throw an error + * MiniSearch.getDefault('notExisting') + * // => throws 'MiniSearch: unknown option "notExisting"' + * ``` + */ + MiniSearch.getDefault = function (optionName) { + if (defaultOptions.hasOwnProperty(optionName)) { + return getOwnProperty(defaultOptions, optionName); + } + else { + throw new Error("MiniSearch: unknown option \"".concat(optionName, "\"")); + } + }; + /** + * @ignore + */ + MiniSearch.loadJS = function (js, options) { + var e_11, _a, e_12, _b; + var index = js.index, documentCount = js.documentCount, nextId = js.nextId, documentIds = js.documentIds, fieldIds = js.fieldIds, fieldLength = js.fieldLength, averageFieldLength = js.averageFieldLength, storedFields = js.storedFields, serializationVersion = js.serializationVersion; + if (serializationVersion !== 1) { + throw new Error('MiniSearch: cannot deserialize an index created with an incompatible version'); + } + var miniSearch = new MiniSearch(options); + miniSearch._documentCount = documentCount; + miniSearch._nextId = nextId; + miniSearch._documentIds = objectToNumericMap(documentIds); + miniSearch._fieldIds = fieldIds; + miniSearch._fieldLength = objectToNumericMap(fieldLength); + miniSearch._averageFieldLength = averageFieldLength; + miniSearch._storedFields = objectToNumericMap(storedFields); + miniSearch._index = new SearchableMap(); + try { + for (var index_1 = __values(index), index_1_1 = index_1.next(); !index_1_1.done; index_1_1 = index_1.next()) { + var _c = __read(index_1_1.value, 2), term = _c[0], data = _c[1]; + var dataMap = new Map(); + try { + for (var _d = (e_12 = void 0, __values(Object.keys(data))), _e = _d.next(); !_e.done; _e = _d.next()) { + var fieldId = _e.value; + var _f = data[fieldId], df = _f.df, ds = _f.ds; + dataMap.set(parseInt(fieldId, 10), { df: df, ds: objectToNumericMap(ds) }); + } + } + catch (e_12_1) { e_12 = { error: e_12_1 }; } + finally { + try { + if (_e && !_e.done && (_b = _d.return)) _b.call(_d); + } + finally { if (e_12) throw e_12.error; } + } + miniSearch._index.set(term, dataMap); + } + } + catch (e_11_1) { e_11 = { error: e_11_1 }; } + finally { + try { + if (index_1_1 && !index_1_1.done && (_a = index_1.return)) _a.call(index_1); + } + finally { if (e_11) throw e_11.error; } + } + return miniSearch; + }; + /** + * @ignore + */ + MiniSearch.prototype.executeQuery = function (query, searchOptions) { + var _this = this; + if (searchOptions === void 0) { searchOptions = {}; } + if (typeof query === 'string') { + return this.executeSearch(query, searchOptions); + } + else { + var results = query.queries.map(function (subquery) { + var options = __assign(__assign(__assign({}, searchOptions), query), { queries: undefined }); + return _this.executeQuery(subquery, options); + }); + return this.combineResults(results, query.combineWith); + } + }; + /** + * @ignore + */ + MiniSearch.prototype.executeSearch = function (queryString, searchOptions) { + var _this = this; + if (searchOptions === void 0) { searchOptions = {}; } + var _a = this._options, tokenize = _a.tokenize, processTerm = _a.processTerm, globalSearchOptions = _a.searchOptions; + var options = __assign(__assign({ tokenize: tokenize, processTerm: processTerm }, globalSearchOptions), searchOptions); + var searchTokenize = options.tokenize, searchProcessTerm = options.processTerm; + var terms = searchTokenize(queryString) + .map(function (term) { return searchProcessTerm(term); }) + .filter(function (term) { return !!term; }); + var queries = terms.map(termToQuerySpec(options)); + var results = queries.map(function (query) { return _this.executeQuerySpec(query, options); }); + return this.combineResults(results, options.combineWith); + }; + /** + * @ignore + */ + MiniSearch.prototype.executeQuerySpec = function (query, searchOptions) { + var e_13, _a, e_14, _b; + var options = __assign(__assign({}, this._options.searchOptions), searchOptions); + var boosts = (options.fields || this._options.fields).reduce(function (boosts, field) { + var _a; + return (__assign(__assign({}, boosts), (_a = {}, _a[field] = getOwnProperty(boosts, field) || 1, _a))); + }, options.boost || {}); + var boostDocument = options.boostDocument, weights = options.weights, maxFuzzy = options.maxFuzzy; + var _c = __assign(__assign({}, defaultSearchOptions.weights), weights), fuzzyWeight = _c.fuzzy, prefixWeight = _c.prefix; + var results = this.termResults(query.term, boosts, boostDocument, this._index.get(query.term)); + var prefixMatches; + var fuzzyMatches; + if (query.prefix) { + prefixMatches = this._index.atPrefix(query.term); + } + if (query.fuzzy) { + var fuzzy = (query.fuzzy === true) ? 0.2 : query.fuzzy; + var maxDistance = fuzzy < 1 ? Math.min(maxFuzzy, Math.round(query.term.length * fuzzy)) : fuzzy; + fuzzyMatches = this._index.fuzzyGet(query.term, maxDistance); + } + if (prefixMatches) { + try { + for (var prefixMatches_1 = __values(prefixMatches), prefixMatches_1_1 = prefixMatches_1.next(); !prefixMatches_1_1.done; prefixMatches_1_1 = prefixMatches_1.next()) { + var _d = __read(prefixMatches_1_1.value, 2), term = _d[0], data = _d[1]; + var distance = term.length - query.term.length; + if (!distance) { + continue; + } // Skip exact match. + // Delete the term from fuzzy results (if present) if it is also a + // prefix result. This entry will always be scored as a prefix result. + fuzzyMatches === null || fuzzyMatches === void 0 ? void 0 : fuzzyMatches.delete(term); + var weightedDistance = (0.3 * distance) / term.length; + this.termResults(term, boosts, boostDocument, data, results, prefixWeight, weightedDistance); + } + } + catch (e_13_1) { e_13 = { error: e_13_1 }; } + finally { + try { + if (prefixMatches_1_1 && !prefixMatches_1_1.done && (_a = prefixMatches_1.return)) _a.call(prefixMatches_1); + } + finally { if (e_13) throw e_13.error; } + } + } + if (fuzzyMatches) { + try { + for (var _e = __values(fuzzyMatches.keys()), _f = _e.next(); !_f.done; _f = _e.next()) { + var term = _f.value; + var _g = __read(fuzzyMatches.get(term), 2), data = _g[0], distance = _g[1]; + if (!distance) { + continue; + } // Skip exact match. + var weightedDistance = distance / term.length; + this.termResults(term, boosts, boostDocument, data, results, fuzzyWeight, weightedDistance); + } + } + catch (e_14_1) { e_14 = { error: e_14_1 }; } + finally { + try { + if (_f && !_f.done && (_b = _e.return)) _b.call(_e); + } + finally { if (e_14) throw e_14.error; } + } + } + return results; + }; + /** + * @ignore + */ + MiniSearch.prototype.combineResults = function (results, combineWith) { + if (combineWith === void 0) { combineWith = OR; } + if (results.length === 0) { + return new Map(); + } + var operator = combineWith.toLowerCase(); + return results.reduce(combinators[operator]) || new Map(); + }; + /** + * Allows serialization of the index to JSON, to possibly store it and later + * deserialize it with `MiniSearch.loadJSON`. + * + * Normally one does not directly call this method, but rather call the + * standard JavaScript `JSON.stringify()` passing the `MiniSearch` instance, + * and JavaScript will internally call this method. Upon deserialization, one + * must pass to `loadJSON` the same options used to create the original + * instance that was serialized. + * + * ### Usage: + * + * ```javascript + * // Serialize the index: + * let miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * miniSearch.addAll(documents) + * const json = JSON.stringify(miniSearch) + * + * // Later, to deserialize it: + * miniSearch = MiniSearch.loadJSON(json, { fields: ['title', 'text'] }) + * ``` + * + * @return A plain-object serializeable representation of the search index. + */ + MiniSearch.prototype.toJSON = function () { + var e_15, _a, e_16, _b; + var index = []; + try { + for (var _c = __values(this._index), _d = _c.next(); !_d.done; _d = _c.next()) { + var _e = __read(_d.value, 2), term = _e[0], fieldIndex = _e[1]; + var data = {}; + try { + for (var fieldIndex_1 = (e_16 = void 0, __values(fieldIndex)), fieldIndex_1_1 = fieldIndex_1.next(); !fieldIndex_1_1.done; fieldIndex_1_1 = fieldIndex_1.next()) { + var _f = __read(fieldIndex_1_1.value, 2), fieldId = _f[0], _g = _f[1], df = _g.df, ds = _g.ds; + data[fieldId] = { df: df, ds: Object.fromEntries(ds) }; + } + } + catch (e_16_1) { e_16 = { error: e_16_1 }; } + finally { + try { + if (fieldIndex_1_1 && !fieldIndex_1_1.done && (_b = fieldIndex_1.return)) _b.call(fieldIndex_1); + } + finally { if (e_16) throw e_16.error; } + } + index.push([term, data]); + } + } + catch (e_15_1) { e_15 = { error: e_15_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_15) throw e_15.error; } + } + return { + documentCount: this._documentCount, + nextId: this._nextId, + documentIds: Object.fromEntries(this._documentIds), + fieldIds: this._fieldIds, + fieldLength: Object.fromEntries(this._fieldLength), + averageFieldLength: this._averageFieldLength, + storedFields: Object.fromEntries(this._storedFields), + index: index, + serializationVersion: 1 + }; + }; + /** + * @ignore + */ + MiniSearch.prototype.termResults = function (term, boosts, boostDocument, indexData, results, weight, editDistance) { + var e_17, _a, e_18, _b, _c; + if (results === void 0) { results = new Map(); } + if (weight === void 0) { weight = 1; } + if (editDistance === void 0) { editDistance = 0; } + if (indexData == null) + return results; + try { + for (var _d = __values(Object.keys(boosts)), _e = _d.next(); !_e.done; _e = _d.next()) { + var field = _e.value; + var fieldBoost = boosts[field]; + var fieldId = this._fieldIds[field]; + var entry = indexData.get(fieldId); + if (entry == null) + continue; + try { + for (var _f = (e_18 = void 0, __values(entry.ds)), _g = _f.next(); !_g.done; _g = _f.next()) { + var _h = __read(_g.value, 2), documentId = _h[0], tf = _h[1]; + var docBoost = boostDocument ? boostDocument(this._documentIds.get(documentId), term) : 1; + if (!docBoost) + continue; + var normalizedLength = this._fieldLength.get(documentId)[fieldId] / this._averageFieldLength[fieldId]; + var score = weight * docBoost * calculateScore(tf, entry.df, this._documentCount, normalizedLength, fieldBoost, editDistance); + var result = results.get(documentId); + if (result) { + result.score += score; + var match = getOwnProperty(result.match, term); + if (match) { + match.push(field); + } + else { + result.match[term] = [field]; + result.terms.push(term); + } + } + else { + results.set(documentId, { + score: score, + match: (_c = {}, _c[term] = [field], _c), + terms: [term] + }); + } + } + } + catch (e_18_1) { e_18 = { error: e_18_1 }; } + finally { + try { + if (_g && !_g.done && (_b = _f.return)) _b.call(_f); + } + finally { if (e_18) throw e_18.error; } + } + } + } + catch (e_17_1) { e_17 = { error: e_17_1 }; } + finally { + try { + if (_e && !_e.done && (_a = _d.return)) _a.call(_d); + } + finally { if (e_17) throw e_17.error; } + } + return results; + }; + /** + * @ignore + */ + MiniSearch.prototype.addTerm = function (fieldId, documentId, term) { + var indexData = this._index.fetch(term, createMap); + var fieldIndex = indexData.get(fieldId); + if (fieldIndex == null) { + fieldIndex = { df: 1, ds: new Map() }; + fieldIndex.ds.set(documentId, 1); + indexData.set(fieldId, fieldIndex); + } + else { + var docs = fieldIndex.ds.get(documentId); + if (docs == null) { + fieldIndex.df += 1; + } + fieldIndex.ds.set(documentId, (docs || 0) + 1); + } + }; + /** + * @ignore + */ + MiniSearch.prototype.removeTerm = function (fieldId, documentId, term) { + if (!this._index.has(term)) { + this.warnDocumentChanged(documentId, fieldId, term); + return; + } + var indexData = this._index.fetch(term, createMap); + var fieldIndex = indexData.get(fieldId); + if (fieldIndex == null || fieldIndex.ds.get(documentId) == null) { + this.warnDocumentChanged(documentId, fieldId, term); + } + else if (fieldIndex.ds.get(documentId) <= 1) { + if (fieldIndex.df <= 1) { + indexData.delete(fieldId); + } + else { + fieldIndex.df -= 1; + fieldIndex.ds.delete(documentId); + } + } + else { + fieldIndex.ds.set(documentId, fieldIndex.ds.get(documentId) - 1); + } + if (this._index.get(term).size === 0) { + this._index.delete(term); + } + }; + /** + * @ignore + */ + MiniSearch.prototype.warnDocumentChanged = function (shortDocumentId, fieldId, term) { + var e_19, _a; + if (console == null || console.warn == null) { + return; + } + try { + for (var _b = __values(Object.keys(this._fieldIds)), _c = _b.next(); !_c.done; _c = _b.next()) { + var fieldName = _c.value; + if (this._fieldIds[fieldName] === fieldId) { + console.warn("MiniSearch: document with ID ".concat(this._documentIds.get(shortDocumentId), " has changed before removal: term \"").concat(term, "\" was not present in field \"").concat(fieldName, "\". Removing a document after it has changed can corrupt the index!")); + return; + } + } + } + catch (e_19_1) { e_19 = { error: e_19_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_19) throw e_19.error; } + } + }; + /** + * @ignore + */ + MiniSearch.prototype.addDocumentId = function (documentId) { + var shortDocumentId = this._nextId; + this._documentIds.set(shortDocumentId, documentId); + this._documentCount += 1; + this._nextId += 1; + return shortDocumentId; + }; + /** + * @ignore + */ + MiniSearch.prototype.addFields = function (fields) { + for (var i = 0; i < fields.length; i++) { + this._fieldIds[fields[i]] = i; + } + }; + /** + * @ignore + */ + MiniSearch.prototype.addFieldLength = function (documentId, fieldId, count, length) { + var fieldLengths = this._fieldLength.get(documentId); + if (fieldLengths == null) + this._fieldLength.set(documentId, fieldLengths = []); + fieldLengths[fieldId] = length; + var averageFieldLength = this._averageFieldLength[fieldId] || 0; + var totalLength = (averageFieldLength * count) + length; + this._averageFieldLength[fieldId] = totalLength / (count + 1); + }; + /** + * @ignore + */ + MiniSearch.prototype.removeFieldLength = function (documentId, fieldId, count, length) { + var totalLength = (this._averageFieldLength[fieldId] * count) - length; + this._averageFieldLength[fieldId] = totalLength / (count - 1); + }; + /** + * @ignore + */ + MiniSearch.prototype.saveStoredFields = function (documentId, doc) { + var e_20, _a; + var _b = this._options, storeFields = _b.storeFields, extractField = _b.extractField; + if (storeFields == null || storeFields.length === 0) { + return; + } + var documentFields = this._storedFields.get(documentId); + if (documentFields == null) + this._storedFields.set(documentId, documentFields = {}); + try { + for (var storeFields_1 = __values(storeFields), storeFields_1_1 = storeFields_1.next(); !storeFields_1_1.done; storeFields_1_1 = storeFields_1.next()) { + var fieldName = storeFields_1_1.value; + var fieldValue = extractField(doc, fieldName); + if (fieldValue !== undefined) + documentFields[fieldName] = fieldValue; + } + } + catch (e_20_1) { e_20 = { error: e_20_1 }; } + finally { + try { + if (storeFields_1_1 && !storeFields_1_1.done && (_a = storeFields_1.return)) _a.call(storeFields_1); + } + finally { if (e_20) throw e_20.error; } + } + }; + return MiniSearch; +}()); +var getOwnProperty = function (object, property) { + return Object.prototype.hasOwnProperty.call(object, property) ? object[property] : undefined; +}; +var combinators = (_a = {}, + _a[OR] = function (a, b) { + var e_21, _a, _b; + try { + for (var _c = __values(b.keys()), _d = _c.next(); !_d.done; _d = _c.next()) { + var documentId = _d.value; + var existing = a.get(documentId); + if (existing == null) { + a.set(documentId, b.get(documentId)); + } + else { + var _e = b.get(documentId), score = _e.score, match = _e.match, terms = _e.terms; + existing.score = (existing.score + score) * 1.5; + existing.match = Object.assign(existing.match, match); + (_b = existing.terms).push.apply(_b, __spreadArray([], __read(terms), false)); + } + } + } + catch (e_21_1) { e_21 = { error: e_21_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_21) throw e_21.error; } + } + return a; + }, + _a[AND] = function (a, b) { + var e_22, _a; + var combined = new Map(); + try { + for (var _b = __values(b.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var documentId = _c.value; + var existing = a.get(documentId); + if (existing == null) + continue; + var _d = b.get(documentId), score = _d.score, match = _d.match, terms = _d.terms; + combined.set(documentId, { + score: existing.score + score, + match: Object.assign(existing.match, match), + terms: __spreadArray(__spreadArray([], __read(existing.terms), false), __read(terms), false) + }); + } + } + catch (e_22_1) { e_22 = { error: e_22_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_22) throw e_22.error; } + } + return combined; + }, + _a[AND_NOT] = function (a, b) { + var e_23, _a; + try { + for (var _b = __values(b.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var documentId = _c.value; + a.delete(documentId); + } + } + catch (e_23_1) { e_23 = { error: e_23_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_23) throw e_23.error; } + } + return a; + }, + _a); +var tfIdf = function (tf, df, n) { return tf * Math.log(n / df); }; +var calculateScore = function (termFrequency, documentFrequency, documentCount, normalizedLength, boost, editDistance) { + var weight = boost / (1 + (0.333 * boost * editDistance)); + return weight * tfIdf(termFrequency, documentFrequency, documentCount) / normalizedLength; +}; +var termToQuerySpec = function (options) { return function (term, i, terms) { + var fuzzy = (typeof options.fuzzy === 'function') + ? options.fuzzy(term, i, terms) + : (options.fuzzy || false); + var prefix = (typeof options.prefix === 'function') + ? options.prefix(term, i, terms) + : (options.prefix === true); + return { term: term, fuzzy: fuzzy, prefix: prefix }; +}; }; +var uniq = function (array) { + return array.filter(function (element, i, array) { return array.indexOf(element) === i; }); +}; +var defaultOptions = { + idField: 'id', + extractField: function (document, fieldName) { return document[fieldName]; }, + tokenize: function (text, fieldName) { return text.split(SPACE_OR_PUNCTUATION); }, + processTerm: function (term, fieldName) { return term.toLowerCase(); }, + fields: undefined, + searchOptions: undefined, + storeFields: [] +}; +var defaultSearchOptions = { + combineWith: OR, + prefix: false, + fuzzy: false, + maxFuzzy: 6, + boost: {}, + weights: { fuzzy: 0.45, prefix: 0.375 } +}; +var defaultAutoSuggestOptions = { + prefix: function (term, i, terms) { + return i === terms.length - 1; + } +}; +var createMap = function () { return new Map(); }; +var objectToNumericMap = function (object) { + var e_24, _a; + var map = new Map(); + try { + for (var _b = __values(Object.keys(object)), _c = _b.next(); !_c.done; _c = _b.next()) { + var key = _c.value; + map.set(parseInt(key, 10), object[key]); + } + } + catch (e_24_1) { e_24 = { error: e_24_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_24) throw e_24.error; } + } + return map; +}; +// This regular expression matches any Unicode space or punctuation character +// Adapted from https://unicode.org/cldr/utility/list-unicodeset.jsp?a=%5Cp%7BZ%7D%5Cp%7BP%7D&abb=on&c=on&esc=on +var SPACE_OR_PUNCTUATION = /[\n\r -#%-*,-/:;?@[-\]_{}\u00A0\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u1680\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2000-\u200A\u2010-\u2029\u202F-\u2043\u2045-\u2051\u2053-\u205F\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u3000-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]+/u; + +export { MiniSearch as default }; +//# sourceMappingURL=index.js.map diff --git a/node_modules/minisearch/dist/es/index.js.map b/node_modules/minisearch/dist/es/index.js.map new file mode 100644 index 0000000..cddfe44 --- /dev/null +++ b/node_modules/minisearch/dist/es/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../../node_modules/tslib/tslib.es6.js","../../src/SearchableMap/TreeIterator.ts","../../src/SearchableMap/fuzzySearch.ts","../../src/SearchableMap/SearchableMap.ts","../../src/MiniSearch.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n",null,null,null,null],"names":["last"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAiBA;AACO,IAAI,QAAQ,GAAG,WAAW;AACjC,IAAI,QAAQ,GAAG,MAAM,CAAC,MAAM,IAAI,SAAS,QAAQ,CAAC,CAAC,EAAE;AACrD,QAAQ,KAAK,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;AAC7D,YAAY,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAC7B,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CA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AE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;SACxC;;;;;;;;;IAED,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED;AACA;AACA,IAAM,oBAAoB,GAAG,8xCAA8xC;;;;"} \ No newline at end of file diff --git a/node_modules/minisearch/dist/es5m/SearchableMap.js b/node_modules/minisearch/dist/es5m/SearchableMap.js new file mode 100644 index 0000000..6364fa9 --- /dev/null +++ b/node_modules/minisearch/dist/es5m/SearchableMap.js @@ -0,0 +1,672 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ + +function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +} + +function __read(o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +} + +/** @ignore */ +var ENTRIES = 'ENTRIES'; +/** @ignore */ +var KEYS = 'KEYS'; +/** @ignore */ +var VALUES = 'VALUES'; +/** @ignore */ +var LEAF = ''; +/** + * @private + */ +var TreeIterator = /** @class */ (function () { + function TreeIterator(set, type) { + var node = set._tree; + var keys = Array.from(node.keys()); + this.set = set; + this._type = type; + this._path = keys.length > 0 ? [{ node: node, keys: keys }] : []; + } + TreeIterator.prototype.next = function () { + var value = this.dive(); + this.backtrack(); + return value; + }; + TreeIterator.prototype.dive = function () { + if (this._path.length === 0) { + return { done: true, value: undefined }; + } + var _a = last$1(this._path), node = _a.node, keys = _a.keys; + if (last$1(keys) === LEAF) { + return { done: false, value: this.result() }; + } + this._path.push({ node: node.get(last$1(keys)), keys: Array.from(node.get(last$1(keys)).keys()) }); + return this.dive(); + }; + TreeIterator.prototype.backtrack = function () { + if (this._path.length === 0) { + return; + } + last$1(this._path).keys.pop(); + if (last$1(this._path).keys.length > 0) { + return; + } + this._path.pop(); + this.backtrack(); + }; + TreeIterator.prototype.key = function () { + return this.set._prefix + this._path + .map(function (_a) { + var keys = _a.keys; + return last$1(keys); + }) + .filter(function (key) { return key !== LEAF; }) + .join(''); + }; + TreeIterator.prototype.value = function () { + return last$1(this._path).node.get(LEAF); + }; + TreeIterator.prototype.result = function () { + if (this._type === VALUES) { + return this.value(); + } + if (this._type === KEYS) { + return this.key(); + } + return [this.key(), this.value()]; + }; + TreeIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return TreeIterator; +}()); +var last$1 = function (array) { + return array[array.length - 1]; +}; + +/** + * @ignore + */ +var fuzzySearch = function (node, query, maxDistance) { + var results = new Map(); + if (query === undefined) + return results; + // Number of columns in the Levenshtein matrix. + var n = query.length + 1; + // Matching terms can never be longer than N + maxDistance. + var maxLength = n + maxDistance; + // Fill first matrix row with consecutive numbers 0 1 2 3 ... (n - 1) + var matrix = new Uint8Array(maxLength * n); + for (var i = 0; i < n; i++) + matrix[i] = i; + recurse(node, query, maxDistance, results, matrix, n, n, ''); + return results; +}; +// Modified version of http://stevehanov.ca/blog/?id=114 +// This builds a Levenshtein matrix for a given query and continuously updates +// it for nodes in the radix tree that fall within the given maximum edit +// distance. Keeping the same matrix around is beneficial especially for larger +// edit distances. +// +// k a t e <-- query +// 0 1 2 3 4 +// c 1 1 2 3 4 +// a 2 2 1 2 3 +// t 3 3 2 1 [2] <-- edit distance +// ^ +// ^ term in radix tree, rows are added and removed as needed +var recurse = function (node, query, maxDistance, results, matrix, offset, n, prefix) { + var e_1, _a; + try { + key: for (var _b = __values(node.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var key = _c.value; + if (key === LEAF) { + // We've reached a leaf node. Check if the edit distance acceptable and + // store the result if it is. + var distance = matrix[offset - 1]; + if (distance <= maxDistance) { + results.set(prefix, [node.get(key), distance]); + } + } + else { + // Iterate over all characters in the key. Update the Levenshtein matrix + // and check if the minimum distance in the last row is still within the + // maximum edit distance. If it is, we can recurse over all child nodes. + for (var i = 0; i < key.length; i++) { + var char = key[i]; + var thisRowOffset = offset + n * i; + var prevRowOffset = thisRowOffset - n; + // Set the first column based on the previous row, and initialize the + // minimum distance in the current row. + var minDistance = matrix[thisRowOffset] = matrix[prevRowOffset] + 1; + // Iterate over remaining columns (characters in the query). + for (var j = 0; j < n - 1; j++) { + var different = char !== query[j]; + // It might make sense to only read the matrix positions used for + // deletion/insertion if the characters are different. But we want to + // avoid conditional reads for performance reasons. + var rpl = matrix[prevRowOffset + j] + +different; + var del = matrix[prevRowOffset + j + 1] + 1; + var ins = matrix[thisRowOffset + j] + 1; + var dist = matrix[thisRowOffset + j + 1] = Math.min(rpl, del, ins); + if (dist < minDistance) + minDistance = dist; + } + // Because distance will never decrease, we can stop. There will be no + // matching child nodes. + if (minDistance > maxDistance) { + continue key; + } + } + recurse(node.get(key), query, maxDistance, results, matrix, offset + n * key.length, n, prefix + key); + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_1) throw e_1.error; } + } +}; + +/** + * A class implementing the same interface as a standard JavaScript + * [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) + * with string keys, but adding support for efficiently searching entries with + * prefix or fuzzy search. This class is used internally by [[MiniSearch]] as + * the inverted index data structure. The implementation is a radix tree + * (compressed prefix tree). + * + * Since this class can be of general utility beyond _MiniSearch_, it is + * exported by the `minisearch` package and can be imported (or required) as + * `minisearch/SearchableMap`. + * + * @typeParam T The type of the values stored in the map. + */ +var SearchableMap = /** @class */ (function () { + /** + * The constructor is normally called without arguments, creating an empty + * map. In order to create a [[SearchableMap]] from an iterable or from an + * object, check [[SearchableMap.from]] and [[SearchableMap.fromObject]]. + * + * The constructor arguments are for internal use, when creating derived + * mutable views of a map at a prefix. + */ + function SearchableMap(tree, prefix) { + if (tree === void 0) { tree = new Map(); } + if (prefix === void 0) { prefix = ''; } + this._size = undefined; + this._tree = tree; + this._prefix = prefix; + } + /** + * Creates and returns a mutable view of this [[SearchableMap]], containing only + * entries that share the given prefix. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set("unicorn", 1) + * map.set("universe", 2) + * map.set("university", 3) + * map.set("unique", 4) + * map.set("hello", 5) + * + * let uni = map.atPrefix("uni") + * uni.get("unique") // => 4 + * uni.get("unicorn") // => 1 + * uni.get("hello") // => undefined + * + * let univer = map.atPrefix("univer") + * univer.get("unique") // => undefined + * univer.get("universe") // => 2 + * univer.get("university") // => 3 + * ``` + * + * @param prefix The prefix + * @return A [[SearchableMap]] representing a mutable view of the original Map at the given prefix + */ + SearchableMap.prototype.atPrefix = function (prefix) { + var e_1, _a; + if (!prefix.startsWith(this._prefix)) { + throw new Error('Mismatched prefix'); + } + var _b = __read(trackDown(this._tree, prefix.slice(this._prefix.length)), 2), node = _b[0], path = _b[1]; + if (node === undefined) { + var _c = __read(last(path), 2), parentNode = _c[0], key = _c[1]; + try { + for (var _d = __values(parentNode.keys()), _e = _d.next(); !_e.done; _e = _d.next()) { + var k = _e.value; + if (k !== LEAF && k.startsWith(key)) { + var node_1 = new Map(); + node_1.set(k.slice(key.length), parentNode.get(k)); + return new SearchableMap(node_1, prefix); + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (_e && !_e.done && (_a = _d.return)) _a.call(_d); + } + finally { if (e_1) throw e_1.error; } + } + } + return new SearchableMap(node, prefix); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear + */ + SearchableMap.prototype.clear = function () { + this._size = undefined; + this._tree.clear(); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete + * @param key Key to delete + */ + SearchableMap.prototype.delete = function (key) { + this._size = undefined; + return remove(this._tree, key); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries + * @return An iterator iterating through `[key, value]` entries. + */ + SearchableMap.prototype.entries = function () { + return new TreeIterator(this, ENTRIES); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach + * @param fn Iteration function + */ + SearchableMap.prototype.forEach = function (fn) { + var e_2, _a; + try { + for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) { + var _d = __read(_c.value, 2), key = _d[0], value = _d[1]; + fn(key, value, this); + } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_2) throw e_2.error; } + } + }; + /** + * Returns a Map of all the entries that have a key within the given edit + * distance from the search key. The keys of the returned Map are the matching + * keys, while the values are two-element arrays where the first element is + * the value associated to the key, and the second is the edit distance of the + * key to the search key. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set('hello', 'world') + * map.set('hell', 'yeah') + * map.set('ciao', 'mondo') + * + * // Get all entries that match the key 'hallo' with a maximum edit distance of 2 + * map.fuzzyGet('hallo', 2) + * // => Map(2) { 'hello' => ['world', 1], 'hell' => ['yeah', 2] } + * + * // In the example, the "hello" key has value "world" and edit distance of 1 + * // (change "e" to "a"), the key "hell" has value "yeah" and edit distance of 2 + * // (change "e" to "a", delete "o") + * ``` + * + * @param key The search key + * @param maxEditDistance The maximum edit distance (Levenshtein) + * @return A Map of the matching keys to their value and edit distance + */ + SearchableMap.prototype.fuzzyGet = function (key, maxEditDistance) { + return fuzzySearch(this._tree, key, maxEditDistance); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get + * @param key Key to get + * @return Value associated to the key, or `undefined` if the key is not + * found. + */ + SearchableMap.prototype.get = function (key) { + var node = lookup(this._tree, key); + return node !== undefined ? node.get(LEAF) : undefined; + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has + * @param key Key + * @return True if the key is in the map, false otherwise + */ + SearchableMap.prototype.has = function (key) { + var node = lookup(this._tree, key); + return node !== undefined && node.has(LEAF); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys + * @return An `Iterable` iterating through keys + */ + SearchableMap.prototype.keys = function () { + return new TreeIterator(this, KEYS); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set + * @param key Key to set + * @param value Value to associate to the key + * @return The [[SearchableMap]] itself, to allow chaining + */ + SearchableMap.prototype.set = function (key, value) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + node.set(LEAF, value); + return this; + }; + Object.defineProperty(SearchableMap.prototype, "size", { + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size + */ + get: function () { + if (this._size) { + return this._size; + } + /** @ignore */ + this._size = 0; + var iter = this.entries(); + while (!iter.next().done) + this._size += 1; + return this._size; + }, + enumerable: false, + configurable: true + }); + /** + * Updates the value at the given key using the provided function. The function + * is called with the current value at the key, and its return value is used as + * the new value to be set. + * + * ### Example: + * + * ```javascript + * // Increment the current value by one + * searchableMap.update('somekey', (currentValue) => currentValue == null ? 0 : currentValue + 1) + * ``` + * + * If the value at the given key is or will be an object, it might not require + * re-assignment. In that case it is better to use `fetch()`, because it is + * faster. + * + * @param key The key to update + * @param fn The function used to compute the new value from the current one + * @return The [[SearchableMap]] itself, to allow chaining + */ + SearchableMap.prototype.update = function (key, fn) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + node.set(LEAF, fn(node.get(LEAF))); + return this; + }; + /** + * Fetches the value of the given key. If the value does not exist, calls the + * given function to create a new value, which is inserted at the given key + * and subsequently returned. + * + * ### Example: + * + * ```javascript + * const map = searchableMap.fetch('somekey', () => new Map()) + * map.set('foo', 'bar') + * ``` + * + * @param key The key to update + * @param defaultValue A function that creates a new value if the key does not exist + * @return The existing or new value at the given key + */ + SearchableMap.prototype.fetch = function (key, initial) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + var value = node.get(LEAF); + if (value === undefined) { + node.set(LEAF, value = initial()); + } + return value; + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values + * @return An `Iterable` iterating through values. + */ + SearchableMap.prototype.values = function () { + return new TreeIterator(this, VALUES); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/@@iterator + */ + SearchableMap.prototype[Symbol.iterator] = function () { + return this.entries(); + }; + /** + * Creates a [[SearchableMap]] from an `Iterable` of entries + * + * @param entries Entries to be inserted in the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + SearchableMap.from = function (entries) { + var e_3, _a; + var tree = new SearchableMap(); + try { + for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) { + var _b = __read(entries_1_1.value, 2), key = _b[0], value = _b[1]; + tree.set(key, value); + } + } + catch (e_3_1) { e_3 = { error: e_3_1 }; } + finally { + try { + if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1); + } + finally { if (e_3) throw e_3.error; } + } + return tree; + }; + /** + * Creates a [[SearchableMap]] from the iterable properties of a JavaScript object + * + * @param object Object of entries for the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + SearchableMap.fromObject = function (object) { + return SearchableMap.from(Object.entries(object)); + }; + return SearchableMap; +}()); +var trackDown = function (tree, key, path) { + var e_4, _a; + if (path === void 0) { path = []; } + if (key.length === 0 || tree == null) { + return [tree, path]; + } + try { + for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var k = _c.value; + if (k !== LEAF && key.startsWith(k)) { + path.push([tree, k]); // performance: update in place + return trackDown(tree.get(k), key.slice(k.length), path); + } + } + } + catch (e_4_1) { e_4 = { error: e_4_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_4) throw e_4.error; } + } + path.push([tree, key]); // performance: update in place + return trackDown(undefined, '', path); +}; +var lookup = function (tree, key) { + var e_5, _a; + if (key.length === 0 || tree == null) { + return tree; + } + try { + for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var k = _c.value; + if (k !== LEAF && key.startsWith(k)) { + return lookup(tree.get(k), key.slice(k.length)); + } + } + } + catch (e_5_1) { e_5 = { error: e_5_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_5) throw e_5.error; } + } +}; +var createPath = function (tree, key) { + var e_6, _a, e_7, _b; + if (key.length === 0 || tree == null) { + return tree; + } + try { + for (var _c = __values(tree.keys()), _d = _c.next(); !_d.done; _d = _c.next()) { + var k = _d.value; + if (k !== LEAF && key.startsWith(k)) { + return createPath(tree.get(k), key.slice(k.length)); + } + } + } + catch (e_6_1) { e_6 = { error: e_6_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_6) throw e_6.error; } + } + try { + for (var _e = __values(tree.keys()), _f = _e.next(); !_f.done; _f = _e.next()) { + var k = _f.value; + if (k !== LEAF && k.startsWith(key[0])) { + var offset = commonPrefixOffset(key, k); + var node_2 = new Map(); + node_2.set(k.slice(offset), tree.get(k)); + tree.set(key.slice(0, offset), node_2); + tree.delete(k); + return createPath(node_2, key.slice(offset)); + } + } + } + catch (e_7_1) { e_7 = { error: e_7_1 }; } + finally { + try { + if (_f && !_f.done && (_b = _e.return)) _b.call(_e); + } + finally { if (e_7) throw e_7.error; } + } + var node = new Map(); + tree.set(key, node); + return node; +}; +var commonPrefixOffset = function (a, b) { + var length = Math.min(a.length, b.length); + for (var i = 0; i < length; i++) { + if (a[i] !== b[i]) + return i; + } + return length; +}; +var remove = function (tree, key) { + var _a = __read(trackDown(tree, key), 2), node = _a[0], path = _a[1]; + if (node === undefined) { + return; + } + node.delete(LEAF); + if (node.size === 0) { + cleanup(path); + } + else if (node.size === 1) { + var _b = __read(node.entries().next().value, 2), key_1 = _b[0], value = _b[1]; + merge(path, key_1, value); + } +}; +var cleanup = function (path) { + if (path.length === 0) { + return; + } + var _a = __read(last(path), 2), node = _a[0], key = _a[1]; + node.delete(key); + if (node.size === 0) { + cleanup(path.slice(0, -1)); + } + else if (node.size === 1) { + var _b = __read(node.entries().next().value, 2), key_2 = _b[0], value = _b[1]; + if (key_2 !== LEAF) { + merge(path.slice(0, -1), key_2, value); + } + } +}; +var merge = function (path, key, value) { + if (path.length === 0) { + return; + } + var _a = __read(last(path), 2), node = _a[0], nodeKey = _a[1]; + node.set(nodeKey + key, value); + node.delete(nodeKey); +}; +var last = function (array) { + return array[array.length - 1]; +}; + +export { SearchableMap as default }; +//# sourceMappingURL=SearchableMap.js.map diff --git a/node_modules/minisearch/dist/es5m/SearchableMap.js.map b/node_modules/minisearch/dist/es5m/SearchableMap.js.map new file mode 100644 index 0000000..cec0f7a --- /dev/null +++ b/node_modules/minisearch/dist/es5m/SearchableMap.js.map @@ -0,0 +1 @@ +{"version":3,"file":"SearchableMap.js","sources":["../../node_modules/tslib/tslib.es6.js","../../src/SearchableMap/TreeIterator.ts","../../src/SearchableMap/fuzzySearch.ts","../../src/SearchableMap/SearchableMap.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n",null,null,null],"names":["last"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAyGA;AACO,SAAS,QAAQ,CAAC,CAAC,EAAE;AAC5B,IAAI,IAAI,CAAC,GAAG,OAAO,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAA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ACH,CAAC,CAAA;AAED,IAAM,KAAK,GAAG,UAAU,IAAa,EAAE,GAAW,EAAE,KAAQ;IAC1D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QAAE,OAAM;KAAE;IAE3B,IAAA,KAAA,OAAkB,IAAI,CAAC,IAAI,CAAC,IAAA,EAA3B,IAAI,QAAA,EAAE,OAAO,QAAc,CAAA;IAClC,IAAK,CAAC,GAAG,CAAC,OAAO,GAAG,GAAG,EAAE,KAAK,CAAC,CAAA;IAC/B,IAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AACvB,CAAC,CAAA;AAED,IAAM,IAAI,GAAG,UAAU,KAAU;IAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AAChC,CAAC;;;;"} \ No newline at end of file diff --git a/node_modules/minisearch/dist/es5m/index.js b/node_modules/minisearch/dist/es5m/index.js new file mode 100644 index 0000000..65b9bd3 --- /dev/null +++ b/node_modules/minisearch/dist/es5m/index.js @@ -0,0 +1,1956 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ + +var __assign = function() { + __assign = Object.assign || function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; + +function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); +} + +function __read(o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +} + +function __spreadArray(to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +} + +/** @ignore */ +var ENTRIES = 'ENTRIES'; +/** @ignore */ +var KEYS = 'KEYS'; +/** @ignore */ +var VALUES = 'VALUES'; +/** @ignore */ +var LEAF = ''; +/** + * @private + */ +var TreeIterator = /** @class */ (function () { + function TreeIterator(set, type) { + var node = set._tree; + var keys = Array.from(node.keys()); + this.set = set; + this._type = type; + this._path = keys.length > 0 ? [{ node: node, keys: keys }] : []; + } + TreeIterator.prototype.next = function () { + var value = this.dive(); + this.backtrack(); + return value; + }; + TreeIterator.prototype.dive = function () { + if (this._path.length === 0) { + return { done: true, value: undefined }; + } + var _a = last$1(this._path), node = _a.node, keys = _a.keys; + if (last$1(keys) === LEAF) { + return { done: false, value: this.result() }; + } + this._path.push({ node: node.get(last$1(keys)), keys: Array.from(node.get(last$1(keys)).keys()) }); + return this.dive(); + }; + TreeIterator.prototype.backtrack = function () { + if (this._path.length === 0) { + return; + } + last$1(this._path).keys.pop(); + if (last$1(this._path).keys.length > 0) { + return; + } + this._path.pop(); + this.backtrack(); + }; + TreeIterator.prototype.key = function () { + return this.set._prefix + this._path + .map(function (_a) { + var keys = _a.keys; + return last$1(keys); + }) + .filter(function (key) { return key !== LEAF; }) + .join(''); + }; + TreeIterator.prototype.value = function () { + return last$1(this._path).node.get(LEAF); + }; + TreeIterator.prototype.result = function () { + if (this._type === VALUES) { + return this.value(); + } + if (this._type === KEYS) { + return this.key(); + } + return [this.key(), this.value()]; + }; + TreeIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return TreeIterator; +}()); +var last$1 = function (array) { + return array[array.length - 1]; +}; + +/** + * @ignore + */ +var fuzzySearch = function (node, query, maxDistance) { + var results = new Map(); + if (query === undefined) + return results; + // Number of columns in the Levenshtein matrix. + var n = query.length + 1; + // Matching terms can never be longer than N + maxDistance. + var maxLength = n + maxDistance; + // Fill first matrix row with consecutive numbers 0 1 2 3 ... (n - 1) + var matrix = new Uint8Array(maxLength * n); + for (var i = 0; i < n; i++) + matrix[i] = i; + recurse(node, query, maxDistance, results, matrix, n, n, ''); + return results; +}; +// Modified version of http://stevehanov.ca/blog/?id=114 +// This builds a Levenshtein matrix for a given query and continuously updates +// it for nodes in the radix tree that fall within the given maximum edit +// distance. Keeping the same matrix around is beneficial especially for larger +// edit distances. +// +// k a t e <-- query +// 0 1 2 3 4 +// c 1 1 2 3 4 +// a 2 2 1 2 3 +// t 3 3 2 1 [2] <-- edit distance +// ^ +// ^ term in radix tree, rows are added and removed as needed +var recurse = function (node, query, maxDistance, results, matrix, offset, n, prefix) { + var e_1, _a; + try { + key: for (var _b = __values(node.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var key = _c.value; + if (key === LEAF) { + // We've reached a leaf node. Check if the edit distance acceptable and + // store the result if it is. + var distance = matrix[offset - 1]; + if (distance <= maxDistance) { + results.set(prefix, [node.get(key), distance]); + } + } + else { + // Iterate over all characters in the key. Update the Levenshtein matrix + // and check if the minimum distance in the last row is still within the + // maximum edit distance. If it is, we can recurse over all child nodes. + for (var i = 0; i < key.length; i++) { + var char = key[i]; + var thisRowOffset = offset + n * i; + var prevRowOffset = thisRowOffset - n; + // Set the first column based on the previous row, and initialize the + // minimum distance in the current row. + var minDistance = matrix[thisRowOffset] = matrix[prevRowOffset] + 1; + // Iterate over remaining columns (characters in the query). + for (var j = 0; j < n - 1; j++) { + var different = char !== query[j]; + // It might make sense to only read the matrix positions used for + // deletion/insertion if the characters are different. But we want to + // avoid conditional reads for performance reasons. + var rpl = matrix[prevRowOffset + j] + +different; + var del = matrix[prevRowOffset + j + 1] + 1; + var ins = matrix[thisRowOffset + j] + 1; + var dist = matrix[thisRowOffset + j + 1] = Math.min(rpl, del, ins); + if (dist < minDistance) + minDistance = dist; + } + // Because distance will never decrease, we can stop. There will be no + // matching child nodes. + if (minDistance > maxDistance) { + continue key; + } + } + recurse(node.get(key), query, maxDistance, results, matrix, offset + n * key.length, n, prefix + key); + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_1) throw e_1.error; } + } +}; + +/** + * A class implementing the same interface as a standard JavaScript + * [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) + * with string keys, but adding support for efficiently searching entries with + * prefix or fuzzy search. This class is used internally by [[MiniSearch]] as + * the inverted index data structure. The implementation is a radix tree + * (compressed prefix tree). + * + * Since this class can be of general utility beyond _MiniSearch_, it is + * exported by the `minisearch` package and can be imported (or required) as + * `minisearch/SearchableMap`. + * + * @typeParam T The type of the values stored in the map. + */ +var SearchableMap = /** @class */ (function () { + /** + * The constructor is normally called without arguments, creating an empty + * map. In order to create a [[SearchableMap]] from an iterable or from an + * object, check [[SearchableMap.from]] and [[SearchableMap.fromObject]]. + * + * The constructor arguments are for internal use, when creating derived + * mutable views of a map at a prefix. + */ + function SearchableMap(tree, prefix) { + if (tree === void 0) { tree = new Map(); } + if (prefix === void 0) { prefix = ''; } + this._size = undefined; + this._tree = tree; + this._prefix = prefix; + } + /** + * Creates and returns a mutable view of this [[SearchableMap]], containing only + * entries that share the given prefix. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set("unicorn", 1) + * map.set("universe", 2) + * map.set("university", 3) + * map.set("unique", 4) + * map.set("hello", 5) + * + * let uni = map.atPrefix("uni") + * uni.get("unique") // => 4 + * uni.get("unicorn") // => 1 + * uni.get("hello") // => undefined + * + * let univer = map.atPrefix("univer") + * univer.get("unique") // => undefined + * univer.get("universe") // => 2 + * univer.get("university") // => 3 + * ``` + * + * @param prefix The prefix + * @return A [[SearchableMap]] representing a mutable view of the original Map at the given prefix + */ + SearchableMap.prototype.atPrefix = function (prefix) { + var e_1, _a; + if (!prefix.startsWith(this._prefix)) { + throw new Error('Mismatched prefix'); + } + var _b = __read(trackDown(this._tree, prefix.slice(this._prefix.length)), 2), node = _b[0], path = _b[1]; + if (node === undefined) { + var _c = __read(last(path), 2), parentNode = _c[0], key = _c[1]; + try { + for (var _d = __values(parentNode.keys()), _e = _d.next(); !_e.done; _e = _d.next()) { + var k = _e.value; + if (k !== LEAF && k.startsWith(key)) { + var node_1 = new Map(); + node_1.set(k.slice(key.length), parentNode.get(k)); + return new SearchableMap(node_1, prefix); + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (_e && !_e.done && (_a = _d.return)) _a.call(_d); + } + finally { if (e_1) throw e_1.error; } + } + } + return new SearchableMap(node, prefix); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear + */ + SearchableMap.prototype.clear = function () { + this._size = undefined; + this._tree.clear(); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete + * @param key Key to delete + */ + SearchableMap.prototype.delete = function (key) { + this._size = undefined; + return remove(this._tree, key); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries + * @return An iterator iterating through `[key, value]` entries. + */ + SearchableMap.prototype.entries = function () { + return new TreeIterator(this, ENTRIES); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach + * @param fn Iteration function + */ + SearchableMap.prototype.forEach = function (fn) { + var e_2, _a; + try { + for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) { + var _d = __read(_c.value, 2), key = _d[0], value = _d[1]; + fn(key, value, this); + } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_2) throw e_2.error; } + } + }; + /** + * Returns a Map of all the entries that have a key within the given edit + * distance from the search key. The keys of the returned Map are the matching + * keys, while the values are two-element arrays where the first element is + * the value associated to the key, and the second is the edit distance of the + * key to the search key. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set('hello', 'world') + * map.set('hell', 'yeah') + * map.set('ciao', 'mondo') + * + * // Get all entries that match the key 'hallo' with a maximum edit distance of 2 + * map.fuzzyGet('hallo', 2) + * // => Map(2) { 'hello' => ['world', 1], 'hell' => ['yeah', 2] } + * + * // In the example, the "hello" key has value "world" and edit distance of 1 + * // (change "e" to "a"), the key "hell" has value "yeah" and edit distance of 2 + * // (change "e" to "a", delete "o") + * ``` + * + * @param key The search key + * @param maxEditDistance The maximum edit distance (Levenshtein) + * @return A Map of the matching keys to their value and edit distance + */ + SearchableMap.prototype.fuzzyGet = function (key, maxEditDistance) { + return fuzzySearch(this._tree, key, maxEditDistance); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get + * @param key Key to get + * @return Value associated to the key, or `undefined` if the key is not + * found. + */ + SearchableMap.prototype.get = function (key) { + var node = lookup(this._tree, key); + return node !== undefined ? node.get(LEAF) : undefined; + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has + * @param key Key + * @return True if the key is in the map, false otherwise + */ + SearchableMap.prototype.has = function (key) { + var node = lookup(this._tree, key); + return node !== undefined && node.has(LEAF); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys + * @return An `Iterable` iterating through keys + */ + SearchableMap.prototype.keys = function () { + return new TreeIterator(this, KEYS); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set + * @param key Key to set + * @param value Value to associate to the key + * @return The [[SearchableMap]] itself, to allow chaining + */ + SearchableMap.prototype.set = function (key, value) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + node.set(LEAF, value); + return this; + }; + Object.defineProperty(SearchableMap.prototype, "size", { + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size + */ + get: function () { + if (this._size) { + return this._size; + } + /** @ignore */ + this._size = 0; + var iter = this.entries(); + while (!iter.next().done) + this._size += 1; + return this._size; + }, + enumerable: false, + configurable: true + }); + /** + * Updates the value at the given key using the provided function. The function + * is called with the current value at the key, and its return value is used as + * the new value to be set. + * + * ### Example: + * + * ```javascript + * // Increment the current value by one + * searchableMap.update('somekey', (currentValue) => currentValue == null ? 0 : currentValue + 1) + * ``` + * + * If the value at the given key is or will be an object, it might not require + * re-assignment. In that case it is better to use `fetch()`, because it is + * faster. + * + * @param key The key to update + * @param fn The function used to compute the new value from the current one + * @return The [[SearchableMap]] itself, to allow chaining + */ + SearchableMap.prototype.update = function (key, fn) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + node.set(LEAF, fn(node.get(LEAF))); + return this; + }; + /** + * Fetches the value of the given key. If the value does not exist, calls the + * given function to create a new value, which is inserted at the given key + * and subsequently returned. + * + * ### Example: + * + * ```javascript + * const map = searchableMap.fetch('somekey', () => new Map()) + * map.set('foo', 'bar') + * ``` + * + * @param key The key to update + * @param defaultValue A function that creates a new value if the key does not exist + * @return The existing or new value at the given key + */ + SearchableMap.prototype.fetch = function (key, initial) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + var value = node.get(LEAF); + if (value === undefined) { + node.set(LEAF, value = initial()); + } + return value; + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values + * @return An `Iterable` iterating through values. + */ + SearchableMap.prototype.values = function () { + return new TreeIterator(this, VALUES); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/@@iterator + */ + SearchableMap.prototype[Symbol.iterator] = function () { + return this.entries(); + }; + /** + * Creates a [[SearchableMap]] from an `Iterable` of entries + * + * @param entries Entries to be inserted in the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + SearchableMap.from = function (entries) { + var e_3, _a; + var tree = new SearchableMap(); + try { + for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) { + var _b = __read(entries_1_1.value, 2), key = _b[0], value = _b[1]; + tree.set(key, value); + } + } + catch (e_3_1) { e_3 = { error: e_3_1 }; } + finally { + try { + if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1); + } + finally { if (e_3) throw e_3.error; } + } + return tree; + }; + /** + * Creates a [[SearchableMap]] from the iterable properties of a JavaScript object + * + * @param object Object of entries for the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + SearchableMap.fromObject = function (object) { + return SearchableMap.from(Object.entries(object)); + }; + return SearchableMap; +}()); +var trackDown = function (tree, key, path) { + var e_4, _a; + if (path === void 0) { path = []; } + if (key.length === 0 || tree == null) { + return [tree, path]; + } + try { + for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var k = _c.value; + if (k !== LEAF && key.startsWith(k)) { + path.push([tree, k]); // performance: update in place + return trackDown(tree.get(k), key.slice(k.length), path); + } + } + } + catch (e_4_1) { e_4 = { error: e_4_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_4) throw e_4.error; } + } + path.push([tree, key]); // performance: update in place + return trackDown(undefined, '', path); +}; +var lookup = function (tree, key) { + var e_5, _a; + if (key.length === 0 || tree == null) { + return tree; + } + try { + for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var k = _c.value; + if (k !== LEAF && key.startsWith(k)) { + return lookup(tree.get(k), key.slice(k.length)); + } + } + } + catch (e_5_1) { e_5 = { error: e_5_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_5) throw e_5.error; } + } +}; +var createPath = function (tree, key) { + var e_6, _a, e_7, _b; + if (key.length === 0 || tree == null) { + return tree; + } + try { + for (var _c = __values(tree.keys()), _d = _c.next(); !_d.done; _d = _c.next()) { + var k = _d.value; + if (k !== LEAF && key.startsWith(k)) { + return createPath(tree.get(k), key.slice(k.length)); + } + } + } + catch (e_6_1) { e_6 = { error: e_6_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_6) throw e_6.error; } + } + try { + for (var _e = __values(tree.keys()), _f = _e.next(); !_f.done; _f = _e.next()) { + var k = _f.value; + if (k !== LEAF && k.startsWith(key[0])) { + var offset = commonPrefixOffset(key, k); + var node_2 = new Map(); + node_2.set(k.slice(offset), tree.get(k)); + tree.set(key.slice(0, offset), node_2); + tree.delete(k); + return createPath(node_2, key.slice(offset)); + } + } + } + catch (e_7_1) { e_7 = { error: e_7_1 }; } + finally { + try { + if (_f && !_f.done && (_b = _e.return)) _b.call(_e); + } + finally { if (e_7) throw e_7.error; } + } + var node = new Map(); + tree.set(key, node); + return node; +}; +var commonPrefixOffset = function (a, b) { + var length = Math.min(a.length, b.length); + for (var i = 0; i < length; i++) { + if (a[i] !== b[i]) + return i; + } + return length; +}; +var remove = function (tree, key) { + var _a = __read(trackDown(tree, key), 2), node = _a[0], path = _a[1]; + if (node === undefined) { + return; + } + node.delete(LEAF); + if (node.size === 0) { + cleanup(path); + } + else if (node.size === 1) { + var _b = __read(node.entries().next().value, 2), key_1 = _b[0], value = _b[1]; + merge(path, key_1, value); + } +}; +var cleanup = function (path) { + if (path.length === 0) { + return; + } + var _a = __read(last(path), 2), node = _a[0], key = _a[1]; + node.delete(key); + if (node.size === 0) { + cleanup(path.slice(0, -1)); + } + else if (node.size === 1) { + var _b = __read(node.entries().next().value, 2), key_2 = _b[0], value = _b[1]; + if (key_2 !== LEAF) { + merge(path.slice(0, -1), key_2, value); + } + } +}; +var merge = function (path, key, value) { + if (path.length === 0) { + return; + } + var _a = __read(last(path), 2), node = _a[0], nodeKey = _a[1]; + node.set(nodeKey + key, value); + node.delete(nodeKey); +}; +var last = function (array) { + return array[array.length - 1]; +}; + +var _a; +var OR = 'or'; +var AND = 'and'; +var AND_NOT = 'and_not'; +/** + * [[MiniSearch]] is the main entrypoint class, implementing a full-text search + * engine in memory. + * + * @typeParam T The type of the documents being indexed. + * + * ### Basic example: + * + * ```javascript + * const documents = [ + * { + * id: 1, + * title: 'Moby Dick', + * text: 'Call me Ishmael. Some years ago...', + * category: 'fiction' + * }, + * { + * id: 2, + * title: 'Zen and the Art of Motorcycle Maintenance', + * text: 'I can see by my watch...', + * category: 'fiction' + * }, + * { + * id: 3, + * title: 'Neuromancer', + * text: 'The sky above the port was...', + * category: 'fiction' + * }, + * { + * id: 4, + * title: 'Zen and the Art of Archery', + * text: 'At first sight it must seem...', + * category: 'non-fiction' + * }, + * // ...and more + * ] + * + * // Create a search engine that indexes the 'title' and 'text' fields for + * // full-text search. Search results will include 'title' and 'category' (plus the + * // id field, that is always stored and returned) + * const miniSearch = new MiniSearch({ + * fields: ['title', 'text'], + * storeFields: ['title', 'category'] + * }) + * + * // Add documents to the index + * miniSearch.addAll(documents) + * + * // Search for documents: + * let results = miniSearch.search('zen art motorcycle') + * // => [ + * // { id: 2, title: 'Zen and the Art of Motorcycle Maintenance', category: 'fiction', score: 2.77258 }, + * // { id: 4, title: 'Zen and the Art of Archery', category: 'non-fiction', score: 1.38629 } + * // ] + * ``` + */ +var MiniSearch = /** @class */ (function () { + /** + * @param options Configuration options + * + * ### Examples: + * + * ```javascript + * // Create a search engine that indexes the 'title' and 'text' fields of your + * // documents: + * const miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * ``` + * + * ### ID Field: + * + * ```javascript + * // Your documents are assumed to include a unique 'id' field, but if you want + * // to use a different field for document identification, you can set the + * // 'idField' option: + * const miniSearch = new MiniSearch({ idField: 'key', fields: ['title', 'text'] }) + * ``` + * + * ### Options and defaults: + * + * ```javascript + * // The full set of options (here with their default value) is: + * const miniSearch = new MiniSearch({ + * // idField: field that uniquely identifies a document + * idField: 'id', + * + * // extractField: function used to get the value of a field in a document. + * // By default, it assumes the document is a flat object with field names as + * // property keys and field values as string property values, but custom logic + * // can be implemented by setting this option to a custom extractor function. + * extractField: (document, fieldName) => document[fieldName], + * + * // tokenize: function used to split fields into individual terms. By + * // default, it is also used to tokenize search queries, unless a specific + * // `tokenize` search option is supplied. When tokenizing an indexed field, + * // the field name is passed as the second argument. + * tokenize: (string, _fieldName) => string.split(SPACE_OR_PUNCTUATION), + * + * // processTerm: function used to process each tokenized term before + * // indexing. It can be used for stemming and normalization. Return a falsy + * // value in order to discard a term. By default, it is also used to process + * // search queries, unless a specific `processTerm` option is supplied as a + * // search option. When processing a term from a indexed field, the field + * // name is passed as the second argument. + * processTerm: (term, _fieldName) => term.toLowerCase(), + * + * // searchOptions: default search options, see the `search` method for + * // details + * searchOptions: undefined, + * + * // fields: document fields to be indexed. Mandatory, but not set by default + * fields: undefined + * + * // storeFields: document fields to be stored and returned as part of the + * // search results. + * storeFields: [] + * }) + * ``` + */ + function MiniSearch(options) { + if ((options === null || options === void 0 ? void 0 : options.fields) == null) { + throw new Error('MiniSearch: option "fields" must be provided'); + } + this._options = __assign(__assign(__assign({}, defaultOptions), options), { searchOptions: __assign(__assign({}, defaultSearchOptions), (options.searchOptions || {})) }); + this._index = new SearchableMap(); + this._documentCount = 0; + this._documentIds = new Map(); + // Fields are defined during initialization, don't change, are few in + // number, rarely need iterating over, and have string keys. Therefore in + // this case an object is a better candidate than a Map to store the mapping + // from field key to ID. + this._fieldIds = {}; + this._fieldLength = new Map(); + this._averageFieldLength = []; + this._nextId = 0; + this._storedFields = new Map(); + this.addFields(this._options.fields); + } + /** + * Adds a document to the index + * + * @param document The document to be indexed + */ + MiniSearch.prototype.add = function (document) { + var e_1, _a, e_2, _b; + var _c = this._options, extractField = _c.extractField, tokenize = _c.tokenize, processTerm = _c.processTerm, fields = _c.fields, idField = _c.idField; + var id = extractField(document, idField); + if (id == null) { + throw new Error("MiniSearch: document does not have ID field \"".concat(idField, "\"")); + } + var shortDocumentId = this.addDocumentId(id); + this.saveStoredFields(shortDocumentId, document); + try { + for (var fields_1 = __values(fields), fields_1_1 = fields_1.next(); !fields_1_1.done; fields_1_1 = fields_1.next()) { + var field = fields_1_1.value; + var fieldValue = extractField(document, field); + if (fieldValue == null) + continue; + var tokens = tokenize(fieldValue.toString(), field); + var fieldId = this._fieldIds[field]; + this.addFieldLength(shortDocumentId, fieldId, this.documentCount - 1, tokens.length); + try { + for (var tokens_1 = (e_2 = void 0, __values(tokens)), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) { + var term = tokens_1_1.value; + var processedTerm = processTerm(term, field); + if (processedTerm) { + this.addTerm(fieldId, shortDocumentId, processedTerm); + } + } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { + if (tokens_1_1 && !tokens_1_1.done && (_b = tokens_1.return)) _b.call(tokens_1); + } + finally { if (e_2) throw e_2.error; } + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (fields_1_1 && !fields_1_1.done && (_a = fields_1.return)) _a.call(fields_1); + } + finally { if (e_1) throw e_1.error; } + } + }; + /** + * Adds all the given documents to the index + * + * @param documents An array of documents to be indexed + */ + MiniSearch.prototype.addAll = function (documents) { + var e_3, _a; + try { + for (var documents_1 = __values(documents), documents_1_1 = documents_1.next(); !documents_1_1.done; documents_1_1 = documents_1.next()) { + var document_1 = documents_1_1.value; + this.add(document_1); + } + } + catch (e_3_1) { e_3 = { error: e_3_1 }; } + finally { + try { + if (documents_1_1 && !documents_1_1.done && (_a = documents_1.return)) _a.call(documents_1); + } + finally { if (e_3) throw e_3.error; } + } + }; + /** + * Adds all the given documents to the index asynchronously. + * + * Returns a promise that resolves (to `undefined`) when the indexing is done. + * This method is useful when index many documents, to avoid blocking the main + * thread. The indexing is performed asynchronously and in chunks. + * + * @param documents An array of documents to be indexed + * @param options Configuration options + * @return A promise resolving to `undefined` when the indexing is done + */ + MiniSearch.prototype.addAllAsync = function (documents, options) { + var _this = this; + if (options === void 0) { options = {}; } + var _a = options.chunkSize, chunkSize = _a === void 0 ? 10 : _a; + var acc = { chunk: [], promise: Promise.resolve() }; + var _b = documents.reduce(function (_a, document, i) { + var chunk = _a.chunk, promise = _a.promise; + chunk.push(document); + if ((i + 1) % chunkSize === 0) { + return { + chunk: [], + promise: promise + .then(function () { return new Promise(function (resolve) { return setTimeout(resolve, 0); }); }) + .then(function () { return _this.addAll(chunk); }) + }; + } + else { + return { chunk: chunk, promise: promise }; + } + }, acc), chunk = _b.chunk, promise = _b.promise; + return promise.then(function () { return _this.addAll(chunk); }); + }; + /** + * Removes the given document from the index. + * + * The document to delete must NOT have changed between indexing and deletion, + * otherwise the index will be corrupted. Therefore, when reindexing a document + * after a change, the correct order of operations is: + * + * 1. remove old version + * 2. apply changes + * 3. index new version + * + * @param document The document to be removed + */ + MiniSearch.prototype.remove = function (document) { + var e_4, _a, e_5, _b, e_6, _c; + var _d = this._options, tokenize = _d.tokenize, processTerm = _d.processTerm, extractField = _d.extractField, fields = _d.fields, idField = _d.idField; + var id = extractField(document, idField); + if (id == null) { + throw new Error("MiniSearch: document does not have ID field \"".concat(idField, "\"")); + } + try { + for (var _e = __values(this._documentIds), _f = _e.next(); !_f.done; _f = _e.next()) { + var _g = __read(_f.value, 2), shortId = _g[0], longId = _g[1]; + if (id === longId) { + try { + for (var fields_2 = (e_5 = void 0, __values(fields)), fields_2_1 = fields_2.next(); !fields_2_1.done; fields_2_1 = fields_2.next()) { + var field = fields_2_1.value; + var fieldValue = extractField(document, field); + if (fieldValue == null) + continue; + var tokens = tokenize(fieldValue.toString(), field); + var fieldId = this._fieldIds[field]; + try { + for (var tokens_2 = (e_6 = void 0, __values(tokens)), tokens_2_1 = tokens_2.next(); !tokens_2_1.done; tokens_2_1 = tokens_2.next()) { + var term = tokens_2_1.value; + var processedTerm = processTerm(term, field); + if (processedTerm) { + this.removeTerm(fieldId, shortId, processedTerm); + } + } + } + catch (e_6_1) { e_6 = { error: e_6_1 }; } + finally { + try { + if (tokens_2_1 && !tokens_2_1.done && (_c = tokens_2.return)) _c.call(tokens_2); + } + finally { if (e_6) throw e_6.error; } + } + this.removeFieldLength(shortId, fieldId, this.documentCount, tokens.length); + } + } + catch (e_5_1) { e_5 = { error: e_5_1 }; } + finally { + try { + if (fields_2_1 && !fields_2_1.done && (_b = fields_2.return)) _b.call(fields_2); + } + finally { if (e_5) throw e_5.error; } + } + this._storedFields.delete(shortId); + this._documentIds.delete(shortId); + this._fieldLength.delete(shortId); + this._documentCount -= 1; + return; + } + } + } + catch (e_4_1) { e_4 = { error: e_4_1 }; } + finally { + try { + if (_f && !_f.done && (_a = _e.return)) _a.call(_e); + } + finally { if (e_4) throw e_4.error; } + } + throw new Error("MiniSearch: cannot remove document with ID ".concat(id, ": it is not in the index")); + }; + /** + * Removes all the given documents from the index. If called with no arguments, + * it removes _all_ documents from the index. + * + * @param documents The documents to be removed. If this argument is omitted, + * all documents are removed. Note that, for removing all documents, it is + * more efficient to call this method with no arguments than to pass all + * documents. + */ + MiniSearch.prototype.removeAll = function (documents) { + var e_7, _a; + if (documents) { + try { + for (var documents_2 = __values(documents), documents_2_1 = documents_2.next(); !documents_2_1.done; documents_2_1 = documents_2.next()) { + var document_2 = documents_2_1.value; + this.remove(document_2); + } + } + catch (e_7_1) { e_7 = { error: e_7_1 }; } + finally { + try { + if (documents_2_1 && !documents_2_1.done && (_a = documents_2.return)) _a.call(documents_2); + } + finally { if (e_7) throw e_7.error; } + } + } + else if (arguments.length > 0) { + throw new Error('Expected documents to be present. Omit the argument to remove all documents.'); + } + else { + this._index = new SearchableMap(); + this._documentCount = 0; + this._documentIds = new Map(); + this._fieldLength = new Map(); + this._averageFieldLength = []; + this._storedFields = new Map(); + this._nextId = 0; + } + }; + /** + * Search for documents matching the given search query. + * + * The result is a list of scored document IDs matching the query, sorted by + * descending score, and each including data about which terms were matched and + * in which fields. + * + * ### Basic usage: + * + * ```javascript + * // Search for "zen art motorcycle" with default options: terms have to match + * // exactly, and individual terms are joined with OR + * miniSearch.search('zen art motorcycle') + * // => [ { id: 2, score: 2.77258, match: { ... } }, { id: 4, score: 1.38629, match: { ... } } ] + * ``` + * + * ### Restrict search to specific fields: + * + * ```javascript + * // Search only in the 'title' field + * miniSearch.search('zen', { fields: ['title'] }) + * ``` + * + * ### Field boosting: + * + * ```javascript + * // Boost a field + * miniSearch.search('zen', { boost: { title: 2 } }) + * ``` + * + * ### Prefix search: + * + * ```javascript + * // Search for "moto" with prefix search (it will match documents + * // containing terms that start with "moto" or "neuro") + * miniSearch.search('moto neuro', { prefix: true }) + * ``` + * + * ### Fuzzy search: + * + * ```javascript + * // Search for "ismael" with fuzzy search (it will match documents containing + * // terms similar to "ismael", with a maximum edit distance of 0.2 term.length + * // (rounded to nearest integer) + * miniSearch.search('ismael', { fuzzy: 0.2 }) + * ``` + * + * ### Combining strategies: + * + * ```javascript + * // Mix of exact match, prefix search, and fuzzy search + * miniSearch.search('ismael mob', { + * prefix: true, + * fuzzy: 0.2 + * }) + * ``` + * + * ### Advanced prefix and fuzzy search: + * + * ```javascript + * // Perform fuzzy and prefix search depending on the search term. Here + * // performing prefix and fuzzy search only on terms longer than 3 characters + * miniSearch.search('ismael mob', { + * prefix: term => term.length > 3 + * fuzzy: term => term.length > 3 ? 0.2 : null + * }) + * ``` + * + * ### Combine with AND: + * + * ```javascript + * // Combine search terms with AND (to match only documents that contain both + * // "motorcycle" and "art") + * miniSearch.search('motorcycle art', { combineWith: 'AND' }) + * ``` + * + * ### Combine with AND_NOT: + * + * There is also an AND_NOT combinator, that finds documents that match the + * first term, but do not match any of the other terms. This combinator is + * rarely useful with simple queries, and is meant to be used with advanced + * query combinations (see later for more details). + * + * ### Filtering results: + * + * ```javascript + * // Filter only results in the 'fiction' category (assuming that 'category' + * // is a stored field) + * miniSearch.search('motorcycle art', { + * filter: (result) => result.category === 'fiction' + * }) + * ``` + * + * ### Advanced combination of queries: + * + * It is possible to combine different subqueries with OR, AND, and AND_NOT, + * and even with different search options, by passing a query expression + * tree object as the first argument, instead of a string. + * + * ```javascript + * // Search for documents that contain "zen" and ("motorcycle" or "archery") + * miniSearch.search({ + * combineWith: 'AND', + * queries: [ + * 'zen', + * { + * combineWith: 'OR', + * queries: ['motorcycle', 'archery'] + * } + * ] + * }) + * + * // Search for documents that contain ("apple" or "pear") but not "juice" and + * // not "tree" + * miniSearch.search({ + * combineWith: 'AND_NOT', + * queries: [ + * { + * combineWith: 'OR', + * queries: ['apple', 'pear'] + * }, + * 'juice', + * 'tree' + * ] + * }) + * ``` + * + * Each node in the expression tree can be either a string, or an object that + * supports all `SearchOptions` fields, plus a `queries` array field for + * subqueries. + * + * Note that, while this can become complicated to do by hand for complex or + * deeply nested queries, it provides a formalized expression tree API for + * external libraries that implement a parser for custom query languages. + * + * @param query Search query + * @param options Search options. Each option, if not given, defaults to the corresponding value of `searchOptions` given to the constructor, or to the library default. + */ + MiniSearch.prototype.search = function (query, searchOptions) { + var e_8, _a; + if (searchOptions === void 0) { searchOptions = {}; } + var combinedResults = this.executeQuery(query, searchOptions); + var results = []; + try { + for (var combinedResults_1 = __values(combinedResults), combinedResults_1_1 = combinedResults_1.next(); !combinedResults_1_1.done; combinedResults_1_1 = combinedResults_1.next()) { + var _b = __read(combinedResults_1_1.value, 2), docId = _b[0], _c = _b[1], score = _c.score, match = _c.match, terms = _c.terms; + var result = { + id: this._documentIds.get(docId), + terms: uniq(terms), + score: score, + match: match + }; + Object.assign(result, this._storedFields.get(docId)); + if (searchOptions.filter == null || searchOptions.filter(result)) { + results.push(result); + } + } + } + catch (e_8_1) { e_8 = { error: e_8_1 }; } + finally { + try { + if (combinedResults_1_1 && !combinedResults_1_1.done && (_a = combinedResults_1.return)) _a.call(combinedResults_1); + } + finally { if (e_8) throw e_8.error; } + } + results.sort(function (_a, _b) { + var a = _a.score; + var b = _b.score; + return a < b ? 1 : -1; + }); + return results; + }; + /** + * Provide suggestions for the given search query + * + * The result is a list of suggested modified search queries, derived from the + * given search query, each with a relevance score, sorted by descending score. + * + * ### Basic usage: + * + * ```javascript + * // Get suggestions for 'neuro': + * miniSearch.autoSuggest('neuro') + * // => [ { suggestion: 'neuromancer', terms: [ 'neuromancer' ], score: 0.46240 } ] + * ``` + * + * ### Multiple words: + * + * ```javascript + * // Get suggestions for 'zen ar': + * miniSearch.autoSuggest('zen ar') + * // => [ + * // { suggestion: 'zen archery art', terms: [ 'zen', 'archery', 'art' ], score: 1.73332 }, + * // { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 } + * // ] + * ``` + * + * ### Fuzzy suggestions: + * + * ```javascript + * // Correct spelling mistakes using fuzzy search: + * miniSearch.autoSuggest('neromancer', { fuzzy: 0.2 }) + * // => [ { suggestion: 'neuromancer', terms: [ 'neuromancer' ], score: 1.03998 } ] + * ``` + * + * ### Filtering: + * + * ```javascript + * // Get suggestions for 'zen ar', but only within the 'fiction' category + * // (assuming that 'category' is a stored field): + * miniSearch.autoSuggest('zen ar', { + * filter: (result) => result.category === 'fiction' + * }) + * // => [ + * // { suggestion: 'zen archery art', terms: [ 'zen', 'archery', 'art' ], score: 1.73332 }, + * // { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 } + * // ] + * ``` + * + * @param queryString Query string to be expanded into suggestions + * @param options Search options. The supported options and default values + * are the same as for the `search` method, except that by default prefix + * search is performed on the last term in the query. + * @return A sorted array of suggestions sorted by relevance score. + */ + MiniSearch.prototype.autoSuggest = function (queryString, options) { + var e_9, _a, e_10, _b; + if (options === void 0) { options = {}; } + options = __assign(__assign({}, defaultAutoSuggestOptions), options); + var suggestions = new Map(); + try { + for (var _c = __values(this.search(queryString, options)), _d = _c.next(); !_d.done; _d = _c.next()) { + var _e = _d.value, score = _e.score, terms = _e.terms; + var phrase = terms.join(' '); + var suggestion = suggestions.get(phrase); + if (suggestion != null) { + suggestion.score += score; + suggestion.count += 1; + } + else { + suggestions.set(phrase, { score: score, terms: terms, count: 1 }); + } + } + } + catch (e_9_1) { e_9 = { error: e_9_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_9) throw e_9.error; } + } + var results = []; + try { + for (var suggestions_1 = __values(suggestions), suggestions_1_1 = suggestions_1.next(); !suggestions_1_1.done; suggestions_1_1 = suggestions_1.next()) { + var _f = __read(suggestions_1_1.value, 2), suggestion = _f[0], _g = _f[1], score = _g.score, terms = _g.terms, count = _g.count; + results.push({ suggestion: suggestion, terms: terms, score: score / count }); + } + } + catch (e_10_1) { e_10 = { error: e_10_1 }; } + finally { + try { + if (suggestions_1_1 && !suggestions_1_1.done && (_b = suggestions_1.return)) _b.call(suggestions_1); + } + finally { if (e_10) throw e_10.error; } + } + results.sort(function (_a, _b) { + var a = _a.score; + var b = _b.score; + return a < b ? 1 : -1; + }); + return results; + }; + Object.defineProperty(MiniSearch.prototype, "documentCount", { + /** + * Number of documents in the index + */ + get: function () { + return this._documentCount; + }, + enumerable: false, + configurable: true + }); + /** + * Deserializes a JSON index (serialized with `JSON.stringify(miniSearch)`) + * and instantiates a MiniSearch instance. It should be given the same options + * originally used when serializing the index. + * + * ### Usage: + * + * ```javascript + * // If the index was serialized with: + * let miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * miniSearch.addAll(documents) + * + * const json = JSON.stringify(miniSearch) + * // It can later be deserialized like this: + * miniSearch = MiniSearch.loadJSON(json, { fields: ['title', 'text'] }) + * ``` + * + * @param json JSON-serialized index + * @param options configuration options, same as the constructor + * @return An instance of MiniSearch deserialized from the given JSON. + */ + MiniSearch.loadJSON = function (json, options) { + if (options == null) { + throw new Error('MiniSearch: loadJSON should be given the same options used when serializing the index'); + } + return MiniSearch.loadJS(JSON.parse(json), options); + }; + /** + * Returns the default value of an option. It will throw an error if no option + * with the given name exists. + * + * @param optionName Name of the option + * @return The default value of the given option + * + * ### Usage: + * + * ```javascript + * // Get default tokenizer + * MiniSearch.getDefault('tokenize') + * + * // Get default term processor + * MiniSearch.getDefault('processTerm') + * + * // Unknown options will throw an error + * MiniSearch.getDefault('notExisting') + * // => throws 'MiniSearch: unknown option "notExisting"' + * ``` + */ + MiniSearch.getDefault = function (optionName) { + if (defaultOptions.hasOwnProperty(optionName)) { + return getOwnProperty(defaultOptions, optionName); + } + else { + throw new Error("MiniSearch: unknown option \"".concat(optionName, "\"")); + } + }; + /** + * @ignore + */ + MiniSearch.loadJS = function (js, options) { + var e_11, _a, e_12, _b; + var index = js.index, documentCount = js.documentCount, nextId = js.nextId, documentIds = js.documentIds, fieldIds = js.fieldIds, fieldLength = js.fieldLength, averageFieldLength = js.averageFieldLength, storedFields = js.storedFields, serializationVersion = js.serializationVersion; + if (serializationVersion !== 1) { + throw new Error('MiniSearch: cannot deserialize an index created with an incompatible version'); + } + var miniSearch = new MiniSearch(options); + miniSearch._documentCount = documentCount; + miniSearch._nextId = nextId; + miniSearch._documentIds = objectToNumericMap(documentIds); + miniSearch._fieldIds = fieldIds; + miniSearch._fieldLength = objectToNumericMap(fieldLength); + miniSearch._averageFieldLength = averageFieldLength; + miniSearch._storedFields = objectToNumericMap(storedFields); + miniSearch._index = new SearchableMap(); + try { + for (var index_1 = __values(index), index_1_1 = index_1.next(); !index_1_1.done; index_1_1 = index_1.next()) { + var _c = __read(index_1_1.value, 2), term = _c[0], data = _c[1]; + var dataMap = new Map(); + try { + for (var _d = (e_12 = void 0, __values(Object.keys(data))), _e = _d.next(); !_e.done; _e = _d.next()) { + var fieldId = _e.value; + var _f = data[fieldId], df = _f.df, ds = _f.ds; + dataMap.set(parseInt(fieldId, 10), { df: df, ds: objectToNumericMap(ds) }); + } + } + catch (e_12_1) { e_12 = { error: e_12_1 }; } + finally { + try { + if (_e && !_e.done && (_b = _d.return)) _b.call(_d); + } + finally { if (e_12) throw e_12.error; } + } + miniSearch._index.set(term, dataMap); + } + } + catch (e_11_1) { e_11 = { error: e_11_1 }; } + finally { + try { + if (index_1_1 && !index_1_1.done && (_a = index_1.return)) _a.call(index_1); + } + finally { if (e_11) throw e_11.error; } + } + return miniSearch; + }; + /** + * @ignore + */ + MiniSearch.prototype.executeQuery = function (query, searchOptions) { + var _this = this; + if (searchOptions === void 0) { searchOptions = {}; } + if (typeof query === 'string') { + return this.executeSearch(query, searchOptions); + } + else { + var results = query.queries.map(function (subquery) { + var options = __assign(__assign(__assign({}, searchOptions), query), { queries: undefined }); + return _this.executeQuery(subquery, options); + }); + return this.combineResults(results, query.combineWith); + } + }; + /** + * @ignore + */ + MiniSearch.prototype.executeSearch = function (queryString, searchOptions) { + var _this = this; + if (searchOptions === void 0) { searchOptions = {}; } + var _a = this._options, tokenize = _a.tokenize, processTerm = _a.processTerm, globalSearchOptions = _a.searchOptions; + var options = __assign(__assign({ tokenize: tokenize, processTerm: processTerm }, globalSearchOptions), searchOptions); + var searchTokenize = options.tokenize, searchProcessTerm = options.processTerm; + var terms = searchTokenize(queryString) + .map(function (term) { return searchProcessTerm(term); }) + .filter(function (term) { return !!term; }); + var queries = terms.map(termToQuerySpec(options)); + var results = queries.map(function (query) { return _this.executeQuerySpec(query, options); }); + return this.combineResults(results, options.combineWith); + }; + /** + * @ignore + */ + MiniSearch.prototype.executeQuerySpec = function (query, searchOptions) { + var e_13, _a, e_14, _b; + var options = __assign(__assign({}, this._options.searchOptions), searchOptions); + var boosts = (options.fields || this._options.fields).reduce(function (boosts, field) { + var _a; + return (__assign(__assign({}, boosts), (_a = {}, _a[field] = getOwnProperty(boosts, field) || 1, _a))); + }, options.boost || {}); + var boostDocument = options.boostDocument, weights = options.weights, maxFuzzy = options.maxFuzzy; + var _c = __assign(__assign({}, defaultSearchOptions.weights), weights), fuzzyWeight = _c.fuzzy, prefixWeight = _c.prefix; + var results = this.termResults(query.term, boosts, boostDocument, this._index.get(query.term)); + var prefixMatches; + var fuzzyMatches; + if (query.prefix) { + prefixMatches = this._index.atPrefix(query.term); + } + if (query.fuzzy) { + var fuzzy = (query.fuzzy === true) ? 0.2 : query.fuzzy; + var maxDistance = fuzzy < 1 ? Math.min(maxFuzzy, Math.round(query.term.length * fuzzy)) : fuzzy; + fuzzyMatches = this._index.fuzzyGet(query.term, maxDistance); + } + if (prefixMatches) { + try { + for (var prefixMatches_1 = __values(prefixMatches), prefixMatches_1_1 = prefixMatches_1.next(); !prefixMatches_1_1.done; prefixMatches_1_1 = prefixMatches_1.next()) { + var _d = __read(prefixMatches_1_1.value, 2), term = _d[0], data = _d[1]; + var distance = term.length - query.term.length; + if (!distance) { + continue; + } // Skip exact match. + // Delete the term from fuzzy results (if present) if it is also a + // prefix result. This entry will always be scored as a prefix result. + fuzzyMatches === null || fuzzyMatches === void 0 ? void 0 : fuzzyMatches.delete(term); + var weightedDistance = (0.3 * distance) / term.length; + this.termResults(term, boosts, boostDocument, data, results, prefixWeight, weightedDistance); + } + } + catch (e_13_1) { e_13 = { error: e_13_1 }; } + finally { + try { + if (prefixMatches_1_1 && !prefixMatches_1_1.done && (_a = prefixMatches_1.return)) _a.call(prefixMatches_1); + } + finally { if (e_13) throw e_13.error; } + } + } + if (fuzzyMatches) { + try { + for (var _e = __values(fuzzyMatches.keys()), _f = _e.next(); !_f.done; _f = _e.next()) { + var term = _f.value; + var _g = __read(fuzzyMatches.get(term), 2), data = _g[0], distance = _g[1]; + if (!distance) { + continue; + } // Skip exact match. + var weightedDistance = distance / term.length; + this.termResults(term, boosts, boostDocument, data, results, fuzzyWeight, weightedDistance); + } + } + catch (e_14_1) { e_14 = { error: e_14_1 }; } + finally { + try { + if (_f && !_f.done && (_b = _e.return)) _b.call(_e); + } + finally { if (e_14) throw e_14.error; } + } + } + return results; + }; + /** + * @ignore + */ + MiniSearch.prototype.combineResults = function (results, combineWith) { + if (combineWith === void 0) { combineWith = OR; } + if (results.length === 0) { + return new Map(); + } + var operator = combineWith.toLowerCase(); + return results.reduce(combinators[operator]) || new Map(); + }; + /** + * Allows serialization of the index to JSON, to possibly store it and later + * deserialize it with `MiniSearch.loadJSON`. + * + * Normally one does not directly call this method, but rather call the + * standard JavaScript `JSON.stringify()` passing the `MiniSearch` instance, + * and JavaScript will internally call this method. Upon deserialization, one + * must pass to `loadJSON` the same options used to create the original + * instance that was serialized. + * + * ### Usage: + * + * ```javascript + * // Serialize the index: + * let miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * miniSearch.addAll(documents) + * const json = JSON.stringify(miniSearch) + * + * // Later, to deserialize it: + * miniSearch = MiniSearch.loadJSON(json, { fields: ['title', 'text'] }) + * ``` + * + * @return A plain-object serializeable representation of the search index. + */ + MiniSearch.prototype.toJSON = function () { + var e_15, _a, e_16, _b; + var index = []; + try { + for (var _c = __values(this._index), _d = _c.next(); !_d.done; _d = _c.next()) { + var _e = __read(_d.value, 2), term = _e[0], fieldIndex = _e[1]; + var data = {}; + try { + for (var fieldIndex_1 = (e_16 = void 0, __values(fieldIndex)), fieldIndex_1_1 = fieldIndex_1.next(); !fieldIndex_1_1.done; fieldIndex_1_1 = fieldIndex_1.next()) { + var _f = __read(fieldIndex_1_1.value, 2), fieldId = _f[0], _g = _f[1], df = _g.df, ds = _g.ds; + data[fieldId] = { df: df, ds: Object.fromEntries(ds) }; + } + } + catch (e_16_1) { e_16 = { error: e_16_1 }; } + finally { + try { + if (fieldIndex_1_1 && !fieldIndex_1_1.done && (_b = fieldIndex_1.return)) _b.call(fieldIndex_1); + } + finally { if (e_16) throw e_16.error; } + } + index.push([term, data]); + } + } + catch (e_15_1) { e_15 = { error: e_15_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_15) throw e_15.error; } + } + return { + documentCount: this._documentCount, + nextId: this._nextId, + documentIds: Object.fromEntries(this._documentIds), + fieldIds: this._fieldIds, + fieldLength: Object.fromEntries(this._fieldLength), + averageFieldLength: this._averageFieldLength, + storedFields: Object.fromEntries(this._storedFields), + index: index, + serializationVersion: 1 + }; + }; + /** + * @ignore + */ + MiniSearch.prototype.termResults = function (term, boosts, boostDocument, indexData, results, weight, editDistance) { + var e_17, _a, e_18, _b, _c; + if (results === void 0) { results = new Map(); } + if (weight === void 0) { weight = 1; } + if (editDistance === void 0) { editDistance = 0; } + if (indexData == null) + return results; + try { + for (var _d = __values(Object.keys(boosts)), _e = _d.next(); !_e.done; _e = _d.next()) { + var field = _e.value; + var fieldBoost = boosts[field]; + var fieldId = this._fieldIds[field]; + var entry = indexData.get(fieldId); + if (entry == null) + continue; + try { + for (var _f = (e_18 = void 0, __values(entry.ds)), _g = _f.next(); !_g.done; _g = _f.next()) { + var _h = __read(_g.value, 2), documentId = _h[0], tf = _h[1]; + var docBoost = boostDocument ? boostDocument(this._documentIds.get(documentId), term) : 1; + if (!docBoost) + continue; + var normalizedLength = this._fieldLength.get(documentId)[fieldId] / this._averageFieldLength[fieldId]; + var score = weight * docBoost * calculateScore(tf, entry.df, this._documentCount, normalizedLength, fieldBoost, editDistance); + var result = results.get(documentId); + if (result) { + result.score += score; + var match = getOwnProperty(result.match, term); + if (match) { + match.push(field); + } + else { + result.match[term] = [field]; + result.terms.push(term); + } + } + else { + results.set(documentId, { + score: score, + match: (_c = {}, _c[term] = [field], _c), + terms: [term] + }); + } + } + } + catch (e_18_1) { e_18 = { error: e_18_1 }; } + finally { + try { + if (_g && !_g.done && (_b = _f.return)) _b.call(_f); + } + finally { if (e_18) throw e_18.error; } + } + } + } + catch (e_17_1) { e_17 = { error: e_17_1 }; } + finally { + try { + if (_e && !_e.done && (_a = _d.return)) _a.call(_d); + } + finally { if (e_17) throw e_17.error; } + } + return results; + }; + /** + * @ignore + */ + MiniSearch.prototype.addTerm = function (fieldId, documentId, term) { + var indexData = this._index.fetch(term, createMap); + var fieldIndex = indexData.get(fieldId); + if (fieldIndex == null) { + fieldIndex = { df: 1, ds: new Map() }; + fieldIndex.ds.set(documentId, 1); + indexData.set(fieldId, fieldIndex); + } + else { + var docs = fieldIndex.ds.get(documentId); + if (docs == null) { + fieldIndex.df += 1; + } + fieldIndex.ds.set(documentId, (docs || 0) + 1); + } + }; + /** + * @ignore + */ + MiniSearch.prototype.removeTerm = function (fieldId, documentId, term) { + if (!this._index.has(term)) { + this.warnDocumentChanged(documentId, fieldId, term); + return; + } + var indexData = this._index.fetch(term, createMap); + var fieldIndex = indexData.get(fieldId); + if (fieldIndex == null || fieldIndex.ds.get(documentId) == null) { + this.warnDocumentChanged(documentId, fieldId, term); + } + else if (fieldIndex.ds.get(documentId) <= 1) { + if (fieldIndex.df <= 1) { + indexData.delete(fieldId); + } + else { + fieldIndex.df -= 1; + fieldIndex.ds.delete(documentId); + } + } + else { + fieldIndex.ds.set(documentId, fieldIndex.ds.get(documentId) - 1); + } + if (this._index.get(term).size === 0) { + this._index.delete(term); + } + }; + /** + * @ignore + */ + MiniSearch.prototype.warnDocumentChanged = function (shortDocumentId, fieldId, term) { + var e_19, _a; + if (console == null || console.warn == null) { + return; + } + try { + for (var _b = __values(Object.keys(this._fieldIds)), _c = _b.next(); !_c.done; _c = _b.next()) { + var fieldName = _c.value; + if (this._fieldIds[fieldName] === fieldId) { + console.warn("MiniSearch: document with ID ".concat(this._documentIds.get(shortDocumentId), " has changed before removal: term \"").concat(term, "\" was not present in field \"").concat(fieldName, "\". Removing a document after it has changed can corrupt the index!")); + return; + } + } + } + catch (e_19_1) { e_19 = { error: e_19_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_19) throw e_19.error; } + } + }; + /** + * @ignore + */ + MiniSearch.prototype.addDocumentId = function (documentId) { + var shortDocumentId = this._nextId; + this._documentIds.set(shortDocumentId, documentId); + this._documentCount += 1; + this._nextId += 1; + return shortDocumentId; + }; + /** + * @ignore + */ + MiniSearch.prototype.addFields = function (fields) { + for (var i = 0; i < fields.length; i++) { + this._fieldIds[fields[i]] = i; + } + }; + /** + * @ignore + */ + MiniSearch.prototype.addFieldLength = function (documentId, fieldId, count, length) { + var fieldLengths = this._fieldLength.get(documentId); + if (fieldLengths == null) + this._fieldLength.set(documentId, fieldLengths = []); + fieldLengths[fieldId] = length; + var averageFieldLength = this._averageFieldLength[fieldId] || 0; + var totalLength = (averageFieldLength * count) + length; + this._averageFieldLength[fieldId] = totalLength / (count + 1); + }; + /** + * @ignore + */ + MiniSearch.prototype.removeFieldLength = function (documentId, fieldId, count, length) { + var totalLength = (this._averageFieldLength[fieldId] * count) - length; + this._averageFieldLength[fieldId] = totalLength / (count - 1); + }; + /** + * @ignore + */ + MiniSearch.prototype.saveStoredFields = function (documentId, doc) { + var e_20, _a; + var _b = this._options, storeFields = _b.storeFields, extractField = _b.extractField; + if (storeFields == null || storeFields.length === 0) { + return; + } + var documentFields = this._storedFields.get(documentId); + if (documentFields == null) + this._storedFields.set(documentId, documentFields = {}); + try { + for (var storeFields_1 = __values(storeFields), storeFields_1_1 = storeFields_1.next(); !storeFields_1_1.done; storeFields_1_1 = storeFields_1.next()) { + var fieldName = storeFields_1_1.value; + var fieldValue = extractField(doc, fieldName); + if (fieldValue !== undefined) + documentFields[fieldName] = fieldValue; + } + } + catch (e_20_1) { e_20 = { error: e_20_1 }; } + finally { + try { + if (storeFields_1_1 && !storeFields_1_1.done && (_a = storeFields_1.return)) _a.call(storeFields_1); + } + finally { if (e_20) throw e_20.error; } + } + }; + return MiniSearch; +}()); +var getOwnProperty = function (object, property) { + return Object.prototype.hasOwnProperty.call(object, property) ? object[property] : undefined; +}; +var combinators = (_a = {}, + _a[OR] = function (a, b) { + var e_21, _a, _b; + try { + for (var _c = __values(b.keys()), _d = _c.next(); !_d.done; _d = _c.next()) { + var documentId = _d.value; + var existing = a.get(documentId); + if (existing == null) { + a.set(documentId, b.get(documentId)); + } + else { + var _e = b.get(documentId), score = _e.score, match = _e.match, terms = _e.terms; + existing.score = (existing.score + score) * 1.5; + existing.match = Object.assign(existing.match, match); + (_b = existing.terms).push.apply(_b, __spreadArray([], __read(terms), false)); + } + } + } + catch (e_21_1) { e_21 = { error: e_21_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_21) throw e_21.error; } + } + return a; + }, + _a[AND] = function (a, b) { + var e_22, _a; + var combined = new Map(); + try { + for (var _b = __values(b.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var documentId = _c.value; + var existing = a.get(documentId); + if (existing == null) + continue; + var _d = b.get(documentId), score = _d.score, match = _d.match, terms = _d.terms; + combined.set(documentId, { + score: existing.score + score, + match: Object.assign(existing.match, match), + terms: __spreadArray(__spreadArray([], __read(existing.terms), false), __read(terms), false) + }); + } + } + catch (e_22_1) { e_22 = { error: e_22_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_22) throw e_22.error; } + } + return combined; + }, + _a[AND_NOT] = function (a, b) { + var e_23, _a; + try { + for (var _b = __values(b.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var documentId = _c.value; + a.delete(documentId); + } + } + catch (e_23_1) { e_23 = { error: e_23_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_23) throw e_23.error; } + } + return a; + }, + _a); +var tfIdf = function (tf, df, n) { return tf * Math.log(n / df); }; +var calculateScore = function (termFrequency, documentFrequency, documentCount, normalizedLength, boost, editDistance) { + var weight = boost / (1 + (0.333 * boost * editDistance)); + return weight * tfIdf(termFrequency, documentFrequency, documentCount) / normalizedLength; +}; +var termToQuerySpec = function (options) { return function (term, i, terms) { + var fuzzy = (typeof options.fuzzy === 'function') + ? options.fuzzy(term, i, terms) + : (options.fuzzy || false); + var prefix = (typeof options.prefix === 'function') + ? options.prefix(term, i, terms) + : (options.prefix === true); + return { term: term, fuzzy: fuzzy, prefix: prefix }; +}; }; +var uniq = function (array) { + return array.filter(function (element, i, array) { return array.indexOf(element) === i; }); +}; +var defaultOptions = { + idField: 'id', + extractField: function (document, fieldName) { return document[fieldName]; }, + tokenize: function (text, fieldName) { return text.split(SPACE_OR_PUNCTUATION); }, + processTerm: function (term, fieldName) { return term.toLowerCase(); }, + fields: undefined, + searchOptions: undefined, + storeFields: [] +}; +var defaultSearchOptions = { + combineWith: OR, + prefix: false, + fuzzy: false, + maxFuzzy: 6, + boost: {}, + weights: { fuzzy: 0.45, prefix: 0.375 } +}; +var defaultAutoSuggestOptions = { + prefix: function (term, i, terms) { + return i === terms.length - 1; + } +}; +var createMap = function () { return new Map(); }; +var objectToNumericMap = function (object) { + var e_24, _a; + var map = new Map(); + try { + for (var _b = __values(Object.keys(object)), _c = _b.next(); !_c.done; _c = _b.next()) { + var key = _c.value; + map.set(parseInt(key, 10), object[key]); + } + } + catch (e_24_1) { e_24 = { error: e_24_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_24) throw e_24.error; } + } + return map; +}; +// This regular expression matches any Unicode space or punctuation character +// Adapted from https://unicode.org/cldr/utility/list-unicodeset.jsp?a=%5Cp%7BZ%7D%5Cp%7BP%7D&abb=on&c=on&esc=on +var SPACE_OR_PUNCTUATION = /[\n\r -#%-*,-/:;?@[-\]_{}\u00A0\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u1680\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2000-\u200A\u2010-\u2029\u202F-\u2043\u2045-\u2051\u2053-\u205F\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u3000-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]+/u; + +export { MiniSearch as default }; +//# sourceMappingURL=index.js.map diff --git a/node_modules/minisearch/dist/es5m/index.js.map b/node_modules/minisearch/dist/es5m/index.js.map new file mode 100644 index 0000000..cddfe44 --- /dev/null +++ b/node_modules/minisearch/dist/es5m/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../../node_modules/tslib/tslib.es6.js","../../src/SearchableMap/TreeIterator.ts","../../src/SearchableMap/fuzzySearch.ts","../../src/SearchableMap/SearchableMap.ts","../../src/MiniSearch.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n",null,null,null,null],"names":["last"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAiBA;AACO,IAAI,QAAQ,GAAG,WAAW;AACjC,IAAI,QAAQ,GAAG,MAAM,CAAC,MAAM,IAAI,SAAS,QAAQ,CAAC,CAAC,EAAE;AACrD,QAAQ,KAAK,IAAI,CAAC,EAAE,CAAC,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,IAAM,SAAS,GAAG,cAAM,OAAA,IAAI,GAAG,EAAE,GAAA,CAAA;AAIjC,IAAM,kBAAkB,GAAG,UAAI,MAA4B;;IACzD,IAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAA;;QAErB,KAAkB,IAAA,KAAA,SAAA,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,gBAAA,4BAAE;YAAlC,IAAM,GAAG,WAAA;YACZ,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;SACxC;;;;;;;;;IAED,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED;AACA;AACA,IAAM,oBAAoB,GAAG,8xCAA8xC;;;;"} \ No newline at end of file diff --git a/node_modules/minisearch/dist/types/index.d.ts b/node_modules/minisearch/dist/types/index.d.ts new file mode 100644 index 0000000..3a2973f --- /dev/null +++ b/node_modules/minisearch/dist/types/index.d.ts @@ -0,0 +1,995 @@ +declare type RadixTree = Map>; +declare type Entry = [string, T]; + +declare type IteratorType = 'ENTRIES' | 'KEYS' | 'VALUES'; +declare type IteratorPath = { + node: RadixTree; + keys: string[]; +}[]; +declare type IterableSet = { + _tree: RadixTree; + _prefix: string; +}; +/** + * @private + */ +declare class TreeIterator implements Iterator { + set: IterableSet; + _type: IteratorType; + _path: IteratorPath; + constructor(set: IterableSet, type: IteratorType); + next(): IteratorResult; + dive(): IteratorResult; + backtrack(): void; + key(): string; + value(): T; + result(): unknown; + [Symbol.iterator](): this; +} + +declare type FuzzyResult = [T, number]; +declare type FuzzyResults = Map>; + +/** + * A class implementing the same interface as a standard JavaScript + * [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) + * with string keys, but adding support for efficiently searching entries with + * prefix or fuzzy search. This class is used internally by [[MiniSearch]] as + * the inverted index data structure. The implementation is a radix tree + * (compressed prefix tree). + * + * Since this class can be of general utility beyond _MiniSearch_, it is + * exported by the `minisearch` package and can be imported (or required) as + * `minisearch/SearchableMap`. + * + * @typeParam T The type of the values stored in the map. + */ +declare class SearchableMap { + /** + * @internal + */ + _tree: RadixTree; + /** + * @internal + */ + _prefix: string; + private _size; + /** + * The constructor is normally called without arguments, creating an empty + * map. In order to create a [[SearchableMap]] from an iterable or from an + * object, check [[SearchableMap.from]] and [[SearchableMap.fromObject]]. + * + * The constructor arguments are for internal use, when creating derived + * mutable views of a map at a prefix. + */ + constructor(tree?: RadixTree, prefix?: string); + /** + * Creates and returns a mutable view of this [[SearchableMap]], containing only + * entries that share the given prefix. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set("unicorn", 1) + * map.set("universe", 2) + * map.set("university", 3) + * map.set("unique", 4) + * map.set("hello", 5) + * + * let uni = map.atPrefix("uni") + * uni.get("unique") // => 4 + * uni.get("unicorn") // => 1 + * uni.get("hello") // => undefined + * + * let univer = map.atPrefix("univer") + * univer.get("unique") // => undefined + * univer.get("universe") // => 2 + * univer.get("university") // => 3 + * ``` + * + * @param prefix The prefix + * @return A [[SearchableMap]] representing a mutable view of the original Map at the given prefix + */ + atPrefix(prefix: string): SearchableMap; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear + */ + clear(): void; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete + * @param key Key to delete + */ + delete(key: string): void; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries + * @return An iterator iterating through `[key, value]` entries. + */ + entries(): TreeIterator>; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach + * @param fn Iteration function + */ + forEach(fn: (key: string, value: T, map: SearchableMap) => void): void; + /** + * Returns a Map of all the entries that have a key within the given edit + * distance from the search key. The keys of the returned Map are the matching + * keys, while the values are two-element arrays where the first element is + * the value associated to the key, and the second is the edit distance of the + * key to the search key. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set('hello', 'world') + * map.set('hell', 'yeah') + * map.set('ciao', 'mondo') + * + * // Get all entries that match the key 'hallo' with a maximum edit distance of 2 + * map.fuzzyGet('hallo', 2) + * // => Map(2) { 'hello' => ['world', 1], 'hell' => ['yeah', 2] } + * + * // In the example, the "hello" key has value "world" and edit distance of 1 + * // (change "e" to "a"), the key "hell" has value "yeah" and edit distance of 2 + * // (change "e" to "a", delete "o") + * ``` + * + * @param key The search key + * @param maxEditDistance The maximum edit distance (Levenshtein) + * @return A Map of the matching keys to their value and edit distance + */ + fuzzyGet(key: string, maxEditDistance: number): FuzzyResults; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get + * @param key Key to get + * @return Value associated to the key, or `undefined` if the key is not + * found. + */ + get(key: string): T | undefined; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has + * @param key Key + * @return True if the key is in the map, false otherwise + */ + has(key: string): boolean; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys + * @return An `Iterable` iterating through keys + */ + keys(): TreeIterator; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set + * @param key Key to set + * @param value Value to associate to the key + * @return The [[SearchableMap]] itself, to allow chaining + */ + set(key: string, value: T): SearchableMap; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size + */ + get size(): number; + /** + * Updates the value at the given key using the provided function. The function + * is called with the current value at the key, and its return value is used as + * the new value to be set. + * + * ### Example: + * + * ```javascript + * // Increment the current value by one + * searchableMap.update('somekey', (currentValue) => currentValue == null ? 0 : currentValue + 1) + * ``` + * + * If the value at the given key is or will be an object, it might not require + * re-assignment. In that case it is better to use `fetch()`, because it is + * faster. + * + * @param key The key to update + * @param fn The function used to compute the new value from the current one + * @return The [[SearchableMap]] itself, to allow chaining + */ + update(key: string, fn: (value: T) => T): SearchableMap; + /** + * Fetches the value of the given key. If the value does not exist, calls the + * given function to create a new value, which is inserted at the given key + * and subsequently returned. + * + * ### Example: + * + * ```javascript + * const map = searchableMap.fetch('somekey', () => new Map()) + * map.set('foo', 'bar') + * ``` + * + * @param key The key to update + * @param defaultValue A function that creates a new value if the key does not exist + * @return The existing or new value at the given key + */ + fetch(key: string, initial: () => T): T; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values + * @return An `Iterable` iterating through values. + */ + values(): TreeIterator; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/@@iterator + */ + [Symbol.iterator](): TreeIterator>; + /** + * Creates a [[SearchableMap]] from an `Iterable` of entries + * + * @param entries Entries to be inserted in the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + static from(entries: Iterable> | Entry[]): SearchableMap; + /** + * Creates a [[SearchableMap]] from the iterable properties of a JavaScript object + * + * @param object Object of entries for the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + static fromObject(object: { + [key: string]: T; + }): SearchableMap; +} + +/** + * Search options to customize the search behavior. + */ +declare type SearchOptions = { + /** + * Names of the fields to search in. If omitted, all fields are searched. + */ + fields?: string[]; + /** + * Function used to filter search results, for example on the basis of stored + * fields. It takes as argument each search result and should return a boolean + * to indicate if the result should be kept or not. + */ + filter?: (result: SearchResult) => boolean; + /** + * Key-value object of field names to boosting values. By default, fields are + * assigned a boosting factor of 1. If one assigns to a field a boosting value + * of 2, a result that matches the query in that field is assigned a score + * twice as high as a result matching the query in another field, all else + * being equal. + */ + boost?: { + [fieldName: string]: number; + }; + /** + * Relative weights to assign to prefix search results and fuzzy search + * results. Exact matches are assigned a weight of 1. + */ + weights?: { + fuzzy: number; + prefix: number; + }; + /** + * Function to calculate a boost factor for documents. It takes as arguments + * the document ID, and a term that matches the search in that document, and + * should return a boosting factor. + */ + boostDocument?: (documentId: any, term: string) => number; + /** + * Controls whether to perform prefix search. It can be a simple boolean, or a + * function. + * + * If a boolean is passed, prefix search is performed if true. + * + * If a function is passed, it is called upon search with a search term, the + * positional index of that search term in the tokenized search query, and the + * tokenized search query. The function should return a boolean to indicate + * whether to perform prefix search for that search term. + */ + prefix?: boolean | ((term: string, index: number, terms: string[]) => boolean); + /** + * Controls whether to perform fuzzy search. It can be a simple boolean, or a + * number, or a function. + * + * If a boolean is given, fuzzy search with a default fuzziness parameter is + * performed if true. + * + * If a number higher or equal to 1 is given, fuzzy search is performed, with + * a maximum edit distance (Levenshtein) equal to the number. + * + * If a number between 0 and 1 is given, fuzzy search is performed within a + * maximum edit distance corresponding to that fraction of the term length, + * approximated to the nearest integer. For example, 0.2 would mean an edit + * distance of 20% of the term length, so 1 character in a 5-characters term. + * The calculated fuzziness value is limited by the `maxFuzzy` option, to + * prevent slowdown for very long queries. + * + * If a function is passed, the function is called upon search with a search + * term, a positional index of that term in the tokenized search query, and + * the tokenized search query. It should return a boolean or a number, with + * the meaning documented above. + */ + fuzzy?: boolean | number | ((term: string, index: number, terms: string[]) => boolean | number); + /** + * Controls the maximum fuzziness when using a fractional fuzzy value. This is + * set to 6 by default. Very high edit distances usually don't produce + * meaningful results, but can excessively impact search performance. + */ + maxFuzzy?: number; + /** + * The operand to combine partial results for each term. By default it is + * "OR", so results matching _any_ of the search terms are returned by a + * search. If "AND" is given, only results matching _all_ the search terms are + * returned by a search. + */ + combineWith?: string; + /** + * Function to tokenize the search query. By default, the same tokenizer used + * for indexing is used also for search. + */ + tokenize?: (text: string) => string[]; + /** + * Function to process or normalize terms in the search query. By default, the + * same term processor used for indexing is used also for search. + */ + processTerm?: (term: string) => string | null | undefined | false; +}; +declare type SearchOptionsWithDefaults = SearchOptions & { + boost: { + [fieldName: string]: number; + }; + weights: { + fuzzy: number; + prefix: number; + }; + prefix: boolean | ((term: string, index: number, terms: string[]) => boolean); + fuzzy: boolean | number | ((term: string, index: number, terms: string[]) => boolean | number); + maxFuzzy: number; + combineWith: string; +}; +/** + * Configuration options passed to the [[MiniSearch]] constructor + * + * @typeParam T The type of documents being indexed. + */ +declare type Options = { + /** + * Names of the document fields to be indexed. + */ + fields: string[]; + /** + * Name of the ID field, uniquely identifying a document. + */ + idField?: string; + /** + * Names of fields to store, so that search results would include them. By + * default none, so resuts would only contain the id field. + */ + storeFields?: string[]; + /** + * Function used to extract the value of each field in documents. By default, + * the documents are assumed to be plain objects with field names as keys, + * but by specifying a custom `extractField` function one can completely + * customize how the fields are extracted. + * + * The function takes as arguments the document, and the name of the field to + * extract from it. It should return the field value as a string. + */ + extractField?: (document: T, fieldName: string) => string; + tokenize?: (text: string, fieldName?: string) => string[]; + /** + * Function used to process a term before indexing or search. This can be + * used for normalization (such as stemming). By default, terms are + * downcased, and otherwise no other normalization is performed. + * + * The function takes as arguments a term to process, and the name of the + * field it comes from. It should return the processed term as a string, or a + * falsy value to reject the term entirely. + */ + processTerm?: (term: string, fieldName?: string) => string | null | undefined | false; + /** + * Default search options (see the [[SearchOptions]] type and the + * [[MiniSearch.search]] method for details) + */ + searchOptions?: SearchOptions; +}; +declare type OptionsWithDefaults = Options & { + storeFields: string[]; + idField: string; + extractField: (document: T, fieldName: string) => string; + tokenize: (text: string, fieldName: string) => string[]; + processTerm: (term: string, fieldName: string) => string | null | undefined | false; + searchOptions: SearchOptionsWithDefaults; +}; +/** + * The type of auto-suggestions + */ +declare type Suggestion = { + /** + * The suggestion + */ + suggestion: string; + /** + * Suggestion as an array of terms + */ + terms: string[]; + /** + * Score for the suggestion + */ + score: number; +}; +/** + * Match information for a search result. It is a key-value object where keys + * are terms that matched, and values are the list of fields that the term was + * found in. + */ +declare type MatchInfo = { + [term: string]: string[]; +}; +/** + * Type of the search results. Each search result indicates the document ID, the + * terms that matched, the match information, the score, and all the stored + * fields. + */ +declare type SearchResult = { + /** + * The document ID + */ + id: any; + /** + * List of terms that matched + */ + terms: string[]; + /** + * Score of the search results + */ + score: number; + /** + * Match information, see [[MatchInfo]] + */ + match: MatchInfo; + /** + * Stored fields + */ + [key: string]: any; +}; +/** + * @ignore + */ +declare type AsPlainObject = { + documentCount: number; + nextId: number; + documentIds: { + [shortId: string]: any; + }; + fieldIds: { + [fieldName: string]: number; + }; + fieldLength: { + [shortId: string]: number[]; + }; + averageFieldLength: number[]; + storedFields: { + [shortId: string]: any; + }; + index: [string, { + [fieldId: string]: SerializedIndexEntry; + }][]; + serializationVersion: number; +}; +declare type QueryCombination = SearchOptions & { + queries: Query[]; +}; +/** + * Search query expression, either a query string or an expression tree + * combining several queries with a combination of AND or OR. + */ +declare type Query = QueryCombination | string; +/** + * [[MiniSearch]] is the main entrypoint class, implementing a full-text search + * engine in memory. + * + * @typeParam T The type of the documents being indexed. + * + * ### Basic example: + * + * ```javascript + * const documents = [ + * { + * id: 1, + * title: 'Moby Dick', + * text: 'Call me Ishmael. Some years ago...', + * category: 'fiction' + * }, + * { + * id: 2, + * title: 'Zen and the Art of Motorcycle Maintenance', + * text: 'I can see by my watch...', + * category: 'fiction' + * }, + * { + * id: 3, + * title: 'Neuromancer', + * text: 'The sky above the port was...', + * category: 'fiction' + * }, + * { + * id: 4, + * title: 'Zen and the Art of Archery', + * text: 'At first sight it must seem...', + * category: 'non-fiction' + * }, + * // ...and more + * ] + * + * // Create a search engine that indexes the 'title' and 'text' fields for + * // full-text search. Search results will include 'title' and 'category' (plus the + * // id field, that is always stored and returned) + * const miniSearch = new MiniSearch({ + * fields: ['title', 'text'], + * storeFields: ['title', 'category'] + * }) + * + * // Add documents to the index + * miniSearch.addAll(documents) + * + * // Search for documents: + * let results = miniSearch.search('zen art motorcycle') + * // => [ + * // { id: 2, title: 'Zen and the Art of Motorcycle Maintenance', category: 'fiction', score: 2.77258 }, + * // { id: 4, title: 'Zen and the Art of Archery', category: 'non-fiction', score: 1.38629 } + * // ] + * ``` + */ +declare class MiniSearch { + protected _options: OptionsWithDefaults; + protected _index: SearchableMap; + protected _documentCount: number; + protected _documentIds: Map; + protected _fieldIds: { + [key: string]: number; + }; + protected _fieldLength: Map; + protected _averageFieldLength: number[]; + protected _nextId: number; + protected _storedFields: Map>; + /** + * @param options Configuration options + * + * ### Examples: + * + * ```javascript + * // Create a search engine that indexes the 'title' and 'text' fields of your + * // documents: + * const miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * ``` + * + * ### ID Field: + * + * ```javascript + * // Your documents are assumed to include a unique 'id' field, but if you want + * // to use a different field for document identification, you can set the + * // 'idField' option: + * const miniSearch = new MiniSearch({ idField: 'key', fields: ['title', 'text'] }) + * ``` + * + * ### Options and defaults: + * + * ```javascript + * // The full set of options (here with their default value) is: + * const miniSearch = new MiniSearch({ + * // idField: field that uniquely identifies a document + * idField: 'id', + * + * // extractField: function used to get the value of a field in a document. + * // By default, it assumes the document is a flat object with field names as + * // property keys and field values as string property values, but custom logic + * // can be implemented by setting this option to a custom extractor function. + * extractField: (document, fieldName) => document[fieldName], + * + * // tokenize: function used to split fields into individual terms. By + * // default, it is also used to tokenize search queries, unless a specific + * // `tokenize` search option is supplied. When tokenizing an indexed field, + * // the field name is passed as the second argument. + * tokenize: (string, _fieldName) => string.split(SPACE_OR_PUNCTUATION), + * + * // processTerm: function used to process each tokenized term before + * // indexing. It can be used for stemming and normalization. Return a falsy + * // value in order to discard a term. By default, it is also used to process + * // search queries, unless a specific `processTerm` option is supplied as a + * // search option. When processing a term from a indexed field, the field + * // name is passed as the second argument. + * processTerm: (term, _fieldName) => term.toLowerCase(), + * + * // searchOptions: default search options, see the `search` method for + * // details + * searchOptions: undefined, + * + * // fields: document fields to be indexed. Mandatory, but not set by default + * fields: undefined + * + * // storeFields: document fields to be stored and returned as part of the + * // search results. + * storeFields: [] + * }) + * ``` + */ + constructor(options: Options); + /** + * Adds a document to the index + * + * @param document The document to be indexed + */ + add(document: T): void; + /** + * Adds all the given documents to the index + * + * @param documents An array of documents to be indexed + */ + addAll(documents: T[]): void; + /** + * Adds all the given documents to the index asynchronously. + * + * Returns a promise that resolves (to `undefined`) when the indexing is done. + * This method is useful when index many documents, to avoid blocking the main + * thread. The indexing is performed asynchronously and in chunks. + * + * @param documents An array of documents to be indexed + * @param options Configuration options + * @return A promise resolving to `undefined` when the indexing is done + */ + addAllAsync(documents: T[], options?: { + chunkSize?: number; + }): Promise; + /** + * Removes the given document from the index. + * + * The document to delete must NOT have changed between indexing and deletion, + * otherwise the index will be corrupted. Therefore, when reindexing a document + * after a change, the correct order of operations is: + * + * 1. remove old version + * 2. apply changes + * 3. index new version + * + * @param document The document to be removed + */ + remove(document: T): void; + /** + * Removes all the given documents from the index. If called with no arguments, + * it removes _all_ documents from the index. + * + * @param documents The documents to be removed. If this argument is omitted, + * all documents are removed. Note that, for removing all documents, it is + * more efficient to call this method with no arguments than to pass all + * documents. + */ + removeAll(documents?: T[]): void; + /** + * Search for documents matching the given search query. + * + * The result is a list of scored document IDs matching the query, sorted by + * descending score, and each including data about which terms were matched and + * in which fields. + * + * ### Basic usage: + * + * ```javascript + * // Search for "zen art motorcycle" with default options: terms have to match + * // exactly, and individual terms are joined with OR + * miniSearch.search('zen art motorcycle') + * // => [ { id: 2, score: 2.77258, match: { ... } }, { id: 4, score: 1.38629, match: { ... } } ] + * ``` + * + * ### Restrict search to specific fields: + * + * ```javascript + * // Search only in the 'title' field + * miniSearch.search('zen', { fields: ['title'] }) + * ``` + * + * ### Field boosting: + * + * ```javascript + * // Boost a field + * miniSearch.search('zen', { boost: { title: 2 } }) + * ``` + * + * ### Prefix search: + * + * ```javascript + * // Search for "moto" with prefix search (it will match documents + * // containing terms that start with "moto" or "neuro") + * miniSearch.search('moto neuro', { prefix: true }) + * ``` + * + * ### Fuzzy search: + * + * ```javascript + * // Search for "ismael" with fuzzy search (it will match documents containing + * // terms similar to "ismael", with a maximum edit distance of 0.2 term.length + * // (rounded to nearest integer) + * miniSearch.search('ismael', { fuzzy: 0.2 }) + * ``` + * + * ### Combining strategies: + * + * ```javascript + * // Mix of exact match, prefix search, and fuzzy search + * miniSearch.search('ismael mob', { + * prefix: true, + * fuzzy: 0.2 + * }) + * ``` + * + * ### Advanced prefix and fuzzy search: + * + * ```javascript + * // Perform fuzzy and prefix search depending on the search term. Here + * // performing prefix and fuzzy search only on terms longer than 3 characters + * miniSearch.search('ismael mob', { + * prefix: term => term.length > 3 + * fuzzy: term => term.length > 3 ? 0.2 : null + * }) + * ``` + * + * ### Combine with AND: + * + * ```javascript + * // Combine search terms with AND (to match only documents that contain both + * // "motorcycle" and "art") + * miniSearch.search('motorcycle art', { combineWith: 'AND' }) + * ``` + * + * ### Combine with AND_NOT: + * + * There is also an AND_NOT combinator, that finds documents that match the + * first term, but do not match any of the other terms. This combinator is + * rarely useful with simple queries, and is meant to be used with advanced + * query combinations (see later for more details). + * + * ### Filtering results: + * + * ```javascript + * // Filter only results in the 'fiction' category (assuming that 'category' + * // is a stored field) + * miniSearch.search('motorcycle art', { + * filter: (result) => result.category === 'fiction' + * }) + * ``` + * + * ### Advanced combination of queries: + * + * It is possible to combine different subqueries with OR, AND, and AND_NOT, + * and even with different search options, by passing a query expression + * tree object as the first argument, instead of a string. + * + * ```javascript + * // Search for documents that contain "zen" and ("motorcycle" or "archery") + * miniSearch.search({ + * combineWith: 'AND', + * queries: [ + * 'zen', + * { + * combineWith: 'OR', + * queries: ['motorcycle', 'archery'] + * } + * ] + * }) + * + * // Search for documents that contain ("apple" or "pear") but not "juice" and + * // not "tree" + * miniSearch.search({ + * combineWith: 'AND_NOT', + * queries: [ + * { + * combineWith: 'OR', + * queries: ['apple', 'pear'] + * }, + * 'juice', + * 'tree' + * ] + * }) + * ``` + * + * Each node in the expression tree can be either a string, or an object that + * supports all `SearchOptions` fields, plus a `queries` array field for + * subqueries. + * + * Note that, while this can become complicated to do by hand for complex or + * deeply nested queries, it provides a formalized expression tree API for + * external libraries that implement a parser for custom query languages. + * + * @param query Search query + * @param options Search options. Each option, if not given, defaults to the corresponding value of `searchOptions` given to the constructor, or to the library default. + */ + search(query: Query, searchOptions?: SearchOptions): SearchResult[]; + /** + * Provide suggestions for the given search query + * + * The result is a list of suggested modified search queries, derived from the + * given search query, each with a relevance score, sorted by descending score. + * + * ### Basic usage: + * + * ```javascript + * // Get suggestions for 'neuro': + * miniSearch.autoSuggest('neuro') + * // => [ { suggestion: 'neuromancer', terms: [ 'neuromancer' ], score: 0.46240 } ] + * ``` + * + * ### Multiple words: + * + * ```javascript + * // Get suggestions for 'zen ar': + * miniSearch.autoSuggest('zen ar') + * // => [ + * // { suggestion: 'zen archery art', terms: [ 'zen', 'archery', 'art' ], score: 1.73332 }, + * // { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 } + * // ] + * ``` + * + * ### Fuzzy suggestions: + * + * ```javascript + * // Correct spelling mistakes using fuzzy search: + * miniSearch.autoSuggest('neromancer', { fuzzy: 0.2 }) + * // => [ { suggestion: 'neuromancer', terms: [ 'neuromancer' ], score: 1.03998 } ] + * ``` + * + * ### Filtering: + * + * ```javascript + * // Get suggestions for 'zen ar', but only within the 'fiction' category + * // (assuming that 'category' is a stored field): + * miniSearch.autoSuggest('zen ar', { + * filter: (result) => result.category === 'fiction' + * }) + * // => [ + * // { suggestion: 'zen archery art', terms: [ 'zen', 'archery', 'art' ], score: 1.73332 }, + * // { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 } + * // ] + * ``` + * + * @param queryString Query string to be expanded into suggestions + * @param options Search options. The supported options and default values + * are the same as for the `search` method, except that by default prefix + * search is performed on the last term in the query. + * @return A sorted array of suggestions sorted by relevance score. + */ + autoSuggest(queryString: string, options?: SearchOptions): Suggestion[]; + /** + * Number of documents in the index + */ + get documentCount(): number; + /** + * Deserializes a JSON index (serialized with `JSON.stringify(miniSearch)`) + * and instantiates a MiniSearch instance. It should be given the same options + * originally used when serializing the index. + * + * ### Usage: + * + * ```javascript + * // If the index was serialized with: + * let miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * miniSearch.addAll(documents) + * + * const json = JSON.stringify(miniSearch) + * // It can later be deserialized like this: + * miniSearch = MiniSearch.loadJSON(json, { fields: ['title', 'text'] }) + * ``` + * + * @param json JSON-serialized index + * @param options configuration options, same as the constructor + * @return An instance of MiniSearch deserialized from the given JSON. + */ + static loadJSON(json: string, options: Options): MiniSearch; + /** + * Returns the default value of an option. It will throw an error if no option + * with the given name exists. + * + * @param optionName Name of the option + * @return The default value of the given option + * + * ### Usage: + * + * ```javascript + * // Get default tokenizer + * MiniSearch.getDefault('tokenize') + * + * // Get default term processor + * MiniSearch.getDefault('processTerm') + * + * // Unknown options will throw an error + * MiniSearch.getDefault('notExisting') + * // => throws 'MiniSearch: unknown option "notExisting"' + * ``` + */ + static getDefault(optionName: string): any; + /** + * @ignore + */ + static loadJS(js: AsPlainObject, options: Options): MiniSearch; + /** + * @ignore + */ + private executeQuery; + /** + * @ignore + */ + private executeSearch; + /** + * @ignore + */ + private executeQuerySpec; + /** + * @ignore + */ + private combineResults; + /** + * Allows serialization of the index to JSON, to possibly store it and later + * deserialize it with `MiniSearch.loadJSON`. + * + * Normally one does not directly call this method, but rather call the + * standard JavaScript `JSON.stringify()` passing the `MiniSearch` instance, + * and JavaScript will internally call this method. Upon deserialization, one + * must pass to `loadJSON` the same options used to create the original + * instance that was serialized. + * + * ### Usage: + * + * ```javascript + * // Serialize the index: + * let miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * miniSearch.addAll(documents) + * const json = JSON.stringify(miniSearch) + * + * // Later, to deserialize it: + * miniSearch = MiniSearch.loadJSON(json, { fields: ['title', 'text'] }) + * ``` + * + * @return A plain-object serializeable representation of the search index. + */ + toJSON(): AsPlainObject; + /** + * @ignore + */ + private termResults; + /** + * @ignore + */ + private addTerm; + /** + * @ignore + */ + private removeTerm; + /** + * @ignore + */ + private warnDocumentChanged; + /** + * @ignore + */ + private addDocumentId; + /** + * @ignore + */ + private addFields; + /** + * @ignore + */ + private addFieldLength; + /** + * @ignore + */ + private removeFieldLength; + /** + * @ignore + */ + private saveStoredFields; +} +declare type SerializedIndexEntry = { + df: number; + ds: { + [key: string]: number; + }; +}; + +export { AsPlainObject, MatchInfo, Options, Query, QueryCombination, SearchOptions, SearchResult, Suggestion, MiniSearch as default }; diff --git a/node_modules/minisearch/dist/umd/SearchableMap.js b/node_modules/minisearch/dist/umd/SearchableMap.js new file mode 100644 index 0000000..4a5671f --- /dev/null +++ b/node_modules/minisearch/dist/umd/SearchableMap.js @@ -0,0 +1,680 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MiniSearch = factory()); +})(this, (function () { 'use strict'; + + /*! ***************************************************************************** + Copyright (c) Microsoft Corporation. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH + REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, + INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THIS SOFTWARE. + ***************************************************************************** */ + + function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); + } + + function __read(o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; + } + + /** @ignore */ + var ENTRIES = 'ENTRIES'; + /** @ignore */ + var KEYS = 'KEYS'; + /** @ignore */ + var VALUES = 'VALUES'; + /** @ignore */ + var LEAF = ''; + /** + * @private + */ + var TreeIterator = /** @class */ (function () { + function TreeIterator(set, type) { + var node = set._tree; + var keys = Array.from(node.keys()); + this.set = set; + this._type = type; + this._path = keys.length > 0 ? [{ node: node, keys: keys }] : []; + } + TreeIterator.prototype.next = function () { + var value = this.dive(); + this.backtrack(); + return value; + }; + TreeIterator.prototype.dive = function () { + if (this._path.length === 0) { + return { done: true, value: undefined }; + } + var _a = last$1(this._path), node = _a.node, keys = _a.keys; + if (last$1(keys) === LEAF) { + return { done: false, value: this.result() }; + } + this._path.push({ node: node.get(last$1(keys)), keys: Array.from(node.get(last$1(keys)).keys()) }); + return this.dive(); + }; + TreeIterator.prototype.backtrack = function () { + if (this._path.length === 0) { + return; + } + last$1(this._path).keys.pop(); + if (last$1(this._path).keys.length > 0) { + return; + } + this._path.pop(); + this.backtrack(); + }; + TreeIterator.prototype.key = function () { + return this.set._prefix + this._path + .map(function (_a) { + var keys = _a.keys; + return last$1(keys); + }) + .filter(function (key) { return key !== LEAF; }) + .join(''); + }; + TreeIterator.prototype.value = function () { + return last$1(this._path).node.get(LEAF); + }; + TreeIterator.prototype.result = function () { + if (this._type === VALUES) { + return this.value(); + } + if (this._type === KEYS) { + return this.key(); + } + return [this.key(), this.value()]; + }; + TreeIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return TreeIterator; + }()); + var last$1 = function (array) { + return array[array.length - 1]; + }; + + /** + * @ignore + */ + var fuzzySearch = function (node, query, maxDistance) { + var results = new Map(); + if (query === undefined) + return results; + // Number of columns in the Levenshtein matrix. + var n = query.length + 1; + // Matching terms can never be longer than N + maxDistance. + var maxLength = n + maxDistance; + // Fill first matrix row with consecutive numbers 0 1 2 3 ... (n - 1) + var matrix = new Uint8Array(maxLength * n); + for (var i = 0; i < n; i++) + matrix[i] = i; + recurse(node, query, maxDistance, results, matrix, n, n, ''); + return results; + }; + // Modified version of http://stevehanov.ca/blog/?id=114 + // This builds a Levenshtein matrix for a given query and continuously updates + // it for nodes in the radix tree that fall within the given maximum edit + // distance. Keeping the same matrix around is beneficial especially for larger + // edit distances. + // + // k a t e <-- query + // 0 1 2 3 4 + // c 1 1 2 3 4 + // a 2 2 1 2 3 + // t 3 3 2 1 [2] <-- edit distance + // ^ + // ^ term in radix tree, rows are added and removed as needed + var recurse = function (node, query, maxDistance, results, matrix, offset, n, prefix) { + var e_1, _a; + try { + key: for (var _b = __values(node.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var key = _c.value; + if (key === LEAF) { + // We've reached a leaf node. Check if the edit distance acceptable and + // store the result if it is. + var distance = matrix[offset - 1]; + if (distance <= maxDistance) { + results.set(prefix, [node.get(key), distance]); + } + } + else { + // Iterate over all characters in the key. Update the Levenshtein matrix + // and check if the minimum distance in the last row is still within the + // maximum edit distance. If it is, we can recurse over all child nodes. + for (var i = 0; i < key.length; i++) { + var char = key[i]; + var thisRowOffset = offset + n * i; + var prevRowOffset = thisRowOffset - n; + // Set the first column based on the previous row, and initialize the + // minimum distance in the current row. + var minDistance = matrix[thisRowOffset] = matrix[prevRowOffset] + 1; + // Iterate over remaining columns (characters in the query). + for (var j = 0; j < n - 1; j++) { + var different = char !== query[j]; + // It might make sense to only read the matrix positions used for + // deletion/insertion if the characters are different. But we want to + // avoid conditional reads for performance reasons. + var rpl = matrix[prevRowOffset + j] + +different; + var del = matrix[prevRowOffset + j + 1] + 1; + var ins = matrix[thisRowOffset + j] + 1; + var dist = matrix[thisRowOffset + j + 1] = Math.min(rpl, del, ins); + if (dist < minDistance) + minDistance = dist; + } + // Because distance will never decrease, we can stop. There will be no + // matching child nodes. + if (minDistance > maxDistance) { + continue key; + } + } + recurse(node.get(key), query, maxDistance, results, matrix, offset + n * key.length, n, prefix + key); + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_1) throw e_1.error; } + } + }; + + /** + * A class implementing the same interface as a standard JavaScript + * [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) + * with string keys, but adding support for efficiently searching entries with + * prefix or fuzzy search. This class is used internally by [[MiniSearch]] as + * the inverted index data structure. The implementation is a radix tree + * (compressed prefix tree). + * + * Since this class can be of general utility beyond _MiniSearch_, it is + * exported by the `minisearch` package and can be imported (or required) as + * `minisearch/SearchableMap`. + * + * @typeParam T The type of the values stored in the map. + */ + var SearchableMap = /** @class */ (function () { + /** + * The constructor is normally called without arguments, creating an empty + * map. In order to create a [[SearchableMap]] from an iterable or from an + * object, check [[SearchableMap.from]] and [[SearchableMap.fromObject]]. + * + * The constructor arguments are for internal use, when creating derived + * mutable views of a map at a prefix. + */ + function SearchableMap(tree, prefix) { + if (tree === void 0) { tree = new Map(); } + if (prefix === void 0) { prefix = ''; } + this._size = undefined; + this._tree = tree; + this._prefix = prefix; + } + /** + * Creates and returns a mutable view of this [[SearchableMap]], containing only + * entries that share the given prefix. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set("unicorn", 1) + * map.set("universe", 2) + * map.set("university", 3) + * map.set("unique", 4) + * map.set("hello", 5) + * + * let uni = map.atPrefix("uni") + * uni.get("unique") // => 4 + * uni.get("unicorn") // => 1 + * uni.get("hello") // => undefined + * + * let univer = map.atPrefix("univer") + * univer.get("unique") // => undefined + * univer.get("universe") // => 2 + * univer.get("university") // => 3 + * ``` + * + * @param prefix The prefix + * @return A [[SearchableMap]] representing a mutable view of the original Map at the given prefix + */ + SearchableMap.prototype.atPrefix = function (prefix) { + var e_1, _a; + if (!prefix.startsWith(this._prefix)) { + throw new Error('Mismatched prefix'); + } + var _b = __read(trackDown(this._tree, prefix.slice(this._prefix.length)), 2), node = _b[0], path = _b[1]; + if (node === undefined) { + var _c = __read(last(path), 2), parentNode = _c[0], key = _c[1]; + try { + for (var _d = __values(parentNode.keys()), _e = _d.next(); !_e.done; _e = _d.next()) { + var k = _e.value; + if (k !== LEAF && k.startsWith(key)) { + var node_1 = new Map(); + node_1.set(k.slice(key.length), parentNode.get(k)); + return new SearchableMap(node_1, prefix); + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (_e && !_e.done && (_a = _d.return)) _a.call(_d); + } + finally { if (e_1) throw e_1.error; } + } + } + return new SearchableMap(node, prefix); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear + */ + SearchableMap.prototype.clear = function () { + this._size = undefined; + this._tree.clear(); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete + * @param key Key to delete + */ + SearchableMap.prototype.delete = function (key) { + this._size = undefined; + return remove(this._tree, key); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries + * @return An iterator iterating through `[key, value]` entries. + */ + SearchableMap.prototype.entries = function () { + return new TreeIterator(this, ENTRIES); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach + * @param fn Iteration function + */ + SearchableMap.prototype.forEach = function (fn) { + var e_2, _a; + try { + for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) { + var _d = __read(_c.value, 2), key = _d[0], value = _d[1]; + fn(key, value, this); + } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_2) throw e_2.error; } + } + }; + /** + * Returns a Map of all the entries that have a key within the given edit + * distance from the search key. The keys of the returned Map are the matching + * keys, while the values are two-element arrays where the first element is + * the value associated to the key, and the second is the edit distance of the + * key to the search key. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set('hello', 'world') + * map.set('hell', 'yeah') + * map.set('ciao', 'mondo') + * + * // Get all entries that match the key 'hallo' with a maximum edit distance of 2 + * map.fuzzyGet('hallo', 2) + * // => Map(2) { 'hello' => ['world', 1], 'hell' => ['yeah', 2] } + * + * // In the example, the "hello" key has value "world" and edit distance of 1 + * // (change "e" to "a"), the key "hell" has value "yeah" and edit distance of 2 + * // (change "e" to "a", delete "o") + * ``` + * + * @param key The search key + * @param maxEditDistance The maximum edit distance (Levenshtein) + * @return A Map of the matching keys to their value and edit distance + */ + SearchableMap.prototype.fuzzyGet = function (key, maxEditDistance) { + return fuzzySearch(this._tree, key, maxEditDistance); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get + * @param key Key to get + * @return Value associated to the key, or `undefined` if the key is not + * found. + */ + SearchableMap.prototype.get = function (key) { + var node = lookup(this._tree, key); + return node !== undefined ? node.get(LEAF) : undefined; + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has + * @param key Key + * @return True if the key is in the map, false otherwise + */ + SearchableMap.prototype.has = function (key) { + var node = lookup(this._tree, key); + return node !== undefined && node.has(LEAF); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys + * @return An `Iterable` iterating through keys + */ + SearchableMap.prototype.keys = function () { + return new TreeIterator(this, KEYS); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set + * @param key Key to set + * @param value Value to associate to the key + * @return The [[SearchableMap]] itself, to allow chaining + */ + SearchableMap.prototype.set = function (key, value) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + node.set(LEAF, value); + return this; + }; + Object.defineProperty(SearchableMap.prototype, "size", { + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size + */ + get: function () { + if (this._size) { + return this._size; + } + /** @ignore */ + this._size = 0; + var iter = this.entries(); + while (!iter.next().done) + this._size += 1; + return this._size; + }, + enumerable: false, + configurable: true + }); + /** + * Updates the value at the given key using the provided function. The function + * is called with the current value at the key, and its return value is used as + * the new value to be set. + * + * ### Example: + * + * ```javascript + * // Increment the current value by one + * searchableMap.update('somekey', (currentValue) => currentValue == null ? 0 : currentValue + 1) + * ``` + * + * If the value at the given key is or will be an object, it might not require + * re-assignment. In that case it is better to use `fetch()`, because it is + * faster. + * + * @param key The key to update + * @param fn The function used to compute the new value from the current one + * @return The [[SearchableMap]] itself, to allow chaining + */ + SearchableMap.prototype.update = function (key, fn) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + node.set(LEAF, fn(node.get(LEAF))); + return this; + }; + /** + * Fetches the value of the given key. If the value does not exist, calls the + * given function to create a new value, which is inserted at the given key + * and subsequently returned. + * + * ### Example: + * + * ```javascript + * const map = searchableMap.fetch('somekey', () => new Map()) + * map.set('foo', 'bar') + * ``` + * + * @param key The key to update + * @param defaultValue A function that creates a new value if the key does not exist + * @return The existing or new value at the given key + */ + SearchableMap.prototype.fetch = function (key, initial) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + var value = node.get(LEAF); + if (value === undefined) { + node.set(LEAF, value = initial()); + } + return value; + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values + * @return An `Iterable` iterating through values. + */ + SearchableMap.prototype.values = function () { + return new TreeIterator(this, VALUES); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/@@iterator + */ + SearchableMap.prototype[Symbol.iterator] = function () { + return this.entries(); + }; + /** + * Creates a [[SearchableMap]] from an `Iterable` of entries + * + * @param entries Entries to be inserted in the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + SearchableMap.from = function (entries) { + var e_3, _a; + var tree = new SearchableMap(); + try { + for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) { + var _b = __read(entries_1_1.value, 2), key = _b[0], value = _b[1]; + tree.set(key, value); + } + } + catch (e_3_1) { e_3 = { error: e_3_1 }; } + finally { + try { + if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1); + } + finally { if (e_3) throw e_3.error; } + } + return tree; + }; + /** + * Creates a [[SearchableMap]] from the iterable properties of a JavaScript object + * + * @param object Object of entries for the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + SearchableMap.fromObject = function (object) { + return SearchableMap.from(Object.entries(object)); + }; + return SearchableMap; + }()); + var trackDown = function (tree, key, path) { + var e_4, _a; + if (path === void 0) { path = []; } + if (key.length === 0 || tree == null) { + return [tree, path]; + } + try { + for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var k = _c.value; + if (k !== LEAF && key.startsWith(k)) { + path.push([tree, k]); // performance: update in place + return trackDown(tree.get(k), key.slice(k.length), path); + } + } + } + catch (e_4_1) { e_4 = { error: e_4_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_4) throw e_4.error; } + } + path.push([tree, key]); // performance: update in place + return trackDown(undefined, '', path); + }; + var lookup = function (tree, key) { + var e_5, _a; + if (key.length === 0 || tree == null) { + return tree; + } + try { + for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var k = _c.value; + if (k !== LEAF && key.startsWith(k)) { + return lookup(tree.get(k), key.slice(k.length)); + } + } + } + catch (e_5_1) { e_5 = { error: e_5_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_5) throw e_5.error; } + } + }; + var createPath = function (tree, key) { + var e_6, _a, e_7, _b; + if (key.length === 0 || tree == null) { + return tree; + } + try { + for (var _c = __values(tree.keys()), _d = _c.next(); !_d.done; _d = _c.next()) { + var k = _d.value; + if (k !== LEAF && key.startsWith(k)) { + return createPath(tree.get(k), key.slice(k.length)); + } + } + } + catch (e_6_1) { e_6 = { error: e_6_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_6) throw e_6.error; } + } + try { + for (var _e = __values(tree.keys()), _f = _e.next(); !_f.done; _f = _e.next()) { + var k = _f.value; + if (k !== LEAF && k.startsWith(key[0])) { + var offset = commonPrefixOffset(key, k); + var node_2 = new Map(); + node_2.set(k.slice(offset), tree.get(k)); + tree.set(key.slice(0, offset), node_2); + tree.delete(k); + return createPath(node_2, key.slice(offset)); + } + } + } + catch (e_7_1) { e_7 = { error: e_7_1 }; } + finally { + try { + if (_f && !_f.done && (_b = _e.return)) _b.call(_e); + } + finally { if (e_7) throw e_7.error; } + } + var node = new Map(); + tree.set(key, node); + return node; + }; + var commonPrefixOffset = function (a, b) { + var length = Math.min(a.length, b.length); + for (var i = 0; i < length; i++) { + if (a[i] !== b[i]) + return i; + } + return length; + }; + var remove = function (tree, key) { + var _a = __read(trackDown(tree, key), 2), node = _a[0], path = _a[1]; + if (node === undefined) { + return; + } + node.delete(LEAF); + if (node.size === 0) { + cleanup(path); + } + else if (node.size === 1) { + var _b = __read(node.entries().next().value, 2), key_1 = _b[0], value = _b[1]; + merge(path, key_1, value); + } + }; + var cleanup = function (path) { + if (path.length === 0) { + return; + } + var _a = __read(last(path), 2), node = _a[0], key = _a[1]; + node.delete(key); + if (node.size === 0) { + cleanup(path.slice(0, -1)); + } + else if (node.size === 1) { + var _b = __read(node.entries().next().value, 2), key_2 = _b[0], value = _b[1]; + if (key_2 !== LEAF) { + merge(path.slice(0, -1), key_2, value); + } + } + }; + var merge = function (path, key, value) { + if (path.length === 0) { + return; + } + var _a = __read(last(path), 2), node = _a[0], nodeKey = _a[1]; + node.set(nodeKey + key, value); + node.delete(nodeKey); + }; + var last = function (array) { + return array[array.length - 1]; + }; + + return SearchableMap; + +})); +//# sourceMappingURL=SearchableMap.js.map diff --git a/node_modules/minisearch/dist/umd/SearchableMap.js.map b/node_modules/minisearch/dist/umd/SearchableMap.js.map new file mode 100644 index 0000000..06c0940 --- /dev/null +++ b/node_modules/minisearch/dist/umd/SearchableMap.js.map @@ -0,0 +1 @@ +{"version":3,"file":"SearchableMap.js","sources":["../../node_modules/tslib/tslib.es6.js","../../src/SearchableMap/TreeIterator.ts","../../src/SearchableMap/fuzzySearch.ts","../../src/SearchableMap/SearchableMap.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n",null,null,null],"names":["last"],"mappings":";;;;;;IAAA;IACA;AACA;IACA;IACA;AACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;AAyGA;IACO,SAAS,QAAQ,CAAC,CAAC,EAAE;IAC5B,IAAI,IAAI,CAAC,GAAG,OAAO,MAAM,KAAK,UAAU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AAI,KAAG,KAAK,IAAI,EAAE;gBAChB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAG,EAAE,KAAK,CAAC,CAAA;aACrC;SACF;IACH,CAAC,CAAA;IAED,IAAM,KAAK,GAAG,UAAU,IAAa,EAAE,GAAW,EAAE,KAAQ;QAC1D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YAAE,OAAM;SAAE;QAE3B,IAAA,KAAA,OAAkB,IAAI,CAAC,IAAI,CAAC,IAAA,EAA3B,IAAI,QAAA,EAAE,OAAO,QAAc,CAAA;QAClC,IAAK,CAAC,GAAG,CAAC,OAAO,GAAG,GAAG,EAAE,KAAK,CAAC,CAAA;QAC/B,IAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACvB,CAAC,CAAA;IAED,IAAM,IAAI,GAAG,UAAU,KAAU;QAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAChC,CAAC;;;;;;;;"} \ No newline at end of file diff --git a/node_modules/minisearch/dist/umd/index.js b/node_modules/minisearch/dist/umd/index.js new file mode 100644 index 0000000..af087b0 --- /dev/null +++ b/node_modules/minisearch/dist/umd/index.js @@ -0,0 +1,1964 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MiniSearch = factory()); +})(this, (function () { 'use strict'; + + /*! ***************************************************************************** + Copyright (c) Microsoft Corporation. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH + REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, + INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THIS SOFTWARE. + ***************************************************************************** */ + + var __assign = function() { + __assign = Object.assign || function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); + }; + + function __values(o) { + var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; + if (m) return m.call(o); + if (o && typeof o.length === "number") return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; + throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); + } + + function __read(o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; + } + + function __spreadArray(to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); + } + + /** @ignore */ + var ENTRIES = 'ENTRIES'; + /** @ignore */ + var KEYS = 'KEYS'; + /** @ignore */ + var VALUES = 'VALUES'; + /** @ignore */ + var LEAF = ''; + /** + * @private + */ + var TreeIterator = /** @class */ (function () { + function TreeIterator(set, type) { + var node = set._tree; + var keys = Array.from(node.keys()); + this.set = set; + this._type = type; + this._path = keys.length > 0 ? [{ node: node, keys: keys }] : []; + } + TreeIterator.prototype.next = function () { + var value = this.dive(); + this.backtrack(); + return value; + }; + TreeIterator.prototype.dive = function () { + if (this._path.length === 0) { + return { done: true, value: undefined }; + } + var _a = last$1(this._path), node = _a.node, keys = _a.keys; + if (last$1(keys) === LEAF) { + return { done: false, value: this.result() }; + } + this._path.push({ node: node.get(last$1(keys)), keys: Array.from(node.get(last$1(keys)).keys()) }); + return this.dive(); + }; + TreeIterator.prototype.backtrack = function () { + if (this._path.length === 0) { + return; + } + last$1(this._path).keys.pop(); + if (last$1(this._path).keys.length > 0) { + return; + } + this._path.pop(); + this.backtrack(); + }; + TreeIterator.prototype.key = function () { + return this.set._prefix + this._path + .map(function (_a) { + var keys = _a.keys; + return last$1(keys); + }) + .filter(function (key) { return key !== LEAF; }) + .join(''); + }; + TreeIterator.prototype.value = function () { + return last$1(this._path).node.get(LEAF); + }; + TreeIterator.prototype.result = function () { + if (this._type === VALUES) { + return this.value(); + } + if (this._type === KEYS) { + return this.key(); + } + return [this.key(), this.value()]; + }; + TreeIterator.prototype[Symbol.iterator] = function () { + return this; + }; + return TreeIterator; + }()); + var last$1 = function (array) { + return array[array.length - 1]; + }; + + /** + * @ignore + */ + var fuzzySearch = function (node, query, maxDistance) { + var results = new Map(); + if (query === undefined) + return results; + // Number of columns in the Levenshtein matrix. + var n = query.length + 1; + // Matching terms can never be longer than N + maxDistance. + var maxLength = n + maxDistance; + // Fill first matrix row with consecutive numbers 0 1 2 3 ... (n - 1) + var matrix = new Uint8Array(maxLength * n); + for (var i = 0; i < n; i++) + matrix[i] = i; + recurse(node, query, maxDistance, results, matrix, n, n, ''); + return results; + }; + // Modified version of http://stevehanov.ca/blog/?id=114 + // This builds a Levenshtein matrix for a given query and continuously updates + // it for nodes in the radix tree that fall within the given maximum edit + // distance. Keeping the same matrix around is beneficial especially for larger + // edit distances. + // + // k a t e <-- query + // 0 1 2 3 4 + // c 1 1 2 3 4 + // a 2 2 1 2 3 + // t 3 3 2 1 [2] <-- edit distance + // ^ + // ^ term in radix tree, rows are added and removed as needed + var recurse = function (node, query, maxDistance, results, matrix, offset, n, prefix) { + var e_1, _a; + try { + key: for (var _b = __values(node.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var key = _c.value; + if (key === LEAF) { + // We've reached a leaf node. Check if the edit distance acceptable and + // store the result if it is. + var distance = matrix[offset - 1]; + if (distance <= maxDistance) { + results.set(prefix, [node.get(key), distance]); + } + } + else { + // Iterate over all characters in the key. Update the Levenshtein matrix + // and check if the minimum distance in the last row is still within the + // maximum edit distance. If it is, we can recurse over all child nodes. + for (var i = 0; i < key.length; i++) { + var char = key[i]; + var thisRowOffset = offset + n * i; + var prevRowOffset = thisRowOffset - n; + // Set the first column based on the previous row, and initialize the + // minimum distance in the current row. + var minDistance = matrix[thisRowOffset] = matrix[prevRowOffset] + 1; + // Iterate over remaining columns (characters in the query). + for (var j = 0; j < n - 1; j++) { + var different = char !== query[j]; + // It might make sense to only read the matrix positions used for + // deletion/insertion if the characters are different. But we want to + // avoid conditional reads for performance reasons. + var rpl = matrix[prevRowOffset + j] + +different; + var del = matrix[prevRowOffset + j + 1] + 1; + var ins = matrix[thisRowOffset + j] + 1; + var dist = matrix[thisRowOffset + j + 1] = Math.min(rpl, del, ins); + if (dist < minDistance) + minDistance = dist; + } + // Because distance will never decrease, we can stop. There will be no + // matching child nodes. + if (minDistance > maxDistance) { + continue key; + } + } + recurse(node.get(key), query, maxDistance, results, matrix, offset + n * key.length, n, prefix + key); + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_1) throw e_1.error; } + } + }; + + /** + * A class implementing the same interface as a standard JavaScript + * [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) + * with string keys, but adding support for efficiently searching entries with + * prefix or fuzzy search. This class is used internally by [[MiniSearch]] as + * the inverted index data structure. The implementation is a radix tree + * (compressed prefix tree). + * + * Since this class can be of general utility beyond _MiniSearch_, it is + * exported by the `minisearch` package and can be imported (or required) as + * `minisearch/SearchableMap`. + * + * @typeParam T The type of the values stored in the map. + */ + var SearchableMap = /** @class */ (function () { + /** + * The constructor is normally called without arguments, creating an empty + * map. In order to create a [[SearchableMap]] from an iterable or from an + * object, check [[SearchableMap.from]] and [[SearchableMap.fromObject]]. + * + * The constructor arguments are for internal use, when creating derived + * mutable views of a map at a prefix. + */ + function SearchableMap(tree, prefix) { + if (tree === void 0) { tree = new Map(); } + if (prefix === void 0) { prefix = ''; } + this._size = undefined; + this._tree = tree; + this._prefix = prefix; + } + /** + * Creates and returns a mutable view of this [[SearchableMap]], containing only + * entries that share the given prefix. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set("unicorn", 1) + * map.set("universe", 2) + * map.set("university", 3) + * map.set("unique", 4) + * map.set("hello", 5) + * + * let uni = map.atPrefix("uni") + * uni.get("unique") // => 4 + * uni.get("unicorn") // => 1 + * uni.get("hello") // => undefined + * + * let univer = map.atPrefix("univer") + * univer.get("unique") // => undefined + * univer.get("universe") // => 2 + * univer.get("university") // => 3 + * ``` + * + * @param prefix The prefix + * @return A [[SearchableMap]] representing a mutable view of the original Map at the given prefix + */ + SearchableMap.prototype.atPrefix = function (prefix) { + var e_1, _a; + if (!prefix.startsWith(this._prefix)) { + throw new Error('Mismatched prefix'); + } + var _b = __read(trackDown(this._tree, prefix.slice(this._prefix.length)), 2), node = _b[0], path = _b[1]; + if (node === undefined) { + var _c = __read(last(path), 2), parentNode = _c[0], key = _c[1]; + try { + for (var _d = __values(parentNode.keys()), _e = _d.next(); !_e.done; _e = _d.next()) { + var k = _e.value; + if (k !== LEAF && k.startsWith(key)) { + var node_1 = new Map(); + node_1.set(k.slice(key.length), parentNode.get(k)); + return new SearchableMap(node_1, prefix); + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (_e && !_e.done && (_a = _d.return)) _a.call(_d); + } + finally { if (e_1) throw e_1.error; } + } + } + return new SearchableMap(node, prefix); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear + */ + SearchableMap.prototype.clear = function () { + this._size = undefined; + this._tree.clear(); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete + * @param key Key to delete + */ + SearchableMap.prototype.delete = function (key) { + this._size = undefined; + return remove(this._tree, key); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries + * @return An iterator iterating through `[key, value]` entries. + */ + SearchableMap.prototype.entries = function () { + return new TreeIterator(this, ENTRIES); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach + * @param fn Iteration function + */ + SearchableMap.prototype.forEach = function (fn) { + var e_2, _a; + try { + for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) { + var _d = __read(_c.value, 2), key = _d[0], value = _d[1]; + fn(key, value, this); + } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_2) throw e_2.error; } + } + }; + /** + * Returns a Map of all the entries that have a key within the given edit + * distance from the search key. The keys of the returned Map are the matching + * keys, while the values are two-element arrays where the first element is + * the value associated to the key, and the second is the edit distance of the + * key to the search key. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set('hello', 'world') + * map.set('hell', 'yeah') + * map.set('ciao', 'mondo') + * + * // Get all entries that match the key 'hallo' with a maximum edit distance of 2 + * map.fuzzyGet('hallo', 2) + * // => Map(2) { 'hello' => ['world', 1], 'hell' => ['yeah', 2] } + * + * // In the example, the "hello" key has value "world" and edit distance of 1 + * // (change "e" to "a"), the key "hell" has value "yeah" and edit distance of 2 + * // (change "e" to "a", delete "o") + * ``` + * + * @param key The search key + * @param maxEditDistance The maximum edit distance (Levenshtein) + * @return A Map of the matching keys to their value and edit distance + */ + SearchableMap.prototype.fuzzyGet = function (key, maxEditDistance) { + return fuzzySearch(this._tree, key, maxEditDistance); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get + * @param key Key to get + * @return Value associated to the key, or `undefined` if the key is not + * found. + */ + SearchableMap.prototype.get = function (key) { + var node = lookup(this._tree, key); + return node !== undefined ? node.get(LEAF) : undefined; + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has + * @param key Key + * @return True if the key is in the map, false otherwise + */ + SearchableMap.prototype.has = function (key) { + var node = lookup(this._tree, key); + return node !== undefined && node.has(LEAF); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys + * @return An `Iterable` iterating through keys + */ + SearchableMap.prototype.keys = function () { + return new TreeIterator(this, KEYS); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set + * @param key Key to set + * @param value Value to associate to the key + * @return The [[SearchableMap]] itself, to allow chaining + */ + SearchableMap.prototype.set = function (key, value) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + node.set(LEAF, value); + return this; + }; + Object.defineProperty(SearchableMap.prototype, "size", { + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size + */ + get: function () { + if (this._size) { + return this._size; + } + /** @ignore */ + this._size = 0; + var iter = this.entries(); + while (!iter.next().done) + this._size += 1; + return this._size; + }, + enumerable: false, + configurable: true + }); + /** + * Updates the value at the given key using the provided function. The function + * is called with the current value at the key, and its return value is used as + * the new value to be set. + * + * ### Example: + * + * ```javascript + * // Increment the current value by one + * searchableMap.update('somekey', (currentValue) => currentValue == null ? 0 : currentValue + 1) + * ``` + * + * If the value at the given key is or will be an object, it might not require + * re-assignment. In that case it is better to use `fetch()`, because it is + * faster. + * + * @param key The key to update + * @param fn The function used to compute the new value from the current one + * @return The [[SearchableMap]] itself, to allow chaining + */ + SearchableMap.prototype.update = function (key, fn) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + node.set(LEAF, fn(node.get(LEAF))); + return this; + }; + /** + * Fetches the value of the given key. If the value does not exist, calls the + * given function to create a new value, which is inserted at the given key + * and subsequently returned. + * + * ### Example: + * + * ```javascript + * const map = searchableMap.fetch('somekey', () => new Map()) + * map.set('foo', 'bar') + * ``` + * + * @param key The key to update + * @param defaultValue A function that creates a new value if the key does not exist + * @return The existing or new value at the given key + */ + SearchableMap.prototype.fetch = function (key, initial) { + if (typeof key !== 'string') { + throw new Error('key must be a string'); + } + this._size = undefined; + var node = createPath(this._tree, key); + var value = node.get(LEAF); + if (value === undefined) { + node.set(LEAF, value = initial()); + } + return value; + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values + * @return An `Iterable` iterating through values. + */ + SearchableMap.prototype.values = function () { + return new TreeIterator(this, VALUES); + }; + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/@@iterator + */ + SearchableMap.prototype[Symbol.iterator] = function () { + return this.entries(); + }; + /** + * Creates a [[SearchableMap]] from an `Iterable` of entries + * + * @param entries Entries to be inserted in the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + SearchableMap.from = function (entries) { + var e_3, _a; + var tree = new SearchableMap(); + try { + for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) { + var _b = __read(entries_1_1.value, 2), key = _b[0], value = _b[1]; + tree.set(key, value); + } + } + catch (e_3_1) { e_3 = { error: e_3_1 }; } + finally { + try { + if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1); + } + finally { if (e_3) throw e_3.error; } + } + return tree; + }; + /** + * Creates a [[SearchableMap]] from the iterable properties of a JavaScript object + * + * @param object Object of entries for the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + SearchableMap.fromObject = function (object) { + return SearchableMap.from(Object.entries(object)); + }; + return SearchableMap; + }()); + var trackDown = function (tree, key, path) { + var e_4, _a; + if (path === void 0) { path = []; } + if (key.length === 0 || tree == null) { + return [tree, path]; + } + try { + for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var k = _c.value; + if (k !== LEAF && key.startsWith(k)) { + path.push([tree, k]); // performance: update in place + return trackDown(tree.get(k), key.slice(k.length), path); + } + } + } + catch (e_4_1) { e_4 = { error: e_4_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_4) throw e_4.error; } + } + path.push([tree, key]); // performance: update in place + return trackDown(undefined, '', path); + }; + var lookup = function (tree, key) { + var e_5, _a; + if (key.length === 0 || tree == null) { + return tree; + } + try { + for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var k = _c.value; + if (k !== LEAF && key.startsWith(k)) { + return lookup(tree.get(k), key.slice(k.length)); + } + } + } + catch (e_5_1) { e_5 = { error: e_5_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_5) throw e_5.error; } + } + }; + var createPath = function (tree, key) { + var e_6, _a, e_7, _b; + if (key.length === 0 || tree == null) { + return tree; + } + try { + for (var _c = __values(tree.keys()), _d = _c.next(); !_d.done; _d = _c.next()) { + var k = _d.value; + if (k !== LEAF && key.startsWith(k)) { + return createPath(tree.get(k), key.slice(k.length)); + } + } + } + catch (e_6_1) { e_6 = { error: e_6_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_6) throw e_6.error; } + } + try { + for (var _e = __values(tree.keys()), _f = _e.next(); !_f.done; _f = _e.next()) { + var k = _f.value; + if (k !== LEAF && k.startsWith(key[0])) { + var offset = commonPrefixOffset(key, k); + var node_2 = new Map(); + node_2.set(k.slice(offset), tree.get(k)); + tree.set(key.slice(0, offset), node_2); + tree.delete(k); + return createPath(node_2, key.slice(offset)); + } + } + } + catch (e_7_1) { e_7 = { error: e_7_1 }; } + finally { + try { + if (_f && !_f.done && (_b = _e.return)) _b.call(_e); + } + finally { if (e_7) throw e_7.error; } + } + var node = new Map(); + tree.set(key, node); + return node; + }; + var commonPrefixOffset = function (a, b) { + var length = Math.min(a.length, b.length); + for (var i = 0; i < length; i++) { + if (a[i] !== b[i]) + return i; + } + return length; + }; + var remove = function (tree, key) { + var _a = __read(trackDown(tree, key), 2), node = _a[0], path = _a[1]; + if (node === undefined) { + return; + } + node.delete(LEAF); + if (node.size === 0) { + cleanup(path); + } + else if (node.size === 1) { + var _b = __read(node.entries().next().value, 2), key_1 = _b[0], value = _b[1]; + merge(path, key_1, value); + } + }; + var cleanup = function (path) { + if (path.length === 0) { + return; + } + var _a = __read(last(path), 2), node = _a[0], key = _a[1]; + node.delete(key); + if (node.size === 0) { + cleanup(path.slice(0, -1)); + } + else if (node.size === 1) { + var _b = __read(node.entries().next().value, 2), key_2 = _b[0], value = _b[1]; + if (key_2 !== LEAF) { + merge(path.slice(0, -1), key_2, value); + } + } + }; + var merge = function (path, key, value) { + if (path.length === 0) { + return; + } + var _a = __read(last(path), 2), node = _a[0], nodeKey = _a[1]; + node.set(nodeKey + key, value); + node.delete(nodeKey); + }; + var last = function (array) { + return array[array.length - 1]; + }; + + var _a; + var OR = 'or'; + var AND = 'and'; + var AND_NOT = 'and_not'; + /** + * [[MiniSearch]] is the main entrypoint class, implementing a full-text search + * engine in memory. + * + * @typeParam T The type of the documents being indexed. + * + * ### Basic example: + * + * ```javascript + * const documents = [ + * { + * id: 1, + * title: 'Moby Dick', + * text: 'Call me Ishmael. Some years ago...', + * category: 'fiction' + * }, + * { + * id: 2, + * title: 'Zen and the Art of Motorcycle Maintenance', + * text: 'I can see by my watch...', + * category: 'fiction' + * }, + * { + * id: 3, + * title: 'Neuromancer', + * text: 'The sky above the port was...', + * category: 'fiction' + * }, + * { + * id: 4, + * title: 'Zen and the Art of Archery', + * text: 'At first sight it must seem...', + * category: 'non-fiction' + * }, + * // ...and more + * ] + * + * // Create a search engine that indexes the 'title' and 'text' fields for + * // full-text search. Search results will include 'title' and 'category' (plus the + * // id field, that is always stored and returned) + * const miniSearch = new MiniSearch({ + * fields: ['title', 'text'], + * storeFields: ['title', 'category'] + * }) + * + * // Add documents to the index + * miniSearch.addAll(documents) + * + * // Search for documents: + * let results = miniSearch.search('zen art motorcycle') + * // => [ + * // { id: 2, title: 'Zen and the Art of Motorcycle Maintenance', category: 'fiction', score: 2.77258 }, + * // { id: 4, title: 'Zen and the Art of Archery', category: 'non-fiction', score: 1.38629 } + * // ] + * ``` + */ + var MiniSearch = /** @class */ (function () { + /** + * @param options Configuration options + * + * ### Examples: + * + * ```javascript + * // Create a search engine that indexes the 'title' and 'text' fields of your + * // documents: + * const miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * ``` + * + * ### ID Field: + * + * ```javascript + * // Your documents are assumed to include a unique 'id' field, but if you want + * // to use a different field for document identification, you can set the + * // 'idField' option: + * const miniSearch = new MiniSearch({ idField: 'key', fields: ['title', 'text'] }) + * ``` + * + * ### Options and defaults: + * + * ```javascript + * // The full set of options (here with their default value) is: + * const miniSearch = new MiniSearch({ + * // idField: field that uniquely identifies a document + * idField: 'id', + * + * // extractField: function used to get the value of a field in a document. + * // By default, it assumes the document is a flat object with field names as + * // property keys and field values as string property values, but custom logic + * // can be implemented by setting this option to a custom extractor function. + * extractField: (document, fieldName) => document[fieldName], + * + * // tokenize: function used to split fields into individual terms. By + * // default, it is also used to tokenize search queries, unless a specific + * // `tokenize` search option is supplied. When tokenizing an indexed field, + * // the field name is passed as the second argument. + * tokenize: (string, _fieldName) => string.split(SPACE_OR_PUNCTUATION), + * + * // processTerm: function used to process each tokenized term before + * // indexing. It can be used for stemming and normalization. Return a falsy + * // value in order to discard a term. By default, it is also used to process + * // search queries, unless a specific `processTerm` option is supplied as a + * // search option. When processing a term from a indexed field, the field + * // name is passed as the second argument. + * processTerm: (term, _fieldName) => term.toLowerCase(), + * + * // searchOptions: default search options, see the `search` method for + * // details + * searchOptions: undefined, + * + * // fields: document fields to be indexed. Mandatory, but not set by default + * fields: undefined + * + * // storeFields: document fields to be stored and returned as part of the + * // search results. + * storeFields: [] + * }) + * ``` + */ + function MiniSearch(options) { + if ((options === null || options === void 0 ? void 0 : options.fields) == null) { + throw new Error('MiniSearch: option "fields" must be provided'); + } + this._options = __assign(__assign(__assign({}, defaultOptions), options), { searchOptions: __assign(__assign({}, defaultSearchOptions), (options.searchOptions || {})) }); + this._index = new SearchableMap(); + this._documentCount = 0; + this._documentIds = new Map(); + // Fields are defined during initialization, don't change, are few in + // number, rarely need iterating over, and have string keys. Therefore in + // this case an object is a better candidate than a Map to store the mapping + // from field key to ID. + this._fieldIds = {}; + this._fieldLength = new Map(); + this._averageFieldLength = []; + this._nextId = 0; + this._storedFields = new Map(); + this.addFields(this._options.fields); + } + /** + * Adds a document to the index + * + * @param document The document to be indexed + */ + MiniSearch.prototype.add = function (document) { + var e_1, _a, e_2, _b; + var _c = this._options, extractField = _c.extractField, tokenize = _c.tokenize, processTerm = _c.processTerm, fields = _c.fields, idField = _c.idField; + var id = extractField(document, idField); + if (id == null) { + throw new Error("MiniSearch: document does not have ID field \"".concat(idField, "\"")); + } + var shortDocumentId = this.addDocumentId(id); + this.saveStoredFields(shortDocumentId, document); + try { + for (var fields_1 = __values(fields), fields_1_1 = fields_1.next(); !fields_1_1.done; fields_1_1 = fields_1.next()) { + var field = fields_1_1.value; + var fieldValue = extractField(document, field); + if (fieldValue == null) + continue; + var tokens = tokenize(fieldValue.toString(), field); + var fieldId = this._fieldIds[field]; + this.addFieldLength(shortDocumentId, fieldId, this.documentCount - 1, tokens.length); + try { + for (var tokens_1 = (e_2 = void 0, __values(tokens)), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) { + var term = tokens_1_1.value; + var processedTerm = processTerm(term, field); + if (processedTerm) { + this.addTerm(fieldId, shortDocumentId, processedTerm); + } + } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { + if (tokens_1_1 && !tokens_1_1.done && (_b = tokens_1.return)) _b.call(tokens_1); + } + finally { if (e_2) throw e_2.error; } + } + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (fields_1_1 && !fields_1_1.done && (_a = fields_1.return)) _a.call(fields_1); + } + finally { if (e_1) throw e_1.error; } + } + }; + /** + * Adds all the given documents to the index + * + * @param documents An array of documents to be indexed + */ + MiniSearch.prototype.addAll = function (documents) { + var e_3, _a; + try { + for (var documents_1 = __values(documents), documents_1_1 = documents_1.next(); !documents_1_1.done; documents_1_1 = documents_1.next()) { + var document_1 = documents_1_1.value; + this.add(document_1); + } + } + catch (e_3_1) { e_3 = { error: e_3_1 }; } + finally { + try { + if (documents_1_1 && !documents_1_1.done && (_a = documents_1.return)) _a.call(documents_1); + } + finally { if (e_3) throw e_3.error; } + } + }; + /** + * Adds all the given documents to the index asynchronously. + * + * Returns a promise that resolves (to `undefined`) when the indexing is done. + * This method is useful when index many documents, to avoid blocking the main + * thread. The indexing is performed asynchronously and in chunks. + * + * @param documents An array of documents to be indexed + * @param options Configuration options + * @return A promise resolving to `undefined` when the indexing is done + */ + MiniSearch.prototype.addAllAsync = function (documents, options) { + var _this = this; + if (options === void 0) { options = {}; } + var _a = options.chunkSize, chunkSize = _a === void 0 ? 10 : _a; + var acc = { chunk: [], promise: Promise.resolve() }; + var _b = documents.reduce(function (_a, document, i) { + var chunk = _a.chunk, promise = _a.promise; + chunk.push(document); + if ((i + 1) % chunkSize === 0) { + return { + chunk: [], + promise: promise + .then(function () { return new Promise(function (resolve) { return setTimeout(resolve, 0); }); }) + .then(function () { return _this.addAll(chunk); }) + }; + } + else { + return { chunk: chunk, promise: promise }; + } + }, acc), chunk = _b.chunk, promise = _b.promise; + return promise.then(function () { return _this.addAll(chunk); }); + }; + /** + * Removes the given document from the index. + * + * The document to delete must NOT have changed between indexing and deletion, + * otherwise the index will be corrupted. Therefore, when reindexing a document + * after a change, the correct order of operations is: + * + * 1. remove old version + * 2. apply changes + * 3. index new version + * + * @param document The document to be removed + */ + MiniSearch.prototype.remove = function (document) { + var e_4, _a, e_5, _b, e_6, _c; + var _d = this._options, tokenize = _d.tokenize, processTerm = _d.processTerm, extractField = _d.extractField, fields = _d.fields, idField = _d.idField; + var id = extractField(document, idField); + if (id == null) { + throw new Error("MiniSearch: document does not have ID field \"".concat(idField, "\"")); + } + try { + for (var _e = __values(this._documentIds), _f = _e.next(); !_f.done; _f = _e.next()) { + var _g = __read(_f.value, 2), shortId = _g[0], longId = _g[1]; + if (id === longId) { + try { + for (var fields_2 = (e_5 = void 0, __values(fields)), fields_2_1 = fields_2.next(); !fields_2_1.done; fields_2_1 = fields_2.next()) { + var field = fields_2_1.value; + var fieldValue = extractField(document, field); + if (fieldValue == null) + continue; + var tokens = tokenize(fieldValue.toString(), field); + var fieldId = this._fieldIds[field]; + try { + for (var tokens_2 = (e_6 = void 0, __values(tokens)), tokens_2_1 = tokens_2.next(); !tokens_2_1.done; tokens_2_1 = tokens_2.next()) { + var term = tokens_2_1.value; + var processedTerm = processTerm(term, field); + if (processedTerm) { + this.removeTerm(fieldId, shortId, processedTerm); + } + } + } + catch (e_6_1) { e_6 = { error: e_6_1 }; } + finally { + try { + if (tokens_2_1 && !tokens_2_1.done && (_c = tokens_2.return)) _c.call(tokens_2); + } + finally { if (e_6) throw e_6.error; } + } + this.removeFieldLength(shortId, fieldId, this.documentCount, tokens.length); + } + } + catch (e_5_1) { e_5 = { error: e_5_1 }; } + finally { + try { + if (fields_2_1 && !fields_2_1.done && (_b = fields_2.return)) _b.call(fields_2); + } + finally { if (e_5) throw e_5.error; } + } + this._storedFields.delete(shortId); + this._documentIds.delete(shortId); + this._fieldLength.delete(shortId); + this._documentCount -= 1; + return; + } + } + } + catch (e_4_1) { e_4 = { error: e_4_1 }; } + finally { + try { + if (_f && !_f.done && (_a = _e.return)) _a.call(_e); + } + finally { if (e_4) throw e_4.error; } + } + throw new Error("MiniSearch: cannot remove document with ID ".concat(id, ": it is not in the index")); + }; + /** + * Removes all the given documents from the index. If called with no arguments, + * it removes _all_ documents from the index. + * + * @param documents The documents to be removed. If this argument is omitted, + * all documents are removed. Note that, for removing all documents, it is + * more efficient to call this method with no arguments than to pass all + * documents. + */ + MiniSearch.prototype.removeAll = function (documents) { + var e_7, _a; + if (documents) { + try { + for (var documents_2 = __values(documents), documents_2_1 = documents_2.next(); !documents_2_1.done; documents_2_1 = documents_2.next()) { + var document_2 = documents_2_1.value; + this.remove(document_2); + } + } + catch (e_7_1) { e_7 = { error: e_7_1 }; } + finally { + try { + if (documents_2_1 && !documents_2_1.done && (_a = documents_2.return)) _a.call(documents_2); + } + finally { if (e_7) throw e_7.error; } + } + } + else if (arguments.length > 0) { + throw new Error('Expected documents to be present. Omit the argument to remove all documents.'); + } + else { + this._index = new SearchableMap(); + this._documentCount = 0; + this._documentIds = new Map(); + this._fieldLength = new Map(); + this._averageFieldLength = []; + this._storedFields = new Map(); + this._nextId = 0; + } + }; + /** + * Search for documents matching the given search query. + * + * The result is a list of scored document IDs matching the query, sorted by + * descending score, and each including data about which terms were matched and + * in which fields. + * + * ### Basic usage: + * + * ```javascript + * // Search for "zen art motorcycle" with default options: terms have to match + * // exactly, and individual terms are joined with OR + * miniSearch.search('zen art motorcycle') + * // => [ { id: 2, score: 2.77258, match: { ... } }, { id: 4, score: 1.38629, match: { ... } } ] + * ``` + * + * ### Restrict search to specific fields: + * + * ```javascript + * // Search only in the 'title' field + * miniSearch.search('zen', { fields: ['title'] }) + * ``` + * + * ### Field boosting: + * + * ```javascript + * // Boost a field + * miniSearch.search('zen', { boost: { title: 2 } }) + * ``` + * + * ### Prefix search: + * + * ```javascript + * // Search for "moto" with prefix search (it will match documents + * // containing terms that start with "moto" or "neuro") + * miniSearch.search('moto neuro', { prefix: true }) + * ``` + * + * ### Fuzzy search: + * + * ```javascript + * // Search for "ismael" with fuzzy search (it will match documents containing + * // terms similar to "ismael", with a maximum edit distance of 0.2 term.length + * // (rounded to nearest integer) + * miniSearch.search('ismael', { fuzzy: 0.2 }) + * ``` + * + * ### Combining strategies: + * + * ```javascript + * // Mix of exact match, prefix search, and fuzzy search + * miniSearch.search('ismael mob', { + * prefix: true, + * fuzzy: 0.2 + * }) + * ``` + * + * ### Advanced prefix and fuzzy search: + * + * ```javascript + * // Perform fuzzy and prefix search depending on the search term. Here + * // performing prefix and fuzzy search only on terms longer than 3 characters + * miniSearch.search('ismael mob', { + * prefix: term => term.length > 3 + * fuzzy: term => term.length > 3 ? 0.2 : null + * }) + * ``` + * + * ### Combine with AND: + * + * ```javascript + * // Combine search terms with AND (to match only documents that contain both + * // "motorcycle" and "art") + * miniSearch.search('motorcycle art', { combineWith: 'AND' }) + * ``` + * + * ### Combine with AND_NOT: + * + * There is also an AND_NOT combinator, that finds documents that match the + * first term, but do not match any of the other terms. This combinator is + * rarely useful with simple queries, and is meant to be used with advanced + * query combinations (see later for more details). + * + * ### Filtering results: + * + * ```javascript + * // Filter only results in the 'fiction' category (assuming that 'category' + * // is a stored field) + * miniSearch.search('motorcycle art', { + * filter: (result) => result.category === 'fiction' + * }) + * ``` + * + * ### Advanced combination of queries: + * + * It is possible to combine different subqueries with OR, AND, and AND_NOT, + * and even with different search options, by passing a query expression + * tree object as the first argument, instead of a string. + * + * ```javascript + * // Search for documents that contain "zen" and ("motorcycle" or "archery") + * miniSearch.search({ + * combineWith: 'AND', + * queries: [ + * 'zen', + * { + * combineWith: 'OR', + * queries: ['motorcycle', 'archery'] + * } + * ] + * }) + * + * // Search for documents that contain ("apple" or "pear") but not "juice" and + * // not "tree" + * miniSearch.search({ + * combineWith: 'AND_NOT', + * queries: [ + * { + * combineWith: 'OR', + * queries: ['apple', 'pear'] + * }, + * 'juice', + * 'tree' + * ] + * }) + * ``` + * + * Each node in the expression tree can be either a string, or an object that + * supports all `SearchOptions` fields, plus a `queries` array field for + * subqueries. + * + * Note that, while this can become complicated to do by hand for complex or + * deeply nested queries, it provides a formalized expression tree API for + * external libraries that implement a parser for custom query languages. + * + * @param query Search query + * @param options Search options. Each option, if not given, defaults to the corresponding value of `searchOptions` given to the constructor, or to the library default. + */ + MiniSearch.prototype.search = function (query, searchOptions) { + var e_8, _a; + if (searchOptions === void 0) { searchOptions = {}; } + var combinedResults = this.executeQuery(query, searchOptions); + var results = []; + try { + for (var combinedResults_1 = __values(combinedResults), combinedResults_1_1 = combinedResults_1.next(); !combinedResults_1_1.done; combinedResults_1_1 = combinedResults_1.next()) { + var _b = __read(combinedResults_1_1.value, 2), docId = _b[0], _c = _b[1], score = _c.score, match = _c.match, terms = _c.terms; + var result = { + id: this._documentIds.get(docId), + terms: uniq(terms), + score: score, + match: match + }; + Object.assign(result, this._storedFields.get(docId)); + if (searchOptions.filter == null || searchOptions.filter(result)) { + results.push(result); + } + } + } + catch (e_8_1) { e_8 = { error: e_8_1 }; } + finally { + try { + if (combinedResults_1_1 && !combinedResults_1_1.done && (_a = combinedResults_1.return)) _a.call(combinedResults_1); + } + finally { if (e_8) throw e_8.error; } + } + results.sort(function (_a, _b) { + var a = _a.score; + var b = _b.score; + return a < b ? 1 : -1; + }); + return results; + }; + /** + * Provide suggestions for the given search query + * + * The result is a list of suggested modified search queries, derived from the + * given search query, each with a relevance score, sorted by descending score. + * + * ### Basic usage: + * + * ```javascript + * // Get suggestions for 'neuro': + * miniSearch.autoSuggest('neuro') + * // => [ { suggestion: 'neuromancer', terms: [ 'neuromancer' ], score: 0.46240 } ] + * ``` + * + * ### Multiple words: + * + * ```javascript + * // Get suggestions for 'zen ar': + * miniSearch.autoSuggest('zen ar') + * // => [ + * // { suggestion: 'zen archery art', terms: [ 'zen', 'archery', 'art' ], score: 1.73332 }, + * // { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 } + * // ] + * ``` + * + * ### Fuzzy suggestions: + * + * ```javascript + * // Correct spelling mistakes using fuzzy search: + * miniSearch.autoSuggest('neromancer', { fuzzy: 0.2 }) + * // => [ { suggestion: 'neuromancer', terms: [ 'neuromancer' ], score: 1.03998 } ] + * ``` + * + * ### Filtering: + * + * ```javascript + * // Get suggestions for 'zen ar', but only within the 'fiction' category + * // (assuming that 'category' is a stored field): + * miniSearch.autoSuggest('zen ar', { + * filter: (result) => result.category === 'fiction' + * }) + * // => [ + * // { suggestion: 'zen archery art', terms: [ 'zen', 'archery', 'art' ], score: 1.73332 }, + * // { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 } + * // ] + * ``` + * + * @param queryString Query string to be expanded into suggestions + * @param options Search options. The supported options and default values + * are the same as for the `search` method, except that by default prefix + * search is performed on the last term in the query. + * @return A sorted array of suggestions sorted by relevance score. + */ + MiniSearch.prototype.autoSuggest = function (queryString, options) { + var e_9, _a, e_10, _b; + if (options === void 0) { options = {}; } + options = __assign(__assign({}, defaultAutoSuggestOptions), options); + var suggestions = new Map(); + try { + for (var _c = __values(this.search(queryString, options)), _d = _c.next(); !_d.done; _d = _c.next()) { + var _e = _d.value, score = _e.score, terms = _e.terms; + var phrase = terms.join(' '); + var suggestion = suggestions.get(phrase); + if (suggestion != null) { + suggestion.score += score; + suggestion.count += 1; + } + else { + suggestions.set(phrase, { score: score, terms: terms, count: 1 }); + } + } + } + catch (e_9_1) { e_9 = { error: e_9_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_9) throw e_9.error; } + } + var results = []; + try { + for (var suggestions_1 = __values(suggestions), suggestions_1_1 = suggestions_1.next(); !suggestions_1_1.done; suggestions_1_1 = suggestions_1.next()) { + var _f = __read(suggestions_1_1.value, 2), suggestion = _f[0], _g = _f[1], score = _g.score, terms = _g.terms, count = _g.count; + results.push({ suggestion: suggestion, terms: terms, score: score / count }); + } + } + catch (e_10_1) { e_10 = { error: e_10_1 }; } + finally { + try { + if (suggestions_1_1 && !suggestions_1_1.done && (_b = suggestions_1.return)) _b.call(suggestions_1); + } + finally { if (e_10) throw e_10.error; } + } + results.sort(function (_a, _b) { + var a = _a.score; + var b = _b.score; + return a < b ? 1 : -1; + }); + return results; + }; + Object.defineProperty(MiniSearch.prototype, "documentCount", { + /** + * Number of documents in the index + */ + get: function () { + return this._documentCount; + }, + enumerable: false, + configurable: true + }); + /** + * Deserializes a JSON index (serialized with `JSON.stringify(miniSearch)`) + * and instantiates a MiniSearch instance. It should be given the same options + * originally used when serializing the index. + * + * ### Usage: + * + * ```javascript + * // If the index was serialized with: + * let miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * miniSearch.addAll(documents) + * + * const json = JSON.stringify(miniSearch) + * // It can later be deserialized like this: + * miniSearch = MiniSearch.loadJSON(json, { fields: ['title', 'text'] }) + * ``` + * + * @param json JSON-serialized index + * @param options configuration options, same as the constructor + * @return An instance of MiniSearch deserialized from the given JSON. + */ + MiniSearch.loadJSON = function (json, options) { + if (options == null) { + throw new Error('MiniSearch: loadJSON should be given the same options used when serializing the index'); + } + return MiniSearch.loadJS(JSON.parse(json), options); + }; + /** + * Returns the default value of an option. It will throw an error if no option + * with the given name exists. + * + * @param optionName Name of the option + * @return The default value of the given option + * + * ### Usage: + * + * ```javascript + * // Get default tokenizer + * MiniSearch.getDefault('tokenize') + * + * // Get default term processor + * MiniSearch.getDefault('processTerm') + * + * // Unknown options will throw an error + * MiniSearch.getDefault('notExisting') + * // => throws 'MiniSearch: unknown option "notExisting"' + * ``` + */ + MiniSearch.getDefault = function (optionName) { + if (defaultOptions.hasOwnProperty(optionName)) { + return getOwnProperty(defaultOptions, optionName); + } + else { + throw new Error("MiniSearch: unknown option \"".concat(optionName, "\"")); + } + }; + /** + * @ignore + */ + MiniSearch.loadJS = function (js, options) { + var e_11, _a, e_12, _b; + var index = js.index, documentCount = js.documentCount, nextId = js.nextId, documentIds = js.documentIds, fieldIds = js.fieldIds, fieldLength = js.fieldLength, averageFieldLength = js.averageFieldLength, storedFields = js.storedFields, serializationVersion = js.serializationVersion; + if (serializationVersion !== 1) { + throw new Error('MiniSearch: cannot deserialize an index created with an incompatible version'); + } + var miniSearch = new MiniSearch(options); + miniSearch._documentCount = documentCount; + miniSearch._nextId = nextId; + miniSearch._documentIds = objectToNumericMap(documentIds); + miniSearch._fieldIds = fieldIds; + miniSearch._fieldLength = objectToNumericMap(fieldLength); + miniSearch._averageFieldLength = averageFieldLength; + miniSearch._storedFields = objectToNumericMap(storedFields); + miniSearch._index = new SearchableMap(); + try { + for (var index_1 = __values(index), index_1_1 = index_1.next(); !index_1_1.done; index_1_1 = index_1.next()) { + var _c = __read(index_1_1.value, 2), term = _c[0], data = _c[1]; + var dataMap = new Map(); + try { + for (var _d = (e_12 = void 0, __values(Object.keys(data))), _e = _d.next(); !_e.done; _e = _d.next()) { + var fieldId = _e.value; + var _f = data[fieldId], df = _f.df, ds = _f.ds; + dataMap.set(parseInt(fieldId, 10), { df: df, ds: objectToNumericMap(ds) }); + } + } + catch (e_12_1) { e_12 = { error: e_12_1 }; } + finally { + try { + if (_e && !_e.done && (_b = _d.return)) _b.call(_d); + } + finally { if (e_12) throw e_12.error; } + } + miniSearch._index.set(term, dataMap); + } + } + catch (e_11_1) { e_11 = { error: e_11_1 }; } + finally { + try { + if (index_1_1 && !index_1_1.done && (_a = index_1.return)) _a.call(index_1); + } + finally { if (e_11) throw e_11.error; } + } + return miniSearch; + }; + /** + * @ignore + */ + MiniSearch.prototype.executeQuery = function (query, searchOptions) { + var _this = this; + if (searchOptions === void 0) { searchOptions = {}; } + if (typeof query === 'string') { + return this.executeSearch(query, searchOptions); + } + else { + var results = query.queries.map(function (subquery) { + var options = __assign(__assign(__assign({}, searchOptions), query), { queries: undefined }); + return _this.executeQuery(subquery, options); + }); + return this.combineResults(results, query.combineWith); + } + }; + /** + * @ignore + */ + MiniSearch.prototype.executeSearch = function (queryString, searchOptions) { + var _this = this; + if (searchOptions === void 0) { searchOptions = {}; } + var _a = this._options, tokenize = _a.tokenize, processTerm = _a.processTerm, globalSearchOptions = _a.searchOptions; + var options = __assign(__assign({ tokenize: tokenize, processTerm: processTerm }, globalSearchOptions), searchOptions); + var searchTokenize = options.tokenize, searchProcessTerm = options.processTerm; + var terms = searchTokenize(queryString) + .map(function (term) { return searchProcessTerm(term); }) + .filter(function (term) { return !!term; }); + var queries = terms.map(termToQuerySpec(options)); + var results = queries.map(function (query) { return _this.executeQuerySpec(query, options); }); + return this.combineResults(results, options.combineWith); + }; + /** + * @ignore + */ + MiniSearch.prototype.executeQuerySpec = function (query, searchOptions) { + var e_13, _a, e_14, _b; + var options = __assign(__assign({}, this._options.searchOptions), searchOptions); + var boosts = (options.fields || this._options.fields).reduce(function (boosts, field) { + var _a; + return (__assign(__assign({}, boosts), (_a = {}, _a[field] = getOwnProperty(boosts, field) || 1, _a))); + }, options.boost || {}); + var boostDocument = options.boostDocument, weights = options.weights, maxFuzzy = options.maxFuzzy; + var _c = __assign(__assign({}, defaultSearchOptions.weights), weights), fuzzyWeight = _c.fuzzy, prefixWeight = _c.prefix; + var results = this.termResults(query.term, boosts, boostDocument, this._index.get(query.term)); + var prefixMatches; + var fuzzyMatches; + if (query.prefix) { + prefixMatches = this._index.atPrefix(query.term); + } + if (query.fuzzy) { + var fuzzy = (query.fuzzy === true) ? 0.2 : query.fuzzy; + var maxDistance = fuzzy < 1 ? Math.min(maxFuzzy, Math.round(query.term.length * fuzzy)) : fuzzy; + fuzzyMatches = this._index.fuzzyGet(query.term, maxDistance); + } + if (prefixMatches) { + try { + for (var prefixMatches_1 = __values(prefixMatches), prefixMatches_1_1 = prefixMatches_1.next(); !prefixMatches_1_1.done; prefixMatches_1_1 = prefixMatches_1.next()) { + var _d = __read(prefixMatches_1_1.value, 2), term = _d[0], data = _d[1]; + var distance = term.length - query.term.length; + if (!distance) { + continue; + } // Skip exact match. + // Delete the term from fuzzy results (if present) if it is also a + // prefix result. This entry will always be scored as a prefix result. + fuzzyMatches === null || fuzzyMatches === void 0 ? void 0 : fuzzyMatches.delete(term); + var weightedDistance = (0.3 * distance) / term.length; + this.termResults(term, boosts, boostDocument, data, results, prefixWeight, weightedDistance); + } + } + catch (e_13_1) { e_13 = { error: e_13_1 }; } + finally { + try { + if (prefixMatches_1_1 && !prefixMatches_1_1.done && (_a = prefixMatches_1.return)) _a.call(prefixMatches_1); + } + finally { if (e_13) throw e_13.error; } + } + } + if (fuzzyMatches) { + try { + for (var _e = __values(fuzzyMatches.keys()), _f = _e.next(); !_f.done; _f = _e.next()) { + var term = _f.value; + var _g = __read(fuzzyMatches.get(term), 2), data = _g[0], distance = _g[1]; + if (!distance) { + continue; + } // Skip exact match. + var weightedDistance = distance / term.length; + this.termResults(term, boosts, boostDocument, data, results, fuzzyWeight, weightedDistance); + } + } + catch (e_14_1) { e_14 = { error: e_14_1 }; } + finally { + try { + if (_f && !_f.done && (_b = _e.return)) _b.call(_e); + } + finally { if (e_14) throw e_14.error; } + } + } + return results; + }; + /** + * @ignore + */ + MiniSearch.prototype.combineResults = function (results, combineWith) { + if (combineWith === void 0) { combineWith = OR; } + if (results.length === 0) { + return new Map(); + } + var operator = combineWith.toLowerCase(); + return results.reduce(combinators[operator]) || new Map(); + }; + /** + * Allows serialization of the index to JSON, to possibly store it and later + * deserialize it with `MiniSearch.loadJSON`. + * + * Normally one does not directly call this method, but rather call the + * standard JavaScript `JSON.stringify()` passing the `MiniSearch` instance, + * and JavaScript will internally call this method. Upon deserialization, one + * must pass to `loadJSON` the same options used to create the original + * instance that was serialized. + * + * ### Usage: + * + * ```javascript + * // Serialize the index: + * let miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * miniSearch.addAll(documents) + * const json = JSON.stringify(miniSearch) + * + * // Later, to deserialize it: + * miniSearch = MiniSearch.loadJSON(json, { fields: ['title', 'text'] }) + * ``` + * + * @return A plain-object serializeable representation of the search index. + */ + MiniSearch.prototype.toJSON = function () { + var e_15, _a, e_16, _b; + var index = []; + try { + for (var _c = __values(this._index), _d = _c.next(); !_d.done; _d = _c.next()) { + var _e = __read(_d.value, 2), term = _e[0], fieldIndex = _e[1]; + var data = {}; + try { + for (var fieldIndex_1 = (e_16 = void 0, __values(fieldIndex)), fieldIndex_1_1 = fieldIndex_1.next(); !fieldIndex_1_1.done; fieldIndex_1_1 = fieldIndex_1.next()) { + var _f = __read(fieldIndex_1_1.value, 2), fieldId = _f[0], _g = _f[1], df = _g.df, ds = _g.ds; + data[fieldId] = { df: df, ds: Object.fromEntries(ds) }; + } + } + catch (e_16_1) { e_16 = { error: e_16_1 }; } + finally { + try { + if (fieldIndex_1_1 && !fieldIndex_1_1.done && (_b = fieldIndex_1.return)) _b.call(fieldIndex_1); + } + finally { if (e_16) throw e_16.error; } + } + index.push([term, data]); + } + } + catch (e_15_1) { e_15 = { error: e_15_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_15) throw e_15.error; } + } + return { + documentCount: this._documentCount, + nextId: this._nextId, + documentIds: Object.fromEntries(this._documentIds), + fieldIds: this._fieldIds, + fieldLength: Object.fromEntries(this._fieldLength), + averageFieldLength: this._averageFieldLength, + storedFields: Object.fromEntries(this._storedFields), + index: index, + serializationVersion: 1 + }; + }; + /** + * @ignore + */ + MiniSearch.prototype.termResults = function (term, boosts, boostDocument, indexData, results, weight, editDistance) { + var e_17, _a, e_18, _b, _c; + if (results === void 0) { results = new Map(); } + if (weight === void 0) { weight = 1; } + if (editDistance === void 0) { editDistance = 0; } + if (indexData == null) + return results; + try { + for (var _d = __values(Object.keys(boosts)), _e = _d.next(); !_e.done; _e = _d.next()) { + var field = _e.value; + var fieldBoost = boosts[field]; + var fieldId = this._fieldIds[field]; + var entry = indexData.get(fieldId); + if (entry == null) + continue; + try { + for (var _f = (e_18 = void 0, __values(entry.ds)), _g = _f.next(); !_g.done; _g = _f.next()) { + var _h = __read(_g.value, 2), documentId = _h[0], tf = _h[1]; + var docBoost = boostDocument ? boostDocument(this._documentIds.get(documentId), term) : 1; + if (!docBoost) + continue; + var normalizedLength = this._fieldLength.get(documentId)[fieldId] / this._averageFieldLength[fieldId]; + var score = weight * docBoost * calculateScore(tf, entry.df, this._documentCount, normalizedLength, fieldBoost, editDistance); + var result = results.get(documentId); + if (result) { + result.score += score; + var match = getOwnProperty(result.match, term); + if (match) { + match.push(field); + } + else { + result.match[term] = [field]; + result.terms.push(term); + } + } + else { + results.set(documentId, { + score: score, + match: (_c = {}, _c[term] = [field], _c), + terms: [term] + }); + } + } + } + catch (e_18_1) { e_18 = { error: e_18_1 }; } + finally { + try { + if (_g && !_g.done && (_b = _f.return)) _b.call(_f); + } + finally { if (e_18) throw e_18.error; } + } + } + } + catch (e_17_1) { e_17 = { error: e_17_1 }; } + finally { + try { + if (_e && !_e.done && (_a = _d.return)) _a.call(_d); + } + finally { if (e_17) throw e_17.error; } + } + return results; + }; + /** + * @ignore + */ + MiniSearch.prototype.addTerm = function (fieldId, documentId, term) { + var indexData = this._index.fetch(term, createMap); + var fieldIndex = indexData.get(fieldId); + if (fieldIndex == null) { + fieldIndex = { df: 1, ds: new Map() }; + fieldIndex.ds.set(documentId, 1); + indexData.set(fieldId, fieldIndex); + } + else { + var docs = fieldIndex.ds.get(documentId); + if (docs == null) { + fieldIndex.df += 1; + } + fieldIndex.ds.set(documentId, (docs || 0) + 1); + } + }; + /** + * @ignore + */ + MiniSearch.prototype.removeTerm = function (fieldId, documentId, term) { + if (!this._index.has(term)) { + this.warnDocumentChanged(documentId, fieldId, term); + return; + } + var indexData = this._index.fetch(term, createMap); + var fieldIndex = indexData.get(fieldId); + if (fieldIndex == null || fieldIndex.ds.get(documentId) == null) { + this.warnDocumentChanged(documentId, fieldId, term); + } + else if (fieldIndex.ds.get(documentId) <= 1) { + if (fieldIndex.df <= 1) { + indexData.delete(fieldId); + } + else { + fieldIndex.df -= 1; + fieldIndex.ds.delete(documentId); + } + } + else { + fieldIndex.ds.set(documentId, fieldIndex.ds.get(documentId) - 1); + } + if (this._index.get(term).size === 0) { + this._index.delete(term); + } + }; + /** + * @ignore + */ + MiniSearch.prototype.warnDocumentChanged = function (shortDocumentId, fieldId, term) { + var e_19, _a; + if (console == null || console.warn == null) { + return; + } + try { + for (var _b = __values(Object.keys(this._fieldIds)), _c = _b.next(); !_c.done; _c = _b.next()) { + var fieldName = _c.value; + if (this._fieldIds[fieldName] === fieldId) { + console.warn("MiniSearch: document with ID ".concat(this._documentIds.get(shortDocumentId), " has changed before removal: term \"").concat(term, "\" was not present in field \"").concat(fieldName, "\". Removing a document after it has changed can corrupt the index!")); + return; + } + } + } + catch (e_19_1) { e_19 = { error: e_19_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_19) throw e_19.error; } + } + }; + /** + * @ignore + */ + MiniSearch.prototype.addDocumentId = function (documentId) { + var shortDocumentId = this._nextId; + this._documentIds.set(shortDocumentId, documentId); + this._documentCount += 1; + this._nextId += 1; + return shortDocumentId; + }; + /** + * @ignore + */ + MiniSearch.prototype.addFields = function (fields) { + for (var i = 0; i < fields.length; i++) { + this._fieldIds[fields[i]] = i; + } + }; + /** + * @ignore + */ + MiniSearch.prototype.addFieldLength = function (documentId, fieldId, count, length) { + var fieldLengths = this._fieldLength.get(documentId); + if (fieldLengths == null) + this._fieldLength.set(documentId, fieldLengths = []); + fieldLengths[fieldId] = length; + var averageFieldLength = this._averageFieldLength[fieldId] || 0; + var totalLength = (averageFieldLength * count) + length; + this._averageFieldLength[fieldId] = totalLength / (count + 1); + }; + /** + * @ignore + */ + MiniSearch.prototype.removeFieldLength = function (documentId, fieldId, count, length) { + var totalLength = (this._averageFieldLength[fieldId] * count) - length; + this._averageFieldLength[fieldId] = totalLength / (count - 1); + }; + /** + * @ignore + */ + MiniSearch.prototype.saveStoredFields = function (documentId, doc) { + var e_20, _a; + var _b = this._options, storeFields = _b.storeFields, extractField = _b.extractField; + if (storeFields == null || storeFields.length === 0) { + return; + } + var documentFields = this._storedFields.get(documentId); + if (documentFields == null) + this._storedFields.set(documentId, documentFields = {}); + try { + for (var storeFields_1 = __values(storeFields), storeFields_1_1 = storeFields_1.next(); !storeFields_1_1.done; storeFields_1_1 = storeFields_1.next()) { + var fieldName = storeFields_1_1.value; + var fieldValue = extractField(doc, fieldName); + if (fieldValue !== undefined) + documentFields[fieldName] = fieldValue; + } + } + catch (e_20_1) { e_20 = { error: e_20_1 }; } + finally { + try { + if (storeFields_1_1 && !storeFields_1_1.done && (_a = storeFields_1.return)) _a.call(storeFields_1); + } + finally { if (e_20) throw e_20.error; } + } + }; + return MiniSearch; + }()); + var getOwnProperty = function (object, property) { + return Object.prototype.hasOwnProperty.call(object, property) ? object[property] : undefined; + }; + var combinators = (_a = {}, + _a[OR] = function (a, b) { + var e_21, _a, _b; + try { + for (var _c = __values(b.keys()), _d = _c.next(); !_d.done; _d = _c.next()) { + var documentId = _d.value; + var existing = a.get(documentId); + if (existing == null) { + a.set(documentId, b.get(documentId)); + } + else { + var _e = b.get(documentId), score = _e.score, match = _e.match, terms = _e.terms; + existing.score = (existing.score + score) * 1.5; + existing.match = Object.assign(existing.match, match); + (_b = existing.terms).push.apply(_b, __spreadArray([], __read(terms), false)); + } + } + } + catch (e_21_1) { e_21 = { error: e_21_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_21) throw e_21.error; } + } + return a; + }, + _a[AND] = function (a, b) { + var e_22, _a; + var combined = new Map(); + try { + for (var _b = __values(b.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var documentId = _c.value; + var existing = a.get(documentId); + if (existing == null) + continue; + var _d = b.get(documentId), score = _d.score, match = _d.match, terms = _d.terms; + combined.set(documentId, { + score: existing.score + score, + match: Object.assign(existing.match, match), + terms: __spreadArray(__spreadArray([], __read(existing.terms), false), __read(terms), false) + }); + } + } + catch (e_22_1) { e_22 = { error: e_22_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_22) throw e_22.error; } + } + return combined; + }, + _a[AND_NOT] = function (a, b) { + var e_23, _a; + try { + for (var _b = __values(b.keys()), _c = _b.next(); !_c.done; _c = _b.next()) { + var documentId = _c.value; + a.delete(documentId); + } + } + catch (e_23_1) { e_23 = { error: e_23_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_23) throw e_23.error; } + } + return a; + }, + _a); + var tfIdf = function (tf, df, n) { return tf * Math.log(n / df); }; + var calculateScore = function (termFrequency, documentFrequency, documentCount, normalizedLength, boost, editDistance) { + var weight = boost / (1 + (0.333 * boost * editDistance)); + return weight * tfIdf(termFrequency, documentFrequency, documentCount) / normalizedLength; + }; + var termToQuerySpec = function (options) { return function (term, i, terms) { + var fuzzy = (typeof options.fuzzy === 'function') + ? options.fuzzy(term, i, terms) + : (options.fuzzy || false); + var prefix = (typeof options.prefix === 'function') + ? options.prefix(term, i, terms) + : (options.prefix === true); + return { term: term, fuzzy: fuzzy, prefix: prefix }; + }; }; + var uniq = function (array) { + return array.filter(function (element, i, array) { return array.indexOf(element) === i; }); + }; + var defaultOptions = { + idField: 'id', + extractField: function (document, fieldName) { return document[fieldName]; }, + tokenize: function (text, fieldName) { return text.split(SPACE_OR_PUNCTUATION); }, + processTerm: function (term, fieldName) { return term.toLowerCase(); }, + fields: undefined, + searchOptions: undefined, + storeFields: [] + }; + var defaultSearchOptions = { + combineWith: OR, + prefix: false, + fuzzy: false, + maxFuzzy: 6, + boost: {}, + weights: { fuzzy: 0.45, prefix: 0.375 } + }; + var defaultAutoSuggestOptions = { + prefix: function (term, i, terms) { + return i === terms.length - 1; + } + }; + var createMap = function () { return new Map(); }; + var objectToNumericMap = function (object) { + var e_24, _a; + var map = new Map(); + try { + for (var _b = __values(Object.keys(object)), _c = _b.next(); !_c.done; _c = _b.next()) { + var key = _c.value; + map.set(parseInt(key, 10), object[key]); + } + } + catch (e_24_1) { e_24 = { error: e_24_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_24) throw e_24.error; } + } + return map; + }; + // This regular expression matches any Unicode space or punctuation character + // Adapted from https://unicode.org/cldr/utility/list-unicodeset.jsp?a=%5Cp%7BZ%7D%5Cp%7BP%7D&abb=on&c=on&esc=on + var SPACE_OR_PUNCTUATION = /[\n\r -#%-*,-/:;?@[-\]_{}\u00A0\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u1680\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2000-\u200A\u2010-\u2029\u202F-\u2043\u2045-\u2051\u2053-\u205F\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u3000-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]+/u; + + return MiniSearch; + +})); +//# sourceMappingURL=index.js.map diff --git a/node_modules/minisearch/dist/umd/index.js.map b/node_modules/minisearch/dist/umd/index.js.map new file mode 100644 index 0000000..9971a01 --- /dev/null +++ b/node_modules/minisearch/dist/umd/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../../node_modules/tslib/tslib.es6.js","../../src/SearchableMap/TreeIterator.ts","../../src/SearchableMap/fuzzySearch.ts","../../src/SearchableMap/SearchableMap.ts","../../src/MiniSearch.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(recei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EAAE,GAAA;QACrE,MAAM,EAAE,SAAS;QACjB,aAAa,EAAE,SAAS;QACxB,WAAW,EAAE,EAAE;KAChB,CAAA;IAED,IAAM,oBAAoB,GAAG;QAC3B,WAAW,EAAE,EAAE;QACf,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,KAAK;QACZ,QAAQ,EAAE,CAAC;QACX,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;KACxC,CAAA;IAED,IAAM,yBAAyB,GAAG;QAChC,MAAM,EAAE,UAAC,IAAY,EAAE,CAAS,EAAE,KAAe;YAC/C,OAAA,CAAC,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC;SAAA;KACzB,CAAA;IAED,IAAM,SAAS,GAAG,cAAM,OAAA,IAAI,GAAG,EAAE,GAAA,CAAA;IAIjC,IAAM,kBAAkB,GAAG,UAAI,MAA4B;;QACzD,IAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAA;;YAErB,KAAkB,IAAA,KAAA,SAAA,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,gBAAA,4BAAE;gBAAlC,IAAM,GAAG,WAAA;gBACZ,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;aACxC;;;;;;;;;QAED,OAAO,GAAG,CAAA;IACZ,CAAC,CAAA;IAED;IACA;IACA,IAAM,oBAAoB,GAAG,8xCAA8xC;;;;;;;;"} \ No newline at end of file diff --git a/node_modules/minisearch/package.json b/node_modules/minisearch/package.json new file mode 100644 index 0000000..ce301de --- /dev/null +++ b/node_modules/minisearch/package.json @@ -0,0 +1,85 @@ +{ + "name": "minisearch", + "version": "4.0.3", + "description": "Tiny but powerful full-text search engine for browser and Node", + "main": "dist/umd/index.js", + "module": "dist/es5m/index.js", + "es2015": "dist/es/index.js", + "author": "Luca Ongaro", + "homepage": "https://lucaong.github.io/minisearch/", + "bugs": "https://github.com/lucaong/minisearch/issues", + "repository": { + "type": "git", + "url": "https://github.com/lucaong/minisearch.git" + }, + "keywords": [ + "search", + "full text", + "fuzzy", + "prefix", + "auto suggest", + "auto complete", + "index" + ], + "license": "MIT", + "dependencies": {}, + "devDependencies": { + "@rollup/plugin-typescript": "^8.2.0", + "@typescript-eslint/eslint-plugin": "^4.1.1", + "@typescript-eslint/parser": "^4.1.1", + "benchmark": "^2.1.4", + "core-js": "^3.1.4", + "coveralls": "^3.0.2", + "eslint": "^7.6.0", + "eslint-config-standard": "^16.0.2", + "eslint-plugin-import": "^2.20.2", + "eslint-plugin-node": "^11.1.0", + "eslint-plugin-promise": "^5.1.0", + "fast-check": "^2.1.0", + "jest": "^26.3.0", + "regenerator-runtime": "^0.13.1", + "rollup": "^2.2.0", + "rollup-plugin-dts": "^4.0.0", + "rollup-plugin-terser": "^7.0.0", + "snazzy": "^9.0.0", + "ts-jest": "^26.3.0", + "tslib": "^2.0.1", + "typedoc": "^0.19.1", + "typescript": "^4.0.2" + }, + "files": [ + "/dist/**/*", + "/src/**/*" + ], + "jest": { + "testURL": "http://localhost:3000/", + "transform": { + "\\.(js|ts)$": "ts-jest" + }, + "moduleFileExtensions": [ + "ts", + "js" + ], + "testRegex": "\\.test\\.(ts|js)$", + "setupFilesAfterEnv": [ + "/src/testSetup/jest.js" + ] + }, + "scripts": { + "test": "jest", + "test-watch": "jest --watch", + "coverage": "jest --coverage", + "benchmark": "yarn build-benchmark && NODE_ENV=production node --expose-gc benchmarks/dist/index.js", + "build-benchmark": "BENCHMARKS=true yarn build", + "build": "yarn clean-build && NODE_ENV=production rollup -c", + "clean-build": "rm -rf dist", + "build-minified": "MINIFY=true yarn build", + "build-docs": "typedoc --options typedoc.json && touch docs/.nojekyll && yarn build-examples", + "build-examples": "yarn build && cd examples && yarn install && yarn build && cd ../", + "lint": "eslint 'src/**/*.{js,ts}'", + "lintfix": "eslint --fix 'src/**/*.{js,ts}'", + "prepublishOnly": "yarn test && yarn build" + }, + "sideEffects": false, + "types": "./dist/types/index.d.ts" +} diff --git a/node_modules/minisearch/src/MiniSearch.test.js b/node_modules/minisearch/src/MiniSearch.test.js new file mode 100644 index 0000000..661f713 --- /dev/null +++ b/node_modules/minisearch/src/MiniSearch.test.js @@ -0,0 +1,976 @@ +/* eslint-env jest */ + +import MiniSearch from './MiniSearch' + +describe('MiniSearch', () => { + describe('constructor', () => { + it('throws error if fields option is missing', () => { + expect(() => new MiniSearch()).toThrow('MiniSearch: option "fields" must be provided') + }) + + it('initializes the attributes', () => { + const options = { fields: ['title', 'text'] } + const ms = new MiniSearch(options) + expect(ms._documentCount).toEqual(0) + expect(ms._fieldIds).toEqual({ title: 0, text: 1 }) + expect(ms._documentIds.size).toEqual(0) + expect(ms._fieldLength.size).toEqual(0) + expect(ms._averageFieldLength.length).toEqual(0) + expect(ms._options).toMatchObject(options) + }) + }) + + describe('add', () => { + it('adds the document to the index', () => { + const ms = new MiniSearch({ fields: ['text'] }) + ms.add({ id: 1, text: 'Nel mezzo del cammin di nostra vita' }) + expect(ms.documentCount).toEqual(1) + }) + + it('does not throw error if a field is missing', () => { + const ms = new MiniSearch({ fields: ['title', 'text'] }) + ms.add({ id: 1, text: 'Nel mezzo del cammin di nostra vita' }) + expect(ms.documentCount).toEqual(1) + }) + + it('throws error if the document does not have the ID field', () => { + const ms = new MiniSearch({ idField: 'foo', fields: ['title', 'text'] }) + expect(() => { + ms.add({ text: 'I do not have an ID' }) + }).toThrowError('MiniSearch: document does not have ID field "foo"') + }) + + it('extracts the ID field using extractField', () => { + const extractField = (document, fieldName) => { + if (fieldName === 'id') { return document.id.value } + return MiniSearch.getDefault('extractField')(document, fieldName) + } + const ms = new MiniSearch({ fields: ['text'], extractField }) + + ms.add({ id: { value: 123 }, text: 'Nel mezzo del cammin di nostra vita' }) + + const results = ms.search('vita') + expect(results[0].id).toEqual(123) + }) + + it('rejects falsy terms', () => { + const processTerm = term => term === 'foo' ? null : term + const ms = new MiniSearch({ fields: ['title', 'text'], processTerm }) + expect(() => { + ms.add({ id: 123, text: 'foo bar' }) + }).not.toThrowError() + }) + + it('turns the field to string before tokenization', () => { + const tokenize = jest.fn(x => x.split(/\W+/)) + const ms = new MiniSearch({ fields: ['id', 'tags', 'isBlinky'], tokenize }) + expect(() => { + ms.add({ id: 123, tags: ['foo', 'bar'], isBlinky: false }) + ms.add({ id: 321, isBlinky: true }) + }).not.toThrowError() + + expect(tokenize).toHaveBeenCalledWith('123', 'id') + expect(tokenize).toHaveBeenCalledWith('foo,bar', 'tags') + expect(tokenize).toHaveBeenCalledWith('false', 'isBlinky') + + expect(tokenize).toHaveBeenCalledWith('321', 'id') + expect(tokenize).toHaveBeenCalledWith('true', 'isBlinky') + }) + + it('passes document and field name to the field extractor', () => { + const extractField = jest.fn((document, fieldName) => { + if (fieldName === 'pubDate') { + return document[fieldName] && document[fieldName].toLocaleDateString('it-IT') + } + return fieldName.split('.').reduce((doc, key) => doc && doc[key], document) + }) + const tokenize = jest.fn(string => string.split(/\W+/)) + const ms = new MiniSearch({ + fields: ['title', 'pubDate', 'author.name'], + storeFields: ['category'], + extractField, + tokenize + }) + const document = { + id: 1, + title: 'Divina Commedia', + pubDate: new Date(1320, 0, 1), + author: { name: 'Dante Alighieri' }, + category: 'poetry' + } + ms.add(document) + expect(extractField).toHaveBeenCalledWith(document, 'title') + expect(extractField).toHaveBeenCalledWith(document, 'pubDate') + expect(extractField).toHaveBeenCalledWith(document, 'author.name') + expect(extractField).toHaveBeenCalledWith(document, 'category') + expect(tokenize).toHaveBeenCalledWith(document.title, 'title') + expect(tokenize).toHaveBeenCalledWith('1/1/1320', 'pubDate') + expect(tokenize).toHaveBeenCalledWith(document.author.name, 'author.name') + expect(tokenize).not.toHaveBeenCalledWith(document.category, 'category') + }) + + it('passes field value and name to tokenizer', () => { + const tokenize = jest.fn(string => string.split(/\W+/)) + const ms = new MiniSearch({ fields: ['text', 'title'], tokenize }) + const document = { id: 1, title: 'Divina Commedia', text: 'Nel mezzo del cammin di nostra vita' } + ms.add(document) + expect(tokenize).toHaveBeenCalledWith(document.text, 'text') + expect(tokenize).toHaveBeenCalledWith(document.title, 'title') + }) + + it('passes field value and name to term processor', () => { + const processTerm = jest.fn(term => term.toLowerCase()) + const ms = new MiniSearch({ fields: ['text', 'title'], processTerm }) + const document = { id: 1, title: 'Divina Commedia', text: 'Nel mezzo del cammin di nostra vita' } + ms.add(document) + document.text.split(/\W+/).forEach(term => { + expect(processTerm).toHaveBeenCalledWith(term, 'text') + }) + document.title.split(/\W+/).forEach(term => { + expect(processTerm).toHaveBeenCalledWith(term, 'title') + }) + }) + }) + + describe('remove', () => { + const documents = [ + { id: 1, title: 'Divina Commedia', text: 'Nel mezzo del cammin di nostra vita ... cammin' }, + { id: 2, title: 'I Promessi Sposi', text: 'Quel ramo del lago di Como' }, + { id: 3, title: 'Vita Nova', text: 'In quella parte del libro della mia memoria ... cammin' } + ] + + let ms, _warn + beforeEach(() => { + ms = new MiniSearch({ fields: ['title', 'text'] }) + ms.addAll(documents) + _warn = console.warn + console.warn = jest.fn() + }) + + afterEach(() => { + console.warn = _warn + }) + + it('removes the document from the index', () => { + expect(ms.documentCount).toEqual(3) + ms.remove(documents[0]) + expect(ms.documentCount).toEqual(2) + expect(ms.search('commedia').length).toEqual(0) + expect(ms.search('vita').map(({ id }) => id)).toEqual([3]) + expect(console.warn).not.toHaveBeenCalled() + }) + + it('cleans up all data of the deleted document', () => { + const otherDocument = { id: 4, title: 'Decameron', text: 'Umana cosa è aver compassione degli afflitti' } + const originalFieldLength = new Map(ms._fieldLength) + const originalAverageFieldLength = ms._averageFieldLength.slice() + + ms.add(otherDocument) + ms.remove(otherDocument) + + expect(ms.documentCount).toEqual(3) + expect(ms._fieldLength).toEqual(originalFieldLength) + expect(ms._averageFieldLength).toEqual(originalAverageFieldLength) + }) + + it('does not remove terms from other documents', () => { + ms.remove(documents[0]) + expect(ms.search('cammin').length).toEqual(1) + }) + + it('removes re-added document', () => { + ms.remove(documents[0]) + ms.add(documents[0]) + ms.remove(documents[0]) + expect(console.warn).not.toHaveBeenCalled() + }) + + it('removes documents when using a custom extractField', () => { + const extractField = (document, fieldName) => { + const path = fieldName.split('.') + return path.reduce((doc, key) => doc && doc[key], document) + } + const ms = new MiniSearch({ fields: ['text.value'], storeFields: ['id'], extractField }) + const document = { id: 123, text: { value: 'Nel mezzo del cammin di nostra vita' } } + ms.add(document) + + expect(() => { + ms.remove(document) + }).not.toThrowError() + + expect(ms.search('vita')).toEqual([]) + }) + + it('cleans up the index', () => { + const originalIdsSize = ms._documentIds.size + ms.remove(documents[0]) + expect(ms._index.has('commedia')).toEqual(false) + expect(ms._documentIds.size).toEqual(originalIdsSize - 1) + expect(Array.from(ms._index.get('vita').keys())).toEqual([ms._fieldIds.title]) + }) + + it('throws error if the document does not have the ID field', () => { + const ms = new MiniSearch({ idField: 'foo', fields: ['title', 'text'] }) + expect(() => { + ms.remove({ text: 'I do not have an ID' }) + }).toThrowError('MiniSearch: document does not have ID field "foo"') + }) + + it('extracts the ID field using extractField', () => { + const extractField = (document, fieldName) => { + if (fieldName === 'id') { return document.id.value } + return MiniSearch.getDefault('extractField')(document, fieldName) + } + const ms = new MiniSearch({ fields: ['text'], extractField }) + const document = { id: { value: 123 }, text: 'Nel mezzo del cammin di nostra vita' } + ms.add(document) + + expect(() => { + ms.remove(document) + }).not.toThrowError() + + expect(ms.search('vita')).toEqual([]) + }) + + it('does not crash when the document has field named like default properties of object', () => { + const ms = new MiniSearch({ fields: ['constructor'] }) + const document = { id: 1 } + ms.add(document) + + expect(() => { + ms.remove(document) + }).not.toThrowError() + }) + + it('does not reassign IDs', () => { + ms.remove(documents[0]) + ms.add(documents[0]) + expect(ms.search('commedia').map(result => result.id)).toEqual([documents[0].id]) + expect(ms.search('nova').map(result => result.id)).toEqual([documents[documents.length - 1].id]) + }) + + it('rejects falsy terms', () => { + const processTerm = term => term === 'foo' ? null : term + const ms = new MiniSearch({ fields: ['title', 'text'], processTerm }) + const document = { id: 123, title: 'foo bar' } + ms.add(document) + expect(() => { + ms.remove(document) + }).not.toThrowError() + }) + + describe('when using custom per-field extraction/tokenizer/processing', () => { + const documents = [ + { id: 1, title: 'Divina Commedia', tags: 'dante,virgilio', author: { name: 'Dante Alighieri' } }, + { id: 2, title: 'I Promessi Sposi', tags: 'renzo,lucia', author: { name: 'Alessandro Manzoni' } }, + { id: 3, title: 'Vita Nova', author: { name: 'Dante Alighieri' } } + ] + + let ms, _warn + beforeEach(() => { + ms = new MiniSearch({ + fields: ['title', 'tags', 'authorName'], + extractField: (doc, fieldName) => { + if (fieldName === 'authorName') { + return doc.author.name + } else { + return doc[fieldName] + } + }, + tokenize: (field, fieldName) => { + if (fieldName === 'tags') { + return field.split(',') + } else { + return field.split(/\s+/) + } + }, + processTerm: (term, fieldName) => { + if (fieldName === 'tags') { + return term.toUpperCase() + } else { + return term.toLowerCase() + } + } + }) + ms.addAll(documents) + _warn = console.warn + console.warn = jest.fn() + }) + + afterEach(() => { + console.warn = _warn + }) + + it('removes the document from the index', () => { + expect(ms.documentCount).toEqual(3) + ms.remove(documents[0]) + expect(ms.documentCount).toEqual(2) + expect(ms.search('commedia').length).toEqual(0) + expect(ms.search('vita').map(({ id }) => id)).toEqual([3]) + expect(console.warn).not.toHaveBeenCalled() + }) + }) + + describe('when the document was not in the index', () => { + it('throws an error', () => { + expect(() => ms.remove({ id: 99 })) + .toThrow('MiniSearch: cannot remove document with ID 99: it is not in the index') + }) + }) + + describe('when the document has changed', () => { + it('warns of possible index corruption', () => { + expect(() => ms.remove({ id: 1, title: 'Divina Commedia cammin', text: 'something has changed' })) + .not.toThrow() + expect(console.warn).toHaveBeenCalledTimes(4) + ;[ + ['cammin', 'title'], + ['something', 'text'], + ['has', 'text'], + ['changed', 'text'] + ].forEach(([term, field], i) => { + expect(console.warn).toHaveBeenNthCalledWith(i + 1, `MiniSearch: document with ID 1 has changed before removal: term "${term}" was not present in field "${field}". Removing a document after it has changed can corrupt the index!`) + }) + }) + + it('does not throw error if console.warn is undefined', () => { + console.warn = undefined + expect(() => ms.remove({ id: 1, title: 'Divina Commedia cammin', text: 'something has changed' })) + .not.toThrow() + }) + }) + }) + + describe('removeAll', () => { + const documents = [ + { id: 1, title: 'Divina Commedia', text: 'Nel mezzo del cammin di nostra vita ... cammin' }, + { id: 2, title: 'I Promessi Sposi', text: 'Quel ramo del lago di Como' }, + { id: 3, title: 'Vita Nova', text: 'In quella parte del libro della mia memoria ... cammin' } + ] + + let ms, _warn + beforeEach(() => { + ms = new MiniSearch({ fields: ['title', 'text'] }) + _warn = console.warn + console.warn = jest.fn() + }) + + afterEach(() => { + console.warn = _warn + }) + + it('removes all documents from the index if called with no argument', () => { + const empty = MiniSearch.loadJSON(JSON.stringify(ms), { + fields: ['title', 'text'] + }) + + ms.addAll(documents) + expect(ms.documentCount).toEqual(3) + + ms.removeAll() + + expect(ms).toEqual(empty) + }) + + it('removes the given documents from the index', () => { + ms.addAll(documents) + expect(ms.documentCount).toEqual(3) + + ms.removeAll([documents[0], documents[2]]) + + expect(ms.documentCount).toEqual(1) + expect(ms.search('commedia').length).toEqual(0) + expect(ms.search('vita').length).toEqual(0) + expect(ms.search('lago').length).toEqual(1) + }) + + it('raises an error if called with a falsey argument', () => { + expect(() => { ms.removeAll(null) }).toThrowError() + expect(() => { ms.removeAll(undefined) }).toThrowError() + expect(() => { ms.removeAll(false) }).toThrowError() + expect(() => { ms.removeAll([]) }).not.toThrowError() + }) + }) + + describe('addAll', () => { + it('adds all the documents to the index', () => { + const ms = new MiniSearch({ fields: ['text'] }) + const documents = [ + { id: 1, text: 'Nel mezzo del cammin di nostra vita' }, + { id: 2, text: 'Mi ritrovai per una selva oscura' } + ] + ms.addAll(documents) + expect(ms.documentCount).toEqual(documents.length) + }) + }) + + describe('addAllAsync', () => { + it('adds all the documents to the index', () => { + const ms = new MiniSearch({ fields: ['text'] }) + const documents = [ + { id: 1, text: 'Nel mezzo' }, + { id: 2, text: 'del cammin' }, + { id: 3, text: 'di nostra vita' }, + { id: 4, text: 'Mi ritrovai' }, + { id: 5, text: 'per una' }, + { id: 6, text: 'selva oscura' }, + { id: 7, text: 'ché la' }, + { id: 8, text: 'diritta via' }, + { id: 9, text: 'era smarrita' }, + { id: 10, text: 'ahi quanto' }, + { id: 11, text: 'a dir' }, + { id: 12, text: 'qual era' }, + { id: 13, text: 'è cosa dura' } + ] + + return ms.addAllAsync(documents).then(() => { + expect(ms.documentCount).toEqual(documents.length) + }) + }) + + it('accepts a chunkSize option', () => { + const ms = new MiniSearch({ fields: ['text'] }) + const documents = [ + { id: 1, text: 'Nel mezzo' }, + { id: 2, text: 'del cammin' }, + { id: 3, text: 'di nostra vita' }, + { id: 4, text: 'Mi ritrovai' }, + { id: 5, text: 'per una' }, + { id: 6, text: 'selva oscura' }, + { id: 7, text: 'ché la' }, + { id: 8, text: 'diritta via' }, + { id: 9, text: 'era smarrita' }, + { id: 10, text: 'ahi quanto' }, + { id: 11, text: 'a dir' }, + { id: 12, text: 'qual era' }, + { id: 13, text: 'è cosa dura' } + ] + + return ms.addAllAsync(documents, { chunkSize: 3 }).then(() => { + expect(ms.documentCount).toEqual(documents.length) + }) + }) + }) + + describe('search', () => { + const documents = [ + { id: 1, title: 'Divina Commedia', text: 'Nel mezzo del cammin di nostra vita' }, + { id: 2, title: 'I Promessi Sposi', text: 'Quel ramo del lago di Como', lang: 'it', category: 'fiction' }, + { id: 3, title: 'Vita Nova', text: 'In quella parte del libro della mia memoria', category: 'poetry' } + ] + const ms = new MiniSearch({ fields: ['title', 'text'], storeFields: ['lang', 'category'] }) + ms.addAll(documents) + + it('returns scored results', () => { + const results = ms.search('vita') + expect(results.length).toBeGreaterThan(0) + expect(results.map(({ id }) => id).sort()).toEqual([1, 3]) + expect(results[0].score).toBeGreaterThanOrEqual(results[1].score) + }) + + it('returns stored fields in the results', () => { + const results = ms.search('del') + expect(results.length).toBeGreaterThan(0) + expect(results.map(({ lang }) => lang).sort()).toEqual(['it', undefined, undefined]) + expect(results.map(({ category }) => category).sort()).toEqual(['fiction', 'poetry', undefined]) + }) + + it('returns empty array if there is no match', () => { + const results = ms.search('paguro') + expect(results).toEqual([]) + }) + + it('returns empty array for empty search', () => { + const results = ms.search('') + expect(results).toEqual([]) + }) + + it('returns empty results for terms that are not in the index', () => { + let results + expect(() => { + results = ms.search('sottomarino aeroplano') + }).not.toThrowError() + expect(results.length).toEqual(0) + }) + + it('boosts fields', () => { + const results = ms.search('vita', { boost: { title: 2 } }) + expect(results.map(({ id }) => id)).toEqual([3, 1]) + expect(results[0].score).toBeGreaterThan(results[1].score) + }) + + it('computes a meaningful score when fields are named liked default properties of object', () => { + const ms = new MiniSearch({ fields: ['constructor'] }) + ms.add({ id: 1, constructor: 'something' }) + ms.add({ id: 1, constructor: 'something else' }) + + const results = ms.search('something') + results.forEach((result) => { + expect(Number.isFinite(result.score)).toBe(true) + }) + }) + + it('searches in the given fields', () => { + const results = ms.search('vita', { fields: ['title'] }) + expect(results).toHaveLength(1) + expect(results[0].id).toEqual(3) + }) + + it('combines results with OR by default', () => { + const results = ms.search('cammin como sottomarino') + expect(results.length).toEqual(2) + expect(results.map(({ id }) => id)).toEqual([2, 1]) + }) + + it('combines results with AND if combineWith is AND', () => { + const results = ms.search('vita cammin', { combineWith: 'AND' }) + expect(results.length).toEqual(1) + expect(results.map(({ id }) => id)).toEqual([1]) + expect(ms.search('vita sottomarino', { combineWith: 'AND' }).length).toEqual(0) + expect(ms.search('sottomarino vita', { combineWith: 'AND' }).length).toEqual(0) + }) + + it('combines results with AND_NOT if combineWith is AND_NOT', () => { + const results = ms.search('vita cammin', { combineWith: 'AND_NOT' }) + expect(results.length).toEqual(1) + expect(results.map(({ id }) => id)).toEqual([3]) + expect(ms.search('vita sottomarino', { combineWith: 'AND_NOT' }).length).toEqual(2) + expect(ms.search('sottomarino vita', { combineWith: 'AND_NOT' }).length).toEqual(0) + }) + + it('returns empty results for empty search', () => { + expect(ms.search('')).toEqual([]) + expect(ms.search('', { combineWith: 'OR' })).toEqual([]) + expect(ms.search('', { combineWith: 'AND' })).toEqual([]) + expect(ms.search('', { combineWith: 'AND_NOT' })).toEqual([]) + }) + + it('executes fuzzy search', () => { + const results = ms.search('camin memory', { fuzzy: 2 }) + expect(results.length).toEqual(2) + expect(results.map(({ id }) => id)).toEqual([1, 3]) + }) + + it('executes fuzzy search with maximum fuzziness', () => { + const results = ms.search('comedia', { fuzzy: 0.6, maxFuzzy: 3 }) + expect(results.length).toEqual(1) + expect(results.map(({ id }) => id)).toEqual([1]) + }) + + it('executes prefix search', () => { + const results = ms.search('que', { prefix: true }) + expect(results.length).toEqual(2) + expect(results.map(({ id }) => id)).toEqual([2, 3]) + }) + + it('combines prefix search and fuzzy search', () => { + const results = ms.search('cammino quel', { fuzzy: 0.25, prefix: true }) + expect(results.length).toEqual(3) + expect(results.map(({ id }) => id)).toEqual([2, 1, 3]) + }) + + it('assigns weights to prefix matches and fuzzy matches', () => { + const exact = ms.search('cammino quel') + expect(exact.map(({ id }) => id)).toEqual([2]) + + const prefixLast = ms.search('cammino quel', { fuzzy: true, prefix: true, weights: { prefix: 0.1 } }) + expect(prefixLast.map(({ id }) => id)).toEqual([2, 1, 3]) + expect(prefixLast[0].score).toEqual(exact[0].score) + + const fuzzyLast = ms.search('cammino quel', { fuzzy: true, prefix: true, weights: { fuzzy: 0.1 } }) + expect(fuzzyLast.map(({ id }) => id)).toEqual([2, 3, 1]) + expect(fuzzyLast[0].score).toEqual(exact[0].score) + }) + + it('assigns weight lower than exact match to a match that is both a prefix and fuzzy match', () => { + const ms = new MiniSearch({ fields: ['text'] }) + const documents = [ + { id: 1, text: 'Poi che la gente poverella crebbe' }, + { id: 2, text: 'Deus, venerunt gentes' } + ] + ms.addAll(documents) + expect(ms.documentCount).toEqual(documents.length) + + const exact = ms.search('gente') + const combined = ms.search('gente', { fuzzy: 0.2, prefix: true }) + expect(combined.map(({ id }) => id)).toEqual([1, 2]) + expect(combined[0].score).toEqual(exact[0].score) + expect(combined[1].match.gentes).toEqual(['text']) + }) + + it('accepts a function to compute fuzzy and prefix options from term', () => { + const fuzzy = jest.fn(term => term.length > 4 ? 2 : false) + const prefix = jest.fn(term => term.length > 4) + const results = ms.search('quel comedia', { fuzzy, prefix }) + expect(fuzzy).toHaveBeenNthCalledWith(1, 'quel', 0, ['quel', 'comedia']) + expect(fuzzy).toHaveBeenNthCalledWith(2, 'comedia', 1, ['quel', 'comedia']) + expect(prefix).toHaveBeenNthCalledWith(1, 'quel', 0, ['quel', 'comedia']) + expect(prefix).toHaveBeenNthCalledWith(2, 'comedia', 1, ['quel', 'comedia']) + expect(results.length).toEqual(2) + expect(results.map(({ id }) => id)).toEqual([2, 1]) + }) + + it('boosts documents by calling boostDocument with document ID and term', () => { + const query = 'divina commedia' + const boostFactor = 1.234 + const boostDocument = jest.fn((id, term) => boostFactor) + const resultsWithoutBoost = ms.search(query) + const results = ms.search(query, { boostDocument }) + expect(boostDocument).toHaveBeenCalledWith(1, 'divina') + expect(boostDocument).toHaveBeenCalledWith(1, 'commedia') + expect(results[0].score).toEqual(resultsWithoutBoost[0].score * boostFactor) + }) + + it('skips document if boostDocument returns a falsy value', () => { + const query = 'vita' + const boostDocument = jest.fn((id, term) => id === 3 ? null : 1) + const resultsWithoutBoost = ms.search(query) + const results = ms.search(query, { boostDocument }) + expect(resultsWithoutBoost.map(({ id }) => id)).toContain(3) + expect(results.map(({ id }) => id)).not.toContain(3) + }) + + it('uses a specific search-time tokenizer if specified', () => { + const tokenize = (string) => string.split('X') + const results = ms.search('divinaXcommedia', { tokenize }) + expect(results.length).toBeGreaterThan(0) + expect(results.map(({ id }) => id).sort()).toEqual([1]) + }) + + it('uses a specific search-time term processing function if specified', () => { + const processTerm = (string) => string.replace(/1/g, 'i').replace(/4/g, 'a').toLowerCase() + const results = ms.search('d1v1n4', { processTerm }) + expect(results.length).toBeGreaterThan(0) + expect(results.map(({ id }) => id).sort()).toEqual([1]) + }) + + it('rejects falsy terms', () => { + const processTerm = (term) => term === 'quel' ? null : term + const results = ms.search('quel commedia', { processTerm }) + expect(results.length).toBeGreaterThan(0) + expect(results.map(({ id }) => id).sort()).toEqual([1]) + }) + + it('allows custom filtering of results on the basis of stored fields', () => { + const results = ms.search('del', { + filter: ({ category }) => category === 'poetry' + }) + expect(results.length).toBe(1) + expect(results.every(({ category }) => category === 'poetry')).toBe(true) + }) + + describe('when passing a query tree', () => { + it('searches according to the given combination', () => { + const results = ms.search({ + combineWith: 'OR', + queries: [ + { + combineWith: 'AND', + queries: ['vita', 'cammin'] + }, + 'como sottomarino', + { + combineWith: 'AND', + queries: ['nova', 'pappagallo'] + } + ] + }) + expect(results.length).toEqual(2) + expect(results.map(({ id }) => id)).toEqual([1, 2]) + }) + + it('uses the given options for each subquery, cascading them properly', () => { + const results = ms.search({ + combineWith: 'OR', + fuzzy: true, + queries: [ + { + prefix: true, + fields: ['title'], + queries: ['vit'] + }, + { + combineWith: 'AND', + queries: ['bago', 'coomo'] + } + ], + weights: { + fuzzy: 0.2, + prefix: 0.75 + } + }) + + expect(results.length).toEqual(2) + expect(results.map(({ id }) => id)).toEqual([3, 2]) + }) + }) + + describe('match data', () => { + const documents = [ + { id: 1, title: 'Divina Commedia', text: 'Nel mezzo del cammin di nostra vita' }, + { id: 2, title: 'I Promessi Sposi', text: 'Quel ramo del lago di Como' }, + { id: 3, title: 'Vita Nova', text: 'In quella parte del libro della mia memoria ... vita' } + ] + const ms = new MiniSearch({ fields: ['title', 'text'] }) + ms.addAll(documents) + + it('reports information about matched terms and fields', () => { + const results = ms.search('vita nova') + expect(results.length).toBeGreaterThan(0) + expect(results.map(({ match }) => match)).toEqual([ + { vita: ['title', 'text'], nova: ['title'] }, + { vita: ['text'] } + ]) + expect(results.map(({ terms }) => terms)).toEqual([ + ['vita', 'nova'], + ['vita'] + ]) + }) + + it('reports correct info when combining terms with AND', () => { + const results = ms.search('vita nova', { combineWith: 'AND' }) + expect(results.map(({ match }) => match)).toEqual([ + { vita: ['title', 'text'], nova: ['title'] } + ]) + expect(results.map(({ terms }) => terms)).toEqual([ + ['vita', 'nova'] + ]) + }) + + it('reports correct info for fuzzy and prefix queries', () => { + const results = ms.search('vi nuova', { fuzzy: 0.2, prefix: true }) + expect(results.map(({ match }) => match)).toEqual([ + { vita: ['title', 'text'], nova: ['title'] }, + { vita: ['text'] } + ]) + expect(results.map(({ terms }) => terms)).toEqual([ + ['vita', 'nova'], + ['vita'] + ]) + }) + + it('reports correct info for many fuzzy and prefix queries', () => { + const results = ms.search('vi nuova m de', { fuzzy: 0.2, prefix: true }) + expect(results.map(({ match }) => match)).toEqual([ + { del: ['text'], della: ['text'], memoria: ['text'], mia: ['text'], vita: ['title', 'text'], nova: ['title'] }, + { del: ['text'], mezzo: ['text'], vita: ['text'] }, + { del: ['text'] } + ]) + expect(results.map(({ terms }) => terms)).toEqual([ + ['vita', 'nova', 'memoria', 'mia', 'della', 'del'], + ['vita', 'mezzo', 'del'], + ['del'] + ]) + }) + + it('passes only the query to tokenize', () => { + const tokenize = jest.fn(string => string.split(/\W+/)) + const ms = new MiniSearch({ fields: ['text', 'title'], searchOptions: { tokenize } }) + const query = 'some search query' + ms.search(query) + expect(tokenize).toHaveBeenCalledWith(query) + }) + + it('passes only the term to processTerm', () => { + const processTerm = jest.fn(term => term.toLowerCase()) + const ms = new MiniSearch({ fields: ['text', 'title'], searchOptions: { processTerm } }) + const query = 'some search query' + ms.search(query) + query.split(/\W+/).forEach(term => { + expect(processTerm).toHaveBeenCalledWith(term) + }) + }) + + it('does not break when special properties of object are used as a term', () => { + const specialWords = ['constructor', 'hasOwnProperty', 'isPrototypeOf'] + const ms = new MiniSearch({ fields: ['text'] }) + const processTerm = MiniSearch.getDefault('processTerm') + + ms.add({ id: 1, text: specialWords.join(' ') }) + + specialWords.forEach((word) => { + expect(() => { ms.search(word) }).not.toThrowError() + + const results = ms.search(word) + expect(results[0].id).toEqual(1) + expect(results[0].match[processTerm(word)]).toEqual(['text']) + }) + }) + }) + }) + + describe('default tokenization', () => { + it('splits on non-alphanumeric taking diacritics into account', () => { + const documents = [ + { + id: 1, + text: + `Se la vita è sventura, +perché da noi si dura? +Intatta luna, tale +è lo stato mortale. +Ma tu mortal non sei, +e forse del mio dir poco ti cale` + }, + { + id: 2, + text: 'The estimates range from roughly 1 in 100 to 1 in 100,000. The higher figures come from the working engineers, and the very low figures from management. What are the causes and consequences of this lack of agreement? Since 1 part in 100,000 would imply that one could put a Shuttle up each day for 300 years expecting to lose only one, we could properly ask "What is the cause of management\'s fantastic faith in the machinery?"' + } + ] + const ms = new MiniSearch({ fields: ['text'] }) + ms.addAll(documents) + expect(ms.search('perché').length).toBeGreaterThan(0) + expect(ms.search('perch').length).toEqual(0) + expect(ms.search('luna').length).toBeGreaterThan(0) + + expect(ms.search('300').length).toBeGreaterThan(0) + expect(ms.search('machinery').length).toBeGreaterThan(0) + }) + + it('supports non-latin alphabets', () => { + const documents = [ + { id: 1, title: 'София София' }, + { id: 2, title: 'アネモネ' }, + { id: 3, title: '«τέχνη»' }, + { id: 4, title: 'سمت الرأس' }, + { id: 5, title: '123 45' } + ] + const ms = new MiniSearch({ fields: ['title'] }) + ms.addAll(documents) + + expect(ms.search('софия').map(({ id }) => id)).toEqual([1]) + expect(ms.search('アネモネ').map(({ id }) => id)).toEqual([2]) + expect(ms.search('τέχνη').map(({ id }) => id)).toEqual([3]) + expect(ms.search('الرأس').map(({ id }) => id)).toEqual([4]) + expect(ms.search('123').map(({ id }) => id)).toEqual([5]) + }) + }) + + describe('autoSuggest', () => { + const documents = [ + { id: 1, title: 'Divina Commedia', text: 'Nel mezzo del cammin di nostra vita', category: 'poetry' }, + { id: 2, title: 'I Promessi Sposi', text: 'Quel ramo del lago di Como', category: 'fiction' }, + { id: 3, title: 'Vita Nova', text: 'In quella parte del libro della mia memoria', category: 'poetry' } + ] + const ms = new MiniSearch({ fields: ['title', 'text'], storeFields: ['category'] }) + ms.addAll(documents) + + it('returns scored suggestions', () => { + const results = ms.autoSuggest('com') + expect(results.length).toBeGreaterThan(0) + expect(results.map(({ suggestion }) => suggestion)).toEqual(['como', 'commedia']) + expect(results[0].score).toBeGreaterThan(results[1].score) + }) + + it('returns empty array if there is no match', () => { + const results = ms.autoSuggest('paguro') + expect(results).toEqual([]) + }) + + it('returns empty array for empty search', () => { + const results = ms.autoSuggest('') + expect(results).toEqual([]) + }) + + it('returns scored suggestions for multi-word queries', () => { + const results = ms.autoSuggest('vita no') + expect(results.length).toBeGreaterThan(0) + expect(results.map(({ suggestion }) => suggestion)).toEqual(['vita nova', 'vita nostra']) + expect(results[0].score).toBeGreaterThan(results[1].score) + }) + + it('respects the order of the terms in the query', () => { + const results = ms.autoSuggest('nostra vi') + expect(results.map(({ suggestion }) => suggestion)).toEqual(['nostra vita', 'vita']) + }) + + it('returns empty suggestions for terms that are not in the index', () => { + let results + expect(() => { + results = ms.autoSuggest('sottomarino aeroplano') + }).not.toThrowError() + expect(results.length).toEqual(0) + }) + + it('does not duplicate suggested terms', () => { + const results = ms.autoSuggest('vita', { fuzzy: true, prefix: true }) + expect(results[0].suggestion).toEqual('vita') + expect(results[0].terms).toEqual(['vita']) + }) + + it('applies the given custom filter', () => { + let results = ms.autoSuggest('que', { + filter: ({ category }) => category === 'fiction' + }) + expect(results[0].suggestion).toEqual('quel') + expect(results).toHaveLength(1) + + results = ms.autoSuggest('que', { + filter: ({ category }) => category === 'poetry' + }) + expect(results[0].suggestion).toEqual('quella') + expect(results).toHaveLength(1) + }) + }) + + describe('loadJSON', () => { + const documents = [ + { id: 1, title: 'Divina Commedia', text: 'Nel mezzo del cammin di nostra vita', category: 'poetry' }, + { id: 2, title: 'I Promessi Sposi', text: 'Quel ramo del lago di Como', category: 'fiction' }, + { id: 3, title: 'Vita Nova', text: 'In quella parte del libro della mia memoria', category: 'poetry' } + ] + + it('loads a JSON-serialized search index', () => { + const options = { fields: ['title', 'text'], storeFields: ['category'] } + const ms = new MiniSearch(options) + ms.addAll(documents) + + const json = JSON.stringify(ms) + const deserialized = MiniSearch.loadJSON(json, options) + expect(ms.search('vita')).toEqual(deserialized.search('vita')) + + const original = ms.toJSON() + const final = deserialized.toJSON() + + // Normalize order of data in the serialized index + original.index.sort() + final.index.sort() + + expect(original).toEqual(final) + }) + + it('raises an error if called without options', () => { + const options = { fields: ['title', 'text'] } + const ms = new MiniSearch(options) + ms.addAll(documents) + const json = JSON.stringify(ms) + expect(() => { + MiniSearch.loadJSON(json) + }).toThrowError('MiniSearch: loadJSON should be given the same options used when serializing the index') + }) + + it('raises an error if given an incompatible serialized version', () => { + const options = { fields: ['title', 'text'] } + const json = '{}' + + expect(() => { + MiniSearch.loadJSON(json, options) + }).toThrowError('MiniSearch: cannot deserialize an index created with an incompatible version') + }) + }) + + describe('getDefault', () => { + it('returns the default value of the given option', () => { + expect(MiniSearch.getDefault('idField')).toEqual('id') + expect(MiniSearch.getDefault('extractField')).toBeInstanceOf(Function) + expect(MiniSearch.getDefault('tokenize')).toBeInstanceOf(Function) + expect(MiniSearch.getDefault('processTerm')).toBeInstanceOf(Function) + expect(MiniSearch.getDefault('searchOptions')).toBe(undefined) + expect(MiniSearch.getDefault('fields')).toBe(undefined) + }) + + it('throws an error if there is no option with the given name', () => { + expect(() => { MiniSearch.getDefault('foo') }).toThrowError('MiniSearch: unknown option "foo"') + }) + }) +}) diff --git a/node_modules/minisearch/src/MiniSearch.ts b/node_modules/minisearch/src/MiniSearch.ts new file mode 100644 index 0000000..a848cc2 --- /dev/null +++ b/node_modules/minisearch/src/MiniSearch.ts @@ -0,0 +1,1387 @@ +import SearchableMap from './SearchableMap/SearchableMap' + +const OR = 'or' +const AND = 'and' +const AND_NOT = 'and_not' + +/** + * Search options to customize the search behavior. + */ +export type SearchOptions = { + /** + * Names of the fields to search in. If omitted, all fields are searched. + */ + fields?: string[], + + /** + * Function used to filter search results, for example on the basis of stored + * fields. It takes as argument each search result and should return a boolean + * to indicate if the result should be kept or not. + */ + filter?: (result: SearchResult) => boolean, + + /** + * Key-value object of field names to boosting values. By default, fields are + * assigned a boosting factor of 1. If one assigns to a field a boosting value + * of 2, a result that matches the query in that field is assigned a score + * twice as high as a result matching the query in another field, all else + * being equal. + */ + boost?: { [fieldName: string]: number }, + + /** + * Relative weights to assign to prefix search results and fuzzy search + * results. Exact matches are assigned a weight of 1. + */ + weights?: { fuzzy: number, prefix: number }, + + /** + * Function to calculate a boost factor for documents. It takes as arguments + * the document ID, and a term that matches the search in that document, and + * should return a boosting factor. + */ + boostDocument?: (documentId: any, term: string) => number, + + /** + * Controls whether to perform prefix search. It can be a simple boolean, or a + * function. + * + * If a boolean is passed, prefix search is performed if true. + * + * If a function is passed, it is called upon search with a search term, the + * positional index of that search term in the tokenized search query, and the + * tokenized search query. The function should return a boolean to indicate + * whether to perform prefix search for that search term. + */ + prefix?: boolean | ((term: string, index: number, terms: string[]) => boolean), + + /** + * Controls whether to perform fuzzy search. It can be a simple boolean, or a + * number, or a function. + * + * If a boolean is given, fuzzy search with a default fuzziness parameter is + * performed if true. + * + * If a number higher or equal to 1 is given, fuzzy search is performed, with + * a maximum edit distance (Levenshtein) equal to the number. + * + * If a number between 0 and 1 is given, fuzzy search is performed within a + * maximum edit distance corresponding to that fraction of the term length, + * approximated to the nearest integer. For example, 0.2 would mean an edit + * distance of 20% of the term length, so 1 character in a 5-characters term. + * The calculated fuzziness value is limited by the `maxFuzzy` option, to + * prevent slowdown for very long queries. + * + * If a function is passed, the function is called upon search with a search + * term, a positional index of that term in the tokenized search query, and + * the tokenized search query. It should return a boolean or a number, with + * the meaning documented above. + */ + fuzzy?: boolean | number | ((term: string, index: number, terms: string[]) => boolean | number), + + /** + * Controls the maximum fuzziness when using a fractional fuzzy value. This is + * set to 6 by default. Very high edit distances usually don't produce + * meaningful results, but can excessively impact search performance. + */ + maxFuzzy?: number, + + /** + * The operand to combine partial results for each term. By default it is + * "OR", so results matching _any_ of the search terms are returned by a + * search. If "AND" is given, only results matching _all_ the search terms are + * returned by a search. + */ + combineWith?: string, + + /** + * Function to tokenize the search query. By default, the same tokenizer used + * for indexing is used also for search. + */ + tokenize?: (text: string) => string[], + + /** + * Function to process or normalize terms in the search query. By default, the + * same term processor used for indexing is used also for search. + */ + processTerm?: (term: string) => string | null | undefined | false +} + +type SearchOptionsWithDefaults = SearchOptions & { + boost: { [fieldName: string]: number }, + + weights: { fuzzy: number, prefix: number }, + + prefix: boolean | ((term: string, index: number, terms: string[]) => boolean), + + fuzzy: boolean | number | ((term: string, index: number, terms: string[]) => boolean | number), + + maxFuzzy: number, + + combineWith: string +} + +/** + * Configuration options passed to the [[MiniSearch]] constructor + * + * @typeParam T The type of documents being indexed. + */ +export type Options = { + /** + * Names of the document fields to be indexed. + */ + fields: string[], + + /** + * Name of the ID field, uniquely identifying a document. + */ + idField?: string, + + /** + * Names of fields to store, so that search results would include them. By + * default none, so resuts would only contain the id field. + */ + storeFields?: string[], + + /** + * Function used to extract the value of each field in documents. By default, + * the documents are assumed to be plain objects with field names as keys, + * but by specifying a custom `extractField` function one can completely + * customize how the fields are extracted. + * + * The function takes as arguments the document, and the name of the field to + * extract from it. It should return the field value as a string. + */ + extractField?: (document: T, fieldName: string) => string, + + /* + * Function used to split a field value into individual terms to be indexed. + * The default tokenizer separates terms by space or punctuation, but a + * custom tokenizer can be provided for custom logic. + * + * The function takes as arguments string to tokenize, and the name of the + * field it comes from. It should return the terms as an array of strings. + * When used for tokenizing a search query instead of a document field, the + * `fieldName` is undefined. + */ + tokenize?: (text: string, fieldName?: string) => string[], + + /** + * Function used to process a term before indexing or search. This can be + * used for normalization (such as stemming). By default, terms are + * downcased, and otherwise no other normalization is performed. + * + * The function takes as arguments a term to process, and the name of the + * field it comes from. It should return the processed term as a string, or a + * falsy value to reject the term entirely. + */ + processTerm?: (term: string, fieldName?: string) => string | null | undefined | false, + + /** + * Default search options (see the [[SearchOptions]] type and the + * [[MiniSearch.search]] method for details) + */ + searchOptions?: SearchOptions +} + +type OptionsWithDefaults = Options & { + storeFields: string[], + + idField: string, + + extractField: (document: T, fieldName: string) => string, + + tokenize: (text: string, fieldName: string) => string[], + + processTerm: (term: string, fieldName: string) => string | null | undefined | false, + + searchOptions: SearchOptionsWithDefaults +} + +/** + * The type of auto-suggestions + */ +export type Suggestion = { + /** + * The suggestion + */ + suggestion: string, + + /** + * Suggestion as an array of terms + */ + terms: string[], + + /** + * Score for the suggestion + */ + score: number +} + +/** + * Match information for a search result. It is a key-value object where keys + * are terms that matched, and values are the list of fields that the term was + * found in. + */ +export type MatchInfo = { + [term: string]: string[] +} + +/** + * Type of the search results. Each search result indicates the document ID, the + * terms that matched, the match information, the score, and all the stored + * fields. + */ +export type SearchResult = { + /** + * The document ID + */ + id: any, + + /** + * List of terms that matched + */ + terms: string[], + + /** + * Score of the search results + */ + score: number, + + /** + * Match information, see [[MatchInfo]] + */ + match: MatchInfo, + + /** + * Stored fields + */ + [key: string]: any +} + +/** + * @ignore + */ +export type AsPlainObject = { + documentCount: number, + nextId: number, + documentIds: { [shortId: string]: any } + fieldIds: { [fieldName: string]: number } + fieldLength: { [shortId: string]: number[] } + averageFieldLength: number[], + storedFields: { [shortId: string]: any } + index: [string, { [fieldId: string]: SerializedIndexEntry }][] + serializationVersion: number +} + +export type QueryCombination = SearchOptions & { queries: Query[] } + +/** + * Search query expression, either a query string or an expression tree + * combining several queries with a combination of AND or OR. + */ +export type Query = QueryCombination | string + +type QuerySpec = { + prefix: boolean, + fuzzy: number | boolean, + term: string +} + +type IndexEntry = { df: number, ds: Map } +type IndexData = Map + +type RawResultValue = { score: number, match: MatchInfo, terms: string[] } +type RawResult = Map + +/** + * [[MiniSearch]] is the main entrypoint class, implementing a full-text search + * engine in memory. + * + * @typeParam T The type of the documents being indexed. + * + * ### Basic example: + * + * ```javascript + * const documents = [ + * { + * id: 1, + * title: 'Moby Dick', + * text: 'Call me Ishmael. Some years ago...', + * category: 'fiction' + * }, + * { + * id: 2, + * title: 'Zen and the Art of Motorcycle Maintenance', + * text: 'I can see by my watch...', + * category: 'fiction' + * }, + * { + * id: 3, + * title: 'Neuromancer', + * text: 'The sky above the port was...', + * category: 'fiction' + * }, + * { + * id: 4, + * title: 'Zen and the Art of Archery', + * text: 'At first sight it must seem...', + * category: 'non-fiction' + * }, + * // ...and more + * ] + * + * // Create a search engine that indexes the 'title' and 'text' fields for + * // full-text search. Search results will include 'title' and 'category' (plus the + * // id field, that is always stored and returned) + * const miniSearch = new MiniSearch({ + * fields: ['title', 'text'], + * storeFields: ['title', 'category'] + * }) + * + * // Add documents to the index + * miniSearch.addAll(documents) + * + * // Search for documents: + * let results = miniSearch.search('zen art motorcycle') + * // => [ + * // { id: 2, title: 'Zen and the Art of Motorcycle Maintenance', category: 'fiction', score: 2.77258 }, + * // { id: 4, title: 'Zen and the Art of Archery', category: 'non-fiction', score: 1.38629 } + * // ] + * ``` + */ +export default class MiniSearch { + protected _options: OptionsWithDefaults + protected _index: SearchableMap + protected _documentCount: number + protected _documentIds: Map + protected _fieldIds: { [key: string]: number } + protected _fieldLength: Map + protected _averageFieldLength: number[] + protected _nextId: number + protected _storedFields: Map> + + /** + * @param options Configuration options + * + * ### Examples: + * + * ```javascript + * // Create a search engine that indexes the 'title' and 'text' fields of your + * // documents: + * const miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * ``` + * + * ### ID Field: + * + * ```javascript + * // Your documents are assumed to include a unique 'id' field, but if you want + * // to use a different field for document identification, you can set the + * // 'idField' option: + * const miniSearch = new MiniSearch({ idField: 'key', fields: ['title', 'text'] }) + * ``` + * + * ### Options and defaults: + * + * ```javascript + * // The full set of options (here with their default value) is: + * const miniSearch = new MiniSearch({ + * // idField: field that uniquely identifies a document + * idField: 'id', + * + * // extractField: function used to get the value of a field in a document. + * // By default, it assumes the document is a flat object with field names as + * // property keys and field values as string property values, but custom logic + * // can be implemented by setting this option to a custom extractor function. + * extractField: (document, fieldName) => document[fieldName], + * + * // tokenize: function used to split fields into individual terms. By + * // default, it is also used to tokenize search queries, unless a specific + * // `tokenize` search option is supplied. When tokenizing an indexed field, + * // the field name is passed as the second argument. + * tokenize: (string, _fieldName) => string.split(SPACE_OR_PUNCTUATION), + * + * // processTerm: function used to process each tokenized term before + * // indexing. It can be used for stemming and normalization. Return a falsy + * // value in order to discard a term. By default, it is also used to process + * // search queries, unless a specific `processTerm` option is supplied as a + * // search option. When processing a term from a indexed field, the field + * // name is passed as the second argument. + * processTerm: (term, _fieldName) => term.toLowerCase(), + * + * // searchOptions: default search options, see the `search` method for + * // details + * searchOptions: undefined, + * + * // fields: document fields to be indexed. Mandatory, but not set by default + * fields: undefined + * + * // storeFields: document fields to be stored and returned as part of the + * // search results. + * storeFields: [] + * }) + * ``` + */ + constructor (options: Options) { + if (options?.fields == null) { + throw new Error('MiniSearch: option "fields" must be provided') + } + + this._options = { + ...defaultOptions, + ...options, + searchOptions: { ...defaultSearchOptions, ...(options.searchOptions || {}) } + } + + this._index = new SearchableMap() + + this._documentCount = 0 + + this._documentIds = new Map() + + // Fields are defined during initialization, don't change, are few in + // number, rarely need iterating over, and have string keys. Therefore in + // this case an object is a better candidate than a Map to store the mapping + // from field key to ID. + this._fieldIds = {} + + this._fieldLength = new Map() + + this._averageFieldLength = [] + + this._nextId = 0 + + this._storedFields = new Map() + + this.addFields(this._options.fields) + } + + /** + * Adds a document to the index + * + * @param document The document to be indexed + */ + add (document: T): void { + const { extractField, tokenize, processTerm, fields, idField } = this._options + const id = extractField(document, idField) + if (id == null) { + throw new Error(`MiniSearch: document does not have ID field "${idField}"`) + } + const shortDocumentId = this.addDocumentId(id) + this.saveStoredFields(shortDocumentId, document) + + for (const field of fields) { + const fieldValue = extractField(document, field) + if (fieldValue == null) continue + + const tokens = tokenize(fieldValue.toString(), field) + const fieldId = this._fieldIds[field] + + this.addFieldLength(shortDocumentId, fieldId, this.documentCount - 1, tokens.length) + + for (const term of tokens) { + const processedTerm = processTerm(term, field) + if (processedTerm) { + this.addTerm(fieldId, shortDocumentId, processedTerm) + } + } + } + } + + /** + * Adds all the given documents to the index + * + * @param documents An array of documents to be indexed + */ + addAll (documents: T[]): void { + for (const document of documents) this.add(document) + } + + /** + * Adds all the given documents to the index asynchronously. + * + * Returns a promise that resolves (to `undefined`) when the indexing is done. + * This method is useful when index many documents, to avoid blocking the main + * thread. The indexing is performed asynchronously and in chunks. + * + * @param documents An array of documents to be indexed + * @param options Configuration options + * @return A promise resolving to `undefined` when the indexing is done + */ + addAllAsync (documents: T[], options: { chunkSize?: number } = {}): Promise { + const { chunkSize = 10 } = options + const acc: { chunk: T[], promise: Promise } = { chunk: [], promise: Promise.resolve() } + + const { chunk, promise } = documents.reduce(({ chunk, promise }, document: T, i: number) => { + chunk.push(document) + if ((i + 1) % chunkSize === 0) { + return { + chunk: [], + promise: promise + .then(() => new Promise(resolve => setTimeout(resolve, 0))) + .then(() => this.addAll(chunk)) + } + } else { + return { chunk, promise } + } + }, acc) + + return promise.then(() => this.addAll(chunk)) + } + + /** + * Removes the given document from the index. + * + * The document to delete must NOT have changed between indexing and deletion, + * otherwise the index will be corrupted. Therefore, when reindexing a document + * after a change, the correct order of operations is: + * + * 1. remove old version + * 2. apply changes + * 3. index new version + * + * @param document The document to be removed + */ + remove (document: T): void { + const { tokenize, processTerm, extractField, fields, idField } = this._options + const id = extractField(document, idField) + + if (id == null) { + throw new Error(`MiniSearch: document does not have ID field "${idField}"`) + } + + for (const [shortId, longId] of this._documentIds) { + if (id === longId) { + for (const field of fields) { + const fieldValue = extractField(document, field) + if (fieldValue == null) continue + + const tokens = tokenize(fieldValue.toString(), field) + const fieldId = this._fieldIds[field] + + for (const term of tokens) { + const processedTerm = processTerm(term, field) + if (processedTerm) { + this.removeTerm(fieldId, shortId, processedTerm) + } + } + + this.removeFieldLength(shortId, fieldId, this.documentCount, tokens.length) + } + + this._storedFields.delete(shortId) + this._documentIds.delete(shortId) + this._fieldLength.delete(shortId) + this._documentCount -= 1 + return + } + } + + throw new Error(`MiniSearch: cannot remove document with ID ${id}: it is not in the index`) + } + + /** + * Removes all the given documents from the index. If called with no arguments, + * it removes _all_ documents from the index. + * + * @param documents The documents to be removed. If this argument is omitted, + * all documents are removed. Note that, for removing all documents, it is + * more efficient to call this method with no arguments than to pass all + * documents. + */ + removeAll (documents?: T[]): void { + if (documents) { + for (const document of documents) this.remove(document) + } else if (arguments.length > 0) { + throw new Error('Expected documents to be present. Omit the argument to remove all documents.') + } else { + this._index = new SearchableMap() + this._documentCount = 0 + this._documentIds = new Map() + this._fieldLength = new Map() + this._averageFieldLength = [] + this._storedFields = new Map() + this._nextId = 0 + } + } + + /** + * Search for documents matching the given search query. + * + * The result is a list of scored document IDs matching the query, sorted by + * descending score, and each including data about which terms were matched and + * in which fields. + * + * ### Basic usage: + * + * ```javascript + * // Search for "zen art motorcycle" with default options: terms have to match + * // exactly, and individual terms are joined with OR + * miniSearch.search('zen art motorcycle') + * // => [ { id: 2, score: 2.77258, match: { ... } }, { id: 4, score: 1.38629, match: { ... } } ] + * ``` + * + * ### Restrict search to specific fields: + * + * ```javascript + * // Search only in the 'title' field + * miniSearch.search('zen', { fields: ['title'] }) + * ``` + * + * ### Field boosting: + * + * ```javascript + * // Boost a field + * miniSearch.search('zen', { boost: { title: 2 } }) + * ``` + * + * ### Prefix search: + * + * ```javascript + * // Search for "moto" with prefix search (it will match documents + * // containing terms that start with "moto" or "neuro") + * miniSearch.search('moto neuro', { prefix: true }) + * ``` + * + * ### Fuzzy search: + * + * ```javascript + * // Search for "ismael" with fuzzy search (it will match documents containing + * // terms similar to "ismael", with a maximum edit distance of 0.2 term.length + * // (rounded to nearest integer) + * miniSearch.search('ismael', { fuzzy: 0.2 }) + * ``` + * + * ### Combining strategies: + * + * ```javascript + * // Mix of exact match, prefix search, and fuzzy search + * miniSearch.search('ismael mob', { + * prefix: true, + * fuzzy: 0.2 + * }) + * ``` + * + * ### Advanced prefix and fuzzy search: + * + * ```javascript + * // Perform fuzzy and prefix search depending on the search term. Here + * // performing prefix and fuzzy search only on terms longer than 3 characters + * miniSearch.search('ismael mob', { + * prefix: term => term.length > 3 + * fuzzy: term => term.length > 3 ? 0.2 : null + * }) + * ``` + * + * ### Combine with AND: + * + * ```javascript + * // Combine search terms with AND (to match only documents that contain both + * // "motorcycle" and "art") + * miniSearch.search('motorcycle art', { combineWith: 'AND' }) + * ``` + * + * ### Combine with AND_NOT: + * + * There is also an AND_NOT combinator, that finds documents that match the + * first term, but do not match any of the other terms. This combinator is + * rarely useful with simple queries, and is meant to be used with advanced + * query combinations (see later for more details). + * + * ### Filtering results: + * + * ```javascript + * // Filter only results in the 'fiction' category (assuming that 'category' + * // is a stored field) + * miniSearch.search('motorcycle art', { + * filter: (result) => result.category === 'fiction' + * }) + * ``` + * + * ### Advanced combination of queries: + * + * It is possible to combine different subqueries with OR, AND, and AND_NOT, + * and even with different search options, by passing a query expression + * tree object as the first argument, instead of a string. + * + * ```javascript + * // Search for documents that contain "zen" and ("motorcycle" or "archery") + * miniSearch.search({ + * combineWith: 'AND', + * queries: [ + * 'zen', + * { + * combineWith: 'OR', + * queries: ['motorcycle', 'archery'] + * } + * ] + * }) + * + * // Search for documents that contain ("apple" or "pear") but not "juice" and + * // not "tree" + * miniSearch.search({ + * combineWith: 'AND_NOT', + * queries: [ + * { + * combineWith: 'OR', + * queries: ['apple', 'pear'] + * }, + * 'juice', + * 'tree' + * ] + * }) + * ``` + * + * Each node in the expression tree can be either a string, or an object that + * supports all `SearchOptions` fields, plus a `queries` array field for + * subqueries. + * + * Note that, while this can become complicated to do by hand for complex or + * deeply nested queries, it provides a formalized expression tree API for + * external libraries that implement a parser for custom query languages. + * + * @param query Search query + * @param options Search options. Each option, if not given, defaults to the corresponding value of `searchOptions` given to the constructor, or to the library default. + */ + search (query: Query, searchOptions: SearchOptions = {}): SearchResult[] { + const combinedResults = this.executeQuery(query, searchOptions) + + const results = [] + + for (const [docId, { score, match, terms }] of combinedResults) { + const result = { + id: this._documentIds.get(docId), + terms: uniq(terms), + score, + match + } + + Object.assign(result, this._storedFields.get(docId)) + if (searchOptions.filter == null || searchOptions.filter(result)) { + results.push(result) + } + } + + results.sort(({ score: a }, { score: b }) => a < b ? 1 : -1) + return results + } + + /** + * Provide suggestions for the given search query + * + * The result is a list of suggested modified search queries, derived from the + * given search query, each with a relevance score, sorted by descending score. + * + * ### Basic usage: + * + * ```javascript + * // Get suggestions for 'neuro': + * miniSearch.autoSuggest('neuro') + * // => [ { suggestion: 'neuromancer', terms: [ 'neuromancer' ], score: 0.46240 } ] + * ``` + * + * ### Multiple words: + * + * ```javascript + * // Get suggestions for 'zen ar': + * miniSearch.autoSuggest('zen ar') + * // => [ + * // { suggestion: 'zen archery art', terms: [ 'zen', 'archery', 'art' ], score: 1.73332 }, + * // { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 } + * // ] + * ``` + * + * ### Fuzzy suggestions: + * + * ```javascript + * // Correct spelling mistakes using fuzzy search: + * miniSearch.autoSuggest('neromancer', { fuzzy: 0.2 }) + * // => [ { suggestion: 'neuromancer', terms: [ 'neuromancer' ], score: 1.03998 } ] + * ``` + * + * ### Filtering: + * + * ```javascript + * // Get suggestions for 'zen ar', but only within the 'fiction' category + * // (assuming that 'category' is a stored field): + * miniSearch.autoSuggest('zen ar', { + * filter: (result) => result.category === 'fiction' + * }) + * // => [ + * // { suggestion: 'zen archery art', terms: [ 'zen', 'archery', 'art' ], score: 1.73332 }, + * // { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 } + * // ] + * ``` + * + * @param queryString Query string to be expanded into suggestions + * @param options Search options. The supported options and default values + * are the same as for the `search` method, except that by default prefix + * search is performed on the last term in the query. + * @return A sorted array of suggestions sorted by relevance score. + */ + autoSuggest (queryString: string, options: SearchOptions = {}): Suggestion[] { + options = { ...defaultAutoSuggestOptions, ...options } + + const suggestions: Map & { count: number }> = new Map() + + for (const { score, terms } of this.search(queryString, options)) { + const phrase = terms.join(' ') + const suggestion = suggestions.get(phrase) + if (suggestion != null) { + suggestion.score += score + suggestion.count += 1 + } else { + suggestions.set(phrase, { score, terms, count: 1 }) + } + } + + const results = [] + for (const [suggestion, { score, terms, count }] of suggestions) { + results.push({ suggestion, terms, score: score / count }) + } + + results.sort(({ score: a }, { score: b }) => a < b ? 1 : -1) + return results + } + + /** + * Number of documents in the index + */ + get documentCount (): number { + return this._documentCount + } + + /** + * Deserializes a JSON index (serialized with `JSON.stringify(miniSearch)`) + * and instantiates a MiniSearch instance. It should be given the same options + * originally used when serializing the index. + * + * ### Usage: + * + * ```javascript + * // If the index was serialized with: + * let miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * miniSearch.addAll(documents) + * + * const json = JSON.stringify(miniSearch) + * // It can later be deserialized like this: + * miniSearch = MiniSearch.loadJSON(json, { fields: ['title', 'text'] }) + * ``` + * + * @param json JSON-serialized index + * @param options configuration options, same as the constructor + * @return An instance of MiniSearch deserialized from the given JSON. + */ + static loadJSON (json: string, options: Options): MiniSearch { + if (options == null) { + throw new Error('MiniSearch: loadJSON should be given the same options used when serializing the index') + } + return MiniSearch.loadJS(JSON.parse(json), options) + } + + /** + * Returns the default value of an option. It will throw an error if no option + * with the given name exists. + * + * @param optionName Name of the option + * @return The default value of the given option + * + * ### Usage: + * + * ```javascript + * // Get default tokenizer + * MiniSearch.getDefault('tokenize') + * + * // Get default term processor + * MiniSearch.getDefault('processTerm') + * + * // Unknown options will throw an error + * MiniSearch.getDefault('notExisting') + * // => throws 'MiniSearch: unknown option "notExisting"' + * ``` + */ + static getDefault (optionName: string): any { + if (defaultOptions.hasOwnProperty(optionName)) { + return getOwnProperty(defaultOptions, optionName) + } else { + throw new Error(`MiniSearch: unknown option "${optionName}"`) + } + } + + /** + * @ignore + */ + static loadJS (js: AsPlainObject, options: Options): MiniSearch { + const { + index, + documentCount, + nextId, + documentIds, + fieldIds, + fieldLength, + averageFieldLength, + storedFields, + serializationVersion + } = js + if (serializationVersion !== 1) { + throw new Error('MiniSearch: cannot deserialize an index created with an incompatible version') + } + + const miniSearch = new MiniSearch(options) + + miniSearch._documentCount = documentCount + miniSearch._nextId = nextId + miniSearch._documentIds = objectToNumericMap(documentIds) + miniSearch._fieldIds = fieldIds + miniSearch._fieldLength = objectToNumericMap(fieldLength) + miniSearch._averageFieldLength = averageFieldLength + miniSearch._storedFields = objectToNumericMap(storedFields) + miniSearch._index = new SearchableMap() + + for (const [term, data] of index) { + const dataMap = new Map() as IndexData + + for (const fieldId of Object.keys(data)) { + const { df, ds } = data[fieldId] + + dataMap.set(parseInt(fieldId, 10), { df, ds: objectToNumericMap(ds) as IndexEntry['ds'] }) + } + + miniSearch._index.set(term, dataMap) + } + + return miniSearch + } + + /** + * @ignore + */ + private executeQuery (query: Query, searchOptions: SearchOptions = {}): RawResult { + if (typeof query === 'string') { + return this.executeSearch(query, searchOptions) + } else { + const results = query.queries.map((subquery) => { + const options = { ...searchOptions, ...query, queries: undefined } + return this.executeQuery(subquery, options) + }) + return this.combineResults(results, query.combineWith) + } + } + + /** + * @ignore + */ + private executeSearch (queryString: string, searchOptions: SearchOptions = {}): RawResult { + const { tokenize, processTerm, searchOptions: globalSearchOptions } = this._options + const options = { tokenize, processTerm, ...globalSearchOptions, ...searchOptions } + const { tokenize: searchTokenize, processTerm: searchProcessTerm } = options + const terms = searchTokenize(queryString) + .map((term: string) => searchProcessTerm(term)) + .filter((term) => !!term) as string[] + const queries: QuerySpec[] = terms.map(termToQuerySpec(options)) + const results = queries.map(query => this.executeQuerySpec(query, options)) + + return this.combineResults(results, options.combineWith) + } + + /** + * @ignore + */ + private executeQuerySpec (query: QuerySpec, searchOptions: SearchOptions): RawResult { + const options: SearchOptionsWithDefaults = { ...this._options.searchOptions, ...searchOptions } + + const boosts = (options.fields || this._options.fields).reduce((boosts, field) => + ({ ...boosts, [field]: getOwnProperty(boosts, field) || 1 }), options.boost || {}) + + const { + boostDocument, + weights, + maxFuzzy + } = options + + const { fuzzy: fuzzyWeight, prefix: prefixWeight } = { ...defaultSearchOptions.weights, ...weights } + + const results = this.termResults(query.term, boosts, boostDocument, this._index.get(query.term)) + + let prefixMatches + let fuzzyMatches + + if (query.prefix) { + prefixMatches = this._index.atPrefix(query.term) + } + + if (query.fuzzy) { + const fuzzy = (query.fuzzy === true) ? 0.2 : query.fuzzy + const maxDistance = fuzzy < 1 ? Math.min(maxFuzzy, Math.round(query.term.length * fuzzy)) : fuzzy + fuzzyMatches = this._index.fuzzyGet(query.term, maxDistance) + } + + if (prefixMatches) { + for (const [term, data] of prefixMatches) { + const distance = term.length - query.term.length + if (!distance) { continue } // Skip exact match. + + // Delete the term from fuzzy results (if present) if it is also a + // prefix result. This entry will always be scored as a prefix result. + fuzzyMatches?.delete(term) + + const weightedDistance = (0.3 * distance) / term.length + this.termResults(term, boosts, boostDocument, data, results, prefixWeight, weightedDistance) + } + } + + if (fuzzyMatches) { + for (const term of fuzzyMatches.keys()) { + const [data, distance] = fuzzyMatches.get(term)! + if (!distance) { continue } // Skip exact match. + + const weightedDistance = distance / term.length + this.termResults(term, boosts, boostDocument, data, results, fuzzyWeight, weightedDistance) + } + } + + return results + } + + /** + * @ignore + */ + private combineResults (results: RawResult[], combineWith = OR): RawResult { + if (results.length === 0) { return new Map() } + const operator = combineWith.toLowerCase() + return results.reduce(combinators[operator]) || new Map() + } + + /** + * Allows serialization of the index to JSON, to possibly store it and later + * deserialize it with `MiniSearch.loadJSON`. + * + * Normally one does not directly call this method, but rather call the + * standard JavaScript `JSON.stringify()` passing the `MiniSearch` instance, + * and JavaScript will internally call this method. Upon deserialization, one + * must pass to `loadJSON` the same options used to create the original + * instance that was serialized. + * + * ### Usage: + * + * ```javascript + * // Serialize the index: + * let miniSearch = new MiniSearch({ fields: ['title', 'text'] }) + * miniSearch.addAll(documents) + * const json = JSON.stringify(miniSearch) + * + * // Later, to deserialize it: + * miniSearch = MiniSearch.loadJSON(json, { fields: ['title', 'text'] }) + * ``` + * + * @return A plain-object serializeable representation of the search index. + */ + toJSON (): AsPlainObject { + const index: [string, { [key: string]: SerializedIndexEntry }][] = [] + + for (const [term, fieldIndex] of this._index) { + const data: { [key: string]: SerializedIndexEntry } = {} + + for (const [fieldId, { df, ds }] of fieldIndex) { + data[fieldId] = { df, ds: Object.fromEntries(ds) } + } + + index.push([term, data]) + } + + return { + documentCount: this._documentCount, + nextId: this._nextId, + documentIds: Object.fromEntries(this._documentIds), + fieldIds: this._fieldIds, + fieldLength: Object.fromEntries(this._fieldLength), + averageFieldLength: this._averageFieldLength, + storedFields: Object.fromEntries(this._storedFields), + index, + serializationVersion: 1 + } + } + + /** + * @ignore + */ + private termResults ( + term: string, + boosts: { [field: string]: number }, + boostDocument: ((id: any, term: string) => number) | undefined, + indexData: IndexData, + results: RawResult = new Map(), + weight: number = 1, + editDistance: number = 0 + ): RawResult { + if (indexData == null) return results + + for (const field of Object.keys(boosts)) { + const fieldBoost = boosts[field] + const fieldId = this._fieldIds[field] + const entry = indexData.get(fieldId) + if (entry == null) continue + + for (const [documentId, tf] of entry.ds) { + const docBoost = boostDocument ? boostDocument(this._documentIds.get(documentId), term) : 1 + if (!docBoost) continue + + const normalizedLength = this._fieldLength.get(documentId)![fieldId] / this._averageFieldLength[fieldId] + const score = weight * docBoost * calculateScore(tf, entry.df, this._documentCount, normalizedLength, fieldBoost, editDistance) + + const result = results.get(documentId) + + if (result) { + result.score += score + + const match = getOwnProperty(result.match, term) + if (match) { + match.push(field) + } else { + result.match[term] = [field] + result.terms.push(term) + } + } else { + results.set(documentId, { + score, + match: { [term]: [field] }, + terms: [term] + }) + } + } + } + + return results + } + + /** + * @ignore + */ + private addTerm (fieldId: number, documentId: number, term: string): void { + const indexData = this._index.fetch(term, createMap) + + let fieldIndex = indexData.get(fieldId) + if (fieldIndex == null) { + fieldIndex = { df: 1, ds: new Map() } as IndexEntry + fieldIndex.ds.set(documentId, 1) + indexData.set(fieldId, fieldIndex) + } else { + const docs = fieldIndex.ds.get(documentId) + if (docs == null) { fieldIndex.df += 1 } + fieldIndex.ds.set(documentId, (docs || 0) + 1) + } + } + + /** + * @ignore + */ + private removeTerm (fieldId: number, documentId: number, term: string): void { + if (!this._index.has(term)) { + this.warnDocumentChanged(documentId, fieldId, term) + return + } + + const indexData = this._index.fetch(term, createMap) + + const fieldIndex = indexData.get(fieldId) + if (fieldIndex == null || fieldIndex.ds.get(documentId) == null) { + this.warnDocumentChanged(documentId, fieldId, term) + } else if (fieldIndex.ds.get(documentId)! <= 1) { + if (fieldIndex.df <= 1) { + indexData.delete(fieldId) + } else { + fieldIndex.df -= 1 + fieldIndex.ds.delete(documentId) + } + } else { + fieldIndex.ds.set(documentId, fieldIndex.ds.get(documentId)! - 1) + } + + if (this._index.get(term).size === 0) { + this._index.delete(term) + } + } + + /** + * @ignore + */ + private warnDocumentChanged (shortDocumentId: number, fieldId: number, term: string): void { + if (console == null || console.warn == null) { return } + for (const fieldName of Object.keys(this._fieldIds)) { + if (this._fieldIds[fieldName] === fieldId) { + console.warn(`MiniSearch: document with ID ${this._documentIds.get(shortDocumentId)} has changed before removal: term "${term}" was not present in field "${fieldName}". Removing a document after it has changed can corrupt the index!`) + return + } + } + } + + /** + * @ignore + */ + private addDocumentId (documentId: any): number { + const shortDocumentId = this._nextId + this._documentIds.set(shortDocumentId, documentId) + this._documentCount += 1 + this._nextId += 1 + return shortDocumentId + } + + /** + * @ignore + */ + private addFields (fields: string[]): void { + for (let i = 0; i < fields.length; i++) { + this._fieldIds[fields[i]] = i + } + } + + /** + * @ignore + */ + private addFieldLength (documentId: number, fieldId: number, count: number, length: number): void { + let fieldLengths = this._fieldLength.get(documentId) + if (fieldLengths == null) this._fieldLength.set(documentId, fieldLengths = []) + fieldLengths[fieldId] = length + + const averageFieldLength = this._averageFieldLength[fieldId] || 0 + const totalLength = (averageFieldLength * count) + length + this._averageFieldLength[fieldId] = totalLength / (count + 1) + } + + /** + * @ignore + */ + private removeFieldLength (documentId: number, fieldId: number, count: number, length: number): void { + const totalLength = (this._averageFieldLength[fieldId] * count) - length + this._averageFieldLength[fieldId] = totalLength / (count - 1) + } + + /** + * @ignore + */ + private saveStoredFields (documentId: number, doc: T): void { + const { storeFields, extractField } = this._options + if (storeFields == null || storeFields.length === 0) { return } + + let documentFields = this._storedFields.get(documentId) + if (documentFields == null) this._storedFields.set(documentId, documentFields = {}) + + for (const fieldName of storeFields) { + const fieldValue = extractField(doc, fieldName) + if (fieldValue !== undefined) documentFields[fieldName] = fieldValue + } + } +} + +const getOwnProperty = (object: any, property: string) => + Object.prototype.hasOwnProperty.call(object, property) ? object[property] : undefined + +type CombinatorFunction = (a: RawResult, b: RawResult) => RawResult + +const combinators: { [kind: string]: CombinatorFunction } = { + [OR]: (a: RawResult, b: RawResult) => { + for (const documentId of b.keys()) { + const existing = a.get(documentId) + if (existing == null) { + a.set(documentId, b.get(documentId)!) + } else { + const { score, match, terms } = b.get(documentId)! + existing.score = (existing.score + score) * 1.5 + existing.match = Object.assign(existing.match, match) + existing.terms.push(...terms) + } + } + + return a + }, + [AND]: (a: RawResult, b: RawResult) => { + const combined = new Map() + + for (const documentId of b.keys()) { + const existing = a.get(documentId) + if (existing == null) continue + + const { score, match, terms } = b.get(documentId)! + combined.set(documentId, { + score: existing.score + score, + match: Object.assign(existing.match, match), + terms: [...existing.terms, ...terms] + }) + } + + return combined + }, + [AND_NOT]: (a: RawResult, b: RawResult) => { + for (const documentId of b.keys()) a.delete(documentId) + return a + } +} + +const tfIdf = (tf: number, df: number, n: number): number => tf * Math.log(n / df) + +const calculateScore = ( + termFrequency: number, + documentFrequency: number, + documentCount: number, + normalizedLength: number, + boost: number, + editDistance: number +): number => { + const weight = boost / (1 + (0.333 * boost * editDistance)) + return weight * tfIdf(termFrequency, documentFrequency, documentCount) / normalizedLength +} + +const termToQuerySpec = (options: SearchOptions) => (term: string, i: number, terms: string[]): QuerySpec => { + const fuzzy = (typeof options.fuzzy === 'function') + ? options.fuzzy(term, i, terms) + : (options.fuzzy || false) + const prefix = (typeof options.prefix === 'function') + ? options.prefix(term, i, terms) + : (options.prefix === true) + return { term, fuzzy, prefix } +} + +const uniq = (array: T[]): T[] => + array.filter((element: T, i: number, array: T[]) => array.indexOf(element) === i) + +const defaultOptions = { + idField: 'id', + extractField: (document: { [key: string]: any }, fieldName: string) => document[fieldName], + tokenize: (text: string, fieldName?: string) => text.split(SPACE_OR_PUNCTUATION), + processTerm: (term: string, fieldName?: string) => term.toLowerCase(), + fields: undefined, + searchOptions: undefined, + storeFields: [] +} + +const defaultSearchOptions = { + combineWith: OR, + prefix: false, + fuzzy: false, + maxFuzzy: 6, + boost: {}, + weights: { fuzzy: 0.45, prefix: 0.375 } +} + +const defaultAutoSuggestOptions = { + prefix: (term: string, i: number, terms: string[]): boolean => + i === terms.length - 1 +} + +const createMap = () => new Map() + +type SerializedIndexEntry = { df: number, ds: { [key: string]: number } } + +const objectToNumericMap = (object: { [key: string]: T }): Map => { + const map = new Map() + + for (const key of Object.keys(object)) { + map.set(parseInt(key, 10), object[key]) + } + + return map +} + +// This regular expression matches any Unicode space or punctuation character +// Adapted from https://unicode.org/cldr/utility/list-unicodeset.jsp?a=%5Cp%7BZ%7D%5Cp%7BP%7D&abb=on&c=on&esc=on +const SPACE_OR_PUNCTUATION = /[\n\r -#%-*,-/:;?@[-\]_{}\u00A0\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u1680\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2000-\u200A\u2010-\u2029\u202F-\u2043\u2045-\u2051\u2053-\u205F\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u3000-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]+/u diff --git a/node_modules/minisearch/src/SearchableMap/SearchableMap.test.js b/node_modules/minisearch/src/SearchableMap/SearchableMap.test.js new file mode 100644 index 0000000..ebe9a57 --- /dev/null +++ b/node_modules/minisearch/src/SearchableMap/SearchableMap.test.js @@ -0,0 +1,309 @@ +/* eslint-env jest */ + +import SearchableMap from './SearchableMap' +import * as fc from 'fast-check' + +describe('SearchableMap', () => { + const strings = ['bin', 'border', 'acqua', 'aqua', 'poisson', 'parachute', + 'parapendio', 'acquamarina', 'summertime', 'summer', 'join', 'mediterraneo', + 'perciò', 'borderline', 'bo'] + const keyValues = strings.map((key, i) => [key, i]) + const object = keyValues.reduce((obj, [key, value]) => ({ ...obj, [key]: value })) + + const editDistance = function (a, b, mem = [[0]]) { + mem[a.length] = mem[a.length] || [a.length] + if (mem[a.length][b.length] !== undefined) { return mem[a.length][b.length] } + const d = (a[a.length - 1] === b[b.length - 1]) ? 0 : 1 + const distance = (a.length === 1 && b.length === 1) + ? d + : Math.min( + ((a.length > 0) ? editDistance(a.slice(0, -1), b, mem) + 1 : Infinity), + ((b.length > 0) ? editDistance(a, b.slice(0, -1), mem) + 1 : Infinity), + ((a.length > 0 && b.length > 0) ? editDistance(a.slice(0, -1), b.slice(0, -1), mem) + d : Infinity) + ) + mem[a.length][b.length] = distance + return distance + } + + describe('clear', () => { + it('empties the map', () => { + const map = SearchableMap.from(keyValues) + map.clear() + expect(Array.from(map.entries())).toEqual([]) + }) + }) + + describe('delete', () => { + it('deletes the entry at the given key', () => { + const map = SearchableMap.from(keyValues) + map.delete('border') + expect(map.has('border')).toBe(false) + expect(map.has('summer')).toBe(true) + expect(map.has('borderline')).toBe(true) + expect(map.has('bo')).toBe(true) + }) + + it('changes the size of the map', () => { + const map = SearchableMap.from(keyValues) + const sizeBefore = map.size + map.delete('summertime') + expect(map.size).toEqual(sizeBefore - 1) + }) + + it('does nothing if the entry did not exist', () => { + const map = new SearchableMap() + expect(() => map.delete('something')).not.toThrow() + }) + + it('leaves the radix tree in the same state as before the entry was added', () => { + const map = new SearchableMap() + + map.set('hello', 1) + const before = new SearchableMap(new Map(map._tree)) + + map.set('help', 2) + map.delete('help') + + expect(map).toEqual(before) + }) + }) + + describe('entries', () => { + it('returns an iterator of entries', () => { + const map = SearchableMap.from(keyValues) + const entries = Array.from({ [Symbol.iterator]: () => map.entries() }) + expect(entries.sort()).toEqual(keyValues.sort()) + }) + + it('returns an iterable of entries', () => { + const map = SearchableMap.from(keyValues) + const entries = Array.from(map.entries()) + expect(entries.sort()).toEqual(keyValues.sort()) + }) + + it('returns empty iterator, if the map is empty', () => { + const map = new SearchableMap() + const entries = Array.from(map.entries()) + expect(entries).toEqual([]) + }) + }) + + describe('forEach', () => { + it('iterates through each entry', () => { + const entries = [] + const fn = (key, value) => entries.push([key, value]) + const map = SearchableMap.from(keyValues) + map.forEach(fn) + expect(entries).toEqual(Array.from(map.entries())) + }) + }) + + describe('get', () => { + it('gets the value at key', () => { + const key = 'foo' + const value = 42 + const map = SearchableMap.fromObject({ [key]: value }) + expect(map.get(key)).toBe(value) + }) + + it('returns undefined if the key is not present', () => { + const map = new SearchableMap() + expect(map.get('not-existent')).toBe(undefined) + }) + }) + + describe('has', () => { + it('returns true if the given key exists in the map', () => { + const map = new SearchableMap() + map.set('something', 42) + expect(map.has('something')).toBe(true) + + map.set('something else', null) + expect(map.has('something else')).toBe(true) + }) + + it('returns false if the given key does not exist in the map', () => { + const map = SearchableMap.fromObject({ something: 42 }) + expect(map.has('not-existing')).toBe(false) + expect(map.has('some')).toBe(false) + }) + }) + + describe('keys', () => { + it('returns an iterator of keys', () => { + const map = SearchableMap.from(keyValues) + const keys = Array.from({ [Symbol.iterator]: () => map.keys() }) + expect(keys.sort()).toEqual(strings.sort()) + }) + + it('returns an iterable of keys', () => { + const map = SearchableMap.from(keyValues) + const keys = Array.from(map.keys()) + expect(keys.sort()).toEqual(strings.sort()) + }) + + it('returns empty iterator, if the map is empty', () => { + const map = new SearchableMap() + const keys = Array.from(map.keys()) + expect(keys).toEqual([]) + }) + }) + + describe('set', () => { + it('sets a value at key', () => { + const map = new SearchableMap() + const key = 'foo' + const value = 42 + map.set(key, value) + expect(map.get(key)).toBe(value) + }) + + it('overrides a value at key if it already exists', () => { + const map = SearchableMap.fromObject({ foo: 123 }) + const key = 'foo' + const value = 42 + map.set(key, value) + expect(map.get(key)).toBe(value) + }) + + it('throws error if the given key is not a string', () => { + const map = new SearchableMap() + expect(() => map.set(123, 'foo')).toThrow('key must be a string') + }) + }) + + describe('size', () => { + it('is a property containing the size of the map', () => { + const map = SearchableMap.from(keyValues) + expect(map.size).toEqual(keyValues.length) + map.set('foo', 42) + expect(map.size).toEqual(keyValues.length + 1) + map.delete('border') + expect(map.size).toEqual(keyValues.length) + map.clear() + expect(map.size).toEqual(0) + }) + }) + + describe('update', () => { + it('sets a value at key applying a function to the previous value', () => { + const map = new SearchableMap() + const key = 'foo' + const fn = jest.fn(x => (x || 0) + 1) + map.update(key, fn) + expect(fn).toHaveBeenCalledWith(undefined) + expect(map.get(key)).toBe(1) + map.update(key, fn) + expect(fn).toHaveBeenCalledWith(1) + expect(map.get(key)).toBe(2) + }) + + it('throws error if the given key is not a string', () => { + const map = new SearchableMap() + expect(() => map.update(123, () => {})).toThrow('key must be a string') + }) + }) + + describe('values', () => { + it('returns an iterator of values', () => { + const map = SearchableMap.fromObject(object) + const values = Array.from({ [Symbol.iterator]: () => map.values() }) + expect(values.sort()).toEqual(Object.values(object).sort()) + }) + + it('returns an iterable of values', () => { + const map = SearchableMap.fromObject(object) + const values = Array.from(map.values()) + expect(values.sort()).toEqual(Object.values(object).sort()) + }) + + it('returns empty iterator, if the map is empty', () => { + const map = new SearchableMap() + const values = Array.from(map.values()) + expect(values).toEqual([]) + }) + }) + + describe('atPrefix', () => { + it('returns the submap at the given prefix', () => { + const map = SearchableMap.from(keyValues) + + const sum = map.atPrefix('sum') + expect(Array.from(sum.keys()).sort()).toEqual(strings.filter(string => string.startsWith('sum')).sort()) + + const summer = sum.atPrefix('summer') + expect(Array.from(summer.keys()).sort()).toEqual(strings.filter(string => string.startsWith('summer')).sort()) + + const xyz = map.atPrefix('xyz') + expect(Array.from(xyz.keys())).toEqual([]) + + expect(() => sum.atPrefix('xyz')).toThrow() + }) + + it('correctly computes the size', () => { + const map = SearchableMap.from(keyValues) + const sum = map.atPrefix('sum') + expect(sum.size).toEqual(strings.filter(string => string.startsWith('sum')).length) + }) + }) + + describe('fuzzyGet', () => { + const terms = ['summer', 'acqua', 'aqua', 'acquire', 'poisson', 'qua'] + const keyValues = terms.map((key, i) => [key, i]) + const map = SearchableMap.from(keyValues) + + it('returns all entries having the given maximum edit distance from the given key', () => { + [0, 1, 2, 3].forEach(distance => { + const results = map.fuzzyGet('acqua', distance) + const entries = Array.from(results) + expect(entries.map(([key, [value, dist]]) => [key, dist]).sort()) + .toEqual(terms.map(term => [term, editDistance('acqua', term)]).filter(([, d]) => d <= distance).sort()) + expect(entries.every(([key, [value]]) => map.get(key) === value)).toBe(true) + }) + }) + + it('returns an empty object if no matching entries are found', () => { + expect(map.fuzzyGet('winter', 1)).toEqual(new Map()) + }) + }) + + describe('with generated test data', () => { + it('adds and removes entries', () => { + const arrayOfStrings = fc.array(fc.oneof(fc.unicodeString(), fc.string()), 70) + const string = fc.oneof(fc.unicodeString(0, 4), fc.string(0, 4)) + const int = fc.integer(1, 4) + + fc.assert(fc.property(arrayOfStrings, string, int, (terms, prefix, maxDist) => { + const map = new SearchableMap() + const standardMap = new Map() + const uniqueTerms = [...new Set(terms)] + + terms.forEach((term, i) => { + map.set(term, i) + standardMap.set(term, i) + expect(map.has(term)).toBe(true) + expect(standardMap.get(term)).toEqual(i) + }) + + expect(map.size).toEqual(standardMap.size) + expect(Array.from(map.entries()).sort()).toEqual(Array.from(standardMap.entries()).sort()) + + expect(Array.from(map.atPrefix(prefix).keys()).sort()) + .toEqual(Array.from(new Set(terms)).filter(t => t.startsWith(prefix)).sort()) + + const fuzzy = map.fuzzyGet(terms[0], maxDist) + expect(Array.from(fuzzy, ([key, [value, dist]]) => [key, dist]).sort()) + .toEqual(uniqueTerms.map(term => [term, editDistance(terms[0], term)]) + .filter(([, dist]) => dist <= maxDist).sort()) + + terms.forEach(term => { + map.delete(term) + expect(map.has(term)).toBe(false) + expect(map.get(term)).toEqual(undefined) + }) + + expect(map.size).toEqual(0) + })) + }) + }) +}) diff --git a/node_modules/minisearch/src/SearchableMap/SearchableMap.ts b/node_modules/minisearch/src/SearchableMap/SearchableMap.ts new file mode 100644 index 0000000..274a6d4 --- /dev/null +++ b/node_modules/minisearch/src/SearchableMap/SearchableMap.ts @@ -0,0 +1,412 @@ +import { TreeIterator, ENTRIES, KEYS, VALUES, LEAF } from './TreeIterator' +import fuzzySearch, { FuzzyResults } from './fuzzySearch' +import { RadixTree, Entry, Path } from './types' + +/** + * A class implementing the same interface as a standard JavaScript + * [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) + * with string keys, but adding support for efficiently searching entries with + * prefix or fuzzy search. This class is used internally by [[MiniSearch]] as + * the inverted index data structure. The implementation is a radix tree + * (compressed prefix tree). + * + * Since this class can be of general utility beyond _MiniSearch_, it is + * exported by the `minisearch` package and can be imported (or required) as + * `minisearch/SearchableMap`. + * + * @typeParam T The type of the values stored in the map. + */ +export default class SearchableMap { + /** + * @internal + */ + _tree: RadixTree + + /** + * @internal + */ + _prefix: string + + private _size: number | undefined = undefined + + /** + * The constructor is normally called without arguments, creating an empty + * map. In order to create a [[SearchableMap]] from an iterable or from an + * object, check [[SearchableMap.from]] and [[SearchableMap.fromObject]]. + * + * The constructor arguments are for internal use, when creating derived + * mutable views of a map at a prefix. + */ + constructor (tree: RadixTree = new Map(), prefix = '') { + this._tree = tree + this._prefix = prefix + } + + /** + * Creates and returns a mutable view of this [[SearchableMap]], containing only + * entries that share the given prefix. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set("unicorn", 1) + * map.set("universe", 2) + * map.set("university", 3) + * map.set("unique", 4) + * map.set("hello", 5) + * + * let uni = map.atPrefix("uni") + * uni.get("unique") // => 4 + * uni.get("unicorn") // => 1 + * uni.get("hello") // => undefined + * + * let univer = map.atPrefix("univer") + * univer.get("unique") // => undefined + * univer.get("universe") // => 2 + * univer.get("university") // => 3 + * ``` + * + * @param prefix The prefix + * @return A [[SearchableMap]] representing a mutable view of the original Map at the given prefix + */ + atPrefix (prefix: string): SearchableMap { + if (!prefix.startsWith(this._prefix)) { throw new Error('Mismatched prefix') } + + const [node, path] = trackDown(this._tree, prefix.slice(this._prefix.length)) + + if (node === undefined) { + const [parentNode, key] = last(path) + + for (const k of parentNode!.keys()) { + if (k !== LEAF && k.startsWith(key)) { + const node = new Map() + node.set(k.slice(key.length), parentNode!.get(k)!) + return new SearchableMap(node, prefix) + } + } + } + + return new SearchableMap(node, prefix) + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear + */ + clear (): void { + this._size = undefined + this._tree.clear() + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete + * @param key Key to delete + */ + delete (key: string): void { + this._size = undefined + return remove(this._tree, key) + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries + * @return An iterator iterating through `[key, value]` entries. + */ + entries () { + return new TreeIterator>(this, ENTRIES) + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach + * @param fn Iteration function + */ + forEach (fn: (key: string, value: T, map: SearchableMap) => void): void { + for (const [key, value] of this) { + fn(key, value, this) + } + } + + /** + * Returns a Map of all the entries that have a key within the given edit + * distance from the search key. The keys of the returned Map are the matching + * keys, while the values are two-element arrays where the first element is + * the value associated to the key, and the second is the edit distance of the + * key to the search key. + * + * ### Usage: + * + * ```javascript + * let map = new SearchableMap() + * map.set('hello', 'world') + * map.set('hell', 'yeah') + * map.set('ciao', 'mondo') + * + * // Get all entries that match the key 'hallo' with a maximum edit distance of 2 + * map.fuzzyGet('hallo', 2) + * // => Map(2) { 'hello' => ['world', 1], 'hell' => ['yeah', 2] } + * + * // In the example, the "hello" key has value "world" and edit distance of 1 + * // (change "e" to "a"), the key "hell" has value "yeah" and edit distance of 2 + * // (change "e" to "a", delete "o") + * ``` + * + * @param key The search key + * @param maxEditDistance The maximum edit distance (Levenshtein) + * @return A Map of the matching keys to their value and edit distance + */ + fuzzyGet (key: string, maxEditDistance: number): FuzzyResults { + return fuzzySearch(this._tree, key, maxEditDistance) + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get + * @param key Key to get + * @return Value associated to the key, or `undefined` if the key is not + * found. + */ + get (key: string): T | undefined { + const node = lookup(this._tree, key) + return node !== undefined ? (node.get(LEAF)! as T) : undefined + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has + * @param key Key + * @return True if the key is in the map, false otherwise + */ + has (key: string): boolean { + const node = lookup(this._tree, key) + return node !== undefined && node.has(LEAF) + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys + * @return An `Iterable` iterating through keys + */ + keys () { + return new TreeIterator(this, KEYS) + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set + * @param key Key to set + * @param value Value to associate to the key + * @return The [[SearchableMap]] itself, to allow chaining + */ + set (key: string, value: T): SearchableMap { + if (typeof key !== 'string') { throw new Error('key must be a string') } + this._size = undefined + const node = createPath(this._tree, key) + node.set(LEAF, value) + return this + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size + */ + get size (): number { + if (this._size) { return this._size } + /** @ignore */ + this._size = 0 + + const iter = this.entries() + while (!iter.next().done) this._size! += 1 + + return this._size + } + + /** + * Updates the value at the given key using the provided function. The function + * is called with the current value at the key, and its return value is used as + * the new value to be set. + * + * ### Example: + * + * ```javascript + * // Increment the current value by one + * searchableMap.update('somekey', (currentValue) => currentValue == null ? 0 : currentValue + 1) + * ``` + * + * If the value at the given key is or will be an object, it might not require + * re-assignment. In that case it is better to use `fetch()`, because it is + * faster. + * + * @param key The key to update + * @param fn The function used to compute the new value from the current one + * @return The [[SearchableMap]] itself, to allow chaining + */ + update (key: string, fn: (value: T) => T): SearchableMap { + if (typeof key !== 'string') { throw new Error('key must be a string') } + this._size = undefined + const node = createPath(this._tree, key) + node.set(LEAF, fn(node.get(LEAF) as T)) + return this + } + + /** + * Fetches the value of the given key. If the value does not exist, calls the + * given function to create a new value, which is inserted at the given key + * and subsequently returned. + * + * ### Example: + * + * ```javascript + * const map = searchableMap.fetch('somekey', () => new Map()) + * map.set('foo', 'bar') + * ``` + * + * @param key The key to update + * @param defaultValue A function that creates a new value if the key does not exist + * @return The existing or new value at the given key + */ + fetch (key: string, initial: () => T): T { + if (typeof key !== 'string') { throw new Error('key must be a string') } + this._size = undefined + const node = createPath(this._tree, key) + + let value = node.get(LEAF) as T + if (value === undefined) { + node.set(LEAF, value = initial()) + } + + return value + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values + * @return An `Iterable` iterating through values. + */ + values () { + return new TreeIterator(this, VALUES) + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/@@iterator + */ + [Symbol.iterator] () { + return this.entries() + } + + /** + * Creates a [[SearchableMap]] from an `Iterable` of entries + * + * @param entries Entries to be inserted in the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + static from (entries: Iterable> | Entry[]) { + const tree = new SearchableMap() + for (const [key, value] of entries) { + tree.set(key, value) + } + return tree + } + + /** + * Creates a [[SearchableMap]] from the iterable properties of a JavaScript object + * + * @param object Object of entries for the [[SearchableMap]] + * @return A new [[SearchableMap]] with the given entries + */ + static fromObject (object: { [key: string]: T }) { + return SearchableMap.from(Object.entries(object)) + } +} + +const trackDown = (tree: RadixTree | undefined, key: string, path: Path = []): [RadixTree | undefined, Path] => { + if (key.length === 0 || tree == null) { return [tree, path] } + + for (const k of tree.keys()) { + if (k !== LEAF && key.startsWith(k)) { + path.push([tree, k]) // performance: update in place + return trackDown(tree.get(k) as RadixTree | undefined, key.slice(k.length), path) + } + } + + path.push([tree, key]) // performance: update in place + return trackDown(undefined, '', path) +} + +const lookup = (tree: RadixTree, key: string): RadixTree | undefined => { + if (key.length === 0 || tree == null) { return tree } + + for (const k of tree.keys()) { + if (k !== LEAF && key.startsWith(k)) { + return lookup(tree.get(k) as RadixTree, key.slice(k.length)) + } + } +} + +const createPath = (tree: RadixTree, key: string): RadixTree => { + if (key.length === 0 || tree == null) { return tree } + + for (const k of tree.keys()) { + if (k !== LEAF && key.startsWith(k)) { + return createPath(tree.get(k) as RadixTree, key.slice(k.length)) + } + } + + for (const k of tree.keys()) { + if (k !== LEAF && k.startsWith(key[0])) { + const offset = commonPrefixOffset(key, k) + const node = new Map() + node.set(k.slice(offset), tree.get(k)!) + tree.set(key.slice(0, offset), node) + tree.delete(k) + return createPath(node as RadixTree, key.slice(offset)) + } + } + + const node = new Map() + tree.set(key, node) + return node as RadixTree +} + +const commonPrefixOffset = (a: string, b: string): number => { + const length = Math.min(a.length, b.length) + + for (let i = 0; i < length; i++) { + if (a[i] !== b[i]) return i + } + + return length +} + +const remove = (tree: RadixTree, key: string): void => { + const [node, path] = trackDown(tree, key) + if (node === undefined) { return } + node.delete(LEAF) + + if (node.size === 0) { + cleanup(path) + } else if (node.size === 1) { + const [key, value] = node.entries().next().value + merge(path, key, value) + } +} + +const cleanup = (path: Path): void => { + if (path.length === 0) { return } + + const [node, key] = last(path) + node!.delete(key) + + if (node!.size === 0) { + cleanup(path.slice(0, -1)) + } else if (node!.size === 1) { + const [key, value] = node!.entries().next().value + if (key !== LEAF) { + merge(path.slice(0, -1), key, value) + } + } +} + +const merge = (path: Path, key: string, value: T): void => { + if (path.length === 0) { return } + + const [node, nodeKey] = last(path) + node!.set(nodeKey + key, value) + node!.delete(nodeKey) +} + +const last = (array: T[]): T => { + return array[array.length - 1] +} diff --git a/node_modules/minisearch/src/SearchableMap/TreeIterator.ts b/node_modules/minisearch/src/SearchableMap/TreeIterator.ts new file mode 100644 index 0000000..92be764 --- /dev/null +++ b/node_modules/minisearch/src/SearchableMap/TreeIterator.ts @@ -0,0 +1,91 @@ +import { RadixTree, Entry } from './types' + +/** @ignore */ +const ENTRIES = 'ENTRIES' + +/** @ignore */ +const KEYS = 'KEYS' + +/** @ignore */ +const VALUES = 'VALUES' + +/** @ignore */ +const LEAF = '' + +type IteratorType = 'ENTRIES' | 'KEYS' | 'VALUES' + +type IteratorPath = { + node: RadixTree, + keys: string[] +}[] + +export type IterableSet = { + _tree: RadixTree, + _prefix: string +} + +/** + * @private + */ +class TreeIterator implements Iterator { + set: IterableSet + _type: IteratorType + _path: IteratorPath + + constructor (set: IterableSet, type: IteratorType) { + const node = set._tree + const keys = Array.from(node.keys()) + this.set = set + this._type = type + this._path = keys.length > 0 ? [{ node, keys }] : [] + } + + next (): IteratorResult { + const value = this.dive() + this.backtrack() + return value + } + + dive (): IteratorResult { + if (this._path.length === 0) { return { done: true, value: undefined } } + const { node, keys } = last(this._path)! + if (last(keys) === LEAF) { return { done: false, value: this.result() as V } } + this._path.push({ node: node.get(last(keys)!) as RadixTree, keys: Array.from((node.get(last(keys)!) as RadixTree).keys()) }) + return this.dive() + } + + backtrack (): void { + if (this._path.length === 0) { return } + last(this._path)!.keys.pop() + if (last(this._path)!.keys.length > 0) { return } + this._path.pop() + this.backtrack() + } + + key (): string { + return this.set._prefix + this._path + .map(({ keys }) => last(keys)) + .filter(key => key !== LEAF) + .join('') + } + + value (): T { + return last(this._path)!.node.get(LEAF) as T + } + + result (): unknown { + if (this._type === VALUES) { return this.value() } + if (this._type === KEYS) { return this.key() } + return [this.key(), this.value()] as Entry + } + + [Symbol.iterator] () { + return this + } +} + +const last = (array: T[]): T | undefined => { + return array[array.length - 1] +} + +export { TreeIterator, ENTRIES, KEYS, VALUES, LEAF } diff --git a/node_modules/minisearch/src/SearchableMap/fuzzySearch.ts b/node_modules/minisearch/src/SearchableMap/fuzzySearch.ts new file mode 100644 index 0000000..9250a7e --- /dev/null +++ b/node_modules/minisearch/src/SearchableMap/fuzzySearch.ts @@ -0,0 +1,123 @@ +/* eslint-disable no-labels */ +import { LEAF } from './TreeIterator' +import { RadixTree } from './types' + +export type FuzzyResult = [T, number] + +export type FuzzyResults = Map> + +/** + * @ignore + */ +export const fuzzySearch = (node: RadixTree, query: string, maxDistance: number): FuzzyResults => { + const results: FuzzyResults = new Map() + if (query === undefined) return results + + // Number of columns in the Levenshtein matrix. + const n = query.length + 1 + + // Matching terms can never be longer than N + maxDistance. + const maxLength = n + maxDistance + + // Fill first matrix row with consecutive numbers 0 1 2 3 ... (n - 1) + const matrix = new Uint8Array(maxLength * n) + for (let i = 0; i < n; i++) matrix[i] = i + + recurse( + node, + query, + maxDistance, + results, + matrix, + n, + n, + '' + ) + + return results +} + +// Modified version of http://stevehanov.ca/blog/?id=114 + +// This builds a Levenshtein matrix for a given query and continuously updates +// it for nodes in the radix tree that fall within the given maximum edit +// distance. Keeping the same matrix around is beneficial especially for larger +// edit distances. +// +// k a t e <-- query +// 0 1 2 3 4 +// c 1 1 2 3 4 +// a 2 2 1 2 3 +// t 3 3 2 1 [2] <-- edit distance +// ^ +// ^ term in radix tree, rows are added and removed as needed + +const recurse = ( + node: RadixTree, + query: string, + maxDistance: number, + results: FuzzyResults, + matrix: Uint8Array, + offset: number, + n: number, + prefix: string +): void => { + key: for (const key of node.keys()) { + if (key === LEAF) { + // We've reached a leaf node. Check if the edit distance acceptable and + // store the result if it is. + const distance = matrix[offset - 1] + if (distance <= maxDistance) { + results.set(prefix, [node.get(key) as T, distance]) + } + } else { + // Iterate over all characters in the key. Update the Levenshtein matrix + // and check if the minimum distance in the last row is still within the + // maximum edit distance. If it is, we can recurse over all child nodes. + for (let i = 0; i < key.length; i++) { + const char = key[i] + const thisRowOffset = offset + n * i + const prevRowOffset = thisRowOffset - n + + // Set the first column based on the previous row, and initialize the + // minimum distance in the current row. + let minDistance = matrix[thisRowOffset] = matrix[prevRowOffset] + 1 + + // Iterate over remaining columns (characters in the query). + for (let j = 0; j < n - 1; j++) { + const different = char !== query[j] + + // It might make sense to only read the matrix positions used for + // deletion/insertion if the characters are different. But we want to + // avoid conditional reads for performance reasons. + const rpl = matrix[prevRowOffset + j] + +different + const del = matrix[prevRowOffset + j + 1] + 1 + const ins = matrix[thisRowOffset + j] + 1 + + const dist = matrix[thisRowOffset + j + 1] = Math.min(rpl, del, ins) + + if (dist < minDistance) minDistance = dist + } + + // Because distance will never decrease, we can stop. There will be no + // matching child nodes. + if (minDistance > maxDistance) { + continue key + } + } + + recurse( + node.get(key) as RadixTree, + query, + maxDistance, + results, + matrix, + offset + n * key.length, + n, + prefix + key + ) + } + } +} + +export default fuzzySearch diff --git a/node_modules/minisearch/src/SearchableMap/types.ts b/node_modules/minisearch/src/SearchableMap/types.ts new file mode 100644 index 0000000..82105f7 --- /dev/null +++ b/node_modules/minisearch/src/SearchableMap/types.ts @@ -0,0 +1,5 @@ +export type RadixTree = Map>; + +export type Entry = [string, T] + +export type Path = [RadixTree | undefined, string][] diff --git a/node_modules/minisearch/src/index.ts b/node_modules/minisearch/src/index.ts new file mode 100644 index 0000000..50bef73 --- /dev/null +++ b/node_modules/minisearch/src/index.ts @@ -0,0 +1,4 @@ +import MiniSearch from './MiniSearch' + +export * from './MiniSearch' +export default MiniSearch diff --git a/node_modules/minisearch/src/testSetup/jest.js b/node_modules/minisearch/src/testSetup/jest.js new file mode 100644 index 0000000..b7737e2 --- /dev/null +++ b/node_modules/minisearch/src/testSetup/jest.js @@ -0,0 +1 @@ +/* eslint-env jest */ diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..fcadd6e --- /dev/null +++ b/package-lock.json @@ -0,0 +1,35 @@ +{ + "name": "cubist_minisearch", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "dependencies": { + "fs": "^0.0.1-security", + "minisearch": "^4.0.3" + } + }, + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=" + }, + "node_modules/minisearch": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/minisearch/-/minisearch-4.0.3.tgz", + "integrity": "sha512-yEbNeb41Qk0g9IMJAgmp/kEaW2Ub2cs9MAKphTel24O8mymLheFU7esyfiumeUsvs2f4O0boO0zrp4bc9Po2cA==" + } + }, + "dependencies": { + "fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=" + }, + "minisearch": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/minisearch/-/minisearch-4.0.3.tgz", + "integrity": "sha512-yEbNeb41Qk0g9IMJAgmp/kEaW2Ub2cs9MAKphTel24O8mymLheFU7esyfiumeUsvs2f4O0boO0zrp4bc9Po2cA==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..fb91212 --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "fs": "^0.0.1-security", + "minisearch": "^4.0.3" + } +} diff --git a/resources/js/index.js b/resources/js/index.js new file mode 100644 index 0000000..76210e1 --- /dev/null +++ b/resources/js/index.js @@ -0,0 +1,20 @@ +const args = process.argv.slice(2); +const file = args[0]; +const fields=args[1].split(','); +const storeFields=args[2].split(','); + +const fs = require('fs'); +const MiniSearch = require('minisearch'); + +fs.readFile(file, 'utf8', (err, data) => { + if (err) { + console.error(err) + return + } + let miniSearch = new MiniSearch({ + fields: fields, + storeFields: storeFields, + }); + miniSearch.addAll(JSON.parse(data)); + console.log(JSON.stringify(miniSearch)); +}) \ No newline at end of file diff --git a/src/Index.php b/src/Index.php index 389c519..4b50337 100644 --- a/src/Index.php +++ b/src/Index.php @@ -2,6 +2,8 @@ namespace Cubist\Minisearch; +use Cubist\Util\CommandLine; +use Cubist\Util\Files\Files; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; @@ -19,7 +21,7 @@ class Index implements ShouldQueue, ShouldBeUnique /** * @var string */ - protected $varname='documents'; + protected $varname = 'documents'; /** * @var string @@ -64,12 +66,21 @@ class Index implements ShouldQueue, ShouldBeUnique file_put_contents($this->getOutput(), $this->generateCode()); } - public function generateCode() + public function generateCode($fields = 'title,text,keywords', $storeFields = 'id,title,text,type,url,thumb') { $res = []; foreach ($this->documents as $document) { $res = array_merge($res, $document->process()); } - return 'const '.$this->varname.' = ' . json_encode($res) . ';'; + $tmp = Files::tempnam(); + file_put_contents($tmp, json_encode($res)); + $cl = new CommandLine('nodejs'); + $cl->cd(__DIR__ . '/../js/'); + $cl->setArg(null, 'index.js'); + $cl->setArg(null, $tmp); + $cl->setArg(null, $fields); + $cl->setArg(null, $storeFields); + $cl->execute(); + return $cl->getOutput(); } } \ No newline at end of file