refinerycms-search 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/search_controller.rb +10 -0
- data/app/helpers/search_helper.rb +9 -0
- data/app/models/search_engine.rb +17 -0
- data/app/views/search/show.html.erb +37 -0
- data/app/views/shared/_search.html.erb +6 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +5 -0
- data/lib/gemspec.rb +29 -0
- data/lib/refinerycms-search.rb +27 -0
- data/readme.md +43 -0
- data/refinerycms-search.gemspec +38 -0
- metadata +92 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
class SearchEngine
|
2
|
+
|
3
|
+
# How many results should we show per page
|
4
|
+
RESULTS_LIMIT = 10
|
5
|
+
|
6
|
+
# Perform search over the specified models
|
7
|
+
def self.search(query, page = 1)
|
8
|
+
results = []
|
9
|
+
|
10
|
+
Refinery.searchable_models.each do |model|
|
11
|
+
results << model.limit(RESULTS_LIMIT).with_query(query)
|
12
|
+
end if query.present?
|
13
|
+
|
14
|
+
results.flatten[0..(RESULTS_LIMIT - 1)]
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<% content_for :body_content_page_title do %>
|
2
|
+
Search Results for '<%=h params[:query] %>'
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<% content_for :body_content_left do %>
|
6
|
+
<ul id="search_results">
|
7
|
+
<% @results.each do |result| %>
|
8
|
+
<li>
|
9
|
+
<span class='result_type'>
|
10
|
+
<%= result.class.to_s.titleize %>
|
11
|
+
</span>
|
12
|
+
<%= link_to raw(result.title.gsub(/(#{params[:query]})/i,'<mark>\1</mark>')), result_url(result) %>
|
13
|
+
</li>
|
14
|
+
<% end %>
|
15
|
+
</ul>
|
16
|
+
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<%= render :partial => "/shared/content_page" %>
|
20
|
+
<% content_for :head do %>
|
21
|
+
<style type='text/css'>
|
22
|
+
#search_results {
|
23
|
+
list-style: none;
|
24
|
+
padding: 0;
|
25
|
+
margin: 0;
|
26
|
+
}
|
27
|
+
|
28
|
+
#search_results li {
|
29
|
+
border-bottom: 1px solid #CCC;
|
30
|
+
}
|
31
|
+
|
32
|
+
#search_results li span.result_type {
|
33
|
+
float: right;
|
34
|
+
color: #CCC;
|
35
|
+
}
|
36
|
+
</style>
|
37
|
+
<% end %>
|
data/config/routes.rb
ADDED
data/lib/gemspec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
version = '0.9.8'
|
3
|
+
raise "Could not get version so gemspec can not be built" if version.nil?
|
4
|
+
files = Dir.glob("**/*").flatten.reject do |file|
|
5
|
+
file =~ /\.gem$/
|
6
|
+
end
|
7
|
+
|
8
|
+
gemspec = <<EOF
|
9
|
+
Gem::Specification.new do |s|
|
10
|
+
s.name = %q{refinerycms-search}
|
11
|
+
s.version = %q{#{version}}
|
12
|
+
s.date = %q{#{Time.now.strftime('%Y-%m-%d')}}
|
13
|
+
s.summary = %q{Extra search handling for Refinery CMS}
|
14
|
+
s.description = %q{Provides extra functionality for searching your frontend website using Refinery CMS.}
|
15
|
+
s.homepage = %q{http://refinerycms.com}
|
16
|
+
s.email = %q{info@refinerycms.com}
|
17
|
+
s.authors = ["Resolve Digital"]
|
18
|
+
s.require_paths = %w(lib)
|
19
|
+
|
20
|
+
s.add_dependency 'refinerycms', '>= 0.9.8'
|
21
|
+
|
22
|
+
s.files = [
|
23
|
+
'#{files.join("',\n '")}'
|
24
|
+
]
|
25
|
+
s.require_path = 'lib'
|
26
|
+
end
|
27
|
+
EOF
|
28
|
+
|
29
|
+
File.open(File.expand_path("../../refinerycms-search.gemspec", __FILE__), 'w').puts(gemspec)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'refinery'
|
2
|
+
|
3
|
+
module Refinery
|
4
|
+
module Search
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
config.to_prepare do
|
7
|
+
module ::Refinery
|
8
|
+
class << self
|
9
|
+
attr_accessor :searchable_models
|
10
|
+
|
11
|
+
def searchable_models
|
12
|
+
@searchable_models ||= [Page]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
config.after_initialize do
|
19
|
+
::Refinery::Plugin.register do |plugin|
|
20
|
+
plugin.name = 'refinerycms_search'
|
21
|
+
plugin.version = 1.0
|
22
|
+
plugin.hide_from_menu = true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/readme.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Search plugin for [RefineryCMS](http://www.refinerycms.com)
|
2
|
+
[Github](http://github.com/resolve/refinerycms)
|
3
|
+
|
4
|
+
By: [Resolve Digital](http://www.resolvedigital.com)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Simply use this by adding the following to your ``Gemfile``:
|
9
|
+
|
10
|
+
gem 'refinerycms-search', '~> 0.9.8'
|
11
|
+
|
12
|
+
You'll also need to create a page (from the 'Pages' tab) with a custom URL of '/search'.
|
13
|
+
You can set a custom URL for a page in the Advanced Options.
|
14
|
+
It's probably also a good idea to uncheck the 'show in menu' option for this page.
|
15
|
+
|
16
|
+
Remember to restart your web server.
|
17
|
+
|
18
|
+
A sample search form can be found in [views/shared/_search.html.erb](http://github.com/blob/master/app/views/shared/_search.html.erb).
|
19
|
+
You can either use this partial directly, or copy the appropriate parts.
|
20
|
+
|
21
|
+
## Searching
|
22
|
+
|
23
|
+
The default installation will search in Pages.
|
24
|
+
If you wish to find results in other plugins you have created or installed, you can specify these in ``config/settings.rb`` like so:
|
25
|
+
|
26
|
+
Refinery.searchable_models = [Page]
|
27
|
+
|
28
|
+
Simply add any additional models you wish to search to this array. For example, if you have the [portfolio plugin](http://github.com/resolve/refinerycms-portfolio) installed:
|
29
|
+
|
30
|
+
Refinery.searchable_models = [Page, PortfolioEntry]
|
31
|
+
|
32
|
+
Any model you wish to search will need to be indexed using acts as indexed. To add indexing, simple add:
|
33
|
+
|
34
|
+
acts_as_indexed :fields => [:title, :body]
|
35
|
+
|
36
|
+
If your model doesn't use a ``:title attribute``, remember to add an ``alias_attribute``:
|
37
|
+
|
38
|
+
alias_attribute :title, :name #for example
|
39
|
+
|
40
|
+
You will need to replace the indexed fields with those appropriate for your model.
|
41
|
+
The above line will add indexing to PortfolioEntry in the portfolio plugin, which does not come indexed.
|
42
|
+
|
43
|
+
If you wish to override the url used in the search results just add a ``url`` method to your model and the result of this method will be used instead.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{refinerycms-search}
|
3
|
+
s.version = %q{0.9.8}
|
4
|
+
s.date = %q{2010-10-01}
|
5
|
+
s.summary = %q{Extra search handling for Refinery CMS}
|
6
|
+
s.description = %q{Provides extra functionality for searching your frontend website using Refinery CMS.}
|
7
|
+
s.homepage = %q{http://refinerycms.com}
|
8
|
+
s.email = %q{info@refinerycms.com}
|
9
|
+
s.authors = ["Resolve Digital"]
|
10
|
+
s.require_paths = %w(lib)
|
11
|
+
|
12
|
+
s.add_dependency 'refinerycms', '>= 0.9.8'
|
13
|
+
|
14
|
+
s.files = [
|
15
|
+
'app',
|
16
|
+
'app/controllers',
|
17
|
+
'app/controllers/search_controller.rb',
|
18
|
+
'app/helpers',
|
19
|
+
'app/helpers/search_helper.rb',
|
20
|
+
'app/models',
|
21
|
+
'app/models/search_engine.rb',
|
22
|
+
'app/views',
|
23
|
+
'app/views/search',
|
24
|
+
'app/views/search/show.html.erb',
|
25
|
+
'app/views/shared',
|
26
|
+
'app/views/shared/_search.html.erb',
|
27
|
+
'config',
|
28
|
+
'config/locales',
|
29
|
+
'config/locales/en.yml',
|
30
|
+
'config/routes.rb',
|
31
|
+
'lib',
|
32
|
+
'lib/gemspec.rb',
|
33
|
+
'lib/refinerycms-search.rb',
|
34
|
+
'readme.md',
|
35
|
+
'refinerycms-search.gemspec'
|
36
|
+
]
|
37
|
+
s.require_path = 'lib'
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: refinerycms-search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 43
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 8
|
10
|
+
version: 0.9.8
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Resolve Digital
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-01 00:00:00 +13:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: refinerycms
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 43
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 9
|
33
|
+
- 8
|
34
|
+
version: 0.9.8
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Provides extra functionality for searching your frontend website using Refinery CMS.
|
38
|
+
email: info@refinerycms.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- app/controllers/search_controller.rb
|
47
|
+
- app/helpers/search_helper.rb
|
48
|
+
- app/models/search_engine.rb
|
49
|
+
- app/views/search/show.html.erb
|
50
|
+
- app/views/shared/_search.html.erb
|
51
|
+
- config/locales/en.yml
|
52
|
+
- config/routes.rb
|
53
|
+
- lib/gemspec.rb
|
54
|
+
- lib/refinerycms-search.rb
|
55
|
+
- readme.md
|
56
|
+
- refinerycms-search.gemspec
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://refinerycms.com
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.3.7
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Extra search handling for Refinery CMS
|
91
|
+
test_files: []
|
92
|
+
|