Skip to content
This repository was archived by the owner on Sep 18, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ tmp
# YARD artifacts
.yardoc
_yardoc
doc/
doc/
# jetbrains IDE settings dir
.idea/
# do not commit gems installed locally
vendor/
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,43 @@ You can choose to store `index.json`, `search.min.js` and `lunr.min.js` in a dif
lunr_search:
js_dir: "javascript"

## 11. Indexed Fields

To customize which fields are indexed the "fields" map can be overridden,
e.g. to also make custom front matter fields searchable. The choice of fields has strong influence on the
search results since lunr 2.1.
The defaults are:

lunr_search:
fields:
- title
- categories
- tags
- body

`title`, `date`, `url`, `is_post` and the `body` are special names for Jekyll built-ins.
Since lunr.js 2.1 the index has per-field data, so all fields influence the results
at comparable weight independently of the text length in the field. Boosting is therefore less
necessary but can still be done at query time (but not at index time).

## 12. Stored Document Data for use in the Template

To customize which fields' full values are put into the `index.json` file for use in the search results template,
a `template_fields` list can be configured.
E.g. you can add a custom `description` front matter field for the preview or exclude fields to reduce the index file size.
The fields do not necessarily be indexed, too. The defaults are:

lunr_search:
template_fields:
- title
- url
- date
- categories
- tags
- is_post

Please note that adding the `body` as a template field will make your `index.json` file unsusably large.

## Demo

Search plugin is deployed to [10consulting.com/search](http://10consulting.com/search/).
Expand Down
19 changes: 9 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ task :concat_js do
'bower_components/mustache/mustache.js',
'bower_components/date.format/date.format.js',
'bower_components/uri.js/src/URI.js',
'bower_components/lunr.js/lunr.min.js',
'bower_components/lunr.js/lunr.js',
'js/jquery.lunr.search.js'
]

Expand All @@ -51,21 +51,20 @@ task :concat_js do
end

# Lunr is stored separately so we can use it for index generation
FileUtils.cp('bower_components/lunr.js/lunr.min.js', 'build/lunr.min.js')
FileUtils.cp('bower_components/lunr.js/lunr.js', 'build/lunr.js')
end

task :minify_js do
minified, map = Uglifier.new.compile(File.read('build/search.js'))
File.open('build/search.min.js', 'w') do |file|
file.puts minified
end
end

task :minify_js_map do
minified, map = Uglifier.new.compile_with_map(File.read('build/search.js'))
File.open('build/search.js.map', 'w') { |file| file.write(map) }
File.open('build/search.min.js', 'w') do |file|
file.puts minified
file.write "//# sourceMappingURL=search.js.map"
end
end
minified, map = Uglifier.new.compile_with_map(File.read('build/lunr.js'))
File.open('build/lunr.js.map', 'w') { |file| file.write(map) }
File.open('build/lunr.min.js', 'w') do |file|
file.puts minified
file.write "//# sourceMappingURL=lunr.js.map"
end
end
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"date.format": "~1.2.3",
"jquery": "~2.2.4",
"lunr.js": "~0.7.2",
"lunr.js": "2.1.5",
"mustache": "~2.3.0",
"uri.js": "~1.18.4"
}
Expand Down
Loading