{"id":15743952,"url":"https://github.com/doowb/search-indexer-algolia","last_synced_at":"2025-10-25T01:15:46.164Z","repository":{"id":65493582,"uuid":"80545209","full_name":"doowb/search-indexer-algolia","owner":"doowb","description":"base-search indexer to enable collecting and adding records to an algolia search index","archived":false,"fork":false,"pushed_at":"2018-06-19T00:22:47.000Z","size":14,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-24T04:11:48.370Z","etag":null,"topics":["algolia","base-search","sarge","search","search-indexer"],"latest_commit_sha":null,"homepage":"https://github.com/doowb/search-indexer-algolia","language":"JavaScript","has_issues":true,"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/doowb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-31T17:45:21.000Z","updated_at":"2020-06-14T23:52:15.000Z","dependencies_parsed_at":"2023-01-25T21:05:12.505Z","dependency_job_id":null,"html_url":"https://github.com/doowb/search-indexer-algolia","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fsearch-indexer-algolia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fsearch-indexer-algolia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fsearch-indexer-algolia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fsearch-indexer-algolia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doowb","download_url":"https://codeload.github.com/doowb/search-indexer-algolia/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251357126,"owners_count":21576652,"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":["algolia","base-search","sarge","search","search-indexer"],"created_at":"2024-10-04T03:22:10.500Z","updated_at":"2025-10-25T01:15:41.103Z","avatar_url":"https://github.com/doowb.png","language":"JavaScript","funding_links":[],"categories":["Community Integrations"],"sub_categories":[],"readme":"# search-indexer-algolia [![NPM version](https://img.shields.io/npm/v/search-indexer-algolia.svg?style=flat)](https://www.npmjs.com/package/search-indexer-algolia) [![NPM monthly downloads](https://img.shields.io/npm/dm/search-indexer-algolia.svg?style=flat)](https://npmjs.org/package/search-indexer-algolia) [![NPM total downloads](https://img.shields.io/npm/dt/search-indexer-algolia.svg?style=flat)](https://npmjs.org/package/search-indexer-algolia) [![Linux Build Status](https://img.shields.io/travis/doowb/search-indexer-algolia.svg?style=flat\u0026label=Travis)](https://travis-ci.org/doowb/search-indexer-algolia) [![Windows Build Status](https://img.shields.io/appveyor/ci/doowb/search-indexer-algolia.svg?style=flat\u0026label=AppVeyor)](https://ci.appveyor.com/project/doowb/search-indexer-algolia)\n\n\u003e base-search indexer to enable collecting and adding records to an algolia search index\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save search-indexer-algolia\n```\n\n**HEADS UP!**\n\n\u003e `SECRET_KEY` has been changed to `API_KEY` to reflect the naming conventions of the [algoliasearch](https://www.algolia.com/doc/api-client/javascript/) api. `SECRET_KEY` will still work but will be deprecrated and removed in the next major version.\n\n## Usage\n\n```js\nvar algolia = require('search-indexer-algolia');\n\nvar options = {\n  APPLICATION_ID: '12345',\n  API_KEY: 'xxxxx',\n  index: 'my-index',\n  collectFn: function(file, next) {\n    // customize object being collected\n    var obj = {\n      objectID: file.key,\n      key: file.key\n    };\n    return next(null, obj);\n  }\n};\napp.search.indexer('algolia', algolia(options));\n```\n\n## API\n\n### [indexer](index.js#L27)\n\nCreates a new algolia indexer that may be used in [base-search](https://github.com/node-base/base-search).\n\n**Params**\n\n* `options` **{Object}**: Options for setting up the [algoliasearch](https://www.algolia.com/doc/api-client/javascript/) client and index.\n* `options.APPLICATION_ID` **{String}**: algolia application id\n* `options.API_KEY` **{String}**: algolia api key used for adding records to an index\n* `options.index` **{String}**: algolia index to add records to\n* `options.collectFn` **{Function}**: Custom collect function to use for creating records from file objects. See [collect](#collect) method for more information.\n* `options.indexFn` **{Function}**: Custom index function used to add records to the algolia index. See [index](#index) method for more information.\n* `returns` **{Object}**: Indexer instance to pass to [base-search](https://github.com/node-base/base-search).\n\n**Example**\n\n```js\nvar opts = {\n  APPLICATION_ID: '12345',\n  API_KEY: 'xxxxx'\n};\napp.search.indexer('algolia', algolia(opts));\n```\n\n### [.init](index.js#L62)\n\nInitialize the [algoliasearch](https://www.algolia.com/doc/api-client/javascript/) client and index. The client will only be created the first time this method is called. This is called inside the [collect](#collect) and [index](#index) methods but may be called manually before using.\n\n**Params**\n\n* `options` **{Object}**: Options for setting up the [algoliasearch](https://www.algolia.com/doc/api-client/javascript/) client and index.\n* `options.APPLICATION_ID` **{String}**: algolia application id\n* `options.API_KEY` **{String}**: algolia api key used for adding records to an index\n* `options.index` **{String}**: algolia index to add records to\n* `options.collectFn` **{Function}**: Custom collect function to use for creating records from file objects. See [collect](#collect) method for more information.\n* `options.indexFn` **{Function}**: Custom index function used to add records to the algolia index. See [index](#index) method for more information.\n* `returns` **{Object}**: Indexer instance to pass to [base-search](https://github.com/node-base/base-search).\n\n**Example**\n\n```js\nvar indexer = algolia(opts);\napp.search.indexer('algolia', indexer.init(opts));\n```\n\n### [.collect](index.js#L102)\n\nThis method is called when collecting records to be indexed. It will be called for each file coming through the stream created by `app.search.collect()`. If `options.collectFn` is a function, the function will be called using the `indexer` instance as the context. This provides access to the [algoliasearch](https://www.algolia.com/doc/api-client/javascript/) index by using `this.idx` inside the function.\n\n**Params**\n\n* `file` **{Object}**: File object passed in from [base-search](https://github.com/node-base/base-search)\n* `next` **{Function}**: Callback function to return the customized record or `false` to indicate the file should be skipped.\n\n**Example**\n\n```js\n// set a custom `collectFn` when creating the indexer\nvar opts = {\n  ...\n  collectFn: function(file, next) {\n    if (!file.data.foo) {\n      // passing `false` says to not collect this file\n      return next(null, false);\n    }\n    return next(null, {objectID: file.key, key: file.key, title: file.title});\n  }\n};\napp.search.indexer('algolia', algolia(opts));\n```\n\n### [.index](index.js#L138)\n\nThis method is called when indexing the collected files. It will be passed an object of files collect through the [collect](#collect) method. If `options.indexFn` is a function, the function will be called using the `indexer` instance as the context. This provides access to the [algoliasearch](https://www.algolia.com/doc/api-client/javascript/) index by using `this.idx` inside the function.\n\n**Params**\n\n* `files` **{Object}**: Files object passed in from [base-search](https://github.com/node-base/base-search).\n* `options` **{Object}**: Options object passed in from [base-search](https://github.com/node-base/base-search).\n* `cb` **{Function}**: Callback function passed in from [base-seaerch][] used to indicate that indexing has finished.\n\n**Example**\n\n```js\n// set a custom `indexFn` when creating the indexer\nvar opts = {\n  ...\n  indexFn: function(files, options, cb) {\n    var arr = Object.keys(files)\n      .map(function(key) {\n        return files[key];\n      });\n\n    // add the array of objects to the algolia index\n    this.idx.addObjects(arr, cb);\n  }\n};\napp.search.indexer('algolia', algolia(opts));\n```\n\n## About\n\n### Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\nPlease read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.\n\n### Building docs\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n### Running tests\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n### Author\n\n**Brian Woodward**\n\n* [github/doowb](https://github.com/doowb)\n* [twitter/doowb](https://twitter.com/doowb)\n\n### License\n\nCopyright © 2018, [Brian Woodward](https://github.com/doowb).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.7.0, on June 18, 2018._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fsearch-indexer-algolia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoowb%2Fsearch-indexer-algolia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fsearch-indexer-algolia/lists"}