jekyll_search 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0272796b99e85011ccd3b24088e8d5af7ca1bda1
4
+ data.tar.gz: 7de7bfb19915e80aa22c8010b30a9c68acfae2a3
5
+ SHA512:
6
+ metadata.gz: e63c744a1a09fbe448b8cd5be7a07cbf86b50343d90ef89ae28b5c08038fc7704a3d8c44df995dd4d9a1d0a6d447ce3c66df073ff546c74c58f38280b60d86ea
7
+ data.tar.gz: 17ba283c261386c92ead77570830f6ca8d44540f48dc801a0b19e004967b7ed09b3ec3bba7b1797e1e9d2eb84ece7be4a9813ce70988ff1604144e48438e4a66
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in my_ruby_gem.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Christian Hoffmeister
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # JekyllSearch
2
+
3
+ [![build](https://img.shields.io/travis/choffmeister/jekyll_search/develop.svg)](https://travis-ci.org/choffmeister/jekyll_search)
4
+ [![gem](https://img.shields.io/gem/v/jekyll_search.svg)](https://rubygems.org/gems/jekyll_search)
5
+ [![license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](http://opensource.org/licenses/MIT)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ source 'https://rubygems.org'
13
+
14
+ group :jekyll_plugins do
15
+ gem 'jekyll_search'
16
+ end
17
+ ```
18
+
19
+ or for bleeding edge:
20
+
21
+ ```ruby
22
+ group :jekyll_plugins do
23
+ gem 'jekyll_search', :git => 'https://github.com/choffmeister/jekyll_search.git', :branch => 'develop'
24
+ end
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ ## Usage
32
+
33
+ First you need a machine with [Elasticsearch][elasticsearch] installed. Then configure the search plugin by adding
34
+ the following entries into your Jekyll `_config.yml` (replace the `host` entry if needed):
35
+
36
+ ```yaml
37
+ # Search index settings
38
+ search:
39
+ host: localhost:9200
40
+ ```
41
+
42
+ Now run `jekyll index` to iterate over all pages and index them with Elasticsearch. With `jekyll search my query`
43
+ you can throw some test searches against your freshly created search index.
44
+
45
+ If you want to customize how Elasticsearch creates the search index, then provide an additional `index` property
46
+ in your `_config.yml` (see [here][elasticsearch-createindex]:
47
+
48
+ ```yaml
49
+ # Search index settings
50
+ search:
51
+ host: localhost:9200
52
+ index:
53
+ mappings:
54
+ page:
55
+ properties:
56
+ url:
57
+ type: string
58
+ analyzer: keyword
59
+ title:
60
+ type: string
61
+ analyzer: english
62
+ content:
63
+ type: string
64
+ analyzer: english
65
+ ```
66
+
67
+ ## Contributing
68
+
69
+ 1. Fork it ( https://github.com/choffmeister/jekyll_search/fork )
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create a new Pull Request
74
+
75
+ [elasticsearch]: http://www.elasticsearch.org/
76
+ [elasticsearch-createindex]: http://www.rubydoc.info/gems/elasticsearch-api/Elasticsearch/API/Indices/Actions#create-instance_method
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ multitask :default => [:test]
4
+ task :spec => :test
5
+
6
+ require "rspec/core/rake_task"
7
+ RSpec::Core::RakeTask.new(:test)
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jekyll_search/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll_search"
8
+ spec.version = JekyllSearch::VERSION
9
+ spec.authors = ["Christian Hoffmeister"]
10
+ spec.email = ["mail@choffmeister.de"]
11
+ spec.summary = "An Elasticsearch full text search index generator for Jekyll."
12
+ spec.description = ""
13
+ spec.homepage = "https://github.com/choffmeister/jekyll_search"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2.0"
24
+
25
+ spec.add_dependency "jekyll", ">= 2.5.0"
26
+ spec.add_dependency "elasticsearch", "~> 1.0.6"
27
+ spec.add_dependency "loofah", "~> 2.0.1"
28
+ end
@@ -0,0 +1,3 @@
1
+ module JekyllSearch
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,107 @@
1
+ require 'jekyll'
2
+ require 'elasticsearch'
3
+ require 'loofah'
4
+ require 'loofah/helpers'
5
+
6
+ module Jekyll
7
+ module Commands
8
+ class Index < Command
9
+ class << self
10
+ def init_with_program(prog)
11
+ prog.command(:index) do |c|
12
+ c.syntax "index"
13
+ c.description 'Creates a search index in Elasticsearch.'
14
+
15
+ c.action do |args, options|
16
+ options["serving"] = false
17
+ Index.process(options)
18
+ end
19
+ end
20
+ end
21
+
22
+ def process(options)
23
+ options = configuration_from_options(options)
24
+ destination = options['destination']
25
+
26
+ site = Jekyll::Site.new(options)
27
+ site.process
28
+ settings = site.config['search']
29
+
30
+ client = Elasticsearch::Client.new host: settings['host'], log: false
31
+ create_index(client, settings)
32
+
33
+ pages = site.pages.
34
+ select { |p| p.url =~ /\.html$/ }.
35
+ select { |p| p.data['searchable'].nil? or p.data['searchable'] != false }
36
+
37
+ for page in pages
38
+ body = {
39
+ url: site.baseurl + page.url,
40
+ title: page.data['title'],
41
+ content: clean_content(page.content)
42
+ }
43
+
44
+ client.index index: 'documentation', type: 'page', body: body
45
+ end
46
+ end
47
+
48
+ def clean_content(dirty)
49
+ strip_pre = Loofah::Scrubber.new do |node|
50
+ if node.name == 'pre'
51
+ node.remove
52
+ Loofah::Scrubber::STOP
53
+ end
54
+ end
55
+
56
+ Loofah.fragment(dirty).
57
+ scrub!(:prune).
58
+ scrub!(strip_pre).
59
+ to_text.
60
+ gsub(/([\r\n\t\s]+)/, ' ').strip
61
+ end
62
+
63
+ def create_index(client, settings)
64
+ if client.indices.exists index: 'documentation'
65
+ client.indices.delete index: 'documentation'
66
+ end
67
+
68
+ client.indices.create index: 'documentation', body: (settings['index'] or {})
69
+ end
70
+ end
71
+ end
72
+
73
+ class Search < Command
74
+ class << self
75
+ def init_with_program(prog)
76
+ prog.command(:search) do |c|
77
+ c.syntax "search query"
78
+ c.description 'Searches a search index in Elasticsearch.'
79
+
80
+ c.action do |args, options|
81
+ query = args.join(' ').strip
82
+ options["serving"] = false
83
+ Search.process(options, query)
84
+ end
85
+ end
86
+ end
87
+
88
+ def process(options, query)
89
+ options = configuration_from_options(options)
90
+ site = Jekyll::Site.new(options)
91
+ settings = site.config['search']
92
+
93
+ client = Elasticsearch::Client.new host: settings['host'], log: false
94
+ result = client.search index: 'documentation', body: { query: { match: { content: query } }, highlight: { fields: { content: {} }} }
95
+
96
+ puts "Query: #{query}"
97
+ puts "Total: #{result['hits']['total']}"
98
+ puts "Max score: #{result['hits']['max_score']}"
99
+ for hit in result['hits']['hits']
100
+ puts "Hit at #{hit['_source']['url']} (#{hit['_score']})"
101
+ hit['highlight']['content'].each { |c| puts '- ' + c }
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,5 @@
1
+ require 'jekyll_search'
2
+
3
+ RSpec.describe Jekyll::Commands::Index do
4
+ it 'works'
5
+ end
@@ -0,0 +1,91 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is
54
+ # recommended. For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ =end
91
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Christian Hoffmeister
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: jekyll
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.5.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.5.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: elasticsearch
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.6
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.6
83
+ - !ruby/object:Gem::Dependency
84
+ name: loofah
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 2.0.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 2.0.1
97
+ description: ''
98
+ email:
99
+ - mail@choffmeister.de
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - .travis.yml
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - jekyll_search.gemspec
112
+ - lib/jekyll_search.rb
113
+ - lib/jekyll_search/version.rb
114
+ - spec/lib/jekyll_search_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: https://github.com/choffmeister/jekyll_search
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.0.14
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: An Elasticsearch full text search index generator for Jekyll.
140
+ test_files:
141
+ - spec/lib/jekyll_search_spec.rb
142
+ - spec/spec_helper.rb