nxa-sunspot 0.10.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/History.txt +153 -0
  2. data/LICENSE +18 -0
  3. data/README.rdoc +191 -0
  4. data/Rakefile +9 -0
  5. data/TODO +14 -0
  6. data/VERSION.yml +4 -0
  7. data/bin/sunspot-configure-solr +40 -0
  8. data/bin/sunspot-solr +95 -0
  9. data/lib/light_config.rb +40 -0
  10. data/lib/sunspot.rb +488 -0
  11. data/lib/sunspot/adapters.rb +265 -0
  12. data/lib/sunspot/composite_setup.rb +188 -0
  13. data/lib/sunspot/configuration.rb +56 -0
  14. data/lib/sunspot/data_extractor.rb +50 -0
  15. data/lib/sunspot/dsl.rb +4 -0
  16. data/lib/sunspot/dsl/field_query.rb +150 -0
  17. data/lib/sunspot/dsl/fields.rb +100 -0
  18. data/lib/sunspot/dsl/fulltext.rb +228 -0
  19. data/lib/sunspot/dsl/query.rb +162 -0
  20. data/lib/sunspot/dsl/query_facet.rb +36 -0
  21. data/lib/sunspot/dsl/restriction.rb +25 -0
  22. data/lib/sunspot/dsl/scope.rb +225 -0
  23. data/lib/sunspot/dsl/search.rb +30 -0
  24. data/lib/sunspot/field.rb +181 -0
  25. data/lib/sunspot/field_factory.rb +144 -0
  26. data/lib/sunspot/indexer.rb +133 -0
  27. data/lib/sunspot/query.rb +9 -0
  28. data/lib/sunspot/query/abstract_field_facet.rb +43 -0
  29. data/lib/sunspot/query/boost_query.rb +20 -0
  30. data/lib/sunspot/query/connective.rb +189 -0
  31. data/lib/sunspot/query/date_field_facet.rb +14 -0
  32. data/lib/sunspot/query/dismax.rb +88 -0
  33. data/lib/sunspot/query/field_facet.rb +9 -0
  34. data/lib/sunspot/query/highlighting.rb +55 -0
  35. data/lib/sunspot/query/local.rb +27 -0
  36. data/lib/sunspot/query/pagination.rb +38 -0
  37. data/lib/sunspot/query/query.rb +86 -0
  38. data/lib/sunspot/query/query_facet.rb +16 -0
  39. data/lib/sunspot/query/restriction.rb +254 -0
  40. data/lib/sunspot/query/scope.rb +9 -0
  41. data/lib/sunspot/query/sort.rb +105 -0
  42. data/lib/sunspot/query/sort_composite.rb +33 -0
  43. data/lib/sunspot/query/text_field_boost.rb +15 -0
  44. data/lib/sunspot/schema.rb +147 -0
  45. data/lib/sunspot/search.rb +216 -0
  46. data/lib/sunspot/search/date_facet.rb +35 -0
  47. data/lib/sunspot/search/facet_row.rb +27 -0
  48. data/lib/sunspot/search/field_facet.rb +44 -0
  49. data/lib/sunspot/search/highlight.rb +38 -0
  50. data/lib/sunspot/search/hit.rb +117 -0
  51. data/lib/sunspot/search/query_facet.rb +62 -0
  52. data/lib/sunspot/session.rb +236 -0
  53. data/lib/sunspot/setup.rb +323 -0
  54. data/lib/sunspot/text_field_setup.rb +29 -0
  55. data/lib/sunspot/type.rb +204 -0
  56. data/lib/sunspot/util.rb +210 -0
  57. data/solr/etc/jetty.xml +212 -0
  58. data/solr/etc/webdefault.xml +379 -0
  59. data/solr/lib/jetty-6.1.3.jar +0 -0
  60. data/solr/lib/jetty-util-6.1.3.jar +0 -0
  61. data/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
  62. data/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
  63. data/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
  64. data/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
  65. data/solr/lib/servlet-api-2.5-6.1.3.jar +0 -0
  66. data/solr/solr/conf/elevate.xml +36 -0
  67. data/solr/solr/conf/protwords.txt +21 -0
  68. data/solr/solr/conf/schema.xml +64 -0
  69. data/solr/solr/conf/solrconfig.xml +725 -0
  70. data/solr/solr/conf/stopwords.txt +57 -0
  71. data/solr/solr/conf/synonyms.txt +31 -0
  72. data/solr/solr/lib/geoapi-nogenerics-2.1-M2.jar +0 -0
  73. data/solr/solr/lib/gt2-referencing-2.3.1.jar +0 -0
  74. data/solr/solr/lib/jsr108-0.01.jar +0 -0
  75. data/solr/solr/lib/locallucene.jar +0 -0
  76. data/solr/solr/lib/localsolr.jar +0 -0
  77. data/solr/start.jar +0 -0
  78. data/solr/webapps/solr.war +0 -0
  79. data/spec/api/adapters_spec.rb +33 -0
  80. data/spec/api/indexer/attributes_spec.rb +110 -0
  81. data/spec/api/indexer/batch_spec.rb +46 -0
  82. data/spec/api/indexer/dynamic_fields_spec.rb +33 -0
  83. data/spec/api/indexer/fixed_fields_spec.rb +57 -0
  84. data/spec/api/indexer/fulltext_spec.rb +43 -0
  85. data/spec/api/indexer/removal_spec.rb +46 -0
  86. data/spec/api/indexer/spec_helper.rb +1 -0
  87. data/spec/api/indexer_spec.rb +4 -0
  88. data/spec/api/query/adjust_params_spec.rb +37 -0
  89. data/spec/api/query/connectives_spec.rb +176 -0
  90. data/spec/api/query/dsl_spec.rb +12 -0
  91. data/spec/api/query/dynamic_fields_spec.rb +149 -0
  92. data/spec/api/query/faceting_spec.rb +296 -0
  93. data/spec/api/query/fulltext_spec.rb +281 -0
  94. data/spec/api/query/highlighting_spec.rb +225 -0
  95. data/spec/api/query/local_spec.rb +62 -0
  96. data/spec/api/query/ordering_pagination_spec.rb +95 -0
  97. data/spec/api/query/scope_spec.rb +266 -0
  98. data/spec/api/query/spec_helper.rb +1 -0
  99. data/spec/api/query/text_field_scoping_spec.rb +30 -0
  100. data/spec/api/query/types_spec.rb +20 -0
  101. data/spec/api/search/dynamic_fields_spec.rb +27 -0
  102. data/spec/api/search/faceting_spec.rb +242 -0
  103. data/spec/api/search/highlighting_spec.rb +65 -0
  104. data/spec/api/search/hits_spec.rb +67 -0
  105. data/spec/api/search/results_spec.rb +52 -0
  106. data/spec/api/search/search_spec.rb +23 -0
  107. data/spec/api/search/spec_helper.rb +1 -0
  108. data/spec/api/session_spec.rb +198 -0
  109. data/spec/api/spec_helper.rb +1 -0
  110. data/spec/api/sunspot_spec.rb +18 -0
  111. data/spec/helpers/indexer_helper.rb +29 -0
  112. data/spec/helpers/query_helper.rb +13 -0
  113. data/spec/helpers/search_helper.rb +78 -0
  114. data/spec/integration/dynamic_fields_spec.rb +55 -0
  115. data/spec/integration/faceting_spec.rb +188 -0
  116. data/spec/integration/highlighting_spec.rb +22 -0
  117. data/spec/integration/indexing_spec.rb +7 -0
  118. data/spec/integration/keyword_search_spec.rb +245 -0
  119. data/spec/integration/local_search_spec.rb +56 -0
  120. data/spec/integration/scoped_search_spec.rb +303 -0
  121. data/spec/integration/spec_helper.rb +7 -0
  122. data/spec/integration/stored_fields_spec.rb +10 -0
  123. data/spec/integration/test_pagination.rb +32 -0
  124. data/spec/mocks/adapters.rb +32 -0
  125. data/spec/mocks/blog.rb +3 -0
  126. data/spec/mocks/comment.rb +19 -0
  127. data/spec/mocks/connection.rb +106 -0
  128. data/spec/mocks/mock_adapter.rb +30 -0
  129. data/spec/mocks/mock_record.rb +48 -0
  130. data/spec/mocks/photo.rb +11 -0
  131. data/spec/mocks/post.rb +75 -0
  132. data/spec/mocks/super_class.rb +2 -0
  133. data/spec/mocks/user.rb +8 -0
  134. data/spec/spec_helper.rb +68 -0
  135. data/tasks/gemspec.rake +42 -0
  136. data/tasks/rcov.rake +28 -0
  137. data/tasks/rdoc.rake +22 -0
  138. data/tasks/schema.rake +19 -0
  139. data/tasks/spec.rake +24 -0
  140. data/tasks/todo.rake +4 -0
  141. data/templates/schema.xml.erb +36 -0
  142. metadata +319 -0
