benjaminkrause-sunspot 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/History.txt +107 -0
  2. data/LICENSE +18 -0
  3. data/README.rdoc +159 -0
  4. data/Rakefile +9 -0
  5. data/TODO +11 -0
  6. data/VERSION.yml +4 -0
  7. data/bin/sunspot-configure-solr +46 -0
  8. data/bin/sunspot-solr +86 -0
  9. data/lib/light_config.rb +40 -0
  10. data/lib/sunspot/adapters.rb +265 -0
  11. data/lib/sunspot/composite_setup.rb +184 -0
  12. data/lib/sunspot/configuration.rb +49 -0
  13. data/lib/sunspot/data_extractor.rb +50 -0
  14. data/lib/sunspot/dsl/field_query.rb +77 -0
  15. data/lib/sunspot/dsl/fields.rb +95 -0
  16. data/lib/sunspot/dsl/fulltext.rb +106 -0
  17. data/lib/sunspot/dsl/query.rb +107 -0
  18. data/lib/sunspot/dsl/query_facet.rb +31 -0
  19. data/lib/sunspot/dsl/restriction.rb +25 -0
  20. data/lib/sunspot/dsl/scope.rb +193 -0
  21. data/lib/sunspot/dsl/search.rb +30 -0
  22. data/lib/sunspot/dsl.rb +4 -0
  23. data/lib/sunspot/facet.rb +24 -0
  24. data/lib/sunspot/facet_data.rb +152 -0
  25. data/lib/sunspot/facet_row.rb +12 -0
  26. data/lib/sunspot/field.rb +148 -0
  27. data/lib/sunspot/field_factory.rb +141 -0
  28. data/lib/sunspot/indexer.rb +129 -0
  29. data/lib/sunspot/instantiated_facet.rb +45 -0
  30. data/lib/sunspot/instantiated_facet_row.rb +27 -0
  31. data/lib/sunspot/query/base_query.rb +55 -0
  32. data/lib/sunspot/query/boost_query.rb +20 -0
  33. data/lib/sunspot/query/connective.rb +148 -0
  34. data/lib/sunspot/query/dynamic_query.rb +61 -0
  35. data/lib/sunspot/query/field_facet.rb +129 -0
  36. data/lib/sunspot/query/field_query.rb +69 -0
  37. data/lib/sunspot/query/fulltext_base_query.rb +86 -0
  38. data/lib/sunspot/query/highlighting.rb +36 -0
  39. data/lib/sunspot/query/local.rb +24 -0
  40. data/lib/sunspot/query/pagination.rb +39 -0
  41. data/lib/sunspot/query/query_facet.rb +78 -0
  42. data/lib/sunspot/query/query_facet_row.rb +19 -0
  43. data/lib/sunspot/query/query_field_facet.rb +20 -0
  44. data/lib/sunspot/query/restriction.rb +272 -0
  45. data/lib/sunspot/query/scope.rb +185 -0
  46. data/lib/sunspot/query/sort.rb +105 -0
  47. data/lib/sunspot/query/sort_composite.rb +33 -0
  48. data/lib/sunspot/query/text_field_boost.rb +15 -0
  49. data/lib/sunspot/query.rb +108 -0
  50. data/lib/sunspot/schema.rb +147 -0
  51. data/lib/sunspot/search/highlight.rb +38 -0
  52. data/lib/sunspot/search/hit.rb +113 -0
  53. data/lib/sunspot/search.rb +240 -0
  54. data/lib/sunspot/session.rb +206 -0
  55. data/lib/sunspot/setup.rb +312 -0
  56. data/lib/sunspot/text_field_setup.rb +29 -0
  57. data/lib/sunspot/type.rb +200 -0
  58. data/lib/sunspot/util.rb +190 -0
  59. data/lib/sunspot.rb +459 -0
  60. data/solr/etc/jetty.xml +212 -0
  61. data/solr/etc/webdefault.xml +379 -0
  62. data/solr/lib/jetty-6.1.3.jar +0 -0
  63. data/solr/lib/jetty-util-6.1.3.jar +0 -0
  64. data/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
  65. data/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
  66. data/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
  67. data/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
  68. data/solr/lib/servlet-api-2.5-6.1.3.jar +0 -0
  69. data/solr/solr/conf/elevate.xml +36 -0
  70. data/solr/solr/conf/protwords.txt +21 -0
  71. data/solr/solr/conf/schema.xml +64 -0
  72. data/solr/solr/conf/solrconfig.xml +726 -0
  73. data/solr/solr/conf/stopwords.txt +57 -0
  74. data/solr/solr/conf/synonyms.txt +31 -0
  75. data/solr/start.jar +0 -0
  76. data/solr/webapps/solr.war +0 -0
  77. data/spec/api/adapters_spec.rb +33 -0
  78. data/spec/api/indexer/attributes_spec.rb +100 -0
  79. data/spec/api/indexer/batch_spec.rb +46 -0
  80. data/spec/api/indexer/dynamic_fields_spec.rb +33 -0
  81. data/spec/api/indexer/fixed_fields_spec.rb +57 -0
  82. data/spec/api/indexer/fulltext_spec.rb +43 -0
  83. data/spec/api/indexer/removal_spec.rb +46 -0
  84. data/spec/api/indexer/spec_helper.rb +1 -0
  85. data/spec/api/indexer_spec.rb +4 -0
  86. data/spec/api/query/connectives_spec.rb +161 -0
  87. data/spec/api/query/dsl_spec.rb +12 -0
  88. data/spec/api/query/dynamic_fields_spec.rb +148 -0
  89. data/spec/api/query/faceting_spec.rb +272 -0
  90. data/spec/api/query/fulltext_spec.rb +152 -0
  91. data/spec/api/query/highlighting_spec.rb +82 -0
  92. data/spec/api/query/local_spec.rb +37 -0
  93. data/spec/api/query/ordering_pagination_spec.rb +95 -0
  94. data/spec/api/query/scope_spec.rb +253 -0
  95. data/spec/api/query/spec_helper.rb +1 -0
  96. data/spec/api/query/text_field_scoping_spec.rb +30 -0
  97. data/spec/api/query/types_spec.rb +20 -0
  98. data/spec/api/search/dynamic_fields_spec.rb +27 -0
  99. data/spec/api/search/faceting_spec.rb +206 -0
  100. data/spec/api/search/highlighting_spec.rb +65 -0
  101. data/spec/api/search/hits_spec.rb +62 -0
  102. data/spec/api/search/results_spec.rb +52 -0
  103. data/spec/api/search/search_spec.rb +11 -0
  104. data/spec/api/search/spec_helper.rb +1 -0
  105. data/spec/api/session_spec.rb +157 -0
  106. data/spec/api/spec_helper.rb +1 -0
  107. data/spec/api/sunspot_spec.rb +18 -0
  108. data/spec/helpers/indexer_helper.rb +29 -0
  109. data/spec/helpers/query_helper.rb +13 -0
  110. data/spec/helpers/search_helper.rb +78 -0
  111. data/spec/integration/dynamic_fields_spec.rb +55 -0
  112. data/spec/integration/faceting_spec.rb +169 -0
  113. data/spec/integration/highlighting_spec.rb +22 -0
  114. data/spec/integration/keyword_search_spec.rb +148 -0
  115. data/spec/integration/local_search_spec.rb +47 -0
  116. data/spec/integration/scoped_search_spec.rb +303 -0
  117. data/spec/integration/spec_helper.rb +1 -0
  118. data/spec/integration/stored_fields_spec.rb +10 -0
  119. data/spec/integration/test_pagination.rb +32 -0
  120. data/spec/mocks/adapters.rb +32 -0
  121. data/spec/mocks/blog.rb +3 -0
  122. data/spec/mocks/comment.rb +19 -0
  123. data/spec/mocks/connection.rb +84 -0
  124. data/spec/mocks/mock_adapter.rb +30 -0
  125. data/spec/mocks/mock_record.rb +48 -0
  126. data/spec/mocks/photo.rb +8 -0
  127. data/spec/mocks/post.rb +75 -0
  128. data/spec/mocks/super_class.rb +2 -0
  129. data/spec/mocks/user.rb +8 -0
  130. data/spec/spec_helper.rb +60 -0
  131. data/tasks/gemspec.rake +35 -0
  132. data/tasks/rcov.rake +28 -0
  133. data/tasks/rdoc.rake +22 -0
  134. data/tasks/schema.rake +19 -0
  135. data/tasks/spec.rake +24 -0
  136. data/tasks/todo.rake +4 -0
  137. data/templates/schema.xml.erb +36 -0
  138. metadata +312 -0
