README.md in middleman-search-0.1.1 vs README.md in middleman-search-0.2.0

- old
+ new

@@ -25,12 +25,18 @@ search.resources = ['blog/', 'index.html', 'contactus/index.html'] search.index_path = 'search/lunr-index.json' # defaults to `search.json` search.fields = { title: {boost: 100, store: true, required: true}, content: {boost: 50}, - url: {index: false, store: true} + url: {index: false, store: true}, + author: {boost: 30} } + search.before_index = Proc.new do |to_index, to_store, resource| + if author = resource.data.author + to_index[:author] = data.authors[author].name + end + end end ``` Where `resources` is a list of the beginning of the URL of the resources to index (tested with `String#start_with?`), `index_path` is the relative path of the generated index file in your site, and `fields` is a hash with one entry for each field to be indexed, with a hash of options associated: @@ -39,14 +45,16 @@ - `index` Whether to index this field, defaults to true - `required` The resource will not be indexed if a field marked as required has an empty or null value Note that a special field `id` is included automatically, with an autogenerated identifier to be used as the `ref` for the document. -All fields values are retrieved from the resource `data` (ie its frontmatter), or from a `data` hash inside its `options` in `resource.metadata`, except for: +All fields values are retrieved from the resource `data` (ie its frontmatter), or from the `options` in the `resource.metadata` (i.e., any options specified in a `proxy` page), except for: - `url` which is the actual resource url - `content` the text extracted from the rendered resource, without including its layout -You should also `require` the `lunr.min.js` file to your `all.js` file: +The `before_index` option accepts a callback that will be executed for each resource, and will be executed with the document to be indexed and the map to be stored, in the `index` and `docs` objects of the output respectively (see below), as well as the resource being processed. You can use this callback to modify either of those, or `throw(:skip)` to skip the resource in question. + +You should also `require` the `lunr.min.js` file to your `all.js` file, to actually use the index for search in your website: ```javascript //= require lunr.min ```