{"id":15626359,"url":"https://github.com/bvaughn/js-worker-search","last_synced_at":"2025-05-16T06:07:27.013Z","repository":{"id":48581747,"uuid":"48818068","full_name":"bvaughn/js-worker-search","owner":"bvaughn","description":"JavaScript client-side search API with web-worker support","archived":false,"fork":false,"pushed_at":"2023-04-17T17:56:02.000Z","size":495,"stargazers_count":420,"open_issues_count":4,"forks_count":35,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-11T04:24:35.863Z","etag":null,"topics":["database","indexing","performance","search"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bvaughn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"bvaughn","patreon":null,"open_collective":"brianvaughn","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":"bvaughn","custom":null}},"created_at":"2015-12-30T20:21:53.000Z","updated_at":"2025-04-19T19:57:01.000Z","dependencies_parsed_at":"2024-06-18T13:36:30.999Z","dependency_job_id":"62716e51-8f84-4fd8-8d81-41f1336b2be0","html_url":"https://github.com/bvaughn/js-worker-search","commit_stats":{"total_commits":64,"total_committers":10,"mean_commits":6.4,"dds":0.453125,"last_synced_commit":"5643fc381268aae4e4c3365f380e62d7756b5b6f"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvaughn%2Fjs-worker-search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvaughn%2Fjs-worker-search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvaughn%2Fjs-worker-search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvaughn%2Fjs-worker-search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bvaughn","download_url":"https://codeload.github.com/bvaughn/js-worker-search/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478190,"owners_count":22077676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","indexing","performance","search"],"created_at":"2024-10-03T10:12:05.727Z","updated_at":"2025-05-16T06:07:21.989Z","avatar_url":"https://github.com/bvaughn.png","language":"JavaScript","funding_links":["https://github.com/sponsors/bvaughn","https://opencollective.com/brianvaughn","https://buymeacoffee.com/bvaughn","https://github.com/sponsors/bvaughn/"],"categories":["JavaScript"],"sub_categories":[],"readme":"# js-worker-search\n\n![NPM version](https://img.shields.io/npm/v/js-worker-search.svg)\n![NPM license](https://img.shields.io/npm/l/js-worker-search.svg)\n![NPM total downloads](https://img.shields.io/npm/dt/js-worker-search.svg)\n![NPM monthly downloads](https://img.shields.io/npm/dm/js-worker-search.svg)\n\n---\n### 🎉 [Become a sponsor](https://github.com/sponsors/bvaughn/) or ☕ [Buy me a coffee](http://givebrian.coffee/)\n---\n\nFull text client-side search based on [js-search](https://github.com/bvaughn/js-search) but with added web-worker support for better performance.\n\nCheck out the [redux-search](https://bvaughn.github.io/redux-search/) for an example integration.\n\nOr install it yourself with NPM:\n\n```\nnpm install --save js-worker-search\n```\n\nSearchApi Documentation\n------\n\nForked from [JS search](github.com/bvaughn/js-search), this utility builds a search index and runs actual searches. It auto-detects the capabilities of the current environment (browser or Node) and uses a web-worker based implementation when possible. When no web-worker support is available searching is done on the main (UI) thread.\n\nSearchApi defines the following public methods:\n\n##### `constructor ({ caseSensitive, indexMode, tokenizePattern })`\nBy default, `SearchApi` builds an index to match all substrings.\nYou can override this behavior by passing an named `indexMode` parameter.\nValid values are `INDEX_MODES.ALL_SUBSTRINGS`, `INDEX_MODES.EXACT_WORDS`, and `INDEX_MODES.PREFIXES`.\n\nSearches are case insensitive by default and split on all whitespace characters. Read below for more information on customizing default options.\n\n##### `indexDocument (uid, text)`\nAdds or updates a uid in the search index and associates it with the specified text. Note that at this time uids can only be added or updated in the index, not removed.\n\nParameters:\n* **uid**: Uniquely identifies a searchable object\n* **text**: Searchable text to associate with the uid\n\n##### `search(query)`\nSearches the current index for the specified query text. Only uids matching all of the words within the text will be accepted. If an empty query string is provided all indexed uids will be returned.\n\nDocument searches are case-insensitive (e.g. \"search\" will match \"Search\"). Document searches use substring matching (e.g. \"na\" and \"me\" will both match \"name\").\n\nParameters:\n* **query**: Searchable query text\n\nThis method will return an array of uids.\n\n##### `terminate()`\nIf search is running in a web worker, this will terminate the worker to allow for garbage collection.\n\nExample Usage\n------\n\nUse the API like so:\n\n```javascript\nimport SearchApi from 'js-worker-search'\n\nconst searchApi = new SearchApi()\n\n// Index as many objects as you want.\n// Objects are identified by an id (the first parameter).\n// Each Object can be indexed multiple times (once per string of related text).\nsearchApi.indexDocument('foo', 'Text describing an Object identified as \"foo\"')\nsearchApi.indexDocument('bar', 'Text describing an Object identified as \"bar\"')\n\n// Search for matching documents using the `search` method.\n// In this case the promise will be resolved with the Array ['foo', 'bar'].\n// This is because the word \"describing\" appears in both indices.\nconst promise = searchApi.search('describing')\n```\n\n### Custom index mode\nBy default, `SearchApi` builds an index to match all substrings.\nYou can override this behavior by passing an `indexMode` parameter to the constructor like so:\n\n```js\nimport SearchApi, { INDEX_MODES } from 'js-worker-search'\n\n// all-substrings match by default; same as current\n// eg \"c\", \"ca\", \"a\", \"at\", \"cat\" match \"cat\"\nconst searchApi = new SearchApi()\n\n// prefix matching (eg \"c\", \"ca\", \"cat\" match \"cat\")\nconst searchApi = new SearchApi({\n  indexMode: INDEX_MODES.PREFIXES\n})\n\n// exact words matching (eg only \"cat\" matches \"cat\")\nconst searchApi = new SearchApi({\n  indexMode: INDEX_MODES.EXACT_WORDS\n})\n```\n\n### Custom tokenizer patterns\nBy default, `SearchApi` breaks text into words (tokenizes) using spaces and newlines\nas the delimiting character. If you want to provide your own splitting rule, pass a\nRegExp to the constructor that defines the pattern , like so:\n\n```js\n// Custom tokenizer pattern to include all non alphanumerics as delimeters\n// ex: searching \"Swift\" matches \"Thomas Swift\" and \"Thomas (Swift)\" but not \"swiftly tilting\"\nconst searchApi = new SearchApi({\n    indexMode: INDEX_MODES.EXACT_WORDS,\n    tokenizePattern: /[^a-z0-9]+/,\n})\n```\n\n### Case-sensitive searches\nThe default sanitizer performs a case-insensitive search. If you want to override that\nbehavior and do a case-sensitive search, set the caseSensitive bit to true, like so:\n\n```js\n// custom sanitizer for case-sensitive searches\nconst searchApi = new SearchApi({\n  caseSensitive: true\n})\n```\n\n### Partial matches\nBy default, the search utility only returns documents containing every search token.\nIt can be configured to return documents containing any search token.\n\n```js\n// Change search behavior from AND to OR\nconst searchApi = new SearchApi({\n  matchAnyToken: true\n})\n```\n\nChangelog\n---------\n\nChanges are tracked in the [changelog](CHANGELOG.md).\n\nLicense\n---------\n\njs-worker-search is available under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbvaughn%2Fjs-worker-search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbvaughn%2Fjs-worker-search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbvaughn%2Fjs-worker-search/lists"}