refinerycms-search 0.9.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/search_engine.rb +10 -10
- data/app/views/search/show.html.erb +4 -4
- data/app/views/shared/_search.html.erb +1 -1
- data/config/locales/bg.yml +5 -0
- data/db/migrate/01_create_search_page.rb +18 -0
- data/db/seeds/refinerycms_search.rb +25 -0
- data/lib/gemspec.rb +5 -3
- data/lib/generators/refinerycms_search_generator.rb +8 -0
- data/lib/refinerycms-search.rb +1 -1
- data/readme.md +31 -13
- data/refinerycms-search.gemspec +13 -4
- metadata +20 -16
data/app/models/search_engine.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
class SearchEngine
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
# How many results should we show per page
|
4
|
+
RESULTS_LIMIT = 10
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
# Perform search over the specified models
|
7
|
+
def self.search(query, page = 1)
|
8
|
+
results = []
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
Refinery.searchable_models.each do |model|
|
11
|
+
results << model.limit(RESULTS_LIMIT).with_query(query)
|
12
|
+
end if query.present?
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
results.flatten[0..(RESULTS_LIMIT - 1)]
|
15
|
+
end
|
16
16
|
|
17
17
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<% content_for :
|
1
|
+
<% content_for :body_content_title do %>
|
2
2
|
Search Results for '<%=h params[:query] %>'
|
3
3
|
<% end %>
|
4
4
|
|
@@ -9,7 +9,7 @@
|
|
9
9
|
<span class='result_type'>
|
10
10
|
<%= result.class.to_s.titleize %>
|
11
11
|
</span>
|
12
|
-
<%= link_to raw(result.title.gsub(/(#{params[:query]})/i,'<mark>\1</mark>')), result_url(result) %>
|
12
|
+
<%= link_to raw(result.title.gsub(/(#{Regexp.escape(params[:query])})/i, '<mark>\1</mark>')), result_url(result) %>
|
13
13
|
</li>
|
14
14
|
<% end %>
|
15
15
|
</ul>
|
@@ -17,7 +17,7 @@
|
|
17
17
|
<% end %>
|
18
18
|
|
19
19
|
<%= render :partial => "/shared/content_page" %>
|
20
|
-
<% content_for :
|
20
|
+
<% content_for :stylesheets do %>
|
21
21
|
<style type='text/css'>
|
22
22
|
#search_results {
|
23
23
|
list-style: none;
|
@@ -34,4 +34,4 @@
|
|
34
34
|
color: #CCC;
|
35
35
|
}
|
36
36
|
</style>
|
37
|
-
<% end %>
|
37
|
+
<% end %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateSearchPage < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
load(Rails.root.join('db', 'seeds', 'refinerycms_search.rb'))
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
if defined?(UserPlugin)
|
9
|
+
UserPlugin.destroy_all({:name => "refinerycms_search"})
|
10
|
+
end
|
11
|
+
|
12
|
+
if defined?(Page)
|
13
|
+
Page.delete_all({:link_url => "/search"})
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
if defined?(::User)
|
2
|
+
User.all.each do |user|
|
3
|
+
if user.plugins.where(:name => 'refinerycms_search').blank?
|
4
|
+
user.plugins.create(:name => 'refinerycms_search',
|
5
|
+
:position => (user.plugins.maximum(:position) || -1) +1)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
if defined?(::Page)
|
11
|
+
unless Page.where(:menu_match => "^/search.*$").any?
|
12
|
+
page = Page.create(
|
13
|
+
:title => "Search Results",
|
14
|
+
:show_in_menu => false,
|
15
|
+
:link_url => "/search",
|
16
|
+
:deletable => false,
|
17
|
+
:position => ((Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
|
18
|
+
:menu_match => "^/search.*$"
|
19
|
+
)
|
20
|
+
|
21
|
+
Page.default_parts.each do |default_page_part|
|
22
|
+
page.parts.create(:title => default_page_part, :body => nil)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/gemspec.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# Encoding: UTF-8
|
3
|
+
version = '1.0.0'
|
3
4
|
raise "Could not get version so gemspec can not be built" if version.nil?
|
4
5
|
files = Dir.glob("**/*").flatten.reject do |file|
|
5
6
|
file =~ /\.gem$/
|
6
7
|
end
|
7
8
|
|
8
9
|
gemspec = <<EOF
|
10
|
+
# Encoding: UTF-8
|
9
11
|
Gem::Specification.new do |s|
|
10
12
|
s.name = %q{refinerycms-search}
|
11
13
|
s.version = %q{#{version}}
|
@@ -14,10 +16,10 @@ Gem::Specification.new do |s|
|
|
14
16
|
s.description = %q{Provides extra functionality for searching your frontend website using Refinery CMS.}
|
15
17
|
s.homepage = %q{http://refinerycms.com}
|
16
18
|
s.email = %q{info@refinerycms.com}
|
17
|
-
s.authors = ["
|
19
|
+
s.authors = ["Uģis Ozols", "Joe Sak", "Philip Arndt"]
|
18
20
|
s.require_paths = %w(lib)
|
19
21
|
|
20
|
-
s.add_dependency 'refinerycms', '
|
22
|
+
s.add_dependency 'refinerycms-core', '~> 1.0'
|
21
23
|
|
22
24
|
s.files = [
|
23
25
|
'#{files.join("',\n '")}'
|
data/lib/refinerycms-search.rb
CHANGED
data/readme.md
CHANGED
@@ -3,41 +3,59 @@
|
|
3
3
|
|
4
4
|
By: [Resolve Digital](http://www.resolvedigital.com)
|
5
5
|
|
6
|
+
Powered by: [acts_as_indexed](http://github.com/dougal/acts_as_indexed) - Check his readme and documentation for more info on how it works.
|
7
|
+
|
6
8
|
## Installation
|
7
9
|
|
8
10
|
Simply use this by adding the following to your ``Gemfile``:
|
9
11
|
|
10
|
-
gem 'refinerycms-search', '~> 0.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
gem 'refinerycms-search', '~> 1.0.0', :git => 'git://github.com/resolve/refinerycms-search.git'
|
13
|
+
|
14
|
+
bundle install
|
15
|
+
rails g refinerycms_search
|
16
|
+
rake db:migrate
|
15
17
|
|
16
|
-
|
18
|
+
## Restart your web server and RE-SAVE all records that have not been indexed before.
|
17
19
|
|
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).
|
20
|
+
A sample search form can be found in [views/shared/_search.html.erb](http://github.com/resolve/refinerycms-search/blob/master/app/views/shared/_search.html.erb).
|
19
21
|
You can either use this partial directly, or copy the appropriate parts.
|
20
22
|
|
21
23
|
## Searching
|
22
24
|
|
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/
|
25
|
+
The default installation will search in Pages.
|
26
|
+
If you wish to find results in other plugins you have created or installed, you can specify these in ``config/application.rb`` like so:
|
25
27
|
|
26
|
-
|
28
|
+
config.to_prepare do
|
29
|
+
Refinery.searchable_models = [Page]
|
30
|
+
end
|
27
31
|
|
28
32
|
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
33
|
|
30
|
-
|
34
|
+
config.to_prepare do
|
35
|
+
Refinery.searchable_models = [Page, PortfolioEntry]
|
36
|
+
end
|
37
|
+
|
38
|
+
The above line will add indexing to PortfolioEntry in the portfolio plugin, which does not come indexed.
|
31
39
|
|
32
40
|
Any model you wish to search will need to be indexed using acts as indexed. To add indexing, simple add:
|
33
41
|
|
34
42
|
acts_as_indexed :fields => [:title, :body]
|
35
43
|
|
36
|
-
If your model doesn't use a ``:title attribute
|
44
|
+
If your model doesn't use a ``:title`` attribute, remember to add an ``alias_attribute``:
|
37
45
|
|
38
46
|
alias_attribute :title, :name #for example
|
39
47
|
|
48
|
+
You can use any public method, as well. So if you have ``:first_name`` and ``:last_name`` but a method like ``name`` to join them, it can be indexed.
|
49
|
+
|
50
|
+
acts_as_indexed :fields => [:name, :biography]
|
51
|
+
|
52
|
+
#...
|
53
|
+
|
54
|
+
def name
|
55
|
+
(first_name, last_name).compact.join(' ')
|
56
|
+
end
|
57
|
+
|
40
58
|
You will need to replace the indexed fields with those appropriate for your model.
|
41
|
-
|
59
|
+
|
42
60
|
|
43
61
|
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.
|
data/refinerycms-search.gemspec
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
+
# Encoding: UTF-8
|
1
2
|
Gem::Specification.new do |s|
|
2
3
|
s.name = %q{refinerycms-search}
|
3
|
-
s.version = %q{0.
|
4
|
-
s.date = %q{
|
4
|
+
s.version = %q{1.0.0}
|
5
|
+
s.date = %q{2012-03-15}
|
5
6
|
s.summary = %q{Extra search handling for Refinery CMS}
|
6
7
|
s.description = %q{Provides extra functionality for searching your frontend website using Refinery CMS.}
|
7
8
|
s.homepage = %q{http://refinerycms.com}
|
8
9
|
s.email = %q{info@refinerycms.com}
|
9
|
-
s.authors = ["
|
10
|
+
s.authors = ["Uģis Ozols", "Joe Sak", "Philip Arndt"]
|
10
11
|
s.require_paths = %w(lib)
|
11
12
|
|
12
|
-
s.add_dependency 'refinerycms', '
|
13
|
+
s.add_dependency 'refinerycms-core', '~> 1.0'
|
13
14
|
|
14
15
|
s.files = [
|
15
16
|
'app',
|
@@ -26,10 +27,18 @@ Gem::Specification.new do |s|
|
|
26
27
|
'app/views/shared/_search.html.erb',
|
27
28
|
'config',
|
28
29
|
'config/locales',
|
30
|
+
'config/locales/bg.yml',
|
29
31
|
'config/locales/en.yml',
|
30
32
|
'config/routes.rb',
|
33
|
+
'db',
|
34
|
+
'db/migrate',
|
35
|
+
'db/migrate/01_create_search_page.rb',
|
36
|
+
'db/seeds',
|
37
|
+
'db/seeds/refinerycms_search.rb',
|
31
38
|
'lib',
|
32
39
|
'lib/gemspec.rb',
|
40
|
+
'lib/generators',
|
41
|
+
'lib/generators/refinerycms_search_generator.rb',
|
33
42
|
'lib/refinerycms-search.rb',
|
34
43
|
'readme.md',
|
35
44
|
'refinerycms-search.gemspec'
|
metadata
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refinerycms-search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
7
9
|
- 0
|
8
|
-
|
9
|
-
- 8
|
10
|
-
version: 0.9.8
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
|
-
-
|
13
|
+
- "U\xC4\xA3is Ozols"
|
14
|
+
- Joe Sak
|
15
|
+
- Philip Arndt
|
14
16
|
autorequire:
|
15
17
|
bindir: bin
|
16
18
|
cert_chain: []
|
17
19
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
20
|
+
date: 2012-03-15 00:00:00 Z
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
|
-
name: refinerycms
|
23
|
+
name: refinerycms-core
|
23
24
|
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
26
|
none: false
|
26
27
|
requirements:
|
27
|
-
- -
|
28
|
+
- - ~>
|
28
29
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
30
|
+
hash: 15
|
30
31
|
segments:
|
32
|
+
- 1
|
31
33
|
- 0
|
32
|
-
|
33
|
-
- 8
|
34
|
-
version: 0.9.8
|
34
|
+
version: "1.0"
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
description: Provides extra functionality for searching your frontend website using Refinery CMS.
|
@@ -48,13 +48,16 @@ files:
|
|
48
48
|
- app/models/search_engine.rb
|
49
49
|
- app/views/search/show.html.erb
|
50
50
|
- app/views/shared/_search.html.erb
|
51
|
+
- config/locales/bg.yml
|
51
52
|
- config/locales/en.yml
|
52
53
|
- config/routes.rb
|
54
|
+
- db/migrate/01_create_search_page.rb
|
55
|
+
- db/seeds/refinerycms_search.rb
|
53
56
|
- lib/gemspec.rb
|
57
|
+
- lib/generators/refinerycms_search_generator.rb
|
54
58
|
- lib/refinerycms-search.rb
|
55
59
|
- readme.md
|
56
60
|
- refinerycms-search.gemspec
|
57
|
-
has_rdoc: true
|
58
61
|
homepage: http://refinerycms.com
|
59
62
|
licenses: []
|
60
63
|
|
@@ -84,9 +87,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
87
|
requirements: []
|
85
88
|
|
86
89
|
rubyforge_project:
|
87
|
-
rubygems_version: 1.
|
90
|
+
rubygems_version: 1.8.17
|
88
91
|
signing_key:
|
89
92
|
specification_version: 3
|
90
93
|
summary: Extra search handling for Refinery CMS
|
91
94
|
test_files: []
|
92
95
|
|
96
|
+
has_rdoc:
|