pduey-sunspot_rails 1.2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +1 -0
  3. data/History.txt +54 -0
  4. data/LICENSE +18 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.rdoc +282 -0
  7. data/Rakefile +18 -0
  8. data/TESTING.md +35 -0
  9. data/TODO +8 -0
  10. data/VERSION.yml +4 -0
  11. data/dev_tasks/rdoc.rake +24 -0
  12. data/dev_tasks/release.rake +4 -0
  13. data/dev_tasks/spec.rake +27 -0
  14. data/dev_tasks/todo.rake +4 -0
  15. data/generators/sunspot/sunspot_generator.rb +9 -0
  16. data/generators/sunspot/templates/sunspot.yml +18 -0
  17. data/install.rb +1 -0
  18. data/lib/generators/sunspot_rails.rb +9 -0
  19. data/lib/generators/sunspot_rails/install/install_generator.rb +13 -0
  20. data/lib/generators/sunspot_rails/install/templates/config/sunspot.yml +17 -0
  21. data/lib/sunspot/rails.rb +63 -0
  22. data/lib/sunspot/rails/adapters.rb +83 -0
  23. data/lib/sunspot/rails/configuration.rb +323 -0
  24. data/lib/sunspot/rails/init.rb +5 -0
  25. data/lib/sunspot/rails/log_subscriber.rb +33 -0
  26. data/lib/sunspot/rails/railtie.rb +36 -0
  27. data/lib/sunspot/rails/railties/controller_runtime.rb +36 -0
  28. data/lib/sunspot/rails/request_lifecycle.rb +36 -0
  29. data/lib/sunspot/rails/searchable.rb +420 -0
  30. data/lib/sunspot/rails/server.rb +173 -0
  31. data/lib/sunspot/rails/solr_instrumentation.rb +20 -0
  32. data/lib/sunspot/rails/solr_logging.rb +62 -0
  33. data/lib/sunspot/rails/spec_helper.rb +26 -0
  34. data/lib/sunspot/rails/stub_session_proxy.rb +142 -0
  35. data/lib/sunspot/rails/tasks.rb +66 -0
  36. data/lib/sunspot_rails.rb +12 -0
  37. data/spec/configuration_spec.rb +173 -0
  38. data/spec/model_lifecycle_spec.rb +63 -0
  39. data/spec/model_spec.rb +478 -0
  40. data/spec/rails2/.gitignore +2 -0
  41. data/spec/rails2/Gemfile +15 -0
  42. data/spec/rails2/Rakefile +17 -0
  43. data/spec/rails2/app/controllers/application.rb +10 -0
  44. data/spec/rails2/app/controllers/application_controller.rb +10 -0
  45. data/spec/rails2/app/controllers/posts_controller.rb +6 -0
  46. data/spec/rails2/app/models/author.rb +8 -0
  47. data/spec/rails2/app/models/blog.rb +12 -0
  48. data/spec/rails2/app/models/location.rb +2 -0
  49. data/spec/rails2/app/models/photo_post.rb +2 -0
  50. data/spec/rails2/app/models/post.rb +11 -0
  51. data/spec/rails2/app/models/post_with_auto.rb +10 -0
  52. data/spec/rails2/app/models/post_with_conditional_index.rb +13 -0
  53. data/spec/rails2/app/models/post_with_default_scope.rb +11 -0
  54. data/spec/rails2/config/boot.rb +116 -0
  55. data/spec/rails2/config/database.yml +4 -0
  56. data/spec/rails2/config/environment.rb +41 -0
  57. data/spec/rails2/config/environments/development.rb +27 -0
  58. data/spec/rails2/config/environments/test.rb +27 -0
  59. data/spec/rails2/config/initializers/new_rails_defaults.rb +19 -0
  60. data/spec/rails2/config/initializers/session_store.rb +15 -0
  61. data/spec/rails2/config/preinitializer.rb +19 -0
  62. data/spec/rails2/config/routes.rb +43 -0
  63. data/spec/rails2/config/sunspot.yml +19 -0
  64. data/spec/rails2/db/schema.rb +27 -0
  65. data/spec/rails2/script/console +3 -0
  66. data/spec/rails3/.gitignore +4 -0
  67. data/spec/rails3/Gemfile +15 -0
  68. data/spec/rails3/README +281 -0
  69. data/spec/rails3/Rakefile +7 -0
  70. data/spec/rails3/app/controllers/application.rb +4 -0
  71. data/spec/rails3/app/controllers/application_controller.rb +4 -0
  72. data/spec/rails3/app/controllers/posts_controller.rb +6 -0
  73. data/spec/rails3/app/models/author.rb +8 -0
  74. data/spec/rails3/app/models/blog.rb +12 -0
  75. data/spec/rails3/app/models/location.rb +2 -0
  76. data/spec/rails3/app/models/photo_post.rb +2 -0
  77. data/spec/rails3/app/models/post.rb +11 -0
  78. data/spec/rails3/app/models/post_with_auto.rb +10 -0
  79. data/spec/rails3/app/models/post_with_conditional_index.rb +13 -0
  80. data/spec/rails3/app/models/post_with_default_scope.rb +11 -0
  81. data/spec/rails3/config.ru +4 -0
  82. data/spec/rails3/config/application.rb +46 -0
  83. data/spec/rails3/config/boot.rb +13 -0
  84. data/spec/rails3/config/database.yml +22 -0
  85. data/spec/rails3/config/environment.rb +5 -0
  86. data/spec/rails3/config/environments/development.rb +19 -0
  87. data/spec/rails3/config/environments/test.rb +19 -0
  88. data/spec/rails3/config/initializers/backtrace_silencers.rb +7 -0
  89. data/spec/rails3/config/initializers/inflections.rb +10 -0
  90. data/spec/rails3/config/initializers/mime_types.rb +5 -0
  91. data/spec/rails3/config/initializers/new_rails_defaults.rb +19 -0
  92. data/spec/rails3/config/initializers/secret_token.rb +7 -0
  93. data/spec/rails3/config/initializers/session_store.rb +8 -0
  94. data/spec/rails3/config/locales/en.yml +5 -0
  95. data/spec/rails3/config/routes.rb +59 -0
  96. data/spec/rails3/config/sunspot.yml +19 -0
  97. data/spec/rails3/db/schema.rb +27 -0
  98. data/spec/rails3/script/console +3 -0
  99. data/spec/rails3/script/rails +6 -0
  100. data/spec/rails3/solr/.gitignore +1 -0
  101. data/spec/rails3/solr/conf/elevate.xml +36 -0
  102. data/spec/rails3/solr/conf/schema.xml +238 -0
  103. data/spec/rails3/solr/conf/solrconfig.xml +938 -0
  104. data/spec/rails3/solr/conf/spellings.txt +2 -0
  105. data/spec/rails3/solr/conf/stopwords.txt +58 -0
  106. data/spec/rails3/solr/conf/synonyms.txt +31 -0
  107. data/spec/rails3/solr/lib/lucene-spatial-2.9.1.jar +0 -0
  108. data/spec/rails3/solr/lib/solr-spatial-light-0.0.6.jar +0 -0
  109. data/spec/request_lifecycle_spec.rb +61 -0
  110. data/spec/schema.rb +27 -0
  111. data/spec/server_spec.rb +37 -0
  112. data/spec/session_spec.rb +24 -0
  113. data/spec/spec_helper.rb +46 -0
  114. data/spec/stub_session_proxy_spec.rb +122 -0
  115. data/sunspot_rails.gemspec +44 -0
  116. metadata +322 -0
