refinerycms-pgsearch 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +65 -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 +13 -0
- data/app/views/refinery/search/show.html.erb +19 -0
- data/app/views/refinery/shared/_search.html.erb +6 -0
- data/config/locales/bg.yml +6 -0
- data/config/locales/en.yml +9 -0
- data/config/routes.rb +3 -0
- data/db/seeds.rb +23 -0
- data/lib/generators/refinery/search/search_generator.rb +45 -0
- data/lib/generators/refinery/search/templates/01_create_search_page.rb +16 -0
- data/lib/generators/refinery/search/templates/02_create_pg_search_table.rb +21 -0
- data/lib/generators/refinery/search/templates/03_initializer.rb +23 -0
- data/lib/refinery/search.rb +23 -0
- data/lib/refinery/search/engine.rb +47 -0
- data/lib/refinerycms-pgsearch.rb +1 -0
- data/lib/tasks/search.rake +15 -0
- data/readme.md +55 -0
- data/refinerycms-pgsearch.gemspec +17 -0
- data/spec/models/refinery/search_engine_spec.rb +25 -0
- data/spec/spec_helper.rb +59 -0
- data/tasks/rspec.rake +4 -0
- metadata +106 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,65 @@
|
|
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-jdbcpostgresql-adapter'
|
13
|
+
gem 'jruby-openssl'
|
14
|
+
end
|
15
|
+
|
16
|
+
unless defined?(JRUBY_VERSION)
|
17
|
+
gem 'pg'
|
18
|
+
end
|
19
|
+
|
20
|
+
platforms :mswin, :mingw do
|
21
|
+
gem 'win32console'
|
22
|
+
gem 'rb-fchange', '~> 0.0.5'
|
23
|
+
gem 'rb-notifu', '~> 0.0.4'
|
24
|
+
end
|
25
|
+
|
26
|
+
platforms :ruby do
|
27
|
+
gem 'spork', '~> 0.9.0.rc'
|
28
|
+
gem 'guard-spork'
|
29
|
+
|
30
|
+
unless ENV['TRAVIS']
|
31
|
+
require 'rbconfig'
|
32
|
+
if RbConfig::CONFIG['target_os'] =~ /darwin/i
|
33
|
+
gem 'rb-fsevent', '>= 0.3.9'
|
34
|
+
gem 'ruby_gntp'
|
35
|
+
end
|
36
|
+
if RbConfig::CONFIG['target_os'] =~ /linux/i
|
37
|
+
gem 'rb-inotify', '>= 0.5.1'
|
38
|
+
gem 'libnotify', '~> 0.1.3'
|
39
|
+
gem 'therubyracer', '~> 0.9.9'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
platforms :jruby do
|
45
|
+
unless ENV['TRAVIS']
|
46
|
+
require 'rbconfig'
|
47
|
+
if RbConfig::CONFIG['target_os'] =~ /darwin/i
|
48
|
+
gem 'ruby_gntp'
|
49
|
+
end
|
50
|
+
if RbConfig::CONFIG['target_os'] =~ /linux/i
|
51
|
+
gem 'rb-inotify', '>= 0.5.1'
|
52
|
+
gem 'libnotify', '~> 0.1.3'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Refinery/rails should pull in the proper versions of these
|
59
|
+
group :assets do
|
60
|
+
gem 'sass-rails'
|
61
|
+
gem 'coffee-rails'
|
62
|
+
gem 'uglifier'
|
63
|
+
end
|
64
|
+
|
65
|
+
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,13 @@
|
|
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
|
+
PgSearch.multisearch(query).paginate(:page => page, :per_page => RESULTS_LIMIT)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<% content_for :body_content_title do %>
|
2
|
+
<%= t('.search_results_for', :what => 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_type result.searchable %>
|
11
|
+
</span>
|
12
|
+
<%= link_to result_title(result.searchable).html_safe, result_url(result.searchable) %>
|
13
|
+
</li>
|
14
|
+
<% end %>
|
15
|
+
</ul>
|
16
|
+
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<%= render :partial => "/refinery/content_page" %>
|
data/config/routes.rb
ADDED
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,45 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
module Refinery
|
5
|
+
class SearchGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
desc "Creates the installation files for RefineryCMS Search"
|
9
|
+
|
10
|
+
source_root File.expand_path("../templates", __FILE__)
|
11
|
+
|
12
|
+
def self.next_migration_number(dirname)
|
13
|
+
if ActiveRecord::Base.timestamped_migrations
|
14
|
+
Time.new.utc.strftime("%Y%m%d%H%M%S")
|
15
|
+
else
|
16
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_migration_file
|
21
|
+
migration_template '01_create_search_page.rb', 'db/migrate/create_search_page.rb'
|
22
|
+
sleep 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def pg_search_migration
|
26
|
+
migration_template '02_create_pg_search_table.rb', 'db/migrate/create_pg_search_table.rb'
|
27
|
+
end
|
28
|
+
|
29
|
+
def copy_initializer
|
30
|
+
copy_file "03_initializer.rb", "config/initializers/refinery/search.rb"
|
31
|
+
end
|
32
|
+
|
33
|
+
def append_load_seed_data
|
34
|
+
create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb'))
|
35
|
+
append_file 'db/seeds.rb', :verbose => true do
|
36
|
+
<<-EOH
|
37
|
+
|
38
|
+
# Added by Refinery CMS Search engine
|
39
|
+
Refinery::Search::Engine.load_seed
|
40
|
+
EOH
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateSearchPage < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def up
|
4
|
+
end
|
5
|
+
|
6
|
+
def down
|
7
|
+
if defined?(Refinery::UserPlugin)
|
8
|
+
Refinery::UserPlugin.destroy_all({:name => "refinerycms_search"})
|
9
|
+
end
|
10
|
+
|
11
|
+
if defined?(Refinery::Page)
|
12
|
+
Refinery::Page.delete_all({:link_url => "/search"})
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class CreatePgSearchTable < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
say_with_time("Creating table for pg_search multisearch") do
|
4
|
+
create_table :pg_search_documents do |t|
|
5
|
+
t.text :content
|
6
|
+
t.belongs_to :searchable, :polymorphic => true
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
execute "CREATE EXTENSION IF NOT EXISTS unaccent;"
|
10
|
+
execute "ALTER TABLE pg_search_documents ADD COLUMN tsv tsvector;"
|
11
|
+
execute "CREATE INDEX index_pg_search_documents_tsv ON pg_search_documents USING gin(tsv);"
|
12
|
+
execute "CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON pg_search_documents FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(tsv, 'pg_catalog.english', content)"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
say_with_time("Dropping table for pg_search multisearch") do
|
18
|
+
drop_table :pg_search_documents
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Refinery::Search.configure do |config|
|
2
|
+
config.searchable_models = {
|
3
|
+
# Add a Hash of "ModelName" => [:searchable, :field, :names, :as, :keys]
|
4
|
+
|
5
|
+
# Below are common Refinery models that you might want indexed.
|
6
|
+
# Uncomment any that you wish to use, and then run:
|
7
|
+
# rake refinery:search:rebuild
|
8
|
+
# To rebuild the search index.
|
9
|
+
|
10
|
+
# Refinery::Page
|
11
|
+
# We defined a special method called #all_parts to allow
|
12
|
+
# all of the content in the different Page Parts to be indexed
|
13
|
+
# simply under the parent page.
|
14
|
+
|
15
|
+
"Refinery::Page" => [:title, :all_parts],
|
16
|
+
|
17
|
+
# Refinery::Blog::Post and Refinery::News::Item
|
18
|
+
# These are simple, only indexing fields on the model.
|
19
|
+
|
20
|
+
# "Refinery::Blog::Post" => [:title, :body],
|
21
|
+
# "Refinery::News::Item" => [:title, :body]
|
22
|
+
}
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "refinerycms-core"
|
2
|
+
|
3
|
+
module Refinery
|
4
|
+
autoload :SearchGenerator, 'generators/refinery/search/search_generator'
|
5
|
+
|
6
|
+
module Search
|
7
|
+
require "refinery/search/engine"
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_writer :root
|
11
|
+
mattr_accessor :searchable_models
|
12
|
+
|
13
|
+
def root
|
14
|
+
@root ||= Pathname.new(File.expand_path('../../../', __FILE__))
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure
|
18
|
+
yield self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Refinery
|
2
|
+
module Search
|
3
|
+
class Engine < Rails::Engine
|
4
|
+
include Refinery::Engine
|
5
|
+
|
6
|
+
initializer "register refinery_search plugin" do
|
7
|
+
Refinery::Plugin.register do |plugin|
|
8
|
+
plugin.name = 'refinery_search'
|
9
|
+
plugin.version = 2.0
|
10
|
+
plugin.hide_from_menu = true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
config.to_prepare do
|
15
|
+
::Refinery::Search.searchable_models ||= {"Refinery::Page" => [:title, :all_parts]}
|
16
|
+
end
|
17
|
+
|
18
|
+
config.after_initialize do
|
19
|
+
require 'pg_search'
|
20
|
+
|
21
|
+
PgSearch.multisearch_options = {
|
22
|
+
using: {
|
23
|
+
tsearch: {
|
24
|
+
prefix: true,
|
25
|
+
dictionary: "english",
|
26
|
+
tsvector_column: 'tsv'
|
27
|
+
}
|
28
|
+
},
|
29
|
+
ignoring: :accents
|
30
|
+
}
|
31
|
+
|
32
|
+
::Refinery::Search.searchable_models.each do |model, fields|
|
33
|
+
model.constantize.module_eval do
|
34
|
+
include PgSearch
|
35
|
+
multisearchable :against => fields
|
36
|
+
if fields.include?(:all_parts)
|
37
|
+
def all_parts
|
38
|
+
@all_parts ||= parts.pluck(:body).join(' ')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "refinery/search"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
namespace :refinery do
|
2
|
+
namespace :search do
|
3
|
+
|
4
|
+
task :rebuild => :environment do
|
5
|
+
# Get searchable models from hash keys.
|
6
|
+
Refinery::Search.searchable_models.keys.each do |model|
|
7
|
+
# Delete the old search documents
|
8
|
+
PgSearch::Document.delete_all(:searchable_type => model.to_s)
|
9
|
+
# Add some new ones!
|
10
|
+
model.constantize.find_each{|record| record.update_pg_search_document }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/readme.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Search plugin for [RefineryCMS](http://www.refinerycms.com)
|
2
|
+
[Github](http://github.com/resolve/refinerycms)
|
3
|
+
|
4
|
+
By: [JGW Maxwell](http://jgwmaxwell.com)
|
5
|
+
|
6
|
+
Powered by: [pg_search](http://github.com/Casecommons/pg_search). **This only works on PostgreSQL databases, ideally 9.0+.**
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Simply use this by adding the following to your `Gemfile`:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'refinerycms-pgsearch'
|
14
|
+
# or for the latest and greatest
|
15
|
+
gem 'refinerycms-pgsearch', github: 'jgwmaxwell/refinerycms-pgsearch'
|
16
|
+
```
|
17
|
+
Then run `bundle install`, and `rails g refinery:search` to generate the migrations. Finally, run `rake db:migrate` and `rake db:seed` to finish setting up.
|
18
|
+
|
19
|
+
# # Check The Initializer
|
20
|
+
|
21
|
+
The default installation will search in Pages. If you wish to find results in other plugins you have created or installed, you can specify these in `config/initializers/refinery/search.rb` like so:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Refinery::Search.configure do |config|
|
25
|
+
config.searchable_models = {
|
26
|
+
"Refinery::Page" => [:title, :all_parts],
|
27
|
+
"Refinery::Blog::Post" => [:title, :body]
|
28
|
+
}
|
29
|
+
end
|
30
|
+
```
|
31
|
+
This will index Pages and Blog Posts for you. The format is: `"STRING_OF_MODEL_CLASS" => [:array, :of, :attribute, :symbols]`. You might notice that Pages are indexing `:all_parts` - this is a convenience to get the content out of multiple page parts that will be defined if you use it.
|
32
|
+
|
33
|
+
# # To use your own Models
|
34
|
+
|
35
|
+
Simple pass another line into the hash in the initializer, such as:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
"Employee" => [:name, :bio]
|
39
|
+
```
|
40
|
+
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.
|
41
|
+
|
42
|
+
# # Existing Data and Rebuilding
|
43
|
+
|
44
|
+
If at any point you need to rebuild your search index, run `rake refinery:search:rebuild` to update all your search records!
|
45
|
+
|
46
|
+
# # Searching and Viewing
|
47
|
+
|
48
|
+
A sample search form can be found in [views/refinery/shared/_search.html.erb](http://github.com/jgwmaxwell/refinerycms-pgsearch/blob/master/app/views/refinery/shared/_search.html.erb).
|
49
|
+
You can either use this partial directly, or copy the appropriate parts.
|
50
|
+
|
51
|
+
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.
|
52
|
+
|
53
|
+
# # Migrating from refinerycms-search
|
54
|
+
|
55
|
+
You'll need to run the generator, migrate the database, update the new initializer and remove the old code from `application.rb`. Then remove the `acts_as_indexed` statements from your models but otherwise it should be good to go. Let me know if you need help.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{refinerycms-pgsearch}
|
3
|
+
s.version = %q{0.1}
|
4
|
+
s.date = "#{Date.today.strftime("%Y-%m-%d")}"
|
5
|
+
s.summary = %q{PostgreSQL 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{jgwmaxwell@gmail.com}
|
9
|
+
s.authors = ["JGW Maxwell"]
|
10
|
+
s.require_paths = %w(lib)
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
14
|
+
|
15
|
+
s.add_dependency 'refinerycms-core', '~> 2.0.4'
|
16
|
+
s.add_dependency 'pg_search', '~> 0.5'
|
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
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: refinerycms-pgsearch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- JGW Maxwell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: refinerycms-core
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.4
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.4
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: pg_search
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.5'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.5'
|
46
|
+
description: Provides extra functionality for searching your frontend website using
|
47
|
+
Refinery CMS.
|
48
|
+
email: jgwmaxwell@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- Guardfile
|
56
|
+
- Rakefile
|
57
|
+
- app/controllers/refinery/search_controller.rb
|
58
|
+
- app/helpers/refinery/search_helper.rb
|
59
|
+
- app/models/refinery/search_engine.rb
|
60
|
+
- app/views/refinery/search/show.html.erb
|
61
|
+
- app/views/refinery/shared/_search.html.erb
|
62
|
+
- config/locales/bg.yml
|
63
|
+
- config/locales/en.yml
|
64
|
+
- config/routes.rb
|
65
|
+
- db/seeds.rb
|
66
|
+
- lib/generators/refinery/search/search_generator.rb
|
67
|
+
- lib/generators/refinery/search/templates/01_create_search_page.rb
|
68
|
+
- lib/generators/refinery/search/templates/02_create_pg_search_table.rb
|
69
|
+
- lib/generators/refinery/search/templates/03_initializer.rb
|
70
|
+
- lib/refinery/search.rb
|
71
|
+
- lib/refinery/search/engine.rb
|
72
|
+
- lib/refinerycms-pgsearch.rb
|
73
|
+
- lib/tasks/search.rake
|
74
|
+
- readme.md
|
75
|
+
- refinerycms-pgsearch.gemspec
|
76
|
+
- spec/models/refinery/search_engine_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- tasks/rspec.rake
|
79
|
+
homepage: http://refinerycms.com
|
80
|
+
licenses: []
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.24
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: PostgreSQL search handling for Refinery CMS
|
103
|
+
test_files:
|
104
|
+
- spec/models/refinery/search_engine_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
has_rdoc:
|