refinerycms-search 1.0.0 → 2.0.0
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.
- data/.gitignore +3 -0
- data/.travis.yml +36 -0
- data/Gemfile +69 -0
- data/Guardfile +20 -0
- data/Rakefile +19 -0
- data/app/controllers/refinery/search_controller.rb +12 -0
- data/app/helpers/refinery/search_helper.rb +23 -0
- data/app/models/refinery/search_engine.rb +19 -0
- data/app/views/refinery/search/show.html.erb +22 -0
- data/app/views/{shared → refinery/shared}/_search.html.erb +2 -2
- data/config/locales/bg.yml +5 -4
- data/config/locales/en.yml +9 -4
- data/config/locales/sk.yml +10 -0
- data/config/routes.rb +2 -4
- data/db/migrate/01_create_search_page.rb +6 -8
- data/db/seeds.rb +23 -0
- data/lib/generators/refinery/search_generator.rb +20 -0
- data/lib/refinery/search.rb +18 -0
- data/lib/refinery/search/engine.rb +30 -0
- data/lib/refinerycms-search.rb +1 -27
- data/readme.md +47 -29
- data/refinerycms-search.gemspec +6 -36
- data/spec/models/refinery/search_engine_spec.rb +25 -0
- data/spec/spec_helper.rb +59 -0
- data/tasks/rspec.rake +4 -0
- metadata +57 -61
- data/app/controllers/search_controller.rb +0 -10
- data/app/helpers/search_helper.rb +0 -9
- data/app/models/search_engine.rb +0 -17
- data/app/views/search/show.html.erb +0 -37
- data/db/seeds/refinerycms_search.rb +0 -25
- data/lib/gemspec.rb +0 -31
- data/lib/generators/refinerycms_search_generator.rb +0 -8
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
language: ruby
|
2
|
+
before_install:
|
3
|
+
- 'if [[ "$TRAVIS_RUBY_VERSION" =~ "jruby" ]] ; then gem update --system ; fi'
|
4
|
+
before_script:
|
5
|
+
- "bundle exec rake refinery:testing:dummy_app > /dev/null"
|
6
|
+
script:
|
7
|
+
- "bundle exec rspec spec"
|
8
|
+
notifications:
|
9
|
+
email: true
|
10
|
+
irc:
|
11
|
+
use_notice: true
|
12
|
+
skip_join: true
|
13
|
+
channels:
|
14
|
+
- "irc.freenode.org#refinerycms"
|
15
|
+
campfire:
|
16
|
+
on_success: always
|
17
|
+
on_failure: always
|
18
|
+
rooms:
|
19
|
+
- secure: "JaX+Ckvdd2wqL2bD6t8PHvMDBHxWBlCrkBKPcDKxV0t0DOwzzzwxMryVqcRi\nPsmM/zvmWFATDyRmivhNOpu4lRg9RytSroxZ9nkmbLDqjCyEAZ6tv4yZXME/\nPaxPwmfwgS9g8TKjj3lSWS7rEpqqg0D5S0XIfIHrj6KB6LUmFHc="
|
20
|
+
env:
|
21
|
+
- DB=postgresql
|
22
|
+
- DB=mysql
|
23
|
+
matrix:
|
24
|
+
allow_failures:
|
25
|
+
- rvm: rbx-18mode
|
26
|
+
- rvm: rbx-19mode
|
27
|
+
- rvm: jruby-19mode
|
28
|
+
- rvm: jruby-18mode
|
29
|
+
rvm:
|
30
|
+
- 2.0
|
31
|
+
- 1.9.3
|
32
|
+
- 1.8.7
|
33
|
+
- rbx-19mode
|
34
|
+
- jruby-19mode
|
35
|
+
- rbx-18mode
|
36
|
+
- jruby-18mode
|
data/Gemfile
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem 'refinerycms', '~> 2.0.0'
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem 'refinerycms-testing', '~> 2.0.0'
|
9
|
+
gem 'guard-rspec', '~> 0.6.0'
|
10
|
+
|
11
|
+
platforms :jruby do
|
12
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
13
|
+
gem 'activerecord-jdbcmysql-adapter'
|
14
|
+
gem 'activerecord-jdbcpostgresql-adapter'
|
15
|
+
gem 'jruby-openssl'
|
16
|
+
end
|
17
|
+
|
18
|
+
unless defined?(JRUBY_VERSION)
|
19
|
+
gem 'sqlite3'
|
20
|
+
gem 'mysql2'
|
21
|
+
gem 'pg'
|
22
|
+
end
|
23
|
+
|
24
|
+
platforms :mswin, :mingw do
|
25
|
+
gem 'win32console'
|
26
|
+
gem 'rb-fchange', '~> 0.0.5'
|
27
|
+
gem 'rb-notifu', '~> 0.0.4'
|
28
|
+
end
|
29
|
+
|
30
|
+
platforms :ruby do
|
31
|
+
gem 'spork', '~> 0.9.0.rc'
|
32
|
+
gem 'guard-spork'
|
33
|
+
|
34
|
+
unless ENV['TRAVIS']
|
35
|
+
require 'rbconfig'
|
36
|
+
if RbConfig::CONFIG['target_os'] =~ /darwin/i
|
37
|
+
gem 'rb-fsevent', '>= 0.3.9'
|
38
|
+
gem 'ruby_gntp'
|
39
|
+
end
|
40
|
+
if RbConfig::CONFIG['target_os'] =~ /linux/i
|
41
|
+
gem 'rb-inotify', '>= 0.5.1'
|
42
|
+
gem 'libnotify', '~> 0.1.3'
|
43
|
+
gem 'therubyracer', '~> 0.9.9'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
platforms :jruby do
|
49
|
+
unless ENV['TRAVIS']
|
50
|
+
require 'rbconfig'
|
51
|
+
if RbConfig::CONFIG['target_os'] =~ /darwin/i
|
52
|
+
gem 'ruby_gntp'
|
53
|
+
end
|
54
|
+
if RbConfig::CONFIG['target_os'] =~ /linux/i
|
55
|
+
gem 'rb-inotify', '>= 0.5.1'
|
56
|
+
gem 'libnotify', '~> 0.1.3'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Refinery/rails should pull in the proper versions of these
|
63
|
+
group :assets do
|
64
|
+
gem 'sass-rails'
|
65
|
+
gem 'coffee-rails'
|
66
|
+
gem 'uglifier'
|
67
|
+
end
|
68
|
+
|
69
|
+
gem 'jquery-rails'
|
data/Guardfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
guard 'rspec', :version => 2, :cli => "--color" do
|
2
|
+
watch(%r{^spec/.+_spec\.rb$})
|
3
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
4
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
5
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/controllers/#{m[1]}_#{m[2]}_spec.rb", "spec/requests/#{m[1]}_spec.rb"] }
|
6
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
watch('config/routes.rb') { "spec/routing" }
|
9
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
10
|
+
# Capybara request specs
|
11
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
12
|
+
end
|
13
|
+
|
14
|
+
guard 'spork', :wait => 60, :cucumber => false, :rspec_env => { 'RAILS_ENV' => 'test' } do
|
15
|
+
watch('config/application.rb')
|
16
|
+
watch('config/environment.rb')
|
17
|
+
watch(%r{^config/environments/.+\.rb$})
|
18
|
+
watch(%r{^config/initializers/.+\.rb$})
|
19
|
+
watch('spec/spec_helper.rb')
|
20
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
ENGINE_PATH = File.dirname(__FILE__)
|
9
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
10
|
+
|
11
|
+
if File.exists?(APP_RAKEFILE)
|
12
|
+
load 'rails/tasks/engine.rake'
|
13
|
+
end
|
14
|
+
|
15
|
+
require "refinerycms-testing"
|
16
|
+
Refinery::Testing::Railtie.load_tasks
|
17
|
+
Refinery::Testing::Railtie.load_dummy_tasks(ENGINE_PATH)
|
18
|
+
|
19
|
+
load File.expand_path('../tasks/rspec.rake', __FILE__)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Refinery
|
2
|
+
class SearchController < ::ApplicationController
|
3
|
+
|
4
|
+
# Display search results given the query supplied
|
5
|
+
def show
|
6
|
+
@results = Refinery::SearchEngine.search(params[:query], params[:page])
|
7
|
+
|
8
|
+
present(@page = Refinery::Page.find_by_link_url("/search"))
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Refinery
|
2
|
+
module SearchHelper
|
3
|
+
|
4
|
+
def result_title(result)
|
5
|
+
result.title.gsub /(#{Regexp.escape(params[:query])})/i, '<mark>\1</mark>'
|
6
|
+
end
|
7
|
+
|
8
|
+
def result_type(result)
|
9
|
+
result.class.to_s.titleize.gsub('Refinery/', '').gsub '/', '::'
|
10
|
+
end
|
11
|
+
|
12
|
+
# this is where you register your result URLs based on the
|
13
|
+
# type of result we're dealing with
|
14
|
+
def result_url(result)
|
15
|
+
if result.respond_to? :url
|
16
|
+
refinery.url_for result.url
|
17
|
+
else
|
18
|
+
refinery.url_for send(Refinery.route_for_model(result.class, :admin => false), result)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Refinery
|
2
|
+
class SearchEngine
|
3
|
+
|
4
|
+
# How many results should we show per page
|
5
|
+
RESULTS_LIMIT = 10
|
6
|
+
|
7
|
+
# Perform search over the specified models
|
8
|
+
def self.search(query, page = 1)
|
9
|
+
results = []
|
10
|
+
|
11
|
+
Refinery.searchable_models.each do |model|
|
12
|
+
results << model.limit(RESULTS_LIMIT).with_query(query)
|
13
|
+
end if query.present?
|
14
|
+
|
15
|
+
results.flatten[0..(RESULTS_LIMIT - 1)]
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<% content_for :body_content_title do %>
|
2
|
+
<%= t('.search_results_for', :what => params[:query]) %>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<% content_for :body do %>
|
6
|
+
<% if @results.empty? %>
|
7
|
+
<%= t('.no_results_for', :what => params[:query]) %>
|
8
|
+
<% else %>
|
9
|
+
<ul id="search_results">
|
10
|
+
<% @results.each do |result| %>
|
11
|
+
<li>
|
12
|
+
<span class='result_type'>
|
13
|
+
<%= result_type result %>
|
14
|
+
</span>
|
15
|
+
<%= link_to result_title(result).html_safe, result_url(result) %>
|
16
|
+
</li>
|
17
|
+
<% end %>
|
18
|
+
<% end %>
|
19
|
+
</ul>
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<%= render :partial => "/refinery/content_page" %>
|
@@ -1,6 +1,6 @@
|
|
1
|
-
<%= form_tag
|
1
|
+
<%= form_tag refinery.search_path do -%>
|
2
2
|
<%= text_field_tag :query, {}, {:type => "search",
|
3
3
|
:placeholder => "Search site for...",
|
4
4
|
:value => (params[:query] if params[:query])} %>
|
5
5
|
<%= submit_tag 'Go' %>
|
6
|
-
<% end %>
|
6
|
+
<% end %>
|
data/config/locales/bg.yml
CHANGED
data/config/locales/en.yml
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
en:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
refinery:
|
3
|
+
plugins:
|
4
|
+
refinerycms_search:
|
5
|
+
title: Search
|
6
|
+
description: Extra search handling for Refinery CMS
|
7
|
+
search:
|
8
|
+
show:
|
9
|
+
search_results_for: Search Results for '%{what}'
|
10
|
+
no_results_for: No results found for your search '%{what}'.
|
data/config/routes.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
class CreateSearchPage < ActiveRecord::Migration
|
2
2
|
|
3
|
-
def
|
4
|
-
load(Rails.root.join('db', 'seeds', 'refinerycms_search.rb'))
|
3
|
+
def up
|
5
4
|
end
|
6
5
|
|
7
|
-
def
|
8
|
-
if defined?(UserPlugin)
|
9
|
-
UserPlugin.destroy_all({:name => "refinerycms_search"})
|
6
|
+
def down
|
7
|
+
if defined?(Refinery::UserPlugin)
|
8
|
+
Refinery::UserPlugin.destroy_all({:name => "refinerycms_search"})
|
10
9
|
end
|
11
10
|
|
12
|
-
if defined?(Page)
|
13
|
-
Page.delete_all({:link_url => "/search"})
|
11
|
+
if defined?(Refinery::Page)
|
12
|
+
Refinery::Page.delete_all({:link_url => "/search"})
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
17
15
|
|
18
16
|
end
|
data/db/seeds.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
if defined?(Refinery::User)
|
2
|
+
Refinery::User.all.each do |user|
|
3
|
+
if user.plugins.where(:name => 'refinerycms_search').blank?
|
4
|
+
user.plugins.create(:name => 'refinerycms_search')
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
if defined?(Refinery::Page)
|
10
|
+
unless Refinery::Page.where(:menu_match => "^/search.*$").any?
|
11
|
+
page = Refinery::Page.create(
|
12
|
+
:title => "Search Results",
|
13
|
+
:show_in_menu => false,
|
14
|
+
:link_url => "/search",
|
15
|
+
:deletable => false,
|
16
|
+
:menu_match => "^/search.*$"
|
17
|
+
)
|
18
|
+
|
19
|
+
Refinery::Pages.default_parts.each do |default_page_part|
|
20
|
+
page.parts.create(:title => default_page_part, :body => nil)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Refinery
|
2
|
+
class SearchGenerator < Rails::Generators::Base
|
3
|
+
|
4
|
+
def rake_db
|
5
|
+
rake("refinery_search:install:migrations")
|
6
|
+
end
|
7
|
+
|
8
|
+
def append_load_seed_data
|
9
|
+
create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb'))
|
10
|
+
append_file 'db/seeds.rb', :verbose => true do
|
11
|
+
<<-EOH
|
12
|
+
|
13
|
+
# Added by Refinery CMS Search engine
|
14
|
+
Refinery::Search::Engine.load_seed
|
15
|
+
EOH
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "refinerycms-core"
|
2
|
+
|
3
|
+
module Refinery
|
4
|
+
autoload :SearchGenerator, 'generators/refinery/search_generator'
|
5
|
+
|
6
|
+
module Search
|
7
|
+
require "refinery/search/engine"
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_writer :root
|
11
|
+
|
12
|
+
def root
|
13
|
+
@root ||= Pathname.new(File.expand_path('../../../', __FILE__))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Refinery
|
2
|
+
module Search
|
3
|
+
class Engine < Rails::Engine
|
4
|
+
include Refinery::Engine
|
5
|
+
|
6
|
+
isolate_namespace Refinery
|
7
|
+
engine_name :refinery_search
|
8
|
+
|
9
|
+
initializer "register refinery_search plugin" do
|
10
|
+
Refinery::Plugin.register do |plugin|
|
11
|
+
plugin.name = 'refinery_search'
|
12
|
+
plugin.version = 2.0
|
13
|
+
plugin.hide_from_menu = true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
config.to_prepare do
|
18
|
+
module ::Refinery
|
19
|
+
class << self
|
20
|
+
attr_accessor :searchable_models
|
21
|
+
|
22
|
+
def searchable_models
|
23
|
+
@searchable_models ||= [(Refinery::Page if defined?(Refinery::Page))]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/refinerycms-search.rb
CHANGED
@@ -1,27 +1 @@
|
|
1
|
-
require
|
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.1
|
22
|
-
plugin.hide_from_menu = true
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
1
|
+
require "refinery/search"
|
data/readme.md
CHANGED
@@ -1,61 +1,79 @@
|
|
1
|
-
# Search plugin for [
|
2
|
-
[Github](http://github.com/resolve/refinerycms)
|
3
|
-
|
4
|
-
By: [Resolve Digital](http://www.resolvedigital.com)
|
1
|
+
# Search plugin for [Refinery CMS](http://www.refinerycms.com)
|
5
2
|
|
6
3
|
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
4
|
|
8
5
|
## Installation
|
9
6
|
|
10
|
-
Simply use this by adding the following to your
|
7
|
+
Simply use this by adding the following to your `Gemfile`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'refinerycms-search', '~> 2.0.0'
|
11
|
+
```
|
12
|
+
|
13
|
+
Now, run ``bundle install``
|
14
|
+
|
15
|
+
Next, to install the search plugin run:
|
16
|
+
|
17
|
+
rails generate refinery:search
|
18
|
+
|
19
|
+
Run database migrations:
|
11
20
|
|
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
21
|
rake db:migrate
|
17
22
|
|
18
|
-
|
23
|
+
Finally seed your database and you're done.
|
24
|
+
|
25
|
+
rake db:seed
|
19
26
|
|
20
|
-
|
27
|
+
## RE-SAVE all records that have not been indexed before.
|
28
|
+
|
29
|
+
A sample search form can be found in [views/refinery/shared/_search.html.erb](http://github.com/resolve/refinerycms-search/blob/master/app/views/refinery/shared/_search.html.erb).
|
21
30
|
You can either use this partial directly, or copy the appropriate parts.
|
22
31
|
|
23
32
|
## Searching
|
24
33
|
|
25
34
|
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
|
35
|
+
If you wish to find results in other plugins you have created or installed, you can specify these in `config/application.rb` like so:
|
27
36
|
|
28
|
-
|
29
|
-
|
30
|
-
|
37
|
+
```ruby
|
38
|
+
config.to_prepare do
|
39
|
+
Refinery.searchable_models = [Refinery::Page]
|
40
|
+
end
|
41
|
+
```
|
31
42
|
|
32
43
|
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:
|
33
44
|
|
34
|
-
|
35
|
-
|
36
|
-
|
45
|
+
```ruby
|
46
|
+
config.to_prepare do
|
47
|
+
Refinery.searchable_models = [Refinery::Page, Refinery::PortfolioEntry]
|
48
|
+
end
|
49
|
+
```
|
37
50
|
|
38
51
|
The above line will add indexing to PortfolioEntry in the portfolio plugin, which does not come indexed.
|
39
52
|
|
40
53
|
Any model you wish to search will need to be indexed using acts as indexed. To add indexing, simple add:
|
41
54
|
|
42
|
-
|
55
|
+
```ruby
|
56
|
+
acts_as_indexed :fields => [:title, :body]
|
57
|
+
```
|
43
58
|
|
44
|
-
If your model doesn't use a
|
59
|
+
If your model doesn't use a `:title` attribute, remember to add an `alias_attribute`:
|
45
60
|
|
46
|
-
|
61
|
+
```ruby
|
62
|
+
alias_attribute :title, :name #for example
|
63
|
+
```
|
47
64
|
|
48
|
-
You can use any public method, as well. So if you have
|
65
|
+
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
66
|
|
50
|
-
|
67
|
+
```ruby
|
68
|
+
acts_as_indexed :fields => [:name, :biography]
|
51
69
|
|
52
|
-
|
70
|
+
#...
|
53
71
|
|
54
|
-
|
55
|
-
|
56
|
-
|
72
|
+
def name
|
73
|
+
[first_name, last_name].reject(&:blank?).join(' ')
|
74
|
+
end
|
75
|
+
```
|
57
76
|
|
58
77
|
You will need to replace the indexed fields with those appropriate for your model.
|
59
78
|
|
60
|
-
|
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.
|
79
|
+
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,47 +1,17 @@
|
|
1
|
-
# Encoding: UTF-8
|
2
1
|
Gem::Specification.new do |s|
|
3
2
|
s.name = %q{refinerycms-search}
|
4
|
-
s.version = %q{
|
5
|
-
s.date = %
|
3
|
+
s.version = %q{2.0.0}
|
4
|
+
s.date = "#{Date.today.strftime("%Y-%m-%d")}"
|
6
5
|
s.summary = %q{Extra search handling for Refinery CMS}
|
7
6
|
s.description = %q{Provides extra functionality for searching your frontend website using Refinery CMS.}
|
8
7
|
s.homepage = %q{http://refinerycms.com}
|
9
8
|
s.email = %q{info@refinerycms.com}
|
10
9
|
s.authors = ["Uģis Ozols", "Joe Sak", "Philip Arndt"]
|
11
10
|
s.require_paths = %w(lib)
|
11
|
+
s.license = %q{MIT}
|
12
12
|
|
13
|
-
s.
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
14
15
|
|
15
|
-
s.
|
16
|
-
'app',
|
17
|
-
'app/controllers',
|
18
|
-
'app/controllers/search_controller.rb',
|
19
|
-
'app/helpers',
|
20
|
-
'app/helpers/search_helper.rb',
|
21
|
-
'app/models',
|
22
|
-
'app/models/search_engine.rb',
|
23
|
-
'app/views',
|
24
|
-
'app/views/search',
|
25
|
-
'app/views/search/show.html.erb',
|
26
|
-
'app/views/shared',
|
27
|
-
'app/views/shared/_search.html.erb',
|
28
|
-
'config',
|
29
|
-
'config/locales',
|
30
|
-
'config/locales/bg.yml',
|
31
|
-
'config/locales/en.yml',
|
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',
|
38
|
-
'lib',
|
39
|
-
'lib/gemspec.rb',
|
40
|
-
'lib/generators',
|
41
|
-
'lib/generators/refinerycms_search_generator.rb',
|
42
|
-
'lib/refinerycms-search.rb',
|
43
|
-
'readme.md',
|
44
|
-
'refinerycms-search.gemspec'
|
45
|
-
]
|
46
|
-
s.require_path = 'lib'
|
16
|
+
s.add_dependency 'refinerycms-core', '~> 2.0.4'
|
47
17
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Refinery
|
4
|
+
describe SearchEngine do
|
5
|
+
describe "#search" do
|
6
|
+
context "when page exist" do
|
7
|
+
# we're using page factory because search engine uses
|
8
|
+
# page model as default model
|
9
|
+
let!(:page) { FactoryGirl.create(:page, :title => "testy") }
|
10
|
+
|
11
|
+
it "returns an array consisting of mathcing pages" do
|
12
|
+
result = SearchEngine.search("testy")
|
13
|
+
result.should include(page)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when page does not exist" do
|
18
|
+
it "returns empty array" do
|
19
|
+
result = SearchEngine.search("ugisozols")
|
20
|
+
result.should be_empty
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
$VERBOSE = ENV['VERBOSE'] || false
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../') unless defined?(ENGINE_RAILS_ROOT)
|
6
|
+
|
7
|
+
def setup_environment
|
8
|
+
# Configure Rails Environment
|
9
|
+
ENV["RAILS_ENV"] ||= 'test'
|
10
|
+
|
11
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
12
|
+
|
13
|
+
require 'rspec/rails'
|
14
|
+
require 'capybara/rspec'
|
15
|
+
|
16
|
+
Rails.backtrace_cleaner.remove_silencers!
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.mock_with :rspec
|
20
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
21
|
+
config.filter_run :focus => true
|
22
|
+
config.run_all_when_everything_filtered = true
|
23
|
+
end
|
24
|
+
|
25
|
+
# Set javascript driver for capybara
|
26
|
+
Capybara.javascript_driver = :selenium
|
27
|
+
end
|
28
|
+
|
29
|
+
def each_run
|
30
|
+
Rails.cache.clear
|
31
|
+
ActiveSupport::Dependencies.clear
|
32
|
+
FactoryGirl.reload
|
33
|
+
|
34
|
+
# Requires supporting files with custom matchers and macros, etc,
|
35
|
+
# in ./support/ and its subdirectories including factories.
|
36
|
+
([ENGINE_RAILS_ROOT, Rails.root.to_s].uniq | Refinery::Plugins.registered.pathnames).map{|p|
|
37
|
+
Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s]
|
38
|
+
}.flatten.sort.each do |support_file|
|
39
|
+
require support_file
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# If spork is available in the Gemfile it'll be used but we don't force it.
|
44
|
+
unless (begin; require 'spork'; rescue LoadError; nil end).nil?
|
45
|
+
Spork.prefork do
|
46
|
+
# Loading more in this block will cause your tests to run faster. However,
|
47
|
+
# if you change any configuration or code from libraries loaded here, you'll
|
48
|
+
# need to restart spork for it take effect.
|
49
|
+
setup_environment
|
50
|
+
end
|
51
|
+
|
52
|
+
Spork.each_run do
|
53
|
+
# This code will be run each time you run your specs.
|
54
|
+
each_run
|
55
|
+
end
|
56
|
+
else
|
57
|
+
setup_environment
|
58
|
+
each_run
|
59
|
+
end
|
data/tasks/rspec.rake
ADDED
metadata
CHANGED
@@ -1,96 +1,92 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: refinerycms-search
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 1.0.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
-
|
7
|
+
authors:
|
8
|
+
- Uģis Ozols
|
14
9
|
- Joe Sak
|
15
10
|
- Philip Arndt
|
16
11
|
autorequire:
|
17
12
|
bindir: bin
|
18
13
|
cert_chain: []
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
date: 2012-12-03 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
23
17
|
name: refinerycms-core
|
24
18
|
prerelease: false
|
25
|
-
requirement:
|
26
|
-
|
27
|
-
requirements:
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
28
21
|
- - ~>
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
|
31
|
-
|
32
|
-
- 1
|
33
|
-
- 0
|
34
|
-
version: "1.0"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.0.4
|
24
|
+
none: false
|
35
25
|
type: :runtime
|
36
|
-
version_requirements:
|
37
|
-
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 2.0.4
|
31
|
+
none: false
|
32
|
+
description: Provides extra functionality for searching your frontend website using
|
33
|
+
Refinery CMS.
|
38
34
|
email: info@refinerycms.com
|
39
35
|
executables: []
|
40
|
-
|
41
36
|
extensions: []
|
42
|
-
|
43
37
|
extra_rdoc_files: []
|
44
|
-
|
45
|
-
|
46
|
-
-
|
47
|
-
-
|
48
|
-
-
|
49
|
-
-
|
50
|
-
- app/
|
38
|
+
files:
|
39
|
+
- .gitignore
|
40
|
+
- .travis.yml
|
41
|
+
- Gemfile
|
42
|
+
- Guardfile
|
43
|
+
- Rakefile
|
44
|
+
- app/controllers/refinery/search_controller.rb
|
45
|
+
- app/helpers/refinery/search_helper.rb
|
46
|
+
- app/models/refinery/search_engine.rb
|
47
|
+
- app/views/refinery/search/show.html.erb
|
48
|
+
- app/views/refinery/shared/_search.html.erb
|
51
49
|
- config/locales/bg.yml
|
52
50
|
- config/locales/en.yml
|
51
|
+
- config/locales/sk.yml
|
53
52
|
- config/routes.rb
|
54
53
|
- db/migrate/01_create_search_page.rb
|
55
|
-
- db/seeds
|
56
|
-
- lib/
|
57
|
-
- lib/
|
54
|
+
- db/seeds.rb
|
55
|
+
- lib/generators/refinery/search_generator.rb
|
56
|
+
- lib/refinery/search.rb
|
57
|
+
- lib/refinery/search/engine.rb
|
58
58
|
- lib/refinerycms-search.rb
|
59
59
|
- readme.md
|
60
60
|
- refinerycms-search.gemspec
|
61
|
+
- spec/models/refinery/search_engine_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
- tasks/rspec.rake
|
61
64
|
homepage: http://refinerycms.com
|
62
|
-
licenses:
|
63
|
-
|
65
|
+
licenses:
|
66
|
+
- MIT
|
64
67
|
post_install_message:
|
65
68
|
rdoc_options: []
|
66
|
-
|
67
|
-
require_paths:
|
69
|
+
require_paths:
|
68
70
|
- lib
|
69
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
70
76
|
none: false
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
- 0
|
77
|
-
version: "0"
|
78
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
79
82
|
none: false
|
80
|
-
requirements:
|
81
|
-
- - ">="
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
hash: 3
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
version: "0"
|
87
83
|
requirements: []
|
88
|
-
|
89
84
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.8.
|
85
|
+
rubygems_version: 1.8.24
|
91
86
|
signing_key:
|
92
87
|
specification_version: 3
|
93
88
|
summary: Extra search handling for Refinery CMS
|
94
|
-
test_files:
|
95
|
-
|
89
|
+
test_files:
|
90
|
+
- spec/models/refinery/search_engine_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
96
92
|
has_rdoc:
|
data/app/models/search_engine.rb
DELETED
@@ -1,17 +0,0 @@
|
|
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
|
@@ -1,37 +0,0 @@
|
|
1
|
-
<% content_for :body_content_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(/(#{Regexp.escape(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 :stylesheets 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 %>
|
@@ -1,25 +0,0 @@
|
|
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
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Encoding: UTF-8
|
3
|
-
version = '1.0.0'
|
4
|
-
raise "Could not get version so gemspec can not be built" if version.nil?
|
5
|
-
files = Dir.glob("**/*").flatten.reject do |file|
|
6
|
-
file =~ /\.gem$/
|
7
|
-
end
|
8
|
-
|
9
|
-
gemspec = <<EOF
|
10
|
-
# Encoding: UTF-8
|
11
|
-
Gem::Specification.new do |s|
|
12
|
-
s.name = %q{refinerycms-search}
|
13
|
-
s.version = %q{#{version}}
|
14
|
-
s.date = %q{#{Time.now.strftime('%Y-%m-%d')}}
|
15
|
-
s.summary = %q{Extra search handling for Refinery CMS}
|
16
|
-
s.description = %q{Provides extra functionality for searching your frontend website using Refinery CMS.}
|
17
|
-
s.homepage = %q{http://refinerycms.com}
|
18
|
-
s.email = %q{info@refinerycms.com}
|
19
|
-
s.authors = ["Uģis Ozols", "Joe Sak", "Philip Arndt"]
|
20
|
-
s.require_paths = %w(lib)
|
21
|
-
|
22
|
-
s.add_dependency 'refinerycms-core', '~> 1.0'
|
23
|
-
|
24
|
-
s.files = [
|
25
|
-
'#{files.join("',\n '")}'
|
26
|
-
]
|
27
|
-
s.require_path = 'lib'
|
28
|
-
end
|
29
|
-
EOF
|
30
|
-
|
31
|
-
File.open(File.expand_path("../../refinerycms-search.gemspec", __FILE__), 'w').puts(gemspec)
|