data/lib/sunspot.rb ADDED
@@ -0,0 +1,459 @@
1
+ begin
2
+ require 'time'
3
+ require 'date'
4
+ require 'rsolr'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'rsolr'
8
+ end
9
+
10
+ require File.join(File.dirname(__FILE__), 'light_config')
11
+
12
+ %w(util adapters configuration setup composite_setup text_field_setup field
13
+ field_factory data_extractor indexer query search facet facet_row
14
+ instantiated_facet instantiated_facet_row facet_data session type
15
+ dsl).each do |filename|
16
+ require File.join(File.dirname(__FILE__), 'sunspot', filename)
17
+ end
18
+
19
+ #
20
+ # The Sunspot module provides class-method entry points to most of the
21
+ # functionality provided by the Sunspot library. Internally, the Sunspot
22
+ # singleton class contains a (non-thread-safe!) instance of Sunspot::Session,
23
+ # to which it delegates most of the class methods it exposes. In the method
24
+ # documentation below, this instance is referred to as the "singleton session".
25
+ #
26
+ # Though the singleton session provides a convenient entry point to Sunspot,
27
+ # it is by no means required to use the Sunspot class methods. Multiple sessions
28
+ # may be instantiated and used (if you need to connect to multiple Solr
29
+ # instances, for example.)
30
+ #
31
+ # Note that the configuration of classes for index/search (the +setup+
32
+ # method) is _not_ session-specific, but rather global.
33
+ #
34
+ module Sunspot
35
+ UnrecognizedFieldError = Class.new(Exception)
36
+ UnrecognizedRestrictionError = Class.new(Exception)
37
+ NoAdapterError = Class.new(Exception)
38
+ NoSetupError = Class.new(Exception)
39
+
40
+ class <<self
41
+ # Configures indexing and search for a given class.
42
+ #
43
+ # ==== Parameters
44
+ #
45
+ # clazz<Class>:: class to configure
46
+ #
47
+ # ==== Example
48
+ #
49
+ # Sunspot.setup(Post) do
50
+ # text :title, :body
51
+ # string :author_name
52
+ # integer :blog_id
53
+ # integer :category_ids
54
+ # float :average_rating, :using => :ratings_average
55
+ # time :published_at
56
+ # string :sort_title do
57
+ # title.downcase.sub(/^(an?|the)\W+/, ''/) if title = self.title
58
+ # end
59
+ # end
60
+ #
61
+ # ====== Attribute Fields vs. Virtual Fields
62
+ #
63
+ # Attribute fields call a method on the indexed object and index the
64
+ # return value. All of the fields defined above except for the last one are
65
+ # attribute fields. By default, the field name will also be the attribute
66
+ # used; this can be overriden with the +:using+ option, as in
67
+ # +:average_rating+ above. In that case, the attribute +:ratings_average+
68
+ # will be indexed with the field name +:average_rating+.
69
+ #
70
+ # +:sort_title+ is a virtual field, which evaluates the block inside the
71
+ # context of the instance being indexed, and indexes the value returned
72
+ # by the block. If the block you pass takes an argument, it will be passed
73
+ # the instance rather than being evaluated inside of it; so, the following
74
+ # example is equivalent to the one above (assuming #title is public):
75
+ #
76
+ # Sunspot.setup(Post) do
77
+ # string :sort_title do |post|
78
+ # post.title.downcase.sub(/^(an?|the)\W+/, ''/) if title = self.title
79
+ # end
80
+ # end
81
+ #
82
+ # ===== Field Types
83
+ #
84
+ # The available types are:
85
+ #
86
+ # * +text+
87
+ # * +string+
88
+ # * +integer+
89
+ # * +float+
90
+ # * +time+
91
+ # * +boolean+
92
+ #
93
+ # Note that the +text+ type behaves quite differently from the others -
94
+ # this is the type that is indexed as fulltext, and is searched using the
95
+ # +keywords+ method inside the search DSL. Text fields cannot have
96
+ # restrictions set on them, nor can they be used in order statements or
97
+ # for facets. All other types are indexed literally, and thus can be used
98
+ # for all of those operations. They will not, however, be searched in
99
+ # fulltext. In this way, Sunspot provides a complete barrier between
100
+ # fulltext fields and value fields.
101
+ #
102
+ # It is fine to specify a field both as a text field and a string field;
103
+ # internally, the fields will have different names so there is no danger
104
+ # of conflict.
105
+ #
106
+ # ===== Dynamic Fields
107
+ #
108
+ # For use cases which have highly dynamic data models (for instance, an
109
+ # open set of key-value pairs attached to a model), it may be useful to
110
+ # defer definition of fields until indexing time. Sunspot exposes dynamic
111
+ # fields, which define a data accessor (either attribute or virtual, see
112
+ # above), which accepts a hash of field names to values. Note that the field
113
+ # names in the hash are internally scoped to the base name of the dynamic
114
+ # field, so any time they are referred to, they are referred to using both
115
+ # the base name and the dynamic (runtime-specified) name.
116
+ #
117
+ # Dynamic fields are speficied in the setup block using the type name
118
+ # prefixed by +dynamic_+. For example:
119
+ #
120
+ # Sunspot.setup(Post) do
121
+ # dynamic_string :custom_values do
122
+ # key_value_pairs.inject({}) do |hash, key_value_pair|
123
+ # hash[key_value_pair.key.to_sym] = key_value_pair.value
124
+ # end
125
+ # end
126
+ # end
127
+ #
128
+ # If you later wanted to facet all of the values for the key "cuisine",
129
+ # you could issue:
130
+ #
131
+ # Sunspot.search(Post) do
132
+ # dynamic :custom_values do
133
+ # facet :cuisine
134
+ # end
135
+ # end
136
+ #
137
+ # In the documentation, +:custom_values+ is referred to as the "base name" -
138
+ # that is, the one specified statically - and +:cuisine+ is referred to as
139
+ # the dynamic name, which is the part that is specified at indexing time.
140
+ #
141
+ def setup(clazz, &block)
142
+ Setup.setup(clazz, &block)
143
+ end
144
+
145
+ # Indexes objects on the singleton session.
146
+ #
147
+ # ==== Parameters
148
+ #
149
+ # objects...<Object>:: objects to index (may pass an array or varargs)
150
+ #
151
+ # ==== Example
152
+ #
153
+ # post1, post2 = Array(2) { Post.create }
154
+ # Sunspot.index(post1, post2)
155
+ #
156
+ # Note that indexed objects won't be reflected in search until a commit is
157
+ # sent - see Sunspot.index! and Sunspot.commit
158
+ #
159
+ def index(*objects)
160
+ session.index(*objects)
161
+ end
162
+
163
+ # Indexes objects on the singleton session and commits immediately.
164
+ #
165
+ # See: Sunspot.index and Sunspot.commit
166
+ #
167
+ # ==== Parameters
168
+ #
169
+ # objects...<Object>:: objects to index (may pass an array or varargs)
170
+ #
171
+ def index!(*objects)
172
+ session.index!(*objects)
173
+ end
174
+
175
+ # Commits the singleton session
176
+ #
177
+ # When documents are added to or removed from Solr, the changes are
178
+ # initially stored in memory, and are not reflected in Solr's existing
179
+ # searcher instance. When a commit message is sent, the changes are written
180
+ # to disk, and a new searcher is spawned. Commits are thus fairly
181
+ # expensive, so if your application needs to index several documents as part
182
+ # of a single operation, it is advisable to index them all and then call
183
+ # commit at the end of the operation.
184
+ #
185
+ # Note that Solr can also be configured to automatically perform a commit
186
+ # after either a specified interval after the last change, or after a
187
+ # specified number of documents are added. See
188
+ # http://wiki.apache.org/solr/SolrConfigXml
189
+ #
190
+ def commit
191
+ session.commit
192
+ end
193
+
194
+ #
195
+ # Create a new Search instance, but do not execute it immediately. Generally
196
+ # you will want to use the #search method to execute searches using the
197
+ # DSL; however, if you are building searches dynamically (using the Builder
198
+ # pattern, for instance), it may be easier to access the Query API directly.
199
+ #
200
+ # ==== Parameters
201
+ #
202
+ # types<Class>...::
203
+ # Zero, one, or more types to search for. If no types are passed, all
204
+ # configured types will be searched for.
205
+ #
206
+ # ==== Returns
207
+ #
208
+ # Sunspot::Search::
209
+ # Search object, not yet executed. Query parameters can be added manually;
210
+ # then #execute! should be called.
211
+ #
212
+ def new_search(*types)
213
+ session.new_search(*types)
214
+ end
215
+
216
+
217
+ # Search for objects in the index.
218
+ #
219
+ # ==== Parameters
220
+ #
221
+ # types<Class>...::
222
+ # Zero, one, or more types to search for. If no types are passed, all
223
+ # configured types will be searched.
224
+ #
225
+ # ==== Returns
226
+ #
227
+ # Sunspot::Search:: Object containing results, facets, count, etc.
228
+ #
229
+ # The fields available for restriction, ordering, etc. are those that meet
230
+ # the following criteria:
231
+ #
232
+ # * They are not of type +text+.
233
+ # * They are defined for at least one of the classes being searched
234
+ # * They have the same data type for all of the classes being searched.
235
+ # * They have the same multiple flag for all of the classes being searched.
236
+ # * They have the same stored flag for all of the classes being searched.
237
+ #
238
+ # The restrictions available are the constants defined in the
239
+ # Sunspot::Restriction class. The standard restrictions are:
240
+ #
241
+ # with(:field_name).equal_to(value)
242
+ # with(:field_name, value) # shorthand for above
243
+ # with(:field_name).less_than(value)
244
+ # with(:field_name).greater_than(value)
245
+ # with(:field_name).between(value1..value2)
246
+ # with(:field_name).any_of([value1, value2, value3])
247
+ # with(:field_name).all_of([value1, value2, value3])
248
+ # without(some_instance) # exclude that particular instance
249
+ #
250
+ # +without+ can be substituted for +with+, causing the restriction to be
251
+ # negated. In the last example above, only +without+ works, as it does not
252
+ # make sense to search only for an instance you already have.
253
+ #
254
+ # Equality restrictions can take +nil+ as a value, which restricts the
255
+ # results to documents that have no value for the given field. Passing +nil+
256
+ # as a value to other restriction types is illegal. Thus:
257
+ #
258
+ # with(:field_name, nil) # ok
259
+ # with(:field_name).equal_to(nil) # ok
260
+ # with(:field_name).less_than(nil) # bad
261
+ #
262
+ # ==== Example
263
+ #
264
+ # Sunspot.search(Post) do
265
+ # keywords 'great pizza'
266
+ # with(:published_at).less_than Time.now
267
+ # with :blog_id, 1
268
+ # without current_post
269
+ # facet :category_ids
270
+ # order_by :published_at, :desc
271
+ # paginate 2, 15
272
+ # end
273
+ #
274
+ # If the block passed to #search takes an argument, that argument will
275
+ # present the DSL, and the block will be evaluated in the calling context.
276
+ # This will come in handy for building searches using instance data or
277
+ # methods, e.g.:
278
+ #
279
+ # Sunspot.search(Post) do |query|
280
+ # query.with(:blog_id, @current_blog.id)
281
+ # end
282
+ #
283
+ # See Sunspot::DSL::Search, Sunspot::DSL::Scope, Sunspot::DSL::FieldQuery
284
+ # and Sunspot::DSL::Query for the full API presented inside the block.
285
+ #
286
+ def search(*types, &block)
287
+ session.search(*types, &block)
288
+ end
289
+
290
+ # Remove objects from the index. Any time an object is destroyed, it must
291
+ # be removed from the index; otherwise, the index will contain broken
292
+ # references to objects that do not exist, which will cause errors when
293
+ # those objects are matched in search results.
294
+ #
295
+ # ==== Parameters
296
+ #
297
+ # objects...<Object>::
298
+ # Objects to remove from the index (may pass an array or varargs)
299
+ #
300
+ # ==== Example
301
+ #
302
+ # post.destroy
303
+ # Sunspot.remove(post)
304
+ #
305
+ def remove(*objects)
306
+ session.remove(*objects)
307
+ end
308
+
309
+ #
310
+ # Remove objects from the index and immediately commit. See Sunspot.remove
311
+ #
312
+ # ==== Parameters
313
+ #
314
+ # objects...<Object>:: Objects to remove from the index
315
+ #
316
+ def remove!
317
+ session.remove!(*objects)
318
+ end
319
+
320
+ #
321
+ # Remove an object from the index using its class name and primary key.
322
+ # Useful if you know this information and want to remove an object without
323
+ # instantiating it from persistent storage
324
+ #
325
+ # ==== Parameters
326
+ #
327
+ # clazz<Class>:: Class of the object, or class name as a string or symbol
328
+ # id::
329
+ # Primary key of the object. This should be the same id that would be
330
+ # returned by the class's instance adapter.
331
+ #
332
+ def remove_by_id(clazz, id)
333
+ session.remove_by_id(clazz, id)
334
+ end
335
+
336
+ #
337
+ # Remove an object by class name and primary key, and immediately commit.
338
+ # See #remove_by_id and #commit
339
+ #
340
+ def remove_by_id!(clazz, id)
341
+ session.remove_by_id!(clazz, id)
342
+ end
343
+
344
+ # Remove all objects of the given classes from the index. There isn't much
345
+ # use for this in general operations but it can be useful for maintenance,
346
+ # testing, etc. If no arguments are passed, remove everything from the
347
+ # index.
348
+ #
349
+ # ==== Parameters
350
+ #
351
+ # classes...<Class>::
352
+ # classes for which to remove all instances from the index (may pass an
353
+ # array or varargs)
354
+ #
355
+ # ==== Example
356
+ #
357
+ # Sunspot.remove_all(Post, Blog)
358
+ #
359
+ def remove_all(*classes)
360
+ session.remove_all(*classes)
361
+ end
362
+
363
+ #
364
+ # Remove all objects of the given classes from the index and immediately
365
+ # commit. See Sunspot.remove_all
366
+ #
367
+ # ==== Parameters
368
+ #
369
+ # classes...<Class>::
370
+ # classes for which to remove all instances from the index
371
+ def remove_all!(*classes)
372
+ session.remove_all!(*classes)
373
+ end
374
+
375
+ #
376
+ # Process all adds in a batch. Any Sunspot adds initiated inside the block
377
+ # will be sent in bulk when the block finishes. Useful if your application
378
+ # initiates index adds from various places in code as part of a single
379
+ # operation; doing a batch add will give better performance.
380
+ #
381
+ # ==== Example
382
+ #
383
+ # Sunspot.batch do
384
+ # post = Post.new
385
+ # Sunspot.add(post)
386
+ # comment = Comment.new
387
+ # Sunspot.add(comment)
388
+ # end
389
+ #
390
+ # Sunspot will send both the post and the comment in a single request.
391
+ #
392
+ def batch(&block)
393
+ session.batch(&block)
394
+ end
395
+
396
+ #
397
+ # True if documents have been added, updated, or removed since the last
398
+ # commit.
399
+ #
400
+ # ==== Returns
401
+ #
402
+ # Boolean:: Whether there have been any updates since the last commit
403
+ #
404
+ def dirty?
405
+ session.dirty?
406
+ end
407
+
408
+ #
409
+ # Sends a commit if the session is dirty (see #dirty?).
410
+ #
411
+ def commit_if_dirty
412
+ session.commit_if_dirty
413
+ end
414
+
415
+ # Returns the configuration associated with the singleton session. See
416
+ # Sunspot::Configuration for details.
417
+ #
418
+ # ==== Returns
419
+ #
420
+ # LightConfig::Configuration:: configuration for singleton session
421
+ #
422
+ def config
423
+ session.config
424
+ end
425
+
426
+ #
427
+ # Resets the singleton session. This is useful for clearing out all
428
+ # static data between tests, but probably nowhere else.
429
+ #
430
+ # ==== Parameters
431
+ #
432
+ # keep_config<Boolean>::
433
+ # Whether to retain the configuration used by the current singleton
434
+ # session. Default false.
435
+ #
436
+ def reset!(keep_config = false)
437
+ config =
438
+ if keep_config
439
+ session.config
440
+ else
441
+ Configuration.build
442
+ end
443
+ @session = Session.new(config)
444
+ end
445
+
446
+ private
447
+
448
+ #
449
+ # Get the singleton session, creating it if none yet exists.
450
+ #
451
+ # ==== Returns
452
+ #
453
+ # Sunspot::Session:: the singleton session
454
+ #
455
+ def session #:nodoc:
456
+ @session ||= Session.new
457
+ end
458
+ end
459
+ end
@@ -0,0 +1,212 @@
1
+ <?xml version="1.0"?>
2
+ <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
3
+
4
+ <!-- =============================================================== -->
5
+ <!-- Configure the Jetty Server -->
6
+ <!-- -->
7
+ <!-- Documentation of this file format can be found at: -->
8
+ <!-- http://docs.codehaus.org/display/JETTY/jetty.xml -->
9
+ <!-- -->
10
+ <!-- =============================================================== -->
11
+
12
+
13
+ <Configure id="Server" class="org.mortbay.jetty.Server">
14
+
15
+ <!-- Increase the maximum POST size to 1 MB to be able to handle large shard requests -->
16
+ <Call class="java.lang.System" name="setProperty">
17
+ <Arg>org.mortbay.jetty.Request.maxFormContentSize</Arg>
18
+ <Arg>1000000</Arg>
19
+ </Call>
20
+
21
+ <!-- =========================================================== -->
22
+ <!-- Server Thread Pool -->
23
+ <!-- =========================================================== -->
24
+ <Set name="ThreadPool">
25
+ <!-- Default bounded blocking threadpool
26
+ -->
27
+ <New class="org.mortbay.thread.BoundedThreadPool">
28
+ <Set name="minThreads">10</Set>
29
+ <Set name="lowThreads">50</Set>
30
+ <Set name="maxThreads">10000</Set>
31
+ </New>
32
+
33
+ <!-- Optional Java 5 bounded threadpool with job queue
34
+ <New class="org.mortbay.thread.concurrent.ThreadPool">
35
+ <Arg type="int">0</Arg>
36
+ <Set name="corePoolSize">10</Set>
37
+ <Set name="maximumPoolSize">250</Set>
38
+ </New>
39
+ -->
40
+ </Set>
41
+
42
+
43
+
44
+ <!-- =========================================================== -->
45
+ <!-- Set connectors -->
46
+ <!-- =========================================================== -->
47
+ <!-- One of each type! -->
48
+ <!-- =========================================================== -->
49
+
50
+ <!-- Use this connector for many frequently idle connections
51
+ and for threadless continuations.
52
+ <Call name="addConnector">
53
+ <Arg>
54
+ <New class="org.mortbay.jetty.nio.SelectChannelConnector">
55
+ <Set name="port"><SystemProperty name="jetty.port" default="8983"/></Set>
56
+ <Set name="maxIdleTime">30000</Set>
57
+ <Set name="Acceptors">2</Set>
58
+ <Set name="confidentialPort">8443</Set>
59
+ </New>
60
+ </Arg>
61
+ </Call>
62
+ -->
63
+
64
+ <!-- Use this connector if NIO is not available. -->
65
+ <!-- This connector is currently being used for Solr because the
66
+ nio.SelectChannelConnector showed poor performance under WindowsXP
67
+ from a single client with non-persistent connections (35s vs ~3min)
68
+ to complete 10,000 requests)
69
+ -->
70
+ <Call name="addConnector">
71
+ <Arg>
72
+ <New class="org.mortbay.jetty.bio.SocketConnector">
73
+ <Set name="port"><SystemProperty name="jetty.port" default="8983"/></Set>
74
+ <Set name="maxIdleTime">50000</Set>
75
+ <Set name="lowResourceMaxIdleTime">1500</Set>
76
+ </New>
77
+ </Arg>
78
+ </Call>
79
+
80
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
81
+ <!-- To add a HTTPS SSL listener -->
82
+ <!-- see jetty-ssl.xml to add an ssl connector. use -->
83
+ <!-- java -jar start.jar etc/jetty.xml etc/jetty-ssl.xml -->
84
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
85
+
86
+ <!-- =========================================================== -->
87
+ <!-- Set up global session ID manager -->
88
+ <!-- =========================================================== -->
89
+ <!--
90
+ <Set name="sessionIdManager">
91
+ <New class="org.mortbay.jetty.servlet.HashSessionIdManager">
92
+ <Set name="workerName">node1</Set>
93
+ </New>
94
+ </Set>
95
+ -->
96
+
97
+ <!-- =========================================================== -->
98
+ <!-- Set handler Collection Structure -->
99
+ <!-- =========================================================== -->
100
+ <Set name="handler">
101
+ <New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection">
102
+ <Set name="handlers">
103
+ <Array type="org.mortbay.jetty.Handler">
104
+ <Item>
105
+ <New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection"/>
106
+ </Item>
107
+ <Item>
108
+ <New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler"/>
109
+ </Item>
110
+ <Item>
111
+ <New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler"/>
112
+ </Item>
113
+ </Array>
114
+ </Set>
115
+ </New>
116
+ </Set>
117
+
118
+ <!-- =========================================================== -->
119
+ <!-- Configure the context deployer -->
120
+ <!-- A context deployer will deploy contexts described in -->
121
+ <!-- configuration files discovered in a directory. -->
122
+ <!-- The configuration directory can be scanned for hot -->
123
+ <!-- deployments at the configured scanInterval. -->
124
+ <!-- -->
125
+ <!-- This deployer is configured to deploy contexts configured -->
126
+ <!-- in the $JETTY_HOME/contexts directory -->
127
+ <!-- -->
128
+ <!-- =========================================================== -->
129
+ <Call name="addLifeCycle">
130
+ <Arg>
131
+ <New class="org.mortbay.jetty.deployer.ContextDeployer">
132
+ <Set name="contexts"><Ref id="Contexts"/></Set>
133
+ <Set name="configurationDir"><SystemProperty name="jetty.home" default="."/>/contexts</Set>
134
+ <Set name="scanInterval">1</Set>
135
+ </New>
136
+ </Arg>
137
+ </Call>
138
+
139
+ <!-- =========================================================== -->
140
+ <!-- Configure the webapp deployer. -->
141
+ <!-- A webapp deployer will deploy standard webapps discovered -->
142
+ <!-- in a directory at startup, without the need for additional -->
143
+ <!-- configuration files. It does not support hot deploy or -->
144
+ <!-- non standard contexts (see ContextDeployer above). -->
145
+ <!-- -->
146
+ <!-- This deployer is configured to deploy webapps from the -->
147
+ <!-- $JETTY_HOME/webapps directory -->
148
+ <!-- -->
149
+ <!-- Normally only one type of deployer need be used. -->
150
+ <!-- -->
151
+ <!-- =========================================================== -->
152
+ <Call name="addLifeCycle">
153
+ <Arg>
154
+ <New class="org.mortbay.jetty.deployer.WebAppDeployer">
155
+ <Set name="contexts"><Ref id="Contexts"/></Set>
156
+ <Set name="webAppDir"><SystemProperty name="jetty.home" default="."/>/webapps</Set>
157
+ <Set name="parentLoaderPriority">false</Set>
158
+ <Set name="extract">true</Set>
159
+ <Set name="allowDuplicates">false</Set>
160
+ <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
161
+ </New>
162
+ </Arg>
163
+ </Call>
164
+
165
+ <!-- =========================================================== -->
166
+ <!-- Configure Authentication Realms -->
167
+ <!-- Realms may be configured for the entire server here, or -->
168
+ <!-- they can be configured for a specific web app in a context -->
169
+ <!-- configuration (see $(jetty.home)/contexts/test.xml for an -->
170
+ <!-- example). -->
171
+ <!-- =========================================================== -->
172
+ <Set name="UserRealms">
173
+ <Array type="org.mortbay.jetty.security.UserRealm">
174
+ <!--
175
+ <Item>
176
+ <New class="org.mortbay.jetty.security.HashUserRealm">
177
+ <Set name="name">Test Realm</Set>
178
+ <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
179
+ </New>
180
+ </Item>
181
+ -->
182
+ </Array>
183
+ </Set>
184
+
185
+ <!-- =========================================================== -->
186
+ <!-- Configure Request Log -->
187
+ <!-- Request logs may be configured for the entire server here, -->
188
+ <!-- or they can be configured for a specific web app in a -->
189
+ <!-- contexts configuration (see $(jetty.home)/contexts/test.xml -->
190
+ <!-- for an example). -->
191
+ <!-- =========================================================== -->
192
+ <Ref id="RequestLog">
193
+ <Set name="requestLog">
194
+ <!-- New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog">
195
+ <Arg><SystemProperty name="jetty.logs" default="./logs"/>/yyyy_mm_dd.request.log</Arg>
196
+ <Set name="retainDays">90</Set>
197
+ <Set name="append">true</Set>
198
+ <Set name="extended">false</Set>
199
+ <Set name="LogTimeZone">GMT</Set>
200
+ </New -->
201
+ </Set>
202
+ </Ref>
203
+
204
+ <!-- =========================================================== -->
205
+ <!-- extra options -->
206
+ <!-- =========================================================== -->
207
+ <Set name="stopAtShutdown">true</Set>
208
+ <!-- ensure/prevent Server: header being sent to browsers -->
209
+ <Set name="sendServerVersion">true</Set>
210
+
211
+ </Configure>
212
+