# saber-plugin-search

> Add a fast search to your app.

Latest version **1.0.0** (published 2019-11-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install saber-plugin-search
pnpm add saber-plugin-search
yarn add saber-plugin-search
bun add saber-plugin-search
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-11-03 |
| First published | 2019-08-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | egoist |

## Links

- npm: https://www.npmjs.com/package/saber-plugin-search
- npm.io page: https://npm.io/package/saber-plugin-search

## Recent versions

- 1.0.0 (latest) — 2019-11-03
- 0.1.2-canary.504.adade2d.0 (canary) — 2019-10-06
- 0.1.1 — 2019-10-05
- 0.1.0 — 2019-08-22
- 0.0.2-canary.366.524f251.0 — 2019-08-22

## README

# saber-plugin-search

Adds a hyper-fast, easy to integrate and highly customizable search to your app.

## Install

```bash
yarn add saber-plugin-search
```

## Usage

In your `saber-config.yml`:

```yml
plugins:
  - resolve: saber-plugin-search
```

Then 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:

```js
;[
  {
    type: 'page',
    title: 'About this site',
    excerpt: '...',
    permalink: '/about.html'
  },
  {
    type: 'post',
    title: 'Hello World',
    excerpt: '...',
    permalink: '/posts/hello-world.html'
  }
]
```

Now you can query a keyword like this:

```js
const database = await this.$fetchSearchDatabase()
// Typically you need to get the keyword from an `input` element
// We hardcoded it for convenience
const keyword = 'hello'
const matchedResults = database.filter(page => {
  return page.title.includes(keyword) || page.excerpt.includes(keyword)
})
```

The 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:

```js
import Fuse from 'fuse.js'

const options = {
  keys: [
    {
      name: 'title',
      weight: 0.6
    },
    {
      name: 'excerpt',
      weight: 0.4
    }
  ],
  shouldSort: true // sorts the results by score
}

const fuse = new Fuse(database, options)
const matchedResults = fuse.search(keyword)
```

## Plugin Options

### index

- Type: `string[]`
- Default: `['type', 'title', 'excerpt', 'permalink']`

Only specified page properties will be included in the generated database.

## License

MIT.

---
_Source: https://npm.io/package/saber-plugin-search · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
