Skip to content

Commit

Permalink
Merge pull request #2 from alphagov/replace-tokenizer-separator
Browse files Browse the repository at this point in the history
Add configuration option to replace the default tokenizer separator
  • Loading branch information
lewisnyman authored Aug 1, 2018
2 parents d13cb9a + 84980b8 commit 31def14
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/middleman-search/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class SearchExtension < Middleman::Extension
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 :tokenizer_separator, {}, 'Replace the default tokizer separator'
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
5 changes: 5 additions & 0 deletions lib/middleman-search/search-index-resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def initialize(store, path, options)
@callback = options[:before_index]
@pipeline = options[:pipeline]
@pipeline_remove = options[:pipeline_remove]
@tokenizer_separator = options[:tokenizer_separator]
@cache_index = options[:cache]
@language = options[:language]
@lunr_dirs = options[:lunr_dirs] + [File.expand_path("../../../vendor/assets/javascripts/", __FILE__)]
Expand Down Expand Up @@ -63,6 +64,10 @@ def build_index
source << "this.pipeline.add(lunr.Pipeline.registeredFunctions.#{name});"
end

if @tokenizer_separator
source << "this.tokenizerFn.seperator = #{@tokenizer_separator}"
end

# Use language if set
source << "this.use(lunr.#{@language});" if @language != 'en'

Expand Down

0 comments on commit 31def14

Please sign in to comment.