General information
9 |Sub heading 1
10 |-
11 |
- Info 1 12 |
- Info 2 13 |
- Info 3 14 |
- Info 4 15 |
- Info 5 16 |
├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── contributing.md ├── example ├── config.example.json ├── config.js ├── docs │ ├── about.html │ └── index.html ├── index.js ├── indexer-algolia.js ├── indexer-lunr.js ├── lunr-search.json ├── search-algolia.js └── search-lunr.js ├── index.js ├── lib └── utils.js ├── package.json └── test └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | "env": { 7 | "browser": false, 8 | "es6": true, 9 | "node": true, 10 | "mocha": true 11 | }, 12 | "globals": { 13 | "document": false, 14 | "navigator": false, 15 | "window": false 16 | }, 17 | "rules": { 18 | "accessor-pairs": 2, 19 | "arrow-spacing": [ 20 | 2, 21 | { 22 | "before": true, 23 | "after": true 24 | } 25 | ], 26 | "block-spacing": [ 27 | 2, 28 | "always" 29 | ], 30 | "brace-style": [ 31 | 2, 32 | "1tbs", 33 | { 34 | "allowSingleLine": true 35 | } 36 | ], 37 | "comma-dangle": [ 38 | 2, 39 | "never" 40 | ], 41 | "comma-spacing": [ 42 | 2, 43 | { 44 | "before": false, 45 | "after": true 46 | } 47 | ], 48 | "comma-style": [ 49 | 2, 50 | "last" 51 | ], 52 | "constructor-super": 2, 53 | "curly": [ 54 | 2, 55 | "multi-line" 56 | ], 57 | "dot-location": [ 58 | 2, 59 | "property" 60 | ], 61 | "eol-last": 2, 62 | "eqeqeq": [ 63 | 2, 64 | "allow-null" 65 | ], 66 | "generator-star-spacing": [ 67 | 2, 68 | { 69 | "before": true, 70 | "after": true 71 | } 72 | ], 73 | "handle-callback-err": [ 74 | 2, 75 | "^(err|error)$" 76 | ], 77 | "indent": [ 78 | 2, 79 | 2, 80 | { 81 | "SwitchCase": 1 82 | } 83 | ], 84 | "key-spacing": [ 85 | 2, 86 | { 87 | "beforeColon": false, 88 | "afterColon": true 89 | } 90 | ], 91 | "keyword-spacing": [ 92 | 2, 93 | { 94 | "before": true, 95 | "after": true 96 | } 97 | ], 98 | "new-cap": [ 99 | 2, 100 | { 101 | "newIsCap": true, 102 | "capIsNew": false 103 | } 104 | ], 105 | "new-parens": 2, 106 | "no-array-constructor": 2, 107 | "no-caller": 2, 108 | "no-class-assign": 2, 109 | "no-cond-assign": 2, 110 | "no-const-assign": 2, 111 | "no-control-regex": 2, 112 | "no-debugger": 2, 113 | "no-delete-var": 2, 114 | "no-dupe-args": 2, 115 | "no-dupe-class-members": 2, 116 | "no-dupe-keys": 2, 117 | "no-duplicate-case": 2, 118 | "no-empty-character-class": 2, 119 | "no-eval": 2, 120 | "no-ex-assign": 2, 121 | "no-extend-native": 2, 122 | "no-extra-bind": 2, 123 | "no-extra-boolean-cast": 2, 124 | "no-extra-parens": [ 125 | 2, 126 | "functions" 127 | ], 128 | "no-fallthrough": 2, 129 | "no-floating-decimal": 2, 130 | "no-func-assign": 2, 131 | "no-implied-eval": 2, 132 | "no-inner-declarations": [ 133 | 2, 134 | "functions" 135 | ], 136 | "no-invalid-regexp": 2, 137 | "no-irregular-whitespace": 2, 138 | "no-iterator": 2, 139 | "no-label-var": 2, 140 | "no-labels": 2, 141 | "no-lone-blocks": 2, 142 | "no-mixed-spaces-and-tabs": 2, 143 | "no-multi-spaces": 2, 144 | "no-multi-str": 2, 145 | "no-multiple-empty-lines": [ 146 | 2, 147 | { 148 | "max": 1 149 | } 150 | ], 151 | "no-native-reassign": 0, 152 | "no-negated-in-lhs": 2, 153 | "no-new": 2, 154 | "no-new-func": 2, 155 | "no-new-object": 2, 156 | "no-new-require": 2, 157 | "no-new-wrappers": 2, 158 | "no-obj-calls": 2, 159 | "no-octal": 2, 160 | "no-octal-escape": 2, 161 | "no-proto": 0, 162 | "no-redeclare": 2, 163 | "no-regex-spaces": 2, 164 | "no-return-assign": 2, 165 | "no-self-compare": 2, 166 | "no-sequences": 2, 167 | "no-shadow-restricted-names": 2, 168 | "no-spaced-func": 2, 169 | "no-sparse-arrays": 2, 170 | "no-this-before-super": 2, 171 | "no-throw-literal": 2, 172 | "no-trailing-spaces": 0, 173 | "no-undef": 2, 174 | "no-undef-init": 2, 175 | "no-unexpected-multiline": 2, 176 | "no-unneeded-ternary": [ 177 | 2, 178 | { 179 | "defaultAssignment": false 180 | } 181 | ], 182 | "no-unreachable": 2, 183 | "no-unused-vars": [ 184 | 2, 185 | { 186 | "vars": "all", 187 | "args": "none" 188 | } 189 | ], 190 | "no-useless-call": 0, 191 | "no-with": 2, 192 | "one-var": [ 193 | 0, 194 | { 195 | "initialized": "never" 196 | } 197 | ], 198 | "operator-linebreak": [ 199 | 0, 200 | "after", 201 | { 202 | "overrides": { 203 | "?": "before", 204 | ":": "before" 205 | } 206 | } 207 | ], 208 | "padded-blocks": [ 209 | 0, 210 | "never" 211 | ], 212 | "quotes": [ 213 | 2, 214 | "single", 215 | "avoid-escape" 216 | ], 217 | "radix": 2, 218 | "semi": [ 219 | 2, 220 | "always" 221 | ], 222 | "semi-spacing": [ 223 | 2, 224 | { 225 | "before": false, 226 | "after": true 227 | } 228 | ], 229 | "space-before-blocks": [ 230 | 2, 231 | "always" 232 | ], 233 | "space-before-function-paren": [ 234 | 2, 235 | "never" 236 | ], 237 | "space-in-parens": [ 238 | 2, 239 | "never" 240 | ], 241 | "space-infix-ops": 2, 242 | "space-unary-ops": [ 243 | 2, 244 | { 245 | "words": true, 246 | "nonwords": false 247 | } 248 | ], 249 | "spaced-comment": [ 250 | 0, 251 | "always", 252 | { 253 | "markers": [ 254 | "global", 255 | "globals", 256 | "eslint", 257 | "eslint-disable", 258 | "*package", 259 | "!", 260 | "," 261 | ] 262 | } 263 | ], 264 | "use-isnan": 2, 265 | "valid-typeof": 2, 266 | "wrap-iife": [ 267 | 2, 268 | "any" 269 | ], 270 | "yoda": [ 271 | 2, 272 | "never" 273 | ] 274 | } 275 | } 276 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | tmp 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - 'node' 5 | - '6' 6 | - '5' 7 | - '4' 8 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | ```js 4 | var search = require('{%= name %}'); 5 | ``` 6 | 7 | ## API 8 | {%= apidocs('index.js') %} 9 | 10 | ### Indexers 11 | 12 | Indexers are objects that have `collect` and `index` methods that will be executed when [collect](#collect) or [index](#index) are called on [app.search](#search). 13 | 14 | The indexer objects may be plain objects or instances created with those methods. See the [examples](examples) to see what indexers may look like. 15 | 16 | Simple object to be used in examples below. 17 | 18 | ```js 19 | var indexer = {}; 20 | ``` 21 | 22 | #### .collect 23 | 24 | The collect method on an indexer will be passed a `file` object and a `next` callback. The collect method 25 | should create an object to pass back to `next` that will be added to the `.files` collection on the `search` instance. 26 | 27 | If `file` is a view from [assemble][], we can collect information about the file that we want to index: 28 | 29 | ```js 30 | indexer.collect = function(file, next) { 31 | var obj = { 32 | key: file.key, 33 | title: file.data.title, 34 | category: file.data.category, 35 | url: file.data.url, 36 | body: file.content 37 | }; 38 | // return the object 39 | next(null, obj); 40 | }; 41 | ``` 42 | 43 | #### .index 44 | 45 | The 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. 46 | 47 | ```js 48 | indexer.index = function(files, options, cb) { 49 | for (var key in files) { 50 | if (files.hasOwnProperty(key)) { 51 | console.log(key); 52 | console.log(files[key]); 53 | console.log(); 54 | } 55 | } 56 | cb(); 57 | }; 58 | ``` 59 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Brian Woodward 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # base-search [](https://www.npmjs.com/package/base-search) [](https://npmjs.org/package/base-search) [](https://npmjs.org/package/base-search) [](https://travis-ci.org/node-base/base-search) 2 | 3 | > Base plugin that adds methods for creating, updating and using search indices. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | ```sh 10 | $ npm install --save base-search 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```js 16 | var search = require('base-search'); 17 | ``` 18 | 19 | ## API 20 | 21 | ### [.search](index.js#L20) 22 | 23 | Plugin for [base](https://github.com/node-base/base) applications like [generate](https://github.com/generate/generate), [assemble](https://github.com/assemble/assemble), [verb](https://github.com/verbose/verb), and [update](https://github.com/update/update) to add an instance of [sarge](https://github.com/doowb/sarge) as `app.search` that has methods for creating search indices using [indexers](#indexers). 24 | 25 | **Params** 26 | 27 | * `config` **{Object}**: Configuration object used to specify default indexer to use. 28 | * `returns` **{Function}**: Plugin function passed to `app.use` methods. 29 | 30 | **Example** 31 | 32 | ```js 33 | var app = assemble(); 34 | app.use(search()); 35 | console.log(app.search); 36 | ``` 37 | 38 | ### Indexers 39 | 40 | Indexers are objects that have `collect` and `index` methods that will be executed when [collect](#collect) or [index](#index) are called on [app.search](#search). 41 | 42 | The indexer objects may be plain objects or instances created with those methods. See the [examples](examples) to see what indexers may look like. 43 | 44 | Simple object to be used in examples below. 45 | 46 | ```js 47 | var indexer = {}; 48 | ``` 49 | 50 | #### .collect 51 | 52 | The collect method on an indexer will be passed a `file` object and a `next` callback. The collect method 53 | should create an object to pass back to `next` that will be added to the `.files` collection on the `search` instance. 54 | 55 | If `file` is a view from [assemble](https://github.com/assemble/assemble), we can collect information about the file that we want to index: 56 | 57 | ```js 58 | indexer.collect = function(file, next) { 59 | var obj = { 60 | key: file.key, 61 | title: file.data.title, 62 | category: file.data.category, 63 | url: file.data.url, 64 | body: file.content 65 | }; 66 | // return the object 67 | next(null, obj); 68 | }; 69 | ``` 70 | 71 | #### .index 72 | 73 | The 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. 74 | 75 | ```js 76 | indexer.index = function(files, options, cb) { 77 | for (var key in files) { 78 | if (files.hasOwnProperty(key)) { 79 | console.log(key); 80 | console.log(files[key]); 81 | console.log(); 82 | } 83 | } 84 | cb(); 85 | }; 86 | ``` 87 | 88 | ## About 89 | 90 | ### Related projects 91 | 92 | * [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit") 93 | * [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://github.com/node-base/base) | [homepage](https://github.com/node-base/base "base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common methods, like `set`, `get`, `del` and `use`.") 94 | * [generate](https://www.npmjs.com/package/generate): Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… [more](https://github.com/generate/generate) | [homepage](https://github.com/generate/generate "Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.") 95 | * [sarge](https://www.npmjs.com/package/sarge): Register and use custom search indexers to create, update and use search indices. | [homepage](https://github.com/doowb/sarge "Register and use custom search indexers to create, update and use search indices.") 96 | * [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") 97 | * [update](https://www.npmjs.com/package/update): Be scalable! Update is a new, open source developer framework and CLI for automating updates… [more](https://github.com/update/update) | [homepage](https://github.com/update/update "Be scalable! Update is a new, open source developer framework and CLI for automating updates of any kind in code projects.") 98 | * [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.") 99 | 100 | ### Contributing 101 | 102 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 103 | 104 | Please read the [contributing guide](contributing.md) for advice on opening issues, pull requests, and coding standards. 105 | 106 | ### Building docs 107 | 108 | _(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.)_ 109 | 110 | To generate the readme, run the following command: 111 | 112 | ```sh 113 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 114 | ``` 115 | 116 | ### Running tests 117 | 118 | Install dev dependencies: 119 | 120 | ```sh 121 | $ npm install && npm test 122 | ``` 123 | 124 | ### Author 125 | 126 | **Brian Woodward** 127 | 128 | * [github/doowb](https://github.com/doowb) 129 | * [twitter/doowb](https://twitter.com/doowb) 130 | 131 | ### License 132 | 133 | Copyright © 2017, [Brian Woodward](https://github.com/doowb). 134 | MIT 135 | 136 | *** 137 | 138 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.2, on February 01, 2017._ -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to base-search 2 | 3 | First and foremost, thank you! We appreciate that you want to contribute to base-search, your time is valuable, and your contributions mean a lot to us. 4 | 5 | **What does "contributing" mean?** 6 | 7 | Creating an issue is the simplest form of contributing to a project. But there are many ways to contribute, including the following: 8 | 9 | - Updating or correcting documentation 10 | - Feature requests 11 | - Bug reports 12 | 13 | If you'd like to learn more about contributing in general, the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) has a lot of useful information. 14 | 15 | **Showing support for base-search** 16 | 17 | Please keep in mind that open source software is built by people like you, who spend their free time creating things the rest the community can use. 18 | 19 | Don't have time to contribute? No worries, here are some other ways to show your support for base-search: 20 | 21 | - star the [project](https://github.com/node-base/base-search) 22 | - tweet your support for base-search 23 | 24 | ## Issues 25 | 26 | ### Before creating an issue 27 | 28 | Please try to determine if the issue is caused by an underlying library, and if so, create the issue there. Sometimes this is difficult to know. We only ask that you attempt to give a reasonable attempt to find out. Oftentimes the readme will have advice about where to go to create issues. 29 | 30 | Try to follow these guidelines 31 | 32 | - **Investigate the issue**: 33 | - **Check the readme** - oftentimes you will find notes about creating issues, and where to go depending on the type of issue. 34 | - Create the issue in the appropriate repository. 35 | 36 | ### Creating an issue 37 | 38 | Please be as descriptive as possible when creating an issue. Give us the information we need to successfully answer your question or address your issue by answering the following in your issue: 39 | 40 | - **version**: please note the version of base-search are you using 41 | - **extensions, plugins, helpers, etc** (if applicable): please list any extensions you're using 42 | - **error messages**: please paste any error messages into the issue, or a [gist](https://gist.github.com/) 43 | 44 | ## Above and beyond 45 | 46 | Here are some tips for creating idiomatic issues. Taking just a little bit extra time will make your issue easier to read, easier to resolve, more likely to be found by others who have the same or similar issue in the future. 47 | 48 | - read the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) 49 | - take some time to learn basic markdown. This [markdown cheatsheet](https://gist.github.com/jonschlinkert/5854601) is super helpful, as is the GitHub guide to [basic markdown](https://help.github.com/articles/markdown-basics/). 50 | - Learn about [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown/). And if you want to really go above and beyond, read [mastering markdown](https://guides.github.com/features/mastering-markdown/). 51 | - use backticks to wrap code. This ensures that code will retain its format, making it much more readable to others 52 | - use syntax highlighting by adding the correct language name after the first "code fence" 53 | 54 | 55 | [node-glob]: https://github.com/isaacs/node-glob 56 | [micromatch]: https://github.com/jonschlinkert/micromatch 57 | [so]: http://stackoverflow.com/questions/tagged/base-search -------------------------------------------------------------------------------- /example/config.example.json: -------------------------------------------------------------------------------- 1 | { 2 | "ALGOLIA_APPLICATION_ID": "your-application-id-here", 3 | "ALGOLIA_SECRET_KEY": "your-secret-api-key-here" 4 | } 5 | -------------------------------------------------------------------------------- /example/config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var extend = require('extend-shallow'); 4 | var exists = require('fs-exists-sync'); 5 | var path = require('path'); 6 | 7 | module.exports = function(options) { 8 | var config = {}; 9 | var config = {}; 10 | if (exists(path.join(__dirname, '../tmp/config.json'))) { 11 | config = require('../tmp/config.json'); 12 | } else if (exists(path.join(__dirname, 'config.json'))) { 13 | config = require('./config.json'); 14 | } 15 | config = extend({}, config, options); 16 | return config; 17 | }; 18 | -------------------------------------------------------------------------------- /example/docs/about.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |This is some content in the main content under sub heading 1
11 |This is some content in the main content under sub heading 2
13 |This is some content in the main content under sub heading 3
15 |