cehoffman-acts_as_ferret 0.4.4
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/LICENSE +20 -0
- data/README +68 -0
- data/bin/aaf_install +23 -0
- data/config/ferret_server.yml +24 -0
- data/doc/README.win32 +23 -0
- data/doc/demo/README +154 -0
- data/doc/demo/README_DEMO +23 -0
- data/doc/demo/Rakefile +10 -0
- data/doc/demo/app/controllers/admin/backend_controller.rb +14 -0
- data/doc/demo/app/controllers/admin_area_controller.rb +4 -0
- data/doc/demo/app/controllers/application.rb +5 -0
- data/doc/demo/app/controllers/contents_controller.rb +49 -0
- data/doc/demo/app/controllers/searches_controller.rb +8 -0
- data/doc/demo/app/helpers/admin/backend_helper.rb +2 -0
- data/doc/demo/app/helpers/application_helper.rb +3 -0
- data/doc/demo/app/helpers/content_helper.rb +2 -0
- data/doc/demo/app/helpers/search_helper.rb +2 -0
- data/doc/demo/app/models/comment.rb +48 -0
- data/doc/demo/app/models/content.rb +12 -0
- data/doc/demo/app/models/content_base.rb +28 -0
- data/doc/demo/app/models/search.rb +19 -0
- data/doc/demo/app/models/shared_index1.rb +3 -0
- data/doc/demo/app/models/shared_index2.rb +3 -0
- data/doc/demo/app/models/special_content.rb +3 -0
- data/doc/demo/app/models/stats.rb +20 -0
- data/doc/demo/app/views/admin/backend/search.rhtml +18 -0
- data/doc/demo/app/views/contents/_form.rhtml +10 -0
- data/doc/demo/app/views/contents/edit.rhtml +9 -0
- data/doc/demo/app/views/contents/index.rhtml +24 -0
- data/doc/demo/app/views/contents/new.rhtml +8 -0
- data/doc/demo/app/views/contents/show.rhtml +8 -0
- data/doc/demo/app/views/layouts/application.html.erb +17 -0
- data/doc/demo/app/views/searches/_content.html.erb +2 -0
- data/doc/demo/app/views/searches/search.html.erb +20 -0
- data/doc/demo/config/boot.rb +109 -0
- data/doc/demo/config/database.yml +38 -0
- data/doc/demo/config/environment.rb +69 -0
- data/doc/demo/config/environments/development.rb +16 -0
- data/doc/demo/config/environments/production.rb +19 -0
- data/doc/demo/config/environments/test.rb +21 -0
- data/doc/demo/config/ferret_server.yml +18 -0
- data/doc/demo/config/lighttpd.conf +40 -0
- data/doc/demo/config/routes.rb +9 -0
- data/doc/demo/db/development_structure.sql +15 -0
- data/doc/demo/db/migrate/001_initial_migration.rb +18 -0
- data/doc/demo/db/migrate/002_add_type_to_contents.rb +9 -0
- data/doc/demo/db/migrate/003_create_shared_index1s.rb +11 -0
- data/doc/demo/db/migrate/004_create_shared_index2s.rb +11 -0
- data/doc/demo/db/migrate/005_special_field.rb +9 -0
- data/doc/demo/db/migrate/006_create_stats.rb +15 -0
- data/doc/demo/db/schema.sql +18 -0
- data/doc/demo/doc/README_FOR_APP +2 -0
- data/doc/demo/doc/howto.txt +70 -0
- data/doc/demo/public/.htaccess +40 -0
- data/doc/demo/public/404.html +8 -0
- data/doc/demo/public/500.html +8 -0
- data/doc/demo/public/dispatch.cgi +10 -0
- data/doc/demo/public/dispatch.fcgi +24 -0
- data/doc/demo/public/dispatch.rb +10 -0
- data/doc/demo/public/favicon.ico +0 -0
- data/doc/demo/public/images/rails.png +0 -0
- data/doc/demo/public/index.html +277 -0
- data/doc/demo/public/robots.txt +1 -0
- data/doc/demo/public/stylesheets/scaffold.css +74 -0
- data/doc/demo/script/about +3 -0
- data/doc/demo/script/breakpointer +3 -0
- data/doc/demo/script/console +3 -0
- data/doc/demo/script/destroy +3 -0
- data/doc/demo/script/ferret_server +10 -0
- data/doc/demo/script/generate +3 -0
- data/doc/demo/script/performance/benchmarker +3 -0
- data/doc/demo/script/performance/profiler +3 -0
- data/doc/demo/script/plugin +3 -0
- data/doc/demo/script/process/inspector +3 -0
- data/doc/demo/script/process/reaper +3 -0
- data/doc/demo/script/process/spawner +3 -0
- data/doc/demo/script/process/spinner +3 -0
- data/doc/demo/script/runner +3 -0
- data/doc/demo/script/server +3 -0
- data/doc/demo/test/fixtures/comments.yml +12 -0
- data/doc/demo/test/fixtures/contents.yml +13 -0
- data/doc/demo/test/fixtures/remote_contents.yml +9 -0
- data/doc/demo/test/fixtures/shared_index1s.yml +7 -0
- data/doc/demo/test/fixtures/shared_index2s.yml +7 -0
- data/doc/demo/test/functional/admin/backend_controller_test.rb +35 -0
- data/doc/demo/test/functional/contents_controller_test.rb +81 -0
- data/doc/demo/test/functional/searches_controller_test.rb +71 -0
- data/doc/demo/test/smoke/drb_smoke_test.rb +321 -0
- data/doc/demo/test/smoke/process_stats.rb +21 -0
- data/doc/demo/test/test_helper.rb +30 -0
- data/doc/demo/test/unit/comment_test.rb +217 -0
- data/doc/demo/test/unit/content_test.rb +705 -0
- data/doc/demo/test/unit/ferret_result_test.rb +24 -0
- data/doc/demo/test/unit/multi_index_test.rb +329 -0
- data/doc/demo/test/unit/remote_index_test.rb +23 -0
- data/doc/demo/test/unit/shared_index1_test.rb +108 -0
- data/doc/demo/test/unit/shared_index2_test.rb +13 -0
- data/doc/demo/test/unit/sort_test.rb +21 -0
- data/doc/demo/test/unit/special_content_test.rb +25 -0
- data/doc/demo/vendor/plugins/will_paginate/LICENSE +18 -0
- data/doc/demo/vendor/plugins/will_paginate/README +108 -0
- data/doc/demo/vendor/plugins/will_paginate/Rakefile +23 -0
- data/doc/demo/vendor/plugins/will_paginate/init.rb +21 -0
- data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/collection.rb +45 -0
- data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb +44 -0
- data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/finder.rb +159 -0
- data/doc/demo/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb +95 -0
- data/doc/demo/vendor/plugins/will_paginate/test/array_pagination_test.rb +23 -0
- data/doc/demo/vendor/plugins/will_paginate/test/boot.rb +27 -0
- data/doc/demo/vendor/plugins/will_paginate/test/console +10 -0
- data/doc/demo/vendor/plugins/will_paginate/test/finder_test.rb +219 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/admin.rb +3 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/companies.yml +24 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/company.rb +23 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/developer.rb +11 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/developers_projects.yml +13 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/project.rb +4 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/projects.yml +7 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/replies.yml +20 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/reply.rb +5 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/schema.sql +44 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/topic.rb +19 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/topics.yml +30 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/user.rb +2 -0
- data/doc/demo/vendor/plugins/will_paginate/test/fixtures/users.yml +35 -0
- data/doc/demo/vendor/plugins/will_paginate/test/helper.rb +42 -0
- data/doc/demo/vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb +64 -0
- data/doc/demo/vendor/plugins/will_paginate/test/lib/load_fixtures.rb +10 -0
- data/doc/demo/vendor/plugins/will_paginate/test/pagination_test.rb +136 -0
- data/doc/monit-example +22 -0
- data/init.rb +24 -0
- data/install.rb +18 -0
- data/lib/act_methods.rb +147 -0
- data/lib/acts_as_ferret.rb +584 -0
- data/lib/ar_mysql_auto_reconnect_patch.rb +41 -0
- data/lib/blank_slate.rb +53 -0
- data/lib/bulk_indexer.rb +38 -0
- data/lib/class_methods.rb +270 -0
- data/lib/ferret_extensions.rb +188 -0
- data/lib/ferret_find_methods.rb +141 -0
- data/lib/ferret_result.rb +53 -0
- data/lib/ferret_server.rb +238 -0
- data/lib/index.rb +99 -0
- data/lib/instance_methods.rb +171 -0
- data/lib/local_index.rb +205 -0
- data/lib/more_like_this.rb +217 -0
- data/lib/multi_index.rb +126 -0
- data/lib/rdig_adapter.rb +148 -0
- data/lib/remote_functions.rb +23 -0
- data/lib/remote_index.rb +54 -0
- data/lib/remote_multi_index.rb +20 -0
- data/lib/search_results.rb +50 -0
- data/lib/server_manager.rb +58 -0
- data/lib/unix_daemon.rb +64 -0
- data/lib/without_ar.rb +52 -0
- data/rakefile +141 -0
- data/recipes/aaf_recipes.rb +114 -0
- data/script/ferret_daemon +94 -0
- data/script/ferret_server +10 -0
- data/script/ferret_service +178 -0
- data/tasks/ferret.rake +22 -0
- metadata +258 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Be sure to restart your web server when you modify this file.
|
|
2
|
+
|
|
3
|
+
# Uncomment below to force Rails into production mode when
|
|
4
|
+
# you don't control web/app server and can't set it the proper way
|
|
5
|
+
# ENV['RAILS_ENV'] ||= 'production'
|
|
6
|
+
|
|
7
|
+
# Bootstrap the Rails environment, frameworks, and default configuration
|
|
8
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
|
9
|
+
|
|
10
|
+
Rails::Initializer.run do |config|
|
|
11
|
+
# Settings in config/environments/* take precedence those specified here
|
|
12
|
+
|
|
13
|
+
config.action_controller.session = { :session_key => "_demo_session", :secret => "some secret phrase" }
|
|
14
|
+
|
|
15
|
+
# Skip frameworks you're not going to use
|
|
16
|
+
# config.frameworks -= [ :action_web_service, :action_mailer ]
|
|
17
|
+
|
|
18
|
+
# Add additional load paths for your own custom dirs
|
|
19
|
+
# config.load_paths += %W( #{RAILS_ROOT}/extras )
|
|
20
|
+
|
|
21
|
+
# Force all environments to use the same logger level
|
|
22
|
+
# (by default production uses :info, the others :debug)
|
|
23
|
+
# config.log_level = :debug
|
|
24
|
+
|
|
25
|
+
# Use the database for sessions instead of the file system
|
|
26
|
+
# (create the session table with 'rake create_sessions_table')
|
|
27
|
+
# config.action_controller.session_store = :active_record_store
|
|
28
|
+
|
|
29
|
+
# Enable page/fragment caching by setting a file-based store
|
|
30
|
+
# (remember to create the caching directory and make it readable to the application)
|
|
31
|
+
# config.action_controller.fragment_cache_store = :file_store, "#{RAILS_ROOT}/cache"
|
|
32
|
+
|
|
33
|
+
# Activate observers that should always be running
|
|
34
|
+
# config.active_record.observers = :cacher, :garbage_collector
|
|
35
|
+
|
|
36
|
+
# Make Active Record use UTC-base instead of local time
|
|
37
|
+
# config.active_record.default_timezone = :utc
|
|
38
|
+
|
|
39
|
+
# Use Active Record's schema dumper instead of SQL when creating the test database
|
|
40
|
+
# (enables use of different database adapters for development and test environments)
|
|
41
|
+
# config.active_record.schema_format = :ruby
|
|
42
|
+
|
|
43
|
+
# See Rails::Configuration for more options
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Add new inflection rules using the following format
|
|
47
|
+
# (all these examples are active by default):
|
|
48
|
+
# Inflector.inflections do |inflect|
|
|
49
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
|
50
|
+
# inflect.singular /^(ox)en/i, '\1'
|
|
51
|
+
# inflect.irregular 'person', 'people'
|
|
52
|
+
# inflect.uncountable %w( fish sheep )
|
|
53
|
+
# end
|
|
54
|
+
|
|
55
|
+
# Include your application configuration below
|
|
56
|
+
|
|
57
|
+
ActsAsFerret::remote = false if ENV['AAF_REMOTE'] != 'true'
|
|
58
|
+
ActsAsFerret::raise_drb_errors = ENV['RAISE_DRB_ERRORS'] == 'true'
|
|
59
|
+
|
|
60
|
+
# define the index shared by the SharedIndex1 and SharedIndex2 classes
|
|
61
|
+
ActsAsFerret::define_index 'shared', :remote => ENV['AAF_REMOTE'] == 'true',
|
|
62
|
+
:raise_drb_errors => ENV['RAISE_DRB_ERRORS'] == 'true',
|
|
63
|
+
:fields => {
|
|
64
|
+
:name => { :store => :yes }
|
|
65
|
+
},
|
|
66
|
+
:ferret => {
|
|
67
|
+
:default_field => [ :name ]
|
|
68
|
+
}
|
|
69
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
|
2
|
+
|
|
3
|
+
# In the development environment your application's code is reloaded on
|
|
4
|
+
# every request. This slows down response time but is perfect for development
|
|
5
|
+
# since you don't have to restart the webserver when you make code changes.
|
|
6
|
+
config.cache_classes = false
|
|
7
|
+
|
|
8
|
+
# Log error messages when you accidentally call methods on nil.
|
|
9
|
+
config.whiny_nils = true
|
|
10
|
+
|
|
11
|
+
# Show full error reports and disable caching
|
|
12
|
+
config.action_controller.consider_all_requests_local = true
|
|
13
|
+
config.action_controller.perform_caching = false
|
|
14
|
+
|
|
15
|
+
# Don't care if the mailer can't send
|
|
16
|
+
config.action_mailer.raise_delivery_errors = false
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
|
2
|
+
|
|
3
|
+
# The production environment is meant for finished, "live" apps.
|
|
4
|
+
# Code is not reloaded between requests
|
|
5
|
+
config.cache_classes = true
|
|
6
|
+
|
|
7
|
+
# Use a different logger for distributed setups
|
|
8
|
+
# config.logger = SyslogLogger.new
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# Full error reports are disabled and caching is turned on
|
|
12
|
+
config.action_controller.consider_all_requests_local = false
|
|
13
|
+
config.action_controller.perform_caching = true
|
|
14
|
+
|
|
15
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
|
16
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
|
17
|
+
|
|
18
|
+
# Disable delivery errors if you bad email addresses should just be ignored
|
|
19
|
+
# config.action_mailer.raise_delivery_errors = false
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
|
2
|
+
|
|
3
|
+
# The test environment is used exclusively to run your application's
|
|
4
|
+
# test suite. You never need to work with it otherwise. Remember that
|
|
5
|
+
# your test database is "scratch space" for the test suite and is wiped
|
|
6
|
+
# and recreated between test runs. Don't rely on the data there!
|
|
7
|
+
config.cache_classes = true
|
|
8
|
+
|
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
|
10
|
+
config.whiny_nils = true
|
|
11
|
+
|
|
12
|
+
# Show full error reports and disable caching
|
|
13
|
+
config.action_controller.consider_all_requests_local = true
|
|
14
|
+
config.action_controller.perform_caching = false
|
|
15
|
+
|
|
16
|
+
# Tell ActionMailer not to deliver emails to the real world.
|
|
17
|
+
# The :test delivery method accumulates sent emails in the
|
|
18
|
+
# ActionMailer::Base.deliveries array.
|
|
19
|
+
config.action_mailer.delivery_method = :test
|
|
20
|
+
|
|
21
|
+
#config.log_level = :info
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
production:
|
|
2
|
+
host: ferret.yourdomain.com
|
|
3
|
+
port: 9010
|
|
4
|
+
pid_file: log/ferret.pid
|
|
5
|
+
development:
|
|
6
|
+
host: localhost
|
|
7
|
+
port: 9010
|
|
8
|
+
pid_file: log/ferret.pid
|
|
9
|
+
log_file: log/ferret_server_dev.log
|
|
10
|
+
log_level: info
|
|
11
|
+
test:
|
|
12
|
+
socket: /tmp/ferret.sock
|
|
13
|
+
# host: localhost
|
|
14
|
+
# port: 9009
|
|
15
|
+
pid_file: log/ferret.pid
|
|
16
|
+
log_file: log/ferret_server_test.log
|
|
17
|
+
log_level: debug
|
|
18
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Default configuration file for the lighttpd web server
|
|
2
|
+
# Start using ./script/server lighttpd
|
|
3
|
+
|
|
4
|
+
server.port = 3001
|
|
5
|
+
|
|
6
|
+
server.modules = ( "mod_rewrite", "mod_accesslog", "mod_fastcgi" )
|
|
7
|
+
server.error-handler-404 = "/dispatch.fcgi"
|
|
8
|
+
server.document-root = CWD + "/public/"
|
|
9
|
+
|
|
10
|
+
server.errorlog = CWD + "/log/lighttpd.error.log"
|
|
11
|
+
accesslog.filename = CWD + "/log/lighttpd.access.log"
|
|
12
|
+
|
|
13
|
+
url.rewrite = ( "^/$" => "index.html", "^([^.]+)$" => "$1.html" )
|
|
14
|
+
|
|
15
|
+
# Change *-procs to 2 if you need to use Upload Progress or other tasks that
|
|
16
|
+
# *need* to execute a second request while the first is still pending.
|
|
17
|
+
fastcgi.server = ( ".fcgi" =>
|
|
18
|
+
( "localhost" =>
|
|
19
|
+
(
|
|
20
|
+
"min-procs" => 1,
|
|
21
|
+
"max-procs" => 1,
|
|
22
|
+
"socket" => CWD + "/tmp/sockets/fcgi.socket",
|
|
23
|
+
"bin-path" => CWD + "/public/dispatch.fcgi",
|
|
24
|
+
"bin-environment" => ( "RAILS_ENV" => "development" )
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
mimetype.assign = (
|
|
30
|
+
".css" => "text/css",
|
|
31
|
+
".gif" => "image/gif",
|
|
32
|
+
".htm" => "text/html",
|
|
33
|
+
".html" => "text/html",
|
|
34
|
+
".jpeg" => "image/jpeg",
|
|
35
|
+
".jpg" => "image/jpeg",
|
|
36
|
+
".js" => "text/javascript",
|
|
37
|
+
".png" => "image/png",
|
|
38
|
+
".swf" => "application/x-shockwave-flash",
|
|
39
|
+
".txt" => "text/plain"
|
|
40
|
+
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
CREATE TABLE `comments` (
|
|
2
|
+
`id` int(11) NOT NULL auto_increment,
|
|
3
|
+
`author` varchar(100) NOT NULL default '',
|
|
4
|
+
`content` text NOT NULL,
|
|
5
|
+
`content_id` int(11) default NULL,
|
|
6
|
+
PRIMARY KEY (`id`)
|
|
7
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
8
|
+
|
|
9
|
+
CREATE TABLE `contents` (
|
|
10
|
+
`id` int(11) NOT NULL auto_increment,
|
|
11
|
+
`title` varchar(100) NOT NULL default '',
|
|
12
|
+
`description` text NOT NULL,
|
|
13
|
+
PRIMARY KEY (`id`)
|
|
14
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
15
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class InitialMigration < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table "comments" do |t|
|
|
4
|
+
t.column "author", :string, :limit => 100
|
|
5
|
+
t.column "content", :text
|
|
6
|
+
t.column "content_id", :integer
|
|
7
|
+
end
|
|
8
|
+
create_table "contents" do |t|
|
|
9
|
+
t.column "title", :string, :limit => 100
|
|
10
|
+
t.column "description", :text
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.down
|
|
15
|
+
drop_table "comments"
|
|
16
|
+
drop_table "contents"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class CreateStats < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :stats do |t|
|
|
4
|
+
t.integer :process_id, :processing_time, :open_connections
|
|
5
|
+
t.string :kind, :info
|
|
6
|
+
t.datetime :created_at
|
|
7
|
+
end
|
|
8
|
+
add_index :stats, 'kind'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.down
|
|
12
|
+
# remove_index :stats, 'kind'
|
|
13
|
+
drop_table :stats
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
drop table if exists contents;
|
|
2
|
+
create table contents (
|
|
3
|
+
id int not null auto_increment,
|
|
4
|
+
type varchar(255) not null,
|
|
5
|
+
title varchar(100) not null,
|
|
6
|
+
description text not null,
|
|
7
|
+
special varchar(255) not null,
|
|
8
|
+
primary key (id)
|
|
9
|
+
) TYPE=InnoDB DEFAULT CHARSET=utf8;
|
|
10
|
+
|
|
11
|
+
drop table if exists comments;
|
|
12
|
+
create table comments (
|
|
13
|
+
id int not null auto_increment,
|
|
14
|
+
author varchar(100) not null,
|
|
15
|
+
content text not null,
|
|
16
|
+
content_id int,
|
|
17
|
+
primary key (id)
|
|
18
|
+
) TYPE=InnoDB DEFAULT CHARSET=utf8;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
This is a very minimalistic example of using ferret
|
|
2
|
+
to do full text searches in Rails model data. Tested with
|
|
3
|
+
Ruby 1.8.3, Rails 1.0 and Ferret 0.3.2.
|
|
4
|
+
|
|
5
|
+
You can install the latter with
|
|
6
|
+
gem install ferret
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
The steps it took me to create this small demo project were:
|
|
10
|
+
|
|
11
|
+
Rails project setup
|
|
12
|
+
===================
|
|
13
|
+
These steps are pretty common and have nothing to do with ferret.
|
|
14
|
+
|
|
15
|
+
Create rails project
|
|
16
|
+
rails ferret
|
|
17
|
+
cd ferret
|
|
18
|
+
|
|
19
|
+
Create databases (if you don't use unix and/or sudo, use 'mysql -u root -p')
|
|
20
|
+
sudo mysql
|
|
21
|
+
|
|
22
|
+
create database ferret_development;
|
|
23
|
+
create database ferret_test;
|
|
24
|
+
grant all on ferret_development.* to 'ferret'@'localhost' identified by 'ferret';
|
|
25
|
+
grant all on ferret_test.* to 'ferret'@'localhost' identified by 'ferret';
|
|
26
|
+
|
|
27
|
+
Create database schema
|
|
28
|
+
mysql -u ferret -pferret ferret_development < db/schema.sql
|
|
29
|
+
|
|
30
|
+
Edit config/database.yml (user names and passwords)
|
|
31
|
+
|
|
32
|
+
Create content controller and model
|
|
33
|
+
script/generate scaffold Content
|
|
34
|
+
|
|
35
|
+
Running rake at this point should yield no errors.
|
|
36
|
+
Otherwise check your database configuration.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
Ferret integration
|
|
40
|
+
==================
|
|
41
|
+
Put acs_as_ferret plugin into vendor/plugin
|
|
42
|
+
|
|
43
|
+
Add ferret to the content model class:
|
|
44
|
+
acts_as_ferret :fields => [ 'title', 'description' ]
|
|
45
|
+
|
|
46
|
+
Add unit tests for the find_by_contents method to content_test.rb.
|
|
47
|
+
|
|
48
|
+
running rake should succeed, and there should be an index in
|
|
49
|
+
RAILS_ROOT/index/test/Content.
|
|
50
|
+
|
|
51
|
+
Extend the ContentController with a search method and create the search view
|
|
52
|
+
Add unit tests for the search method to content_controller_test.rb
|
|
53
|
+
Run rake again to see the tests pass.
|
|
54
|
+
Remember that, as a good programmer, you would've written the tests first,
|
|
55
|
+
before implementing the feature ;-)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
Try it out
|
|
59
|
+
==========
|
|
60
|
+
Run the app with script/server and create some content objects. You should
|
|
61
|
+
see the index in RAILS_ROOT/index/development/Content.
|
|
62
|
+
|
|
63
|
+
Try searching at http://localhost:3000/content/search
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
Please contact me if you find any bugs/problems within this howto or
|
|
67
|
+
in the code.
|
|
68
|
+
|
|
69
|
+
Jens Kraemer <jk@jkraemer.net>
|
|
70
|
+
Feel free to use under the terms of the MIT license.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# General Apache options
|
|
2
|
+
AddHandler fastcgi-script .fcgi
|
|
3
|
+
AddHandler cgi-script .cgi
|
|
4
|
+
Options +FollowSymLinks +ExecCGI
|
|
5
|
+
|
|
6
|
+
# If you don't want Rails to look in certain directories,
|
|
7
|
+
# use the following rewrite rules so that Apache won't rewrite certain requests
|
|
8
|
+
#
|
|
9
|
+
# Example:
|
|
10
|
+
# RewriteCond %{REQUEST_URI} ^/notrails.*
|
|
11
|
+
# RewriteRule .* - [L]
|
|
12
|
+
|
|
13
|
+
# Redirect all requests not available on the filesystem to Rails
|
|
14
|
+
# By default the cgi dispatcher is used which is very slow
|
|
15
|
+
#
|
|
16
|
+
# For better performance replace the dispatcher with the fastcgi one
|
|
17
|
+
#
|
|
18
|
+
# Example:
|
|
19
|
+
# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
|
|
20
|
+
RewriteEngine On
|
|
21
|
+
|
|
22
|
+
# If your Rails application is accessed via an Alias directive,
|
|
23
|
+
# then you MUST also set the RewriteBase in this htaccess file.
|
|
24
|
+
#
|
|
25
|
+
# Example:
|
|
26
|
+
# Alias /myrailsapp /path/to/myrailsapp/public
|
|
27
|
+
# RewriteBase /myrailsapp
|
|
28
|
+
|
|
29
|
+
RewriteRule ^$ index.html [QSA]
|
|
30
|
+
RewriteRule ^([^.]+)$ $1.html [QSA]
|
|
31
|
+
RewriteCond %{REQUEST_FILENAME} !-f
|
|
32
|
+
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
|
|
33
|
+
|
|
34
|
+
# In case Rails experiences terminal errors
|
|
35
|
+
# Instead of displaying this message you can supply a file here which will be rendered instead
|
|
36
|
+
#
|
|
37
|
+
# Example:
|
|
38
|
+
# ErrorDocument 500 /500.html
|
|
39
|
+
|
|
40
|
+
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
|