# @bouncingpixel/algolia

> Helpers for algolia, namely a Mongoose model plugin

Latest version **0.5.0** (published 2017-09-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @bouncingpixel/algolia
pnpm add @bouncingpixel/algolia
yarn add @bouncingpixel/algolia
bun add @bouncingpixel/algolia
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2017-09-01 |
| First published | 2017-05-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.9.0 |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Matt Hall |
| Maintainers | bouncingpixel |

## Links

- npm: https://www.npmjs.com/package/@bouncingpixel/algolia
- Repository: https://github.com/BouncingPixel/node-packages/tree/master/algolia
- Homepage: https://github.com/BouncingPixel/node-packages
- Issues: https://github.com/BouncingPixel/node-packages/issues
- npm.io page: https://npm.io/package/@bouncingpixel/algolia

## Dependencies (4)

- [nconf](https://npm.io/package/nconf.md) ^0.8.4
- [winston](https://npm.io/package/winston.md) ^2.3.0
- [algoliasearch](https://npm.io/package/algoliasearch.md) ^3.22.2
- [@bouncingpixel/http-errors](https://npm.io/package/@bouncingpixel/http-errors.md) ^1.0.0

## Recent versions

- 0.5.0 (latest) — 2017-09-01
- 0.4.4 — 2017-08-18
- 0.4.3 — 2017-07-20
- 0.4.2 — 2017-07-20
- 0.4.1 — 2017-06-30
- 0.4.0 — 2017-06-21
- 0.3.1 — 2017-05-31
- 0.3.0 — 2017-05-25
- 0.2.0 — 2017-05-24

## README

# algolia

Server side helpers for Algolia.
Currently only has a Mongoose model plugin that extends Mongoose models for Algolia methods.
For client side, just work directly with the `algoliasearch` package.

## Working With

### Requirements

- NodeJS 6 LTS
- An Algolia account

### Free Algolia requirements

Using the Free plan on Algolia requires the use of the Powered By Logos.
Use any of the logos in the `freeplan-logos` directory and include it with the results or on the search box.
"All that we ask is a link back to Algolia via a logo next to the search bar letting the world know that your search is powered by Algolia."
[Download Powered By ZIP file](https://www.algolia.com/powered-by-algolia.zip)

### Configuration

This module, like many other `@bouncingpixel` modules, relies on nconf.
The following configuration keys should be defined to use this module:

#### Required
- `client:algoliaAppId`
  The ID of the app in Algolia containing all the indecies.
- `algoliaApiKey`
  The read+write API key used on the server side. This should not be exposed to the client side.
- `client:algoliaIndexPrefix`
  All indecies should be named with the prefix, followed by underscore, followed by the name of the data model.
  The prefix allows for multiple instances (dev, staging, prod, per-user etc) to share an app ID and not conflict.
  Algolia does not have a naming standard, but this is what we have come up with and decided to follow.

#### Optional
- `client:algoliaSearchKey`
  The read only API key used on the client side. This is automatically exported to the client.
  This is optional if all searches are done server side. For client side, use the algoliasearch package.

### Using algolia

Algolia is a 3rd party search engine that can be integrated for searching a site's data.
Algolia is an optional utility that is not required, but is included as it commonly is required.

The provided Algolia integration acts as a plugin for Mongoose schemas. The plugin adds post-save hooks to automatically
synchronize data with Algolia. The plugin allows a person to define which fields to listen for changes if not all fields are desired.
The plugin can also automatically remove entries from Algolia when a field is set.
Functions will also be added to the model to query the search index and to save or remove a data object from Algolia.

The plugin assumes each model will have a separate search index. Currently, there is no support for an index with data
collected from multiple models. This functionality may be added later if there is a need for it.

To add the plugin to the schema, use the `plugin` method and pass any desired options for the plugin:

```js
MySchema.plugin(require('../utils/schemas/algolia-methods'), {
  autoSave: true, // boolean if the auto-save post-save hook should be enabled
  includeObjectInIndex: fn, // a function to determine if a particular object should be included in Algolia
  castToObject: fn, // a function to convert an object into the exact data format to be stored in Algolia
  errorsOnNotFound: false, // boolean if the function findOneUpdateAndSync does not find an object to update
  updateIfAnyField: null, // an array of fields that when changed, will cause an automatic sync to Algolia
                          // the default null will assume any change should be sync'd to Algolia
  removeIfFieldSet: ['removed'] // an array of fields that when set to a truthy value will remove the object from Algolia
                                // when unset, the object will be added to Algolia
});
```

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