{"_id":"@alterjs/saber-plugin-search","name":"@alterjs/saber-plugin-search","dist-tags":{"latest":"0.13.0"},"versions":{"0.13.0":{"name":"@alterjs/saber-plugin-search","version":"0.13.0","description":"Add a fast search to your app.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/chawyehsu/saber.git"},"exports":{".":{"import":"./dist/index.min.mjs","require":"./dist/index.min.cjs"}},"main":"./dist/index.min.cjs","module":"./dist/index.min.mjs","scripts":{"build":"rimraf dist && rollup -c && node scripts/build.js","build:example":"saber build example","lint":"eslint src","prepublishOnly":"npm run build"},"peerDependencies":{"@alterjs/saber":"^0.13.0"},"publishConfig":{"access":"public"},"_id":"@alterjs/saber-plugin-search@0.13.0","gitHead":"df690b0df6c45372cb41b7fa42003f08edc08bf5","bugs":{"url":"https://github.com/chawyehsu/saber/issues"},"homepage":"https://github.com/chawyehsu/saber#readme","_nodeVersion":"18.20.4","_npmVersion":"10.7.0","dist":{"integrity":"sha512-sgJhuzSvzD49FeHIfWy8VJoKKLdTfMQWq6AByQMgX/eKUfjCZqE84amP6zL/8wAcTo6q20ooYxnyhsOWvRXADA==","shasum":"1e4758ce094c78c795cc22f17db9421114ec63ad","tarball":"https://registry.npmjs.org/@alterjs/saber-plugin-search/-/saber-plugin-search-0.13.0.tgz","fileCount":6,"unpackedSize":6546,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCEx0n9dSprViKicuSAhTLAttFzPTrppuTn9m8+vi+zHgIhALFmclLBy2SwBRpynow/L7kQ25+Wgn7RixisjS8jEvv1"}]},"_npmUser":{"name":"chawyehsu","email":"su+npm@chawyehsu.com"},"directories":{},"maintainers":[{"name":"chawyehsu","email":"su+npm@chawyehsu.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/saber-plugin-search_0.13.0_1737181517023_0.08186334808448903"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-18T06:25:16.879Z","0.13.0":"2025-01-18T06:25:17.184Z","modified":"2025-01-18T06:25:17.469Z"},"maintainers":[{"name":"chawyehsu","email":"su+npm@chawyehsu.com"}],"description":"Add a fast search to your app.","homepage":"https://github.com/chawyehsu/saber#readme","repository":{"type":"git","url":"git+https://github.com/chawyehsu/saber.git"},"bugs":{"url":"https://github.com/chawyehsu/saber/issues"},"license":"MIT","readme":"# @alterjs/saber-plugin-search\n\nAdds a hyper-fast, easy to integrate and highly customizable search to your app.\n\n## Install\n\n```bash\nyarn add @alterjs/saber-plugin-search\n```\n\n## Usage\n\nIn your `saber-config.yml`:\n\n```yml\nplugins:\n  - resolve: '@alterjs/saber-plugin-search'\n```\n\nThen in your Vue components, you can call `this.$fetchSearchDatabase()` to get the database that you can query from, this method returns a Promise which resolves an array of `Page` objects:\n\n```js\n;[\n  {\n    type: 'page',\n    title: 'About this site',\n    excerpt: '...',\n    permalink: '/about.html',\n  },\n  {\n    type: 'post',\n    title: 'Hello World',\n    excerpt: '...',\n    permalink: '/posts/hello-world.html',\n  },\n]\n```\n\nNow you can query a keyword like this:\n\n```js\nconst database = await this.$fetchSearchDatabase()\n// Typically you need to get the keyword from an `input` element\n// We hardcoded it for convenience\nconst keyword = 'hello'\nconst matchedResults = database.filter((page) => {\n  return page.title.includes(keyword) || page.excerpt.includes(keyword)\n})\n```\n\nThe above example simply uses `String.prototype.includes` to check if the page matches the keyword, however you can use a more powerful library like [Fuse.js](https://fusejs.io/) if you want more accurate result:\n\n```js\nimport Fuse from 'fuse.js'\n\nconst options = {\n  keys: [\n    {\n      name: 'title',\n      weight: 0.6,\n    },\n    {\n      name: 'excerpt',\n      weight: 0.4,\n    },\n  ],\n  shouldSort: true, // sorts the results by score\n}\n\nconst fuse = new Fuse(database, options)\nconst matchedResults = fuse.search(keyword)\n```\n\n## Plugin Options\n\n### index\n\n- Type: `string[]`\n- Default: `['type', 'title', 'excerpt', 'permalink']`\n\nOnly specified page properties will be included in the generated database.\n\n## License\n\nMIT.\n","readmeFilename":"README.md"}