{"id":13518593,"url":"https://github.com/bvaughn/js-search","last_synced_at":"2025-05-14T06:14:27.595Z","repository":{"id":35701370,"uuid":"39978723","full_name":"bvaughn/js-search","owner":"bvaughn","description":"JS Search is an efficient, client-side search library for JavaScript and JSON objects","archived":false,"fork":false,"pushed_at":"2023-05-12T13:18:33.000Z","size":505,"stargazers_count":2222,"open_issues_count":8,"forks_count":112,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-04-11T00:52:08.254Z","etag":null,"topics":["database","indexing","performance","search"],"latest_commit_sha":null,"homepage":"http://bvaughn.github.io/js-search/","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.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-07-31T00:37:40.000Z","updated_at":"2025-04-10T15:07:51.000Z","dependencies_parsed_at":"2022-07-14T08:09:03.393Z","dependency_job_id":"11726dc4-518a-4f7f-89c6-959290703c72","html_url":"https://github.com/bvaughn/js-search","commit_stats":{"total_commits":146,"total_committers":16,"mean_commits":9.125,"dds":0.547945205479452,"last_synced_commit":"501f3d5da0453670556d197a3d02f81402477428"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvaughn%2Fjs-search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvaughn%2Fjs-search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvaughn%2Fjs-search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bvaughn%2Fjs-search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bvaughn","download_url":"https://codeload.github.com/bvaughn/js-search/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248322609,"owners_count":21084336,"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-08-01T05:01:46.621Z","updated_at":"2025-04-11T00:52:13.747Z","avatar_url":"https://github.com/bvaughn.png","language":"JavaScript","readme":"[Installation](#installation) |\n[Overview](#overview) |\n[Tokenization](#tokenization) |\n[Stemming](#stemming) |\n[Stop Words](#stop-words) |\n[Search Index](#configuring-the-search-index) |\n[Index Strategy](#configuring-the-index-strategy)\n\n# Js Search: client-side search library\n\nJs Search enables efficient client-side searches of JavaScript and JSON objects.\nIt is ES5 compatible and does not require jQuery or any other third-party libraries.\n\nJs Search began as a lightweight implementation of [Lunr JS](http://lunrjs.com/), offering runtime performance\nimprovements and a smaller file size. It has since expanded to include a rich feature set- supporting stemming,\nstop-words, and TF-IDF ranking.\n\nHere are some JS Perf benchmarks comparing the two search libraries. (Thanks to [olivernn](https://github.com/olivernn)\nfor tweaking the Lunr side for a better comparison!)\n\n* [Initial building of search index](http://jsperf.com/js-search-vs-lunr-js-build-search-index/5)\n* [Running a search](http://jsperf.com/js-search-vs-lunr-js-running-searches/5)\n\nIf you're looking for a simpler, web-worker optimized JS search utility check out [js-worker-search](https://github.com/bvaughn/js-worker-search).\n\n---\n### If you like this project, 🎉 [become a sponsor](https://github.com/sponsors/bvaughn/) or ☕ [buy me a coffee](http://givebrian.coffee/)\n---\n### Installation\n\nYou can install using either [Bower](http://bower.io/) or [NPM](https://www.npmjs.com/) like so:\n\n```shell\nnpm install js-search\nbower install js-search\n```\n\n### Overview\n\nAt a high level you configure Js Search by telling it which fields it should index for searching and then add the\nobjects to be searched.\n\nFor example, a simple use of JS Search would be as follows:\n\n```javascript\nimport * as JsSearch from 'js-search';\n\nvar theGreatGatsby = {\n  isbn: '9781597226769',\n  title: 'The Great Gatsby',\n  author: {\n    name: 'F. Scott Fitzgerald'\n  },\n  tags: ['book', 'inspirational']\n};\nvar theDaVinciCode = {\n  isbn: '0307474275',\n  title: 'The DaVinci Code',\n  author: {\n    name: 'Dan Brown'\n  },\n  tags: ['book', 'mystery']\n};\nvar angelsAndDemons = {\n  isbn: '074349346X',\n  title: 'Angels \u0026 Demons',\n  author: {\n    name: 'Dan Brown',\n  },\n  tags: ['book', 'mystery']\n};\n\nvar search = new JsSearch.Search('isbn');\nsearch.addIndex('title');\nsearch.addIndex(['author', 'name']);\nsearch.addIndex('tags')\n\nsearch.addDocuments([theGreatGatsby, theDaVinciCode, angelsAndDemons]);\n\nsearch.search('The');    // [theGreatGatsby, theDaVinciCode]\nsearch.search('scott');  // [theGreatGatsby]\nsearch.search('dan');    // [angelsAndDemons, theDaVinciCode]\nsearch.search('mystery') // [angelsAndDemons, theDaVinciCode]\n```\n\n### Tokenization\n\nTokenization is the process of breaking text (e.g. sentences) into smaller, searchable tokens (e.g. words or parts of\nwords). Js Search provides a basic tokenizer that should work well for English but you can provide your own like so:\n\n```javascript\nsearch.tokenizer = {\n  tokenize( text /* string */ ) {\n    // Convert text to an Array of strings and return the Array\n  }\n};\n```\n\n### Stemming\n\nStemming is the process of reducing search tokens to their root (or \"stem\") so that searches for different forms of a\nword will still yield results. For example \"search\", \"searching\" and \"searched\" can all be reduced to the stem \"search\".\n\nJs Search does not implement its own stemming library but it does support stemming through the use of third-party\nlibraries.\n\nTo enable stemming, use the `StemmingTokenizer` like so:\n\n```javascript\nvar stemmer = require('porter-stemmer').stemmer;\n\nsearch.tokenizer =\n\tnew JsSearch.StemmingTokenizer(\n        stemmer, // Function should accept a string param and return a string\n\t    new JsSearch.SimpleTokenizer());\n```\n\n### Stop Words\n\nStop words are very common (e.g. a, an, and, the, of) and are often not semantically meaningful. By default Js Search\ndoes not filter these words, but filtering can be enabled by using the `StopWordsTokenizer` like so:\n\n```javascript\nsearch.tokenizer =\n\tnew JsSearch.StopWordsTokenizer(\n    \tnew JsSearch.SimpleTokenizer());\n```\n\nBy default Js Search uses a slightly modified version of the Google History stop words listed on\n[www.ranks.nl/stopwords](http://www.ranks.nl/stopwords). You can modify this list of stop words by adding or removing\nvalues from the `JsSearch.StopWordsMap` object like so:\n\n```javascript\nJsSearch.StopWordsMap.the = false; // Do not treat \"the\" as a stop word\nJsSearch.StopWordsMap.bob = true;  // Treat \"bob\" as a stop word\n```\n\nNote that stop words are lower case and so using a case-sensitive sanitizer may prevent some stop words from being\nremoved.\n\n### Configuring the search index\n\nThere are two search indices packaged with `js-search`.\n\nTerm frequency–inverse document frequency (or TF-IDF) is a numeric statistic intended to reflect how important a word\n(or words) are to a document within a corpus. The TF-IDF value increases proportionally to the number of times a word\nappears in the document but is offset by the frequency of the word in the corpus. This helps to adjust for the fact that\nsome words (e.g. and, or, the) appear more frequently than others.\n\nBy default Js Search supports TF-IDF ranking but this can be disabled for performance reasons if it is not required. You\ncan specify an alternate [`ISearchIndex`](https://github.com/bvaughn/js-search/blob/master/source/SearchIndex/SearchIndex.js)\nimplementation in order to disable TF-IDF, like so:\n\n```javascript\n// default\nsearch.searchIndex = new JsSearch.TfIdfSearchIndex();\n\n// Search index capable of returning results matching a set of tokens\n// but without any meaningful rank or order.\nsearch.searchIndex = new JsSearch.UnorderedSearchIndex();\n```\n\n### Configuring the index strategy\n\nThere are three index strategies packaged with `js-search`.\n\n`PrefixIndexStrategy` indexes for prefix searches.\n(e.g. the term \"cat\" is indexed as \"c\", \"ca\", and \"cat\" allowing prefix search lookups).\n\n`AllSubstringsIndexStrategy` indexes for all substrings. In other word \"c\", \"ca\", \"cat\", \"a\", \"at\", and \"t\" all match \"cat\".\n\n`ExactWordIndexStrategy` indexes for exact word matches. For example \"bob\" will match \"bob jones\" (but \"bo\" will not).\n\nBy default Js Search supports prefix indexing but this is configurable. You\ncan specify an alternate [`IIndexStrategy`](https://github.com/bvaughn/js-search/blob/master/source/IndexStrategy/IndexStrategy.js)\nimplementation in order to disable prefix indexing, like so:\n\n```javascript\n// default\nsearch.indexStrategy = new JsSearch.PrefixIndexStrategy();\n\n// this index strategy is built for all substrings matches.\nsearch.indexStrategy = new JsSearch.AllSubstringsIndexStrategy();\n\n// this index strategy is built for exact word matches.\nsearch.indexStrategy = new JsSearch.ExactWordIndexStrategy();\n```\n","funding_links":["https://github.com/sponsors/bvaughn/"],"categories":["JavaScript","Utilities","performance","Search Engine","Text Search"],"sub_categories":["React Components","Video","Reactive Programming"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbvaughn%2Fjs-search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbvaughn%2Fjs-search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbvaughn%2Fjs-search/lists"}