documentation-sunspot 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +28 -0
- data/Rakefile +2 -0
- data/documentation-sunspot.gemspec +23 -0
- data/lib/documentation/searchers/sunspot.rb +59 -0
- data/lib/documentation/sunspot.rb +2 -0
- data/lib/documentation/sunspot/version.rb +5 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0efe466327b05099e723a9794f655a01a14b3d3d
|
4
|
+
data.tar.gz: 788d09ebda400d7184e9e338bef90d059bfda439
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4ce153b7c84a87f0721a4ae61a916481478f5953960aa0ad331268095236b547a4b662c1e9d81e64185d01e562a6d610608b65d682a11ffac2d1ca89bcac1ad9
|
7
|
+
data.tar.gz: d7698209b929186934f11415ca7bd6aadb6b1d276755d929f876702e9b9da04695e7301fb74843a9d9d0f3a94b98c2c39cf52a9b6937a94decdbc0d247c21e26
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 jamesprior
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Documentation Sunspot
|
2
|
+
|
3
|
+
This is a module for Documentation which replaces the searcher searcher with one powered by Sunspot and Apache's Solr. See http://sunspot.github.com/ for more information about Sunspot.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the gem to your Gemfile and run `bundle`.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'documentation-sunspot'
|
11
|
+
```
|
12
|
+
|
13
|
+
Once installed, you should add an initializer to your Rails application to add configuration.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
Documentation.config.searcher = Documentation::Searchers::Sunspot.new
|
17
|
+
```
|
18
|
+
|
19
|
+
## Setup
|
20
|
+
|
21
|
+
Once installed, you'll probably want to index all your documents.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# Remove any existing index
|
25
|
+
Documentation.config.searcher.reset
|
26
|
+
# Index all pages
|
27
|
+
Documentation::Page.all.each(&:index)
|
28
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'documentation/sunspot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "documentation-sunspot"
|
8
|
+
spec.version = Documentation::Sunspot::VERSION
|
9
|
+
spec.authors = ["jamesprior"]
|
10
|
+
spec.email = ["james.m.prior@gmail.com"]
|
11
|
+
spec.summary = %q{A search replacement for the documentation engine}
|
12
|
+
spec.description = %q{Documentation is a Rails engine which provides a complete system for managing a set of hierarchical documentation. This gem allows document searching and fragment highlighting with the Sunspot gem and Apache's Solr search index.}
|
13
|
+
spec.homepage = ""
|
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
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Documentation
|
2
|
+
module Searchers
|
3
|
+
class Sunspot < Documentation::Searchers::Abstract
|
4
|
+
|
5
|
+
def setup
|
6
|
+
::Sunspot.setup(Documentation::Page) do
|
7
|
+
text :title, :boost => 2.0
|
8
|
+
text :content, :stored => true
|
9
|
+
string :title, :stored => true
|
10
|
+
string :permalink
|
11
|
+
string :full_permalink
|
12
|
+
time :created_at
|
13
|
+
time :updated_at
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def index(page)
|
18
|
+
::Sunspot.index(page)
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(page)
|
22
|
+
::Sunspot.remove(page)
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset
|
26
|
+
::Sunspot.remove_all(Documentation::Page)
|
27
|
+
end
|
28
|
+
|
29
|
+
def search(query, options = {})
|
30
|
+
# Default options
|
31
|
+
options[:page] ||= 1
|
32
|
+
options[:per_page] ||= 15
|
33
|
+
|
34
|
+
result = ::Sunspot.search(Documentation::Page) do |search|
|
35
|
+
search.keywords query, :highlight => true
|
36
|
+
search.paginate :page => options[:page], :per_page => options[:per_page]
|
37
|
+
end
|
38
|
+
|
39
|
+
search_result = Documentation::SearchResult.new
|
40
|
+
search_result.page = options[:page].to_i
|
41
|
+
search_result.per_page = options[:per_page].to_i
|
42
|
+
search_result.total_results = result.total
|
43
|
+
search_result.query = query
|
44
|
+
search_result.time = result.query_time
|
45
|
+
search_result.raw_results = result.hits.inject(Hash.new) do |hash, hit|
|
46
|
+
hash[hit.primary_key.to_i] = {
|
47
|
+
:score => hit.score,
|
48
|
+
:highlights => hit.highlights(:content).collect{|x| x.format{|word| "{{{#{word}}}}"}}
|
49
|
+
}
|
50
|
+
hash
|
51
|
+
end
|
52
|
+
|
53
|
+
# Return it
|
54
|
+
search_result
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: documentation-sunspot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jamesprior
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-17 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
|
+
description: Documentation is a Rails engine which provides a complete system for
|
42
|
+
managing a set of hierarchical documentation. This gem allows document searching
|
43
|
+
and fragment highlighting with the Sunspot gem and Apache's Solr search index.
|
44
|
+
email:
|
45
|
+
- james.m.prior@gmail.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- ".gitignore"
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- documentation-sunspot.gemspec
|
56
|
+
- lib/documentation/searchers/sunspot.rb
|
57
|
+
- lib/documentation/sunspot.rb
|
58
|
+
- lib/documentation/sunspot/version.rb
|
59
|
+
homepage: ''
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: A search replacement for the documentation engine
|
83
|
+
test_files: []
|
84
|
+
has_rdoc:
|