jekyll_search 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +63 -2
- data/lib/jekyll_search/version.rb +1 -1
- data/lib/jekyll_search.rb +22 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93f638b21ff6bac656f0b96a2fb8976fec06b956
|
4
|
+
data.tar.gz: 83ed6b3e6770ad95b9525e73832c17be3098e650
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e78345248b71e96def1cf31dd344fba3f70b62c9d14ccc3e45244bd36e04abd25dc03ff6195aee41e3bb55674c6a185259704013c8cd39b5b715be48a3f5f39
|
7
|
+
data.tar.gz: 10d31a2a55029a583ce597dc4ba30c4b53d0bb3d91dced2db670173d10b32d796936af3979bef62ba2a110921679f59fb7d199eff0ea663ab47cf6173e8a8bb8
|
data/README.md
CHANGED
@@ -42,10 +42,59 @@ search:
|
|
42
42
|
```
|
43
43
|
|
44
44
|
Now run `jekyll index` to iterate over all pages and index them with Elasticsearch. With `jekyll search my query`
|
45
|
-
you can throw some test searches against your freshly created search index.
|
45
|
+
you can throw some test searches against your freshly created search index. When you plan to integrate a AJAX
|
46
|
+
based search into your Jekyll page, then the following `curl` example should help to get started (see also [here][elasticsearch-searchapi]):
|
47
|
+
|
48
|
+
```text
|
49
|
+
curl -XPOST localhost:9200/myindex/section/_search?pretty -d '{
|
50
|
+
"query": {
|
51
|
+
"match_phrase_prefix": {
|
52
|
+
"content": {
|
53
|
+
"query": "I SEARCH FOR SOMETHING",
|
54
|
+
"slop": 10
|
55
|
+
}
|
56
|
+
}
|
57
|
+
},
|
58
|
+
"highlight": {
|
59
|
+
"fields": {
|
60
|
+
"content": {}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}'
|
64
|
+
```
|
65
|
+
|
66
|
+
```json
|
67
|
+
{
|
68
|
+
// ...
|
69
|
+
"hits": {
|
70
|
+
"total": 7,
|
71
|
+
"max_score": 0.61569,
|
72
|
+
"hits": [
|
73
|
+
{
|
74
|
+
// ...
|
75
|
+
"_score" : 0.61569,
|
76
|
+
"_source": {
|
77
|
+
"url": "/link-to-page.html#headline-id",
|
78
|
+
"title": "The title",
|
79
|
+
"content": "The content"
|
80
|
+
},
|
81
|
+
"highlight": {
|
82
|
+
"content": [
|
83
|
+
"Some <em>highlighted</em> stuff"
|
84
|
+
]
|
85
|
+
}
|
86
|
+
}
|
87
|
+
// ...
|
88
|
+
]
|
89
|
+
}
|
90
|
+
// ...
|
91
|
+
}
|
92
|
+
```
|
93
|
+
|
94
|
+
## Customize search index
|
46
95
|
|
47
96
|
If you want to customize how Elasticsearch creates the search index, then provide an additional `index.settings`
|
48
|
-
property in your `_config.yml` (see [here][elasticsearch-createindex]:
|
97
|
+
property in your `_config.yml` (see also [here][elasticsearch-createindex]):
|
49
98
|
|
50
99
|
```yaml
|
51
100
|
# Search index settings
|
@@ -66,6 +115,17 @@ search:
|
|
66
115
|
content:
|
67
116
|
type: string
|
68
117
|
analyzer: english
|
118
|
+
section:
|
119
|
+
properties:
|
120
|
+
url:
|
121
|
+
type: string
|
122
|
+
analyzer: keyword
|
123
|
+
title:
|
124
|
+
type: string
|
125
|
+
analyzer: english
|
126
|
+
content:
|
127
|
+
type: string
|
128
|
+
analyzer: english
|
69
129
|
```
|
70
130
|
|
71
131
|
## Contributing
|
@@ -77,4 +137,5 @@ search:
|
|
77
137
|
5. Create a new Pull Request
|
78
138
|
|
79
139
|
[elasticsearch]: http://www.elasticsearch.org/
|
140
|
+
[elasticsearch-searchapi]: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-search.html
|
80
141
|
[elasticsearch-createindex]: http://www.rubydoc.info/gems/elasticsearch-api/Elasticsearch/API/Indices/Actions#create-instance_method
|
data/lib/jekyll_search.rb
CHANGED
@@ -31,23 +31,22 @@ module Jekyll
|
|
31
31
|
client = Elasticsearch::Client.new host: settings['host'], log: false
|
32
32
|
create_index(client, settings)
|
33
33
|
|
34
|
-
pages = site.pages
|
35
|
-
|
36
|
-
select { |p| p.data['searchable'].nil? or p.data['searchable'] != false }
|
34
|
+
pages = collect_content(site, site.pages)
|
35
|
+
posts = collect_content(site, site.posts)
|
37
36
|
|
38
|
-
for page in pages
|
37
|
+
for page in pages + posts
|
39
38
|
page_body = {
|
40
|
-
url:
|
41
|
-
title: page
|
42
|
-
content: JekyllSearch::HtmlProcessor.strip_html(page
|
39
|
+
url: page[:url],
|
40
|
+
title: page[:title],
|
41
|
+
content: JekyllSearch::HtmlProcessor.strip_html(page[:content])
|
43
42
|
}
|
44
43
|
|
45
44
|
client.index index: settings['index']['name'], type: 'page', body: page_body
|
46
45
|
|
47
|
-
for section in JekyllSearch::HtmlProcessor.detect_sections(page
|
46
|
+
for section in JekyllSearch::HtmlProcessor.detect_sections(page[:content])
|
48
47
|
section_body = {
|
49
|
-
url: if section[:id] != nil then site.baseurl + page
|
50
|
-
title: if section[:title] != nil then section[:title] else page
|
48
|
+
url: if section[:id] != nil then site.baseurl + page[:url] + '#' + section[:id] else site.baseurl + page[:url] end,
|
49
|
+
title: if section[:title] != nil then section[:title] else page[:title] end,
|
51
50
|
content: JekyllSearch::HtmlProcessor.strip_html(section[:content])
|
52
51
|
}
|
53
52
|
|
@@ -63,6 +62,19 @@ module Jekyll
|
|
63
62
|
|
64
63
|
client.indices.create index: settings['index']['name'], body: (settings['index']['settings'] or {})
|
65
64
|
end
|
65
|
+
|
66
|
+
def collect_content(site, elements)
|
67
|
+
elements.
|
68
|
+
select { |p| p.url =~ /\.html$/ }.
|
69
|
+
select { |p| p.data['searchable'].nil? or p.data['searchable'] != false }.
|
70
|
+
map do |p|
|
71
|
+
{
|
72
|
+
:url => site.baseurl + p.url,
|
73
|
+
:title => p.data['title'],
|
74
|
+
:content => p.content
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
66
78
|
end
|
67
79
|
end
|
68
80
|
|