Skip to content

Commit

Permalink
Add configuration options to remove default pipeline functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisnyman committed Jul 31, 2018
1 parent 19df757 commit f61c737
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ activate :search do |search|
search.resources = ['blog/', 'index.html', 'contactus/index.html']

search.index_path = 'search/lunr-index.json' # defaults to `search.json`

search.lunr_dirs = ['source/vendor/lunr-custom/'] # optional alternate paths where to look for lunr js files

search.language = 'es' # defaults to 'en'
Expand Down Expand Up @@ -123,6 +123,13 @@ Note that if you add a function to the pipeline, it will also be loaded when de-
<%= search_lunr_js_pipeline %>
```

You can also remove pipeline functions that Lunr.js enables by default: trimmer, stemmer, and stopWordFilter.

```ruby
search.pipeline_remove = [
'stopWordFilter'
]
```

## Index file

Expand Down
1 change: 1 addition & 0 deletions lib/middleman-search/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class SearchExtension < Middleman::Extension
option :before_index, nil, 'Callback to execute before indexing a document'
option :index_path, 'search.json', 'Index file path'
option :pipeline, {}, 'Javascript pipeline functions to use in lunr index'
option :pipeline_remove, {}, 'Default pipeline functions to remove'
option :cache, false, 'Avoid the cache to be rebuilt on every request in development mode'
option :language, 'en', 'Language code ("es", "fr") to use when indexing site\'s content'
option :lunr_dirs, [], 'Directories in which to look for custom lunr.js files'
Expand Down
6 changes: 6 additions & 0 deletions lib/middleman-search/search-index-resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def initialize(store, path, options)
@fields = options[:fields]
@callback = options[:before_index]
@pipeline = options[:pipeline]
@pipeline_remove = options[:pipeline_remove]
@cache_index = options[:cache]
@language = options[:language]
@lunr_dirs = options[:lunr_dirs] + [File.expand_path("../../../vendor/assets/javascripts/", __FILE__)]
Expand Down Expand Up @@ -52,6 +53,11 @@ def build_index
# Use autogenerated id field as reference
source << "this.ref('id');"

# Remove default pipeline filters
@pipeline_remove.each do |name|
source << "this.pipeline.remove(lunr.#{name});"
end

# Add functions to pipeline (just registering them isn't enough)
@pipeline.each do |name, function|
source << "this.pipeline.add(lunr.Pipeline.registeredFunctions.#{name});"
Expand Down

0 comments on commit f61c737

Please sign in to comment.