ruben-sunspot 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/Gemfile +9 -0
  2. data/Gemfile.lock +22 -0
  3. data/History.txt +198 -0
  4. data/LICENSE +18 -0
  5. data/README.rdoc +244 -0
  6. data/Rakefile +11 -0
  7. data/TODO +13 -0
  8. data/VERSION.yml +4 -0
  9. data/bin/sunspot-installer +19 -0
  10. data/bin/sunspot-solr +74 -0
  11. data/installer/config/schema.yml +95 -0
  12. data/lib/light_config.rb +40 -0
  13. data/lib/sunspot.rb +529 -0
  14. data/lib/sunspot/adapters.rb +265 -0
  15. data/lib/sunspot/composite_setup.rb +202 -0
  16. data/lib/sunspot/configuration.rb +46 -0
  17. data/lib/sunspot/data_extractor.rb +50 -0
  18. data/lib/sunspot/dsl.rb +5 -0
  19. data/lib/sunspot/dsl/adjustable.rb +47 -0
  20. data/lib/sunspot/dsl/field_query.rb +266 -0
  21. data/lib/sunspot/dsl/fields.rb +113 -0
  22. data/lib/sunspot/dsl/fulltext.rb +243 -0
  23. data/lib/sunspot/dsl/function.rb +14 -0
  24. data/lib/sunspot/dsl/functional.rb +41 -0
  25. data/lib/sunspot/dsl/more_like_this_query.rb +56 -0
  26. data/lib/sunspot/dsl/paginatable.rb +28 -0
  27. data/lib/sunspot/dsl/query_facet.rb +36 -0
  28. data/lib/sunspot/dsl/restriction.rb +25 -0
  29. data/lib/sunspot/dsl/scope.rb +229 -0
  30. data/lib/sunspot/dsl/search.rb +30 -0
  31. data/lib/sunspot/dsl/standard_query.rb +125 -0
  32. data/lib/sunspot/field.rb +192 -0
  33. data/lib/sunspot/field_factory.rb +147 -0
  34. data/lib/sunspot/indexer.rb +131 -0
  35. data/lib/sunspot/installer.rb +31 -0
  36. data/lib/sunspot/installer/library_installer.rb +45 -0
  37. data/lib/sunspot/installer/schema_builder.rb +219 -0
  38. data/lib/sunspot/installer/solrconfig_updater.rb +106 -0
  39. data/lib/sunspot/installer/task_helper.rb +18 -0
  40. data/lib/sunspot/query.rb +10 -0
  41. data/lib/sunspot/query/abstract_field_facet.rb +52 -0
  42. data/lib/sunspot/query/boost_query.rb +24 -0
  43. data/lib/sunspot/query/common_query.rb +85 -0
  44. data/lib/sunspot/query/composite_fulltext.rb +31 -0
  45. data/lib/sunspot/query/connective.rb +195 -0
  46. data/lib/sunspot/query/date_field_facet.rb +14 -0
  47. data/lib/sunspot/query/dismax.rb +126 -0
  48. data/lib/sunspot/query/field_facet.rb +41 -0
  49. data/lib/sunspot/query/filter.rb +38 -0
  50. data/lib/sunspot/query/function_query.rb +52 -0
  51. data/lib/sunspot/query/highlighting.rb +55 -0
  52. data/lib/sunspot/query/local.rb +26 -0
  53. data/lib/sunspot/query/more_like_this.rb +60 -0
  54. data/lib/sunspot/query/more_like_this_query.rb +12 -0
  55. data/lib/sunspot/query/pagination.rb +38 -0
  56. data/lib/sunspot/query/query_facet.rb +16 -0
  57. data/lib/sunspot/query/restriction.rb +265 -0
  58. data/lib/sunspot/query/scope.rb +16 -0
  59. data/lib/sunspot/query/sort.rb +95 -0
  60. data/lib/sunspot/query/sort_composite.rb +33 -0
  61. data/lib/sunspot/query/standard_query.rb +20 -0
  62. data/lib/sunspot/query/text_field_boost.rb +17 -0
  63. data/lib/sunspot/schema.rb +151 -0
  64. data/lib/sunspot/search.rb +9 -0
  65. data/lib/sunspot/search/abstract_search.rb +302 -0
  66. data/lib/sunspot/search/date_facet.rb +35 -0
  67. data/lib/sunspot/search/facet_row.rb +27 -0
  68. data/lib/sunspot/search/field_facet.rb +88 -0
  69. data/lib/sunspot/search/highlight.rb +38 -0
  70. data/lib/sunspot/search/hit.rb +136 -0
  71. data/lib/sunspot/search/more_like_this_search.rb +31 -0
  72. data/lib/sunspot/search/query_facet.rb +62 -0
  73. data/lib/sunspot/search/standard_search.rb +21 -0
  74. data/lib/sunspot/server.rb +152 -0
  75. data/lib/sunspot/session.rb +252 -0
  76. data/lib/sunspot/session_proxy.rb +71 -0
  77. data/lib/sunspot/session_proxy/abstract_session_proxy.rb +29 -0
  78. data/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +66 -0
  79. data/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +89 -0
  80. data/lib/sunspot/session_proxy/master_slave_session_proxy.rb +43 -0
  81. data/lib/sunspot/session_proxy/sharding_session_proxy.rb +215 -0
  82. data/lib/sunspot/session_proxy/thread_local_session_proxy.rb +37 -0
  83. data/lib/sunspot/setup.rb +360 -0
  84. data/lib/sunspot/text_field_setup.rb +29 -0
  85. data/lib/sunspot/type.rb +342 -0
  86. data/lib/sunspot/util.rb +253 -0
  87. data/lib/sunspot/version.rb +3 -0
  88. data/solr/etc/jetty.xml +214 -0
  89. data/solr/etc/webdefault.xml +379 -0
  90. data/solr/lib/jetty-6.1.3.jar +0 -0
  91. data/solr/lib/jetty-util-6.1.3.jar +0 -0
  92. data/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
  93. data/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
  94. data/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
  95. data/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
  96. data/solr/lib/servlet-api-2.5-6.1.3.jar +0 -0
  97. data/solr/solr/conf/admin-extra.html +31 -0
  98. data/solr/solr/conf/elevate.xml +36 -0
  99. data/solr/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
  100. data/solr/solr/conf/protwords.txt +21 -0
  101. data/solr/solr/conf/schema.xml +238 -0
  102. data/solr/solr/conf/scripts.conf +24 -0
  103. data/solr/solr/conf/solrconfig.xml +938 -0
  104. data/solr/solr/conf/spellings.txt +2 -0
  105. data/solr/solr/conf/stopwords.txt +58 -0
  106. data/solr/solr/conf/synonyms.txt +31 -0
  107. data/solr/solr/lib/lucene-spatial-2.9.1.jar +0 -0
  108. data/solr/solr/lib/solr-spatial-light-0.0.6.jar +0 -0
  109. data/solr/start.jar +0 -0
  110. data/solr/webapps/solr.war +0 -0
  111. data/spec/api/adapters_spec.rb +33 -0
  112. data/spec/api/binding_spec.rb +38 -0
  113. data/spec/api/indexer/attributes_spec.rb +149 -0
  114. data/spec/api/indexer/batch_spec.rb +46 -0
  115. data/spec/api/indexer/dynamic_fields_spec.rb +42 -0
  116. data/spec/api/indexer/fixed_fields_spec.rb +57 -0
  117. data/spec/api/indexer/fulltext_spec.rb +43 -0
  118. data/spec/api/indexer/removal_spec.rb +53 -0
  119. data/spec/api/indexer/spec_helper.rb +1 -0
  120. data/spec/api/indexer_spec.rb +14 -0
  121. data/spec/api/query/advanced_manipulation_examples.rb +35 -0
  122. data/spec/api/query/connectives_examples.rb +186 -0
  123. data/spec/api/query/dsl_spec.rb +18 -0
  124. data/spec/api/query/dynamic_fields_examples.rb +165 -0
  125. data/spec/api/query/faceting_examples.rb +399 -0
  126. data/spec/api/query/fulltext_examples.rb +315 -0
  127. data/spec/api/query/function_spec.rb +70 -0
  128. data/spec/api/query/highlighting_examples.rb +225 -0
  129. data/spec/api/query/local_examples.rb +38 -0
  130. data/spec/api/query/more_like_this_spec.rb +140 -0
  131. data/spec/api/query/ordering_pagination_examples.rb +97 -0
  132. data/spec/api/query/scope_examples.rb +263 -0
  133. data/spec/api/query/spec_helper.rb +1 -0
  134. data/spec/api/query/standard_spec.rb +28 -0
  135. data/spec/api/query/text_field_scoping_examples.rb +30 -0
  136. data/spec/api/query/types_spec.rb +20 -0
  137. data/spec/api/search/dynamic_fields_spec.rb +33 -0
  138. data/spec/api/search/faceting_spec.rb +356 -0
  139. data/spec/api/search/highlighting_spec.rb +69 -0
  140. data/spec/api/search/hits_spec.rb +149 -0
  141. data/spec/api/search/results_spec.rb +79 -0
  142. data/spec/api/search/search_spec.rb +23 -0
  143. data/spec/api/search/spec_helper.rb +1 -0
  144. data/spec/api/server_spec.rb +91 -0
  145. data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +85 -0
  146. data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +30 -0
  147. data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +41 -0
  148. data/spec/api/session_proxy/sharding_session_proxy_spec.rb +77 -0
  149. data/spec/api/session_proxy/spec_helper.rb +9 -0
  150. data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +50 -0
  151. data/spec/api/session_spec.rb +198 -0
  152. data/spec/api/spec_helper.rb +3 -0
  153. data/spec/api/sunspot_spec.rb +18 -0
  154. data/spec/ext.rb +11 -0
  155. data/spec/helpers/indexer_helper.rb +29 -0
  156. data/spec/helpers/query_helper.rb +38 -0
  157. data/spec/helpers/search_helper.rb +80 -0
  158. data/spec/integration/dynamic_fields_spec.rb +55 -0
  159. data/spec/integration/faceting_spec.rb +238 -0
  160. data/spec/integration/highlighting_spec.rb +22 -0
  161. data/spec/integration/indexing_spec.rb +33 -0
  162. data/spec/integration/keyword_search_spec.rb +317 -0
  163. data/spec/integration/local_search_spec.rb +91 -0
  164. data/spec/integration/more_like_this_spec.rb +43 -0
  165. data/spec/integration/scoped_search_spec.rb +349 -0
  166. data/spec/integration/spec_helper.rb +7 -0
  167. data/spec/integration/stored_fields_spec.rb +10 -0
  168. data/spec/integration/test_pagination.rb +32 -0
  169. data/spec/mocks/adapters.rb +32 -0
  170. data/spec/mocks/blog.rb +3 -0
  171. data/spec/mocks/comment.rb +21 -0
  172. data/spec/mocks/connection.rb +126 -0
  173. data/spec/mocks/mock_adapter.rb +30 -0
  174. data/spec/mocks/mock_class_sharding_session_proxy.rb +24 -0
  175. data/spec/mocks/mock_record.rb +52 -0
  176. data/spec/mocks/mock_sharding_session_proxy.rb +15 -0
  177. data/spec/mocks/photo.rb +12 -0
  178. data/spec/mocks/post.rb +76 -0
  179. data/spec/mocks/super_class.rb +2 -0
  180. data/spec/mocks/user.rb +8 -0
  181. data/spec/spec_helper.rb +52 -0
  182. data/tasks/gemspec.rake +33 -0
  183. data/tasks/rcov.rake +28 -0
  184. data/tasks/rdoc.rake +27 -0
  185. data/tasks/schema.rake +19 -0
  186. data/tasks/spec.rake +24 -0
  187. data/tasks/todo.rake +4 -0
  188. metadata +356 -0
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ require File.expand_path('../lib/sunspot/version', __FILE__)
4
+
5
+ gem 'sunspot', Sunspot::VERSION, :path => File.expand_path('..', __FILE__)
6
+
7
+ group :test do
8
+ gem 'rspec', '~> 1.3'
9
+ end
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sunspot (1.1.0)
5
+ escape (= 0.0.4)
6
+ rsolr (= 0.12.1)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ builder (3.0.0)
12
+ escape (0.0.4)
13
+ rsolr (0.12.1)
14
+ builder (>= 2.1.2)
15
+ rspec (1.3.1)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ rspec (~> 1.3)
22
+ sunspot (= 1.1.0)!
@@ -0,0 +1,198 @@
1
+ == 1.0.4 2010-03-19
2
+ * Update solr-spatial-light to 0.0.5
3
+ * Fix NullPointerException in repeated geo search
4
+ * Fix missing distances in repeated geo search
5
+ * Don't query the data store more than once when results are missing
6
+
7
+ == 1.0.2 2010-03-11
8
+ * Restore Hit#distance for result geo distance
9
+ * Remove :distance special sort
10
+ * Quote reserved keywords in boolean queries
11
+ * Add Search#facets accessor to retrieve all facets
12
+
13
+ == 1.0.1 2010-03-05
14
+ * Copy all needed config files when sunspot-installer run with force option
15
+
16
+ == 1.0.0 2010-03-03
17
+ * Multiselect Field Faceting
18
+ * Named field facets
19
+ * Upgrade to Solr 1.4
20
+ * Deletion by query
21
+ * Allow :latitude and :longitude as coordinate method names
22
+ * Assumed inconsistency
23
+ * Support for TrieField numeric/time types
24
+ * Built-in Session Proxies: Thread-local, master/slave, sharding
25
+ * Give DSL blocks access to calling context
26
+ * Create sunspot-installer executable, which modifies an existing
27
+ schema/solrconfig to work with Sunspot
28
+ * Support for Long and Double types
29
+ * new_search method accepts DSL block
30
+ * Sunspot::Server now a real class that manages embedded Sunspot instance
31
+ * Add Search#each_hit_with_result method
32
+ * Able to access stored dynamic fields
33
+ * Access dynamic facets using the #facet method
34
+ * Remove accidental existence of dynamic_text fields
35
+ * Upgrade to RSolr 0.12.1
36
+ * Switch from LocalSolr to solr-spatial-light
37
+ * Turn off request logging in Jetty for default Solr install
38
+ * Full support for class-reloading of Sunspot-setup classes
39
+ * Support time ranges outside of 32-bit range
40
+ * Remove sunspot-configure-solr executable
41
+ * new_search method accepts DSL block
42
+
43
+ == 0.10.8 2009-11-24
44
+ * Strictly enforce RSolr 0.9.6 gem dependency (newer ones broken)
45
+
46
+ == 0.10.7 2009-11-16
47
+ * Ignore boost_fields that don't apply
48
+ * Ability to specify text_fields inside connectives
49
+ * Fix bug with newlines in strings incorrectly being considered multi-value
50
+ * Compatibility with RSolr 0.10.1
51
+ * Remove commented-out code entirely
52
+
53
+ == 0.10.6 2009-11-05
54
+ * Support more dismax parameters
55
+ * Support multiple boost queries
56
+ * Allow "extra" facet rows
57
+ * Allow exclusion of fulltext fields
58
+ * Allow specification of per-field highlighting params
59
+ * Specify coordinates using block extraction
60
+ * Return empty array if no highlights available
61
+ * Get stored text fields from hits
62
+ * Update docs to reflect a requirement of at least one search type
63
+ * added --max-memory and --min-memory parameters to sunspot-solr
64
+ * LocalLucene and LocalSolr compatible with Java 1.5
65
+
66
+ == 0.10.5 2009-10-22
67
+ * Fix highlighting for multiple-model search
68
+
69
+ == 0.10.4 2009-10-20
70
+ * Add adjust_params method, allowing experts to manually edit Solr params
71
+ * Track adds and deletes separately in session, and expose delete_dirty? method
72
+ * Allow clients to inject a singleton session proxy
73
+
74
+ == 0.10.3 2009-10-15
75
+ * Contiguous, not continuous
76
+ * Fail fast if less-than-1 radius passed for local search
77
+
78
+ == 0.10.2 2009-10-09
79
+ * Add Sunspot.config.xml_builder option, which is passed to RSolr
80
+
81
+ == 0.10.1 2009-10-08
82
+ * Fix directory bugs in sunspot-solr executable
83
+
84
+ == 0.10.0 2009-10-08
85
+ * Support for geographical search using LocalSolr
86
+ * Support for keyword highlighting, with custom deferred formatting
87
+ * New fulltext DSL for specifying advanced dismax options
88
+ * Support boost queries
89
+ * Support for search-time field boost
90
+ * Support for phrase fields
91
+ * Support for prefix queries
92
+ * Set default search-time field boost in setup
93
+ * Restrict field facet to a set of desired values
94
+ * Query facets support all facet options
95
+ * Allow scoping by text fields
96
+ * Support executing searches repeatedly
97
+ * Allow setting of Solr URL for integration tests in environment variable
98
+ * Add support for master/slave configurations
99
+ * Added logging options to sunspot-solr executable
100
+ * Added default solr config file location to Sunspot::Configuration
101
+ * Informative, non-firehose Search#inspect
102
+ * No longer require arguments to #paginate
103
+ * Silently ignore keyword calls with nil/blank/whitespace keywords
104
+ * Don't require that all searched types have a referenced field
105
+ * Correct backwards ranges
106
+ * Raise descriptive error if no types passed to search
107
+ * Handle empty query facets, query facet rows, and connectives
108
+ * Quote values in range restrictions if they contain spaces
109
+ * Fix bug in Sunspot::Util.full_const_get
110
+ * Remove support for :other option in time faceting
111
+ * Remove order_by_random() method
112
+ * Removed options and Query from public API
113
+ * Use built-in optparse instead of optiflag in bin/sunspot-solr
114
+ * Remove dependency on haml and use erb since it is only used to generate one file
115
+
116
+ == 0.9.0 2009-07-21
117
+ * Use Dismax parser for keyword search
118
+ * Field and document boosting
119
+ * Specify which fields to search in keyword search
120
+ * Allow indexing of multiple values in text fields
121
+ * Access keyword relevance score in Hit objects
122
+ * Allow stored fields, retrieve stored values from Hit objects
123
+ * Support more values in shorthand restrictions
124
+ * Disjunctions and conjunctions
125
+ * Random ordering
126
+ * Control all options for field facets
127
+ * Time range facets
128
+ * Get referenced objects from facets on foreign keys
129
+ * Facet by class
130
+ * Batch indexing
131
+ * New Date field type
132
+ * Direct access to data accessors
133
+ * Executable to configure production Solr instances
134
+ * Replace solr-ruby with RSolr
135
+ * Remove accidental ActiveSupport dependency
136
+
137
+ == 0.8.9 2009-06-23
138
+ * Fix OrderedHash bug in older versions of ActiveSupport
139
+
140
+ == 0.8.8 2009-06-15
141
+ * Escape type names to support namespaced classes
142
+ * Fix bug with anonymous modules in Ruby 1.9
143
+
144
+ == 0.8.7 2009-06-10
145
+ * Add --pid-dir option for sunspot-solr executable
146
+
147
+ == 0.8.5 2009-06-09
148
+ * Added dependencies for sunspot-solr executable to gem dependencies
149
+ * Search for adapters using class ancestors rather than superclasses
150
+
151
+ == 0.8.3 2009-06-03
152
+ * Index objects passed as a collection in a single HTTP request
153
+
154
+ == 0.8.2 2009-05-27
155
+ * Allow specification of Solr home when using sunspot-solr
156
+
157
+ == 0.8.1 2009-05-26
158
+ * Add Search#execute! to public API
159
+
160
+ == 0.8.0 2009-05-22
161
+ * Access query API directly; instantiate search without running it
162
+ * Dynamic fields
163
+ * Search blocks can be evaluated in calling context
164
+
165
+ == 0.7.3 2009-05-06
166
+ * Better exception handling when class doesn't have adapter/setup
167
+
168
+ == 0.7.2 2009-04-29
169
+ * Dirty sessions
170
+
171
+ == 0.7.1 2009-04-29
172
+ * Removed extlib dependency from gemspec
173
+
174
+ == 0.7.0 2009-04-28
175
+ * Less magic in the DSL
176
+ * Restrict by empty values
177
+ * Negative scoping using without() method
178
+ * Exclusion by object identity using without(instance)
179
+ * Support for faceting
180
+ * Explicit commits
181
+ * Boolean field type
182
+ * Attribute field flexibility
183
+ * Virtual field blocks can be evaluated in calling context
184
+ * Order available by multiple fields
185
+ * New adapter API
186
+ * Got rid of builder API
187
+ * Full documentation
188
+
189
+ == 0.0.2 2009-02-14
190
+ * Run sunspot's built-in Solr instance using
191
+ sunspot-solr executable
192
+ * Search hash interpretation delegated to
193
+ Builder object
194
+
195
+ == 0.0.1 2008-12-11
196
+ * Initial release
197
+ * Define indexing for any class using DSL
198
+ * Search indexed classes using DSL
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Permission is hereby granted, free of charge, to any person obtaining
2
+ a copy of this software and associated documentation files (the
3
+ 'Software'), to deal in the Software without restriction, including
4
+ without limitation the rights to use, copy, modify, merge, publish,
5
+ distribute, sublicense, and/or sell copies of the Software, and to
6
+ permit persons to whom the Software is furnished to do so, subject to
7
+ the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be
10
+ included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
13
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
15
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
16
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
17
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,244 @@
1
+ = Sunspot
2
+
3
+ http://outoftime.github.com/sunspot
4
+
5
+ Sunspot is a Ruby library for expressive, powerful interaction with the Solr
6
+ search engine. Sunspot is built on top of the RSolr library, which
7
+ provides a low-level interface for Solr interaction; Sunspot provides a simple,
8
+ intuitive, expressive DSL backed by powerful features for indexing objects and
9
+ searching for them.
10
+
11
+ Sunspot is designed to be easily plugged in to any ORM, or even non-database-backed
12
+ objects such as the filesystem.
13
+
14
+ === Where to learn all about Sunspot: The Wiki!
15
+
16
+ New to Sunspot and using Rails? Check out {Adding Sunspot search to Rails in 5
17
+ minutes or less}[http://wiki.github.com/outoftime/sunspot/adding-sunspot-search-to-rails-in-5-minutes-or-less].
18
+
19
+ This README is intended as a quick primer on what Sunspot is capable of; for
20
+ detailed treatment of Sunspot's full feature range, check out the wiki:
21
+ http://wiki.github.com/outoftime/sunspot
22
+
23
+ The API documentation is also complete and up-to-date; however, because of the
24
+ way Sunspot is structured, it's not the easiest way for new users to get to know
25
+ the library.
26
+
27
+ === Features:
28
+
29
+ * Define indexing strategy for each searchable class using intuitive block-based
30
+ API
31
+ * Clean separation between keyword-searchable fields and fields for
32
+ scoping/ordering
33
+ * Define fields based on existing attributes or "virtual fields" for custom
34
+ indexing
35
+ * Indexes each object's entire superclass hierarchy, for easy searching for all
36
+ objects inheriting from a parent class
37
+ * Intuitive DSL for scoping searches, with all the usual boolean operators
38
+ available
39
+ * Intuitive interface for requesting facets on indexed fields
40
+ * Extensible adapter architecture for easy integration of other ORMs or
41
+ non-model classes
42
+ * Refine search using field facets, date range facets, or ultra-powerful
43
+ query facets
44
+ * Full compatibility with will_paginate
45
+ * Ordering by field value, relevance, geographical distance, or random
46
+
47
+ == Installation
48
+
49
+ gem install sunspot
50
+
51
+ In order to start the packaged Solr installation, run:
52
+
53
+ sunspot-solr start -- [-d /path/to/data/directory] [-p port] [-s path/to/solr/home] [--pid-dir=path/to/pid/dir]
54
+
55
+ If you don't specify a data directory, your Solr index will be stored in your
56
+ operating system's temporary directory.
57
+
58
+ If you specify a solr home, the directory must contain a <code>conf</code>
59
+ directory, which should contain at least <code>schema.xml</code> and
60
+ <code>solrconfig.xml</code>. Be sure to copy the <code>schema.xml</code> out of
61
+ the Sunspot gem's <code>solr/solr/conf</code> directory. Sunspot relies on the
62
+ field name patterns defined in the packaged <code>schema.xml</code>, so those
63
+ cannot be modified.
64
+
65
+ You can also run your own instance of Solr wherever you'd like; just copy the solr/config/schema.xml file out of the gem's solr into your installation.
66
+ You can change the URL at which Sunspot accesses Solr with:
67
+
68
+ Sunspot.config.solr.url = 'http://solr.my.host:9818/solr'
69
+
70
+ == Rails Integration
71
+
72
+ The Sunspot::Rails plugin makes integrating Sunspot into Rails drop-in easy.
73
+
74
+ gem install sunspot_rails
75
+
76
+ See the README for that gem or the Sunspot Wiki for more information.
77
+
78
+ == Using Sunspot
79
+
80
+ === Define an index:
81
+
82
+ class Post
83
+ #...
84
+ end
85
+
86
+ Sunspot.setup(Post) do
87
+ text :title, :body
88
+ string :author_name
89
+ integer :blog_id
90
+ integer :category_ids
91
+ float :average_rating, :using => :ratings_average
92
+ time :published_at
93
+ string :sort_title do
94
+ title.downcase.sub(/^(an?|the)\W+/, ''/) if title = self.title
95
+ end
96
+ end
97
+
98
+ See Sunspot.setup for more information.
99
+
100
+ Note that in order for a class to be searchable, it must have an adapter
101
+ registered for itself or one of its subclasses. Adapters allow Sunspot to load
102
+ objects out of persistent storage, and to determine their primary key for
103
+ indexing. {Sunspot::Rails}[http://github.com/outoftime/sunspot_rails] comes with
104
+ an adapter for ActiveRecord objects, but for other types of models you will need
105
+ to define your own. See Sunspot::Adapters for more information.
106
+
107
+ === Search for objects:
108
+
109
+ search = Sunspot.search Post do
110
+ keywords 'great pizza'
111
+ with :author_name, 'Mark Twain'
112
+ with(:blog_id).any_of [2, 14]
113
+ with(:category_ids).all_of [4, 10]
114
+ with(:published_at).less_than Time.now
115
+ any_of do
116
+ with(:expired_at).greater_than(Time.now)
117
+ with(:expired_at, nil)
118
+ end
119
+ without :title, 'Bad Title'
120
+ without bad_instance # specifically exclude this instance from results
121
+
122
+ paginate :page => 3, :per_page => 15
123
+ order_by :average_rating, :desc
124
+
125
+ facet :blog_id
126
+ end
127
+
128
+ See Sunspot.search for more information.
129
+
130
+ === Work with search results (Haml for readability):
131
+
132
+ .facets
133
+ ul.blog_facet
134
+ - @search.facet(:blog_id).rows.each do |row|
135
+ li.facet_row
136
+ = link_to(row.instance.name, params.merge(:blog_id => row.value))
137
+ %span.count== (#{row.count})
138
+ .page_info== Displaying page #{@search.hits.page} of #{@search.hits.per_page} out of #{@search.total} results
139
+ - @search.each_hit_with_result do |hit, post|
140
+ .search_result
141
+ %h3.title
142
+ = link_to(h(hit.stored(:title)), post_url(post))
143
+ - if hit.score
144
+ %span.relevance== (#{hit.score})
145
+ %p= hit.highlight(:description).format { |word| "<span class=\"highlight\">#{word}</span>" }
146
+ .pagination= will_paginate(search.hits)
147
+
148
+ == About the API documentation
149
+
150
+ All of the methods documented in the RDoc are considered part of Sunspot's
151
+ public API. Methods that are not part of the public API are documented in the
152
+ code, but excluded from the RDoc. If you find yourself needing to access methods
153
+ that are not part of the public API in order to do what you need, please contact
154
+ me so I can rectify the situation!
155
+
156
+ == Dependencies
157
+
158
+ 1. RSolr
159
+ 2. Java 1.5+
160
+
161
+ Sunspot has been tested with MRI 1.8.6 and 1.8.7, REE 1.8.6, YARV 1.9.1, and
162
+ JRuby 1.2.0
163
+
164
+ == Bugs
165
+
166
+ Please submit bug reports to
167
+ http://outoftime.lighthouseapp.com/projects/20339-sunspot
168
+
169
+ == Contribution Guidelines
170
+
171
+ Contributions are very welcome - both new features, enhancements, and bug fixes.
172
+ Bug reports with a failing regression test are also lovely. In order to keep the
173
+ contribution process as organized and smooth as possible, please follow these
174
+ guidelines:
175
+
176
+ * Contributions should be submitted via Sunspot's Lighthouse account, with an
177
+ attached git patch. See below for how to create a git patch.
178
+ * Patches should not make any changes to the gemspec task other than
179
+ adding/removing dependencies (e.g., changing the name, version, email,
180
+ description, etc.)
181
+ * Patches should not include any changes to the gemspec itself.
182
+ * Document any new methods, options, arguments, etc.
183
+ * Write tests.
184
+ * As much as possible, follow the coding and testing styles you see in existing
185
+ code. One could accuse me of being nitpicky about this, but consistent code is
186
+ easier to read, maintain, and enhance.
187
+ * Don't make any massive changes to the structure of library or test code. If
188
+ you think something needs a huge refactor or rearrangement, shoot me a
189
+ message; trying to apply that kind of patch without warning opens the door to
190
+ a world of conflict hurt.
191
+
192
+ Here's how to create a Git patch - assuming you're pulling from the canonical
193
+ Sunspot repository at `upstream`:
194
+
195
+ git fetch upstream
196
+ git format-patch --stdout upstream/master.. > my-awesome.patch
197
+
198
+ == Help and Support
199
+
200
+ === Ask for help
201
+
202
+ * Sunspot Discussion: {ruby-sunspot@googlegroups.com}[mailto:ruby-sunspot@googlegroups.com] / http://groups.google.com/group/ruby-sunspot
203
+ * IRC: {#sunspot-ruby @ Freenode}[irc://chat.freenode.net/#sunspot-ruby]
204
+
205
+ === Tutorials and Articles
206
+
207
+ * {Full-text search in Rails with Sunspot}[http://tech.favoritemedium.com/2010/01/full-text-search-in-rails-with-sunspot.html] (Tropical Software Observations)
208
+ * {Sunspot Full-text Search for Rails/Ruby}[http://therailworld.com/posts/23-Sunspot-Full-text-Search-for-Rails-Ruby] (The Rail World)
209
+ * {A Few Sunspot Tips}[http://blog.trydionel.com/2009/11/19/a-few-sunspot-tips/] (spiral_code)
210
+ * {Sunspot: A Solr-Powered Search Engine for Ruby}[http://www.linux-mag.com/id/7341] (Linux Magazine)
211
+ * {Sunspot Showed Me the Light}[http://bennyfreshness.com/2010/05/sunspot-helped-me-see-the-light/] (ben koonse)
212
+ * {rails3 + heroku + sunspot : madness}[http://anhaminha.tumblr.com/post/632682537/rails3-heroku-sunspot-madness] (anhaminha)
213
+ * {Using Sunspot for Free-Text Search with Redis}[http://masonoise.wordpress.com/2010/02/06/using-sunspot-for-free-text-search-with-redis/] (While I Pondered...)
214
+ * {Default scope with Sunspot}[http://www.cloudspace.com/blog/2010/01/15/default-scope-with-sunspot/] (Cloudspace)
215
+ * {Chef recipe for Sunspot in production}[http://gist.github.com/336403]
216
+ * {Cucumber and Sunspot}[http://opensoul.org/2010/4/7/cucumber-and-sunspot] (opensoul.org)
217
+ * {Testing Sunspot with Cucumber}[http://blog.trydionel.com/2010/02/06/testing-sunspot-with-cucumber/] (spiral_code)
218
+ * {Running cucumber features with sunspot_rails}[http://blog.kabisa.nl/2010/02/03/running-cucumber-features-with-sunspot_rails] (Kabisa Blog)
219
+ * {How To Use Twitter Lists to Determine Influence}[http://www.untitledstartup.com/2010/01/how-to-use-twitter-lists-to-determine-influence/] (Untitled Startup)
220
+ * {Sunspot Quickstart}[http://wiki.websolr.com/index.php/Sunspot_Quickstart] (WebSolr)
221
+ * {Solr, and Sunspot}[http://www.kuahyeow.com/2009/08/solr-and-sunspot.html] (YT!)
222
+ * {The Saga of the Switch}[http://mrb.github.com/2010/04/08/the-saga-of-the-switch.html] (mrb -- includes comparison of Sunspot and Ultrasphinx)
223
+
224
+ == Contributors
225
+
226
+ * Mat Brown (mat@patch.com)
227
+ * Peer Allan (peer.allan@gmail.com)
228
+ * Dmitriy Dzema (dima@dzema.name)
229
+ * Benjamin Krause (bk@benjaminkrause.com)
230
+ * Marcel de Graaf (marcel@slashdev.nl)
231
+ * Brandon Keepers (brandon@opensoul.org)
232
+ * Peter Berkenbosch (peterberkenbosch@me.com)
233
+ * Brian Atkinson
234
+ * Tom Coleman (tom@thesnail.org)
235
+ * Matt Mitchell (goodieboy@gmail.com)
236
+ * Nathan Beyer (nbeyer@gmail.com)
237
+ * Kieran Topping
238
+ * Nicolas Braem (nicolas.braem@gmail.com)
239
+ * Jeremy Ashkenas (jashkenas@gmail.com)
240
+ * Dylan Vaughn (dylanvaughn@yahoo.com)
241
+
242
+ == License
243
+
244
+ Sunspot is distributed under the MIT License, copyright (c) 2008-2009 Mat Brown