{"id":15743917,"url":"https://github.com/doowb/sarge","last_synced_at":"2025-03-13T11:30:31.939Z","repository":{"id":65990638,"uuid":"80682045","full_name":"doowb/sarge","owner":"doowb","description":"Register and use custom search indexers to create, update and use search indices.","archived":false,"fork":false,"pushed_at":"2017-04-05T17:09:37.000Z","size":26,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-26T19:51:43.916Z","etag":null,"topics":["index","indexer","indexing","search"],"latest_commit_sha":null,"homepage":"https://github.com/doowb/sarge","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["doowb","jonschlinkert"]}},"created_at":"2017-02-02T01:17:58.000Z","updated_at":"2021-04-12T21:59:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"a281e781-1b4f-4a02-815e-9f2877614336","html_url":"https://github.com/doowb/sarge","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"afd4ddaa713656fd9de2e4b2076f6633ccef4a9c"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fsarge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fsarge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fsarge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fsarge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doowb","download_url":"https://codeload.github.com/doowb/sarge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243395937,"owners_count":20284237,"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":["index","indexer","indexing","search"],"created_at":"2024-10-04T03:22:00.703Z","updated_at":"2025-03-13T11:30:31.934Z","avatar_url":"https://github.com/doowb.png","language":"JavaScript","funding_links":["https://github.com/sponsors/doowb","https://github.com/sponsors/jonschlinkert"],"categories":[],"sub_categories":[],"readme":"# sarge [![NPM version](https://img.shields.io/npm/v/sarge.svg?style=flat)](https://www.npmjs.com/package/sarge) [![NPM monthly downloads](https://img.shields.io/npm/dm/sarge.svg?style=flat)](https://npmjs.org/package/sarge)  [![NPM total downloads](https://img.shields.io/npm/dt/sarge.svg?style=flat)](https://npmjs.org/package/sarge) [![Linux Build Status](https://img.shields.io/travis/doowb/sarge.svg?style=flat\u0026label=Travis)](https://travis-ci.org/doowb/sarge)\n\n\u003e Register and use custom search indexers to create, update and use search indices.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save sarge\n```\n\n## Usage\n\n```js\nvar Search = require('sarge');\n```\n\n## API\n\n### [Sarge](index.js#L21)\n\nSarge object used to register [indexers](#indexers) and execute the [collect](#collect) and [index](#index) methods on indexers.\n\n**Params**\n\n* `options` **{Object}**: Options to control defaults.\n* `options.indexer` **{String}**: Set a default indexer to use when one isn't specified in [.collect](#collect) or [.index](#index). Defaults to \"default\".\n* `options.indexers` **{Object}**: Optionally set an object of indexers when creating the new instance.\n* `returns` **{Object}**: Instance of Sarge\n\n**Example**\n\n```js\nvar sarge = new Sarge();\n```\n\n### [.indexer](index.js#L53)\n\nGet or set an indexer by name. This throws an error if only name is passed and the indexer is not found.\n\n**Params**\n\n* `name` **{String}**: Name of indexer to get or set.\n* `indexer` **{Object}**: Instance of an indexer. See [indexers](#indexers) for more information.\n* `returns` **{Object}**: Sarge instance when setting, indexer instance when getting.\n\n**Example**\n\n```js\n// set\nsarge.indexer('foo', foo);\n// get\nvar foo = sarge.indexer('foo');\n```\n\n### [.collect](index.js#L86)\n\nCreates a through stream that will execute `.collect` method on specified indexer for each file passing through the stream. The `.collect` method passes an object to the callback that will be collected and then indexed when `.index` is called.\n\n**Params**\n\n* `options` **{Object}**: Options used to specify the indexer to use.\n* `returns` **{Stream}**: Through stream that's used to collect files to index.\n\n**Example**\n\n```js\napp.src('*.md')\n  // use default set on instance or \"default\" indexer\n  .pipe(sarge.collect())\n  // or specify a registred indexer to use\n  .pipe(sarge.collect({indexer: 'foo'}));\n```\n\n### [.index](index.js#L127)\n\nExecutes the `.index` method on the specified indexer passing the collected files and options along with a callback to indicate when indexing is finished.\n\n**Params**\n\n* `options` **{Object}**: Options to specify the indexer to use and to pass into the `.index` method.\n* `options.indexer` **{String}**: Indexer to use. Defaults to 'default'\n* `options.clear` **{Boolean}**: Optionally clear the stored `files` object. This is useful for incremental indexing in a continuous stream.\n* `cb` **{Function}**: Callback function passed into the indexer's `.index` method to specify when indexing is finished.\n\n**Example**\n\n```js\n// use default indexer specified when adding the plugin\nsarge.index(function(err) {\n  if (err) return console.error(err);\n  console.log('indexing finished');\n});\n\n// use registered indexer\nsarge.index({indexer: 'foo'}, function(err) {\n  if (err) return console.error(err);\n  console.log('indexing finished');\n});\n```\n\n### Indexers\n\nIndexers are objects that have `collect` and `index` methods that will be executed when [collect](#collect) or [index](#index) are called on [search](#search).\n\nThe indexer objects may be plain objects or instances created with those methods. See the [examples](examples) to see what indexers may look like.\n\nSimple object to be used in examples below.\n\n```js\nvar indexer = {};\n```\n\n#### .collect\n\nThe collect method on an indexer will be passed a `file` object and a `next` callback. The collect method\nshould create an object to pass back to `next` that will be added to the `.files` collection on the `search` instance.\n\nIf `file` is a view from [assemble](https://github.com/assemble/assemble), we can collect information about the file that we want to index:\n\n```js\nindexer.collect = function(file, next) {\n  var obj = {\n    key: file.key,\n    title: file.data.title,\n    category: file.data.category,\n    url: file.data.url,\n    body: file.content\n  };\n  // return the object\n  next(null, obj);\n};\n```\n\n#### .index\n\nThe index method on an indexer will be passed a `files` object containing all fo the collected files, an `options` object which is the same as the `options` passed into the [search.index](#index) method, and a callback function to call when indexing is complete. The callback function is the same as the one passed into the [search.index](#index) method so users may choose to return additional information if necessary.\n\n```js\nindexer.index = function(files, options, cb) {\n  for (var key in files) {\n    if (files.hasOwnProperty(key)) {\n      console.log(key);\n      console.log(files[key]);\n      console.log();\n    }\n  }\n  cb();\n};\n```\n\n## About\n\n### Related projects\n\n* [base-search](https://www.npmjs.com/package/base-search): Base plugin that adds methods for creating, updating and using search indices. | [homepage](https://github.com/node-base/base-search \"Base plugin that adds methods for creating, updating and using search indices.\")\n* [search-indexer-algolia](https://www.npmjs.com/package/search-indexer-algolia): base-search indexer to enable collecting and adding records to an algolia search index | [homepage](https://github.com/doowb/search-indexer-algolia \"base-search indexer to enable collecting and adding records to an algolia search index\")\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 © 2017, [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.4.3, on April 04, 2017._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fsarge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoowb%2Fsarge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fsarge/lists"}