Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 0 stable merge #20

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions Gemfile
Expand Up @@ -5,9 +5,8 @@ gemspec
gem 'refinerycms', '~> 2.0.0'

group :development, :test do
require 'rbconfig'

gem 'refinerycms-testing', '~> 2.0.0'
gem 'guard-rspec', '~> 0.6.0'

platforms :jruby do
gem 'activerecord-jdbcsqlite3-adapter'
Expand All @@ -29,13 +28,14 @@ group :development, :test do
end

platforms :ruby do
gem 'spork', '0.9.0.rc9'
gem 'spork', '~> 0.9.0.rc'
gem 'guard-spork'

unless ENV['TRAVIS']
require 'rbconfig'
if RbConfig::CONFIG['target_os'] =~ /darwin/i
gem 'rb-fsevent', '>= 0.3.9'
gem 'growl', '~> 1.0.3'
gem 'ruby_gntp'
end
if RbConfig::CONFIG['target_os'] =~ /linux/i
gem 'rb-inotify', '>= 0.5.1'
Expand All @@ -47,8 +47,9 @@ group :development, :test do

platforms :jruby do
unless ENV['TRAVIS']
require 'rbconfig'
if RbConfig::CONFIG['target_os'] =~ /darwin/i
gem 'growl', '~> 1.0.3'
gem 'ruby_gntp'
end
if RbConfig::CONFIG['target_os'] =~ /linux/i
gem 'rb-inotify', '>= 0.5.1'
Expand Down
20 changes: 20 additions & 0 deletions Guardfile
@@ -0,0 +1,20 @@
guard 'rspec', :version => 2, :cli => "--color" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
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"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end

guard 'spork', :wait => 60, :cucumber => false, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('spec/spec_helper.rb')
end
59 changes: 33 additions & 26 deletions readme.md
Expand Up @@ -7,55 +7,62 @@ Powered by: [acts_as_indexed](http://github.com/dougal/acts_as_indexed) - Check

## Installation

Simply use this by adding the following to your ``Gemfile``:
Simply use this by adding the following to your `Gemfile`:

gem 'refinerycms-search', '~> 0.9.8'
```ruby
gem 'refinerycms-search', '~> 2.0.0', :git => 'git://github.com/resolve/refinerycms-search.git', :branch => '2-0-stable'
```

You'll also need to create a page (from the 'Pages' tab) with a custom URL of '/search'.
You can set a custom URL for a page in the Advanced Options via the "Forward this page to another website or page" option.
It's probably also a good idea to uncheck the 'show in menu' option for this page.
## RE-SAVE all records that have not been indexed before.

## Restart your web server and RE-SAVE all records that have not been indexed before.

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).
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).
You can either use this partial directly, or copy the appropriate parts.

## Searching

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/application.rb`` like so:
If you wish to find results in other plugins you have created or installed, you can specify these in `config/application.rb` like so:

config.to_prepare do
Refinery.searchable_models = [Page]
end
```ruby
config.to_prepare do
Refinery.searchable_models = [Refinery::Page]
end
```

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:

config.to_prepare do
Refinery.searchable_models = [Page, PortfolioEntry]
end
```ruby
config.to_prepare do
Refinery.searchable_models = [Refinery::Page, Refinery::PortfolioEntry]
end
```

The above line will add indexing to PortfolioEntry in the portfolio plugin, which does not come indexed.

Any model you wish to search will need to be indexed using acts as indexed. To add indexing, simple add:

acts_as_indexed :fields => [:title, :body]
```ruby
acts_as_indexed :fields => [:title, :body]
```

If your model doesn't use a ``:title`` attribute, remember to add an ``alias_attribute``:
If your model doesn't use a `:title` attribute, remember to add an `alias_attribute`:

alias_attribute :title, :name #for example
```ruby
alias_attribute :title, :name #for example
```

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.
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.

acts_as_indexed :fields => [:name, :biography]
```ruby
acts_as_indexed :fields => [:name, :biography]

#...
#...

def name
(first_name, last_name).compact.join(' ')
end
def name
[first_name, last_name].reject(&:blank?).join(' ')
end
```

You will need to replace the indexed fields with those appropriate for your model.


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.
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.
3 changes: 0 additions & 3 deletions refinerycms-search.gemspec
Expand Up @@ -13,7 +13,4 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- spec/*`.split("\n")

s.add_dependency 'refinerycms-core', '~> 2.0.0'

# Development dependencies
s.add_development_dependency 'refinerycms-testing', '~> 2.0.0'
end