See it in action on my blog.
Add this line to your application's Gemfile:
source 'https://rubygems.org'
group :jekyll_plugins do
gem 'jekyll_search'
end
or for bleeding edge:
group :jekyll_plugins do
gem 'jekyll_search', :git => 'https://github.com/choffmeister/jekyll_search.git', :branch => 'develop'
end
And then execute:
$ bundle
First you need a machine with Elasticsearch installed. Then configure the search plugin by adding
the following entries into your Jekyll _config.yml
(replace the host
entry if needed):
# Search index settings
search:
host: localhost:9200
index:
name: myindex
Now run jekyll index
to iterate over all pages and index them with Elasticsearch. With jekyll search my query
you can throw some test searches against your freshly created search index. When you plan to integrate a AJAX
based search into your Jekyll page, then the following curl
example should help to get started (see also here):
curl -XPOST localhost:9200/myindex/section/_search?pretty -d '{
"query": {
"match_phrase_prefix": {
"content": {
"query": "I SEARCH FOR SOMETHING",
"slop": 10
}
}
},
"highlight": {
"fields": {
"content": {}
}
}
}'
{
// ...
"hits": {
"total": 7,
"max_score": 0.61569,
"hits": [
{
// ...
"_score" : 0.61569,
"_source": {
"url": "/link-to-page.html#headline-id",
"title": "The title",
"content": "The content"
},
"highlight": {
"content": [
"Some <em>highlighted</em> stuff"
]
}
}
// ...
]
}
// ...
}
If you want to customize how Elasticsearch creates the search index, then provide an additional index.settings
property in your _config.yml
(see also here):
# Search index settings
search:
host: localhost:9200
index:
name: myindex
settings:
mappings:
page:
properties:
url:
type: string
analyzer: keyword
title:
type: string
analyzer: english
content:
type: string
analyzer: english
section:
properties:
url:
type: string
analyzer: keyword
title:
type: string
analyzer: english
content:
type: string
analyzer: english
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)