@@ -0,0 +1,19 @@
1
+ test:
2
+ solr:
3
+ hostname: localhost
4
+ port: 8980
5
+ development:
6
+ solr:
7
+ hostname: localhost
8
+ port: 8981
9
+ config_test:
10
+ solr:
11
+ hostname: some.host
12
+ port: 1234
13
+ path: /solr/idx
14
+ log_level: WARNING
15
+ data_path: /my_superior_path/data
16
+ pid_dir: /my_superior_path/pids
17
+ solr_home: /my_superior_path
18
+ auto_commit_after_request: false
19
+ auto_commit_after_delete_request: true
@@ -0,0 +1,27 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table :posts, :force => true do |t|
3
+ t.string :title
4
+ t.string :type
5
+ t.integer :location_id
6
+ t.text :body
7
+ t.references :blog
8
+ t.timestamps
9
+ end
10
+
11
+ create_table :locations, :force => true do |t|
12
+ t.float :lat
13
+ t.float :lng
14
+ end
15
+
16
+ create_table :blogs, :force => true do |t|
17
+ t.string :name
18
+ t.string :subdomain
19
+ t.timestamps
20
+ end
21
+
22
+ create_table :writers, :force => true, :primary_key => :writer_id do |t|
23
+ t.string :name
24
+ t.timestamps
25
+ end
26
+
27
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/console'
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/**/*
@@ -0,0 +1,15 @@
1
+ source :rubygems
2
+
3
+ gem 'rails', '~> 3.0.10'
4
+ gem 'sqlite3-ruby', '~> 1.3.1'
5
+
6
+ gem 'sunspot', :path => File.expand_path('../../../../sunspot', __FILE__)
7
+ gem 'sunspot_solr', :path => File.expand_path('../../../../sunspot_solr', __FILE__)
8
+ gem 'sunspot_rails', :path => File.expand_path('../../..', __FILE__)
9
+
10
+ group :test do
11
+ gem 'rspec-rails', '~> 2.0.0'
12
+ gem 'ruby-debug19', :require => nil, :platforms => :mri_19
13
+ gem 'test-unit', '1.2.3', :platforms => :mri_19
14
+ gem 'ruby-debug', :require => nil, :platforms => :mri_18
15
+ end
@@ -0,0 +1,281 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding the Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Web Servers
48
+
49
+ By default, Rails will try to use Mongrel if it's installed when started with
50
+ <tt>rails server</tt>, otherwise Rails will use WEBrick, the web server that
51
+ ships with Ruby.
52
+
53
+ Mongrel is a Ruby-based web server with a C component (which requires
54
+ compilation) that is suitable for development. If you have Ruby Gems installed,
55
+ getting up and running with mongrel is as easy as:
56
+ <tt>sudo gem install mongrel</tt>.
57
+
58
+ You can find more info at: http://mongrel.rubyforge.org
59
+
60
+ You can alternatively run Rails applications with other Ruby web servers, e.g.,
61
+ {Thin}[http://code.macournoyer.com/thin/], {Ebb}[http://ebb.rubyforge.org/], and
62
+ Apache with {mod_rails}[http://www.modrails.com/]. However, <tt>rails server</tt>
63
+ doesn't search for or start them.
64
+
65
+ For production use, often a web/proxy server, e.g., {Apache}[http://apache.org],
66
+ {Nginx}[http://nginx.net/], {LiteSpeed}[http://litespeedtech.com/],
67
+ {Lighttpd}[http://www.lighttpd.net/], or {IIS}[http://www.iis.net/], is deployed
68
+ as the front end server with the chosen Ruby web server running in the back end
69
+ and receiving the proxied requests via one of several protocols (HTTP, CGI, FCGI).
70
+
71
+
72
+ == Debugging Rails
73
+
74
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
75
+ will help you debug it and get it back on the rails.
76
+
77
+ First area to check is the application log files. Have "tail -f" commands
78
+ running on the server.log and development.log. Rails will automatically display
79
+ debugging and runtime information to these files. Debugging info will also be
80
+ shown in the browser on requests from 127.0.0.1.
81
+
82
+ You can also log your own messages directly into the log file from your code
83
+ using the Ruby logger class from inside your controllers. Example:
84
+
85
+ class WeblogController < ActionController::Base
86
+ def destroy
87
+ @weblog = Weblog.find(params[:id])
88
+ @weblog.destroy
89
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
90
+ end
91
+ end
92
+
93
+ The result will be a message in your log file along the lines of:
94
+
95
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
96
+
97
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
98
+
99
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
100
+ several books available online as well:
101
+
102
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
103
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
104
+
105
+ These two books will bring you up to speed on the Ruby language and also on
106
+ programming in general.
107
+
108
+
109
+ == Debugger
110
+
111
+ Debugger support is available through the debugger command when you start your
112
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
113
+ execution at any point in the code, investigate and change the model, and then,
114
+ resume execution! You need to install ruby-debug to run the server in debugging
115
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
116
+
117
+ class WeblogController < ActionController::Base
118
+ def index
119
+ @posts = Post.find(:all)
120
+ debugger
121
+ end
122
+ end
123
+
124
+ So the controller will accept the action, run the first line, then present you
125
+ with a IRB prompt in the server window. Here you can do things like:
126
+
127
+ >> @posts.inspect
128
+ => "[#<Post:0x14a6be8
129
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
130
+ #<Post:0x14a6620
131
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
132
+ >> @posts.first.title = "hello from a debugger"
133
+ => "hello from a debugger"
134
+
135
+ ...and even better, you can examine how your runtime objects actually work:
136
+
137
+ >> f = @posts.first
138
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
139
+ >> f.
140
+ Display all 152 possibilities? (y or n)
141
+
142
+ Finally, when you're ready to resume execution, you can enter "cont".
143
+
144
+
145
+ == Console
146
+
147
+ The console is a Ruby shell, which allows you to interact with your
148
+ application's domain model. Here you'll have all parts of the application
149
+ configured, just like it is when the application is running. You can inspect
150
+ domain models, change values, and save to the database. Starting the script
151
+ without arguments will launch it in the development environment.
152
+
153
+ To start the console, run <tt>rails console</tt> from the application
154
+ directory.
155
+
156
+ Options:
157
+
158
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
159
+ made to the database.
160
+ * Passing an environment name as an argument will load the corresponding
161
+ environment. Example: <tt>rails console production</tt>.
162
+
163
+ To reload your controllers and models after launching the console run
164
+ <tt>reload!</tt>
165
+
166
+ More information about irb can be found at:
167
+ link:http://www.rubycentral.com/pickaxe/irb.html
168
+
169
+
170
+ == dbconsole
171
+
172
+ You can go to the command line of your database directly through <tt>rails
173
+ dbconsole</tt>. You would be connected to the database with the credentials
174
+ defined in database.yml. Starting the script without arguments will connect you
175
+ to the development database. Passing an argument will connect you to a different
176
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
177
+ PostgreSQL and SQLite 3.
178
+
179
+ == Description of Contents
180
+
181
+ The default directory structure of a generated Ruby on Rails application:
182
+
183
+ |-- app
184
+ | |-- controllers
185
+ | |-- helpers
186
+ | |-- models
187
+ | `-- views
188
+ | `-- layouts
189
+ |-- config
190
+ | |-- environments
191
+ | |-- initializers
192
+ | `-- locales
193
+ |-- db
194
+ |-- doc
195
+ |-- lib
196
+ | `-- tasks
197
+ |-- log
198
+ |-- public
199
+ | |-- images
200
+ | |-- javascripts
201
+ | `-- stylesheets
202
+ |-- script
203
+ | `-- performance
204
+ |-- test
205
+ | |-- fixtures
206
+ | |-- functional
207
+ | |-- integration
208
+ | |-- performance
209
+ | `-- unit
210
+ |-- tmp
211
+ | |-- cache
212
+ | |-- pids
213
+ | |-- sessions
214
+ | `-- sockets
215
+ `-- vendor
216
+ `-- plugins
217
+
218
+ app
219
+ Holds all the code that's specific to this particular application.
220
+
221
+ app/controllers
222
+ Holds controllers that should be named like weblogs_controller.rb for
223
+ automated URL mapping. All controllers should descend from
224
+ ApplicationController which itself descends from ActionController::Base.
225
+
226
+ app/models
227
+ Holds models that should be named like post.rb. Models descend from
228
+ ActiveRecord::Base by default.
229
+
230
+ app/views
231
+ Holds the template files for the view that should be named like
232
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
233
+ eRuby syntax by default.
234
+
235
+ app/views/layouts
236
+ Holds the template files for layouts to be used with views. This models the
237
+ common header/footer method of wrapping views. In your views, define a layout
238
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
239
+ Inside default.html.erb, call <% yield %> to render the view using this
240
+ layout.
241
+
242
+ app/helpers
243
+ Holds view helpers that should be named like weblogs_helper.rb. These are
244
+ generated for you automatically when using generators for controllers.
245
+ Helpers can be used to wrap functionality for your views into methods.
246
+
247
+ config
248
+ Configuration files for the Rails environment, the routing map, the database,
249
+ and other dependencies.
250
+
251
+ db
252
+ Contains the database schema in schema.rb. db/migrate contains all the
253
+ sequence of Migrations for your schema.
254
+
255
+ doc
256
+ This directory is where your application documentation will be stored when
257
+ generated using <tt>rake doc:app</tt>
258
+
259
+ lib
260
+ Application specific libraries. Basically, any kind of custom code that
261
+ doesn't belong under controllers, models, or helpers. This directory is in
262
+ the load path.
263
+
264
+ public
265
+ The directory available for the web server. Contains subdirectories for
266
+ images, stylesheets, and javascripts. Also contains the dispatchers and the
267
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
268
+ server.
269
+
270
+ script
271
+ Helper scripts for automation and generation.
272
+
273
+ test
274
+ Unit and functional tests along with fixtures. When using the rails generate
275
+ command, template test files will be generated for you and placed in this
276
+ directory.
277
+
278
+ vendor
279
+ External libraries that the application depends on. Also includes the plugins
280
+ subdirectory. If the app has frozen rails, those gems also go here, under
281
+ vendor/rails/. This directory is in the load path.
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ Rails::Application.load_tasks
@@ -0,0 +1,4 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ layout 'application'
4
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ layout 'application'
4
+ end
@@ -0,0 +1,6 @@
1
+ class PostsController < ApplicationController
2
+ def create
3
+ PostWithAuto.create(params[:post])
4
+ render :nothing => true
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ class Author < ActiveRecord::Base
2
+ set_table_name :writers
3
+ set_primary_key :writer_id
4
+
5
+ searchable do
6
+ string :name
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ class Blog < ActiveRecord::Base
2
+ has_many :posts
3
+ has_many :comments, :through => :posts
4
+
5
+ searchable :include => { :posts => :author } do
6
+ string :subdomain
7
+ text :name
8
+ end
9
+
10
+ # Make sure that includes are added to with multiple searchable calls
11
+ searchable(:include => :comments) {}
12
+ end
@@ -0,0 +1,2 @@
1
+ class Location < ActiveRecord::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class PhotoPost < PostWithAuto
2
+ end
@@ -0,0 +1,11 @@
1
+ class Post < ActiveRecord::Base
2
+ belongs_to :location
3
+ belongs_to :author
4
+ has_many :comments
5
+
6
+ searchable :auto_index => false, :auto_remove => false do
7
+ string :title
8
+ text :body, :more_like_this => true
9
+ location :location
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ class PostWithAuto < ActiveRecord::Base
2
+ def self.table_name
3
+ 'posts'
4
+ end
5
+
6
+ searchable :ignore_attribute_changes_of => [ :updated_at ] do
7
+ string :title
8
+ text :body, :more_like_this => true
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ class PostWithConditionalIndex < ActiveRecord::Base
2
+ def self.table_name
3
+ 'posts'
4
+ end
5
+
6
+ searchable :auto_index => false, :auto_remove => false, :if => :title_is_present do
7
+ string :title
8
+ end
9
+
10
+ def title_is_present
11
+ title.present?
12
+ end
13
+ end