@@ -0,0 +1,323 @@
1
+ module Sunspot
2
+ #
3
+ # This class encapsulates the search/indexing setup for a given class. Its
4
+ # contents are built using the Sunspot.setup method.
5
+ #
6
+ class Setup #:nodoc:
7
+ def initialize(clazz)
8
+ @clazz = clazz
9
+ @class_name = clazz.name
10
+ @field_factories, @text_field_factories, @dynamic_field_factories,
11
+ @field_factories_cache, @text_field_factories_cache,
12
+ @dynamic_field_factories_cache = *Array.new(6) { Hash.new }
13
+ @stored_field_factories_cache = Hash.new { |h, k| h[k] = [] }
14
+ @dsl = DSL::Fields.new(self)
15
+ add_field_factory(:class, Type::ClassType)
16
+ end
17
+
18
+ def type_names
19
+ [@class_name]
20
+ end
21
+
22
+ #
23
+ # Add field factory for scope/ordering
24
+ #
25
+ def add_field_factory(name, type, options = {}, &block)
26
+ stored = options[:stored]
27
+ field_factory = FieldFactory::Static.new(name, type, options, &block)
28
+ @field_factories[field_factory.signature] = field_factory
29
+ @field_factories_cache[field_factory.name] = field_factory
30
+ if stored
31
+ @stored_field_factories_cache[field_factory.name] << field_factory
32
+ end
33
+ end
34
+
35
+ #
36
+ # Add field_factories for fulltext search
37
+ #
38
+ # ==== Parameters
39
+ #
40
+ # field_factories<Array>:: Array of Sunspot::Field objects
41
+ #
42
+ def add_text_field_factory(name, options = {}, &block)
43
+ stored = options[:stored]
44
+ field_factory = FieldFactory::Static.new(name, Type::TextType, options, &block)
45
+ @text_field_factories[name] = field_factory
46
+ @text_field_factories_cache[field_factory.name] = field_factory
47
+ if stored
48
+ @stored_field_factories_cache[field_factory.name] << field_factory
49
+ end
50
+ end
51
+
52
+ #
53
+ # Add dynamic field_factories
54
+ #
55
+ # ==== Parameters
56
+ #
57
+ # field_factories<Array>:: Array of dynamic field objects
58
+ #
59
+ def add_dynamic_field_factory(name, type, options = {}, &block)
60
+ field_factory = FieldFactory::Dynamic.new(name, type, options, &block)
61
+ @dynamic_field_factories[field_factory.signature] = field_factory
62
+ @dynamic_field_factories_cache[field_factory.name] = field_factory
63
+ end
64
+
65
+ #
66
+ # The coordinates field factory is used for populating the coordinate fields
67
+ # of documents during index, but does not actually generate fields (since
68
+ # the field names used in search are static).
69
+ #
70
+ def set_coordinates_field(name = nil, &block)
71
+ @coordinates_field_factory = FieldFactory::Coordinates.new(name, &block)
72
+ end
73
+
74
+ #
75
+ # Add a document boost to documents at index time. Document boost can be
76
+ # static (the same for all documents of this class), or extracted on a per-
77
+ # document basis using either attribute or block extraction as per usual.
78
+ #
79
+ def add_document_boost(attr_name, &block)
80
+ @document_boost_extractor =
81
+ if attr_name
82
+ if attr_name.respond_to?(:to_f)
83
+ DataExtractor::Constant.new(attr_name)
84
+ else
85
+ DataExtractor::AttributeExtractor.new(attr_name)
86
+ end
87
+ else
88
+ DataExtractor::BlockExtractor.new(&block)
89
+ end
90
+ end
91
+
92
+ #
93
+ # Builder method for evaluating the setup DSL
94
+ #
95
+ def setup(&block)
96
+ @dsl.instance_eval(&block)
97
+ end
98
+
99
+ #
100
+ # Return the Field with the given (public-facing) name
101
+ #
102
+ def field(field_name)
103
+ if field_factory = @field_factories_cache[field_name.to_sym]
104
+ field_factory.build
105
+ else
106
+ raise(
107
+ UnrecognizedFieldError,
108
+ "No field configured for #{@clazz.name} with name '#{field_name}'"
109
+ )
110
+ end
111
+ end
112
+
113
+ #
114
+ # Return one or more text fields with the given public-facing name. This
115
+ # implementation will always return a single field (in an array), but
116
+ # CompositeSetup objects might return more than one.
117
+ #
118
+ def text_fields(field_name)
119
+ text_field =
120
+ if field_factory = @text_field_factories_cache[field_name.to_sym]
121
+ field_factory.build
122
+ else
123
+ raise(
124
+ UnrecognizedFieldError,
125
+ "No text field configured for #{@clazz.name} with name '#{field_name}'"
126
+ )
127
+ end
128
+ [text_field]
129
+ end
130
+
131
+ #
132
+ # Return one or more stored fields (can be either attribute or text fields)
133
+ # for the given name.
134
+ #
135
+ def stored_fields(field_name)
136
+ @stored_field_factories_cache[field_name.to_sym].map do |field_factory|
137
+ field_factory.build
138
+ end
139
+ end
140
+
141
+ #
142
+ # Return the DynamicFieldFactory with the given base name
143
+ #
144
+ def dynamic_field_factory(field_name)
145
+ @dynamic_field_factories_cache[field_name.to_sym] || raise(
146
+ UnrecognizedFieldError,
147
+ "No dynamic field configured for #{@clazz.name} with name '#{field_name}'"
148
+ )
149
+ end
150
+
151
+ #
152
+ # Return all attribute fields
153
+ #
154
+ def fields
155
+ field_factories.map { |field_factory| field_factory.build }
156
+ end
157
+
158
+ #
159
+ # Return all text fields
160
+ #
161
+ def all_text_fields
162
+ text_field_factories.map { |text_field_factory| text_field_factory.build }
163
+ end
164
+
165
+ #
166
+ # Get the field_factories associated with this setup as well as all inherited field_factories
167
+ #
168
+ # ==== Returns
169
+ #
170
+ # Array:: Collection of all field_factories associated with this setup
171
+ #
172
+ def field_factories
173
+ collection_from_inheritable_hash(:field_factories)
174
+ end
175
+
176
+ #
177
+ # Get the text field_factories associated with this setup as well as all inherited
178
+ # text field_factories
179
+ #
180
+ # ==== Returns
181
+ #
182
+ # Array:: Collection of all text field_factories associated with this setup
183
+ #
184
+ def text_field_factories
185
+ collection_from_inheritable_hash(:text_field_factories)
186
+ end
187
+
188
+ #
189
+ # Get all static, dynamic, and text field_factories associated with this setup as
190
+ # well as all inherited field_factories
191
+ #
192
+ # ==== Returns
193
+ #
194
+ # Array:: Collection of all text and scope field_factories associated with this setup
195
+ #
196
+ def all_field_factories
197
+ all_field_factories = []
198
+ all_field_factories.concat(field_factories).concat(text_field_factories).concat(dynamic_field_factories)
199
+ all_field_factories << @coordinates_field_factory if @coordinates_field_factory
200
+ all_field_factories
201
+ end
202
+
203
+ #
204
+ # Get all dynamic field_factories for this and parent setups
205
+ #
206
+ # ==== Returns
207
+ #
208
+ # Array:: Dynamic field_factories
209
+ #
210
+ def dynamic_field_factories
211
+ collection_from_inheritable_hash(:dynamic_field_factories)
212
+ end
213
+
214
+ #
215
+ # Return the class associated with this setup.
216
+ #
217
+ # ==== Returns
218
+ #
219
+ # clazz<Class>:: Class setup is configured for
220
+ #
221
+ def clazz
222
+ Util.full_const_get(@class_name)
223
+ end
224
+
225
+ #
226
+ # Get the document boost for a given model
227
+ #
228
+ def document_boost_for(model)
229
+ if @document_boost_extractor
230
+ @document_boost_extractor.value_for(model)
231
+ end
232
+ end
233
+
234
+ protected
235
+
236
+ #
237
+ # Get the nearest inherited setup, if any
238
+ #
239
+ # ==== Returns
240
+ #
241
+ # Sunspot::Setup:: Setup for the nearest ancestor of this setup's class
242
+ #
243
+ def parent
244
+ Setup.for(clazz.superclass)
245
+ end
246
+
247
+ def get_inheritable_hash(name)
248
+ hash = instance_variable_get(:"@#{name}")
249
+ parent.get_inheritable_hash(name).each_pair do |key, value|
250
+ hash[key] = value unless hash.has_key?(key)
251
+ end if parent
252
+ hash
253
+ end
254
+
255
+ private
256
+
257
+ def collection_from_inheritable_hash(name)
258
+ get_inheritable_hash(name).values
259
+ end
260
+
261
+ class <<self
262
+ #
263
+ # Retrieve or create the Setup instance for the given class, evaluating
264
+ # the given block to add to the setup's configuration
265
+ #
266
+ def setup(clazz, &block) #:nodoc:
267
+ self.for!(clazz).setup(&block)
268
+ end
269
+
270
+ #
271
+ # Retrieve the setup instance for the given class, or for the nearest
272
+ # ancestor that has a setup, if any.
273
+ #
274
+ # ==== Parameters
275
+ #
276
+ # clazz<Class>:: Class for which to retrieve a setup
277
+ #
278
+ # ==== Returns
279
+ #
280
+ # Sunspot::Setup::
281
+ # Setup instance associated with the given class or its nearest ancestor
282
+ #
283
+ def for(clazz) #:nodoc:
284
+ class_name =
285
+ if clazz.respond_to?(:name)
286
+ clazz.name
287
+ else
288
+ clazz
289
+ end
290
+ setups[class_name.to_sym] || self.for(clazz.superclass) if clazz
291
+ end
292
+
293
+ protected
294
+
295
+ #
296
+ # Retrieve or create a Setup instance for this class
297
+ #
298
+ # ==== Parameters
299
+ #
300
+ # clazz<Class>:: Class for which to retrieve a setup
301
+ #
302
+ # ==== Returns
303
+ #
304
+ # Sunspot::Setup:: New or existing setup for this class
305
+ #
306
+ def for!(clazz) #:nodoc:
307
+ setups[clazz.name.to_sym] ||= new(clazz)
308
+ end
309
+
310
+ private
311
+
312
+ # Singleton hash of class names to Setup instances
313
+ #
314
+ # ==== Returns
315
+ #
316
+ # Hash:: Class names keyed to Setup instances
317
+ #
318
+ def setups
319
+ @setups ||= {}
320
+ end
321
+ end
322
+ end
323
+ end
@@ -0,0 +1,29 @@
1
+ module Sunspot
2
+ #
3
+ # A TextFieldSetup encapsulates a regular (or composite) setup, and exposes
4
+ # the #field() method returning text fields instead of attribute fields.
5
+ #
6
+ class TextFieldSetup #:nodoc:
7
+ def initialize(setup)
8
+ @setup = setup
9
+ end
10
+
11
+ #
12
+ # Return a text field with the given name. Duck-type compatible with
13
+ # Setup and CompositeSetup, but return text fields instead.
14
+ #
15
+ def field(name)
16
+ fields = @setup.text_fields(name)
17
+ if fields
18
+ if fields.length == 1
19
+ fields.first
20
+ else
21
+ raise(
22
+ Sunspot::UnrecognizedFieldError,
23
+ "The text field with name #{name} has incompatible configurations for the classes #{@setup.type_names.join(', ')}"
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,204 @@
1
+ module Sunspot
2
+ #
3
+ # This module contains singleton objects that represent the types that can be
4
+ # indexed and searched using Sunspot. Plugin developers should be able to
5
+ # add new constants to the Type module; as long as they implement the
6
+ # appropriate methods, Sunspot should be able to integrate them (note that
7
+ # this capability is untested at the moment). The required methods are:
8
+ #
9
+ # +indexed_name+::
10
+ # Convert a given field name into its form as stored in Solr. This
11
+ # generally means adding a suffix to match a Solr dynamicField definition.
12
+ # +to_indexed+::
13
+ # Convert a value of this type into the appropriate Solr string
14
+ # representation.
15
+ # +cast+::
16
+ # Convert a Solr string representation of a value into the appropriate
17
+ # Ruby type.
18
+ #
19
+ module Type
20
+ #
21
+ # Text is a special type that stores data for fulltext search. Unlike other
22
+ # types, Text fields are tokenized and are made available to the keyword
23
+ # search phrase. Text fields cannot be faceted, ordered upon, or used in
24
+ # restrictions. Similarly, text fields are the only fields that are made
25
+ # available to keyword search.
26
+ #
27
+ module TextType
28
+ class <<self
29
+ def indexed_name(name) #:nodoc:
30
+ "#{name}_text"
31
+ end
32
+
33
+ def to_indexed(value) #:nodoc:
34
+ value.to_s if value
35
+ end
36
+
37
+ def cast(text)
38
+ text
39
+ end
40
+ end
41
+ end
42
+
43
+ #
44
+ # The String type represents string data.
45
+ #
46
+ module StringType
47
+ class <<self
48
+ def indexed_name(name) #:nodoc:
49
+ "#{name}_s"
50
+ end
51
+
52
+ def to_indexed(value) #:nodoc:
53
+ value.to_s if value
54
+ end
55
+
56
+ def cast(string) #:nodoc:
57
+ string
58
+ end
59
+ end
60
+ end
61
+
62
+ #
63
+ # The Integer type represents integers.
64
+ #
65
+ module IntegerType
66
+ class <<self
67
+ def indexed_name(name) #:nodoc:
68
+ "#{name}_i"
69
+ end
70
+
71
+ def to_indexed(value) #:nodoc:
72
+ value.to_i.to_s if value
73
+ end
74
+
75
+ def cast(string) #:nodoc:
76
+ string.to_i
77
+ end
78
+ end
79
+ end
80
+
81
+ #
82
+ # The Float type represents floating-point numbers.
83
+ #
84
+ module FloatType
85
+ class <<self
86
+ def indexed_name(name) #:nodoc:
87
+ "#{name}_f"
88
+ end
89
+
90
+ def to_indexed(value) #:nodoc:
91
+ value.to_f.to_s if value
92
+ end
93
+
94
+ def cast(string) #:nodoc:
95
+ string.to_f
96
+ end
97
+ end
98
+ end
99
+
100
+ #
101
+ # The time type represents times. Note that times are always converted to
102
+ # UTC before indexing, and facets of Time fields always return times in UTC.
103
+ #
104
+ module TimeType
105
+
106
+ class <<self
107
+ def indexed_name(name) #:nodoc:
108
+ "#{name}_d"
109
+ end
110
+
111
+ def to_indexed(value) #:nodoc:
112
+ if value
113
+ time =
114
+ if value.respond_to?(:utc)
115
+ value
116
+ else
117
+ Time.parse(value.to_s)
118
+ end
119
+ time.utc.xmlschema
120
+ end
121
+ end
122
+
123
+ def cast(string) #:nodoc:
124
+ Time.xmlschema(string)
125
+ end
126
+ end
127
+ end
128
+
129
+ #
130
+ # The DateType encapsulates dates (without time information). Internally,
131
+ # Solr does not have a date-only type, so this type indexes data using
132
+ # Solr's DateField type (which is actually date/time), midnight UTC of the
133
+ # indexed date.
134
+ #
135
+ module DateType
136
+ class <<self
137
+ def indexed_name(name) #:nodoc:
138
+ "#{name}_d"
139
+ end
140
+
141
+ def to_indexed(value) #:nodoc:
142
+ if value
143
+ time =
144
+ if %w(year mon mday).all? { |method| value.respond_to?(method) }
145
+ Time.utc(value.year, value.mon, value.mday)
146
+ else
147
+ date = Date.parse(value.to_s)
148
+ Time.utc(date.year, date.mon, date.mday)
149
+ end
150
+ time.utc.xmlschema
151
+ end
152
+ end
153
+
154
+ def cast(string) #:nodoc:
155
+ time = Time.xmlschema(string)
156
+ Date.civil(time.year, time.mon, time.mday)
157
+ end
158
+ end
159
+ end
160
+
161
+ #
162
+ # The boolean type represents true/false values. Note that +nil+ will not be
163
+ # indexed at all; only +false+ will be indexed with a false value.
164
+ #
165
+ module BooleanType
166
+ class <<self
167
+ def indexed_name(name) #:nodoc:
168
+ "#{name}_b"
169
+ end
170
+
171
+ def to_indexed(value) #:nodoc:
172
+ unless value.nil?
173
+ value ? 'true' : 'false'
174
+ end
175
+ end
176
+
177
+ def cast(string) #:nodoc:
178
+ case string
179
+ when 'true'
180
+ true
181
+ when 'false'
182
+ false
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ module ClassType
189
+ class <<self
190
+ def indexed_name(name) #:nodoc:
191
+ 'class_name'
192
+ end
193
+
194
+ def to_indexed(value) #:nodoc:
195
+ value.name
196
+ end
197
+
198
+ def cast(string) #:nodoc:
199
+ Sunspot::Util.full_const_get(string)
200
+ end
201
+ end
202
+ end
203
+ end
204
+ end