sunspot 0.10.9 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/History.txt +30 -0
  2. data/README.rdoc +59 -29
  3. data/Rakefile +2 -0
  4. data/TODO +9 -19
  5. data/VERSION.yml +2 -3
  6. data/bin/sunspot-installer +19 -0
  7. data/bin/sunspot-solr +28 -53
  8. data/installer/config/schema.yml +71 -0
  9. data/lib/sunspot/configuration.rb +0 -10
  10. data/lib/sunspot/dsl/field_query.rb +123 -7
  11. data/lib/sunspot/dsl/fields.rb +17 -4
  12. data/lib/sunspot/dsl/query.rb +11 -3
  13. data/lib/sunspot/dsl/scope.rb +6 -2
  14. data/lib/sunspot/field.rb +4 -7
  15. data/lib/sunspot/field_factory.rb +8 -5
  16. data/lib/sunspot/indexer.rb +22 -20
  17. data/lib/sunspot/installer/library_installer.rb +45 -0
  18. data/lib/sunspot/installer/schema_builder.rb +219 -0
  19. data/lib/sunspot/installer/solrconfig_updater.rb +90 -0
  20. data/lib/sunspot/installer/task_helper.rb +18 -0
  21. data/lib/sunspot/installer.rb +31 -0
  22. data/lib/sunspot/query/abstract_field_facet.rb +5 -1
  23. data/lib/sunspot/query/connective.rb +3 -1
  24. data/lib/sunspot/query/field_facet.rb +33 -1
  25. data/lib/sunspot/query/filter.rb +38 -0
  26. data/lib/sunspot/query/local.rb +10 -11
  27. data/lib/sunspot/query/query.rb +5 -12
  28. data/lib/sunspot/query/restriction.rb +2 -1
  29. data/lib/sunspot/query/scope.rb +1 -1
  30. data/lib/sunspot/query.rb +3 -3
  31. data/lib/sunspot/schema.rb +5 -1
  32. data/lib/sunspot/search/field_facet.rb +59 -15
  33. data/lib/sunspot/search/hit.rb +21 -10
  34. data/lib/sunspot/search/query_facet.rb +2 -2
  35. data/lib/sunspot/search.rb +86 -33
  36. data/lib/sunspot/server.rb +148 -0
  37. data/lib/sunspot/session.rb +39 -51
  38. data/lib/sunspot/session_proxy/abstract_session_proxy.rb +29 -0
  39. data/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +66 -0
  40. data/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +89 -0
  41. data/lib/sunspot/session_proxy/master_slave_session_proxy.rb +43 -0
  42. data/lib/sunspot/session_proxy/sharding_session_proxy.rb +206 -0
  43. data/lib/sunspot/session_proxy/thread_local_session_proxy.rb +30 -0
  44. data/lib/sunspot/session_proxy.rb +71 -0
  45. data/lib/sunspot/setup.rb +24 -10
  46. data/lib/sunspot/type.rb +163 -101
  47. data/lib/sunspot/util.rb +44 -2
  48. data/lib/sunspot/version.rb +3 -0
  49. data/lib/sunspot.rb +50 -17
  50. data/solr/etc/jetty.xml +4 -2
  51. data/solr/solr/conf/admin-extra.html +31 -0
  52. data/solr/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
  53. data/solr/solr/conf/schema.xml +212 -50
  54. data/solr/solr/conf/scripts.conf +24 -0
  55. data/solr/solr/conf/solrconfig.xml +473 -266
  56. data/solr/solr/conf/spellings.txt +2 -0
  57. data/solr/solr/conf/stopwords.txt +1 -0
  58. data/solr/solr/lib/lucene-spatial-2.9.1.jar +0 -0
  59. data/solr/solr/lib/solr-spatial-light-0.0.3.jar +0 -0
  60. data/solr/webapps/solr.war +0 -0
  61. data/spec/api/binding_spec.rb +38 -0
  62. data/spec/api/indexer/attributes_spec.rb +37 -4
  63. data/spec/api/indexer/dynamic_fields_spec.rb +10 -1
  64. data/spec/api/indexer/removal_spec.rb +8 -1
  65. data/spec/api/indexer_spec.rb +10 -0
  66. data/spec/api/query/dsl_spec.rb +6 -0
  67. data/spec/api/query/dynamic_fields_spec.rb +9 -9
  68. data/spec/api/query/facet_local_params_spec.rb +103 -0
  69. data/spec/api/query/local_spec.rb +13 -37
  70. data/spec/api/query/ordering_pagination_spec.rb +0 -6
  71. data/spec/api/search/dynamic_fields_spec.rb +3 -3
  72. data/spec/api/search/faceting_spec.rb +113 -10
  73. data/spec/api/search/hits_spec.rb +49 -0
  74. data/spec/api/search/results_spec.rb +8 -1
  75. data/spec/api/server_spec.rb +85 -0
  76. data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +85 -0
  77. data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +30 -0
  78. data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +41 -0
  79. data/spec/api/session_proxy/sharding_session_proxy_spec.rb +77 -0
  80. data/spec/api/session_proxy/spec_helper.rb +9 -0
  81. data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +33 -0
  82. data/spec/ext.rb +11 -0
  83. data/spec/helpers/search_helper.rb +6 -8
  84. data/spec/integration/faceting_spec.rb +46 -4
  85. data/spec/integration/indexing_spec.rb +27 -1
  86. data/spec/integration/local_search_spec.rb +25 -7
  87. data/spec/integration/scoped_search_spec.rb +48 -36
  88. data/spec/mocks/comment.rb +7 -5
  89. data/spec/mocks/connection.rb +14 -13
  90. data/spec/mocks/mock_class_sharding_session_proxy.rb +24 -0
  91. data/spec/mocks/mock_record.rb +7 -3
  92. data/spec/mocks/mock_sharding_session_proxy.rb +15 -0
  93. data/spec/mocks/photo.rb +4 -3
  94. data/spec/mocks/post.rb +1 -1
  95. data/spec/spec_helper.rb +2 -1
  96. data/tasks/gemspec.rake +26 -36
  97. data/tasks/rdoc.rake +9 -4
  98. metadata +203 -203
  99. data/bin/sunspot-configure-solr +0 -40
  100. data/solr/solr/lib/geoapi-nogenerics-2.1-M2.jar +0 -0
  101. data/solr/solr/lib/gt2-referencing-2.3.1.jar +0 -0
  102. data/solr/solr/lib/jsr108-0.01.jar +0 -0
  103. data/solr/solr/lib/locallucene.jar +0 -0
  104. data/solr/solr/lib/localsolr.jar +0 -0
  105. data/templates/schema.xml.erb +0 -36
data/History.txt CHANGED
@@ -1,3 +1,33 @@
1
+ == 1.0.0 2010-03-03
2
+ * Multiselect Field Faceting
3
+ * Named field facets
4
+ * Upgrade to Solr 1.4
5
+ * Deletion by query
6
+ * Allow :latitude and :longitude as coordinate method names
7
+ * Assumed inconsistency
8
+ * Support for TrieField numeric/time types
9
+ * Built-in Session Proxies: Thread-local, master/slave, sharding
10
+ * Give DSL blocks access to calling context
11
+ * Create sunspot-installer executable, which modifies an existing
12
+ schema/solrconfig to work with Sunspot
13
+ * Support for Long and Double types
14
+ * new_search method accepts DSL block
15
+ * Sunspot::Server now a real class that manages embedded Sunspot instance
16
+ * Add Search#each_hit_with_result method
17
+ * Able to access stored dynamic fields
18
+ * Access dynamic facets using the #facet method
19
+ * Remove accidental existence of dynamic_text fields
20
+ * Upgrade to RSolr 0.12.1
21
+ * Switch from LocalSolr to solr-spatial-light
22
+ * Turn off request logging in Jetty for default Solr install
23
+ * Full support for class-reloading of Sunspot-setup classes
24
+ * Support time ranges outside of 32-bit range
25
+ * Remove sunspot-configure-solr executable
26
+ * new_search method accepts DSL block
27
+
28
+ == 0.10.8 2009-11-24
29
+ * Strictly enforce RSolr 0.9.6 gem dependency (newer ones broken)
30
+
1
31
  == 0.10.7 2009-11-16
2
32
  * Ignore boost_fields that don't apply
3
33
  * Ability to specify text_fields inside connectives
data/README.rdoc CHANGED
@@ -2,31 +2,44 @@
2
2
 
3
3
  http://outoftime.github.com/sunspot
4
4
 
5
- Sunspot is a Ruby library for expressive, powerful interaction with the Solr search engine.
6
- Sunspot is built on top of the RSolr gem, which provides a low-level interface for Solr
7
- interaction; Sunspot provides a simple, intuitive, expressive DSL backed by powerful
8
- features for indexing objects and searching for them.
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.
9
10
 
10
11
  Sunspot is designed to be easily plugged in to any ORM, or even non-database-backed
11
12
  objects such as the filesystem.
12
13
 
14
+ === Where to learn all about Sunspot: The Wiki!
15
+
13
16
  This README is intended as a quick primer on what Sunspot is capable of; for
14
17
  detailed treatment of Sunspot's full feature range, check out the wiki:
15
18
  http://wiki.github.com/outoftime/sunspot
16
19
 
20
+ The API documentation is also complete and up-to-date; however, because of the
21
+ way Sunspot is structured, it's not the easiest way for new users to get to know
22
+ the library.
17
23
 
18
24
  === Features:
19
25
 
20
- * Define indexing strategy for each searchable class using intuitive block-based API
21
- * Clean separation between keyword-searchable fields and fields for scoping/ordering
22
- * Define fields based on existing attributes or "virtual fields" for custom indexing
23
- * Indexes each object's entire superclass hierarchy, for easy searching for all objects inheriting from a parent class
24
- * Intuitive DSL for scoping searches, with all the usual boolean operators available
26
+ * Define indexing strategy for each searchable class using intuitive block-based
27
+ API
28
+ * Clean separation between keyword-searchable fields and fields for
29
+ scoping/ordering
30
+ * Define fields based on existing attributes or "virtual fields" for custom
31
+ indexing
32
+ * Indexes each object's entire superclass hierarchy, for easy searching for all
33
+ objects inheriting from a parent class
34
+ * Intuitive DSL for scoping searches, with all the usual boolean operators
35
+ available
25
36
  * Intuitive interface for requesting facets on indexed fields
26
- * Extensible adapter architecture for easy integration of other ORMs or non-model classes
27
- * Refine search using field facets, date range facets, or ultra-powerful query facets
37
+ * Extensible adapter architecture for easy integration of other ORMs or
38
+ non-model classes
39
+ * Refine search using field facets, date range facets, or ultra-powerful
40
+ query facets
28
41
  * Full compatibility with will_paginate
29
- * Ordering
42
+ * Ordering by field value, relevance, geographical distance, or random
30
43
 
31
44
  == Installation
32
45
 
@@ -36,7 +49,8 @@ In order to start the packaged Solr installation, run:
36
49
 
37
50
  sunspot-solr start -- [-d /path/to/data/directory] [-p port] [-s path/to/solr/home] [--pid-dir=path/to/pid/dir]
38
51
 
39
- If you don't specify a data directory, your Solr index will be stored in your operating system's temporary directory.
52
+ If you don't specify a data directory, your Solr index will be stored in your
53
+ operating system's temporary directory.
40
54
 
41
55
  If you specify a solr home, the directory must contain a <code>conf</code>
42
56
  directory, which should contain at least <code>schema.xml</code> and
@@ -52,8 +66,11 @@ You can change the URL at which Sunspot accesses Solr with:
52
66
 
53
67
  == Rails Integration
54
68
 
55
- The {Sunspot::Rails}[http://github.com/outoftime/sunspot_rails] plugin makes
56
- integrating Sunspot into Rails drop-in easy.
69
+ The Sunspot::Rails plugin makes integrating Sunspot into Rails drop-in easy.
70
+
71
+ gem install sunspot_rails
72
+
73
+ See the README for that gem or the Sunspot Wiki for more information.
57
74
 
58
75
  == Using Sunspot
59
76
 
@@ -115,9 +132,8 @@ See Sunspot.search for more information.
115
132
  li.facet_row
116
133
  = link_to(row.instance.name, params.merge(:blog_id => row.value))
117
134
  %span.count== (#{row.count})
118
- .page_info== Displaying page #{@search.page} of #{@search.per_page} out of #{@search.total} results
119
- - @search.hits.each do |hit|
120
- - post = hit.result
135
+ .page_info== Displaying page #{@search.hits.page} of #{@search.hits.per_page} out of #{@search.total} results
136
+ - @search.each_hit_with_result do |hit, post|
121
137
  .search_result
122
138
  %h3.title
123
139
  = link_to(h(hit.stored(:title)), post_url(post))
@@ -136,9 +152,8 @@ me so I can rectify the situation!
136
152
 
137
153
  == Dependencies
138
154
 
139
- 1. RSolr 0.10.1
140
- 2. Daemons 1.x
141
- 4. Java 1.5+
155
+ 1. RSolr
156
+ 2. Java 1.5+
142
157
 
143
158
  Sunspot has been tested with MRI 1.8.6 and 1.8.7, REE 1.8.6, YARV 1.9.1, and
144
159
  JRuby 1.2.0
@@ -157,8 +172,8 @@ guidelines:
157
172
 
158
173
  * Contributions should be submitted via Sunspot's Lighthouse account, with an
159
174
  attached git patch. See below for how to create a git patch.
160
- * Patches should not make any changes in your patch to the gemspec task other
161
- than adding/removing dependencies (e.g., changing the name, version, email,
175
+ * Patches should not make any changes to the gemspec task other than
176
+ adding/removing dependencies (e.g., changing the name, version, email,
162
177
  description, etc.)
163
178
  * Patches should not include any changes to the gemspec itself.
164
179
  * Document any new methods, options, arguments, etc.
@@ -175,14 +190,28 @@ Here's how to create a Git patch - assuming you're pulling from the canonical
175
190
  Sunspot repository at `upstream`:
176
191
 
177
192
  git fetch upstream
178
- git format-patch upstre
193
+ git format-patch --stdout upstream/master.. > my-awesome.patch
194
+
195
+ == Help and Support
196
+
197
+ === Ask for help
198
+
199
+ * Sunspot Discussion: {ruby-sunspot@googlegroups.com}[mailto:ruby-sunspot@googlegroups.com] / http://groups.google.com/group/ruby-sunspot
200
+ * IRC: {#sunspot-ruby @ Freenode}[irc://chat.freenode.net/#sunspot-ruby]
179
201
 
180
- == Further Reading
202
+ === Tutorials and Articles
181
203
 
182
- * Sunspot Discussion: http://groups.google.com/group/ruby-sunspot
183
- * IRC: #sunspot-ruby @ Freenode
184
- * Posts about Sunspot from my tumblog: http://outofti.me/tagged/sunspot
185
- * Read about it on Linux Magazine: http://www.linux-mag.com/id/7341
204
+ * {Full-text search in Rails with Sunspot}[http://tech.favoritemedium.com/2010/01/full-text-search-in-rails-with-sunspot.html] (Tropical Software Observations)
205
+ * {Sunspot Full-text Search for Rails/Ruby}[http://therailworld.com/posts/23-Sunspot-Full-text-Search-for-Rails-Ruby] (The Rail World)
206
+ * {A Few Sunspot Tips}[http://blog.trydionel.com/2009/11/19/a-few-sunspot-tips/] (spiral_code)
207
+ * {Sunspot: A Solr-Powered Search Engine for Ruby}[http://www.linux-mag.com/id/7341] (Linux Magazine)
208
+ * {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...)
209
+ * {Default scope with Sunspot}[http://www.cloudspace.com/blog/2010/01/15/default-scope-with-sunspot/] (Cloudspace)
210
+ * {Testing Sunspot with Cucumber}[http://blog.trydionel.com/2010/02/06/testing-sunspot-with-cucumber/] (spiral_code)
211
+ * {Running cucumber features with sunspot_rails}[http://blog.kabisa.nl/2010/02/03/running-cucumber-features-with-sunspot_rails] (Kabisa Blog)
212
+ * {How To Use Twitter Lists to Determine Influence}[http://www.untitledstartup.com/2010/01/how-to-use-twitter-lists-to-determine-influence/] (Untitled Startup)
213
+ * {Sunspot Quickstart}[http://wiki.websolr.com/index.php/Sunspot_Quickstart] (WebSolr)
214
+ * {Solr, and Sunspot}[http://www.kuahyeow.com/2009/08/solr-and-sunspot.html] (YT!)
186
215
 
187
216
  == Contributors
188
217
 
@@ -196,6 +225,7 @@ Sunspot repository at `upstream`:
196
225
  * Brian Atkinson
197
226
  * Tom Coleman (tom@thesnail.org)
198
227
  * Matt Mitchell (goodieboy@gmail.com)
228
+ * Nathan Beyer (nbeyer@gmail.com)
199
229
 
200
230
  == License
201
231
 
data/Rakefile CHANGED
@@ -4,6 +4,8 @@ task :environment do
4
4
  require File.dirname(__FILE__) + '/lib/sunspot'
5
5
  end
6
6
 
7
+ require File.join(File.dirname(__FILE__), 'lib', 'sunspot', 'version')
8
+
7
9
  Dir['tasks/**/*.rake'].each { |t| load t }
8
10
 
9
11
  task :default => 'spec:api'
data/TODO CHANGED
@@ -1,22 +1,12 @@
1
- <<<<<<< HEAD:TODO
2
- === 0.10.x ===
3
- * Can retrieve facets from search via string
4
- * Allow #latitude and #longitude as coordinate attributes
5
- * Allow use of #text_fields from inside disjunction
6
- =======
7
- === 1.0 ===
8
- * Built-in session proxies; #thread_local_sessions! method
9
- * Support 1.4, retaining 1.3 support if/as much as possible
10
- * Working local + keyword search
11
- * Facet filter exclusion
12
- >>>>>>> d8e4337... Minor API & documentation improvements:TODO
1
+ === Sunspot 1.0 ===
2
+ * new_search should accept block
13
3
 
14
- * Assumed inconsistency
15
- * Support all operations in batches. Make it smart.
16
- * Don't use more than one commits when one is equivalent
17
- * Preserve adds/deletes that are done after last commit
18
- * Don't do adds and deletes for the same document out of order
19
- * Don't do more than one add for the same document
20
- * Do use as few requests as possible within those constraints
21
4
  === Future ===
5
+ * Shorthand arguments to Sunspot#search
6
+ * Rudimentary fulltext prefixing support
7
+ * commitWithin (need solr-ruby support for this)
22
8
  * Support Solr functions (e.g. dismax :bf)
9
+
10
+ === Solr 1.5 ===
11
+ * Field Collapsing (SOLR-236)
12
+ * Support for official spatial support (SOLR-773)
data/VERSION.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  ---
2
- :major: 0
3
2
  :minor: 10
4
- :patch: 9
5
- :build:
3
+ :patch: 8
4
+ :major: 0
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'sunspot', 'installer')
5
+
6
+ home = ARGV.select { |arg| arg !~ /^-/ }.last || Dir.pwd
7
+ options = {}
8
+
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: sunspot-install [options] [solr-home]"
11
+ opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
12
+ options[:verbose] = v
13
+ end
14
+ opts.on('-f', '--[no-]force', 'Overwrite schema and solrconfig files with Sunspot default, instead of modifying them (recommended for new Solr installation)') do |f|
15
+ options[:force] = f
16
+ end
17
+ end.parse!
18
+
19
+ Sunspot::Installer.execute(home, options)
data/bin/sunspot-solr CHANGED
@@ -1,95 +1,70 @@
1
1
  #!/usr/bin/env ruby
2
- using_gems = false
3
2
  begin
4
3
  require 'fileutils'
5
4
  require 'tempfile'
6
5
  require 'tmpdir'
7
6
  require 'optparse'
8
- require 'daemons'
7
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'sunspot', 'server')
9
8
  rescue LoadError => e
10
- if using_gems
11
- raise(e)
12
- else
13
- using_gems = true
14
- require 'rubygems'
9
+ if require 'rubygems'
15
10
  retry
11
+ else
12
+ raise(e)
16
13
  end
17
14
  end
18
15
 
19
- working_directory = FileUtils.pwd
20
- solr_install = File.expand_path(File.join(File.dirname(__FILE__), '..', 'solr'))
21
-
22
- port = '8983'
23
- data_dir = File.expand_path(File.join(Dir.tmpdir, 'solr_data'))
24
- solr_home = File.join(solr_install, 'solr')
25
- pid_dir = working_directory
26
- log_file = nil
27
- log_level = 'OFF'
28
- min_memory = '128m'
29
- max_memory = '512m'
16
+ server = Sunspot::Server.new
30
17
 
31
18
  OptionParser.new do |opts|
32
19
  opts.banner = "Usage: sunspot-solr start [options]"
33
20
 
34
21
  opts.on '-p', '--port=PORT', 'Port on which to run Solr (default 8983)' do |p|
35
- port = p
22
+ server.port = p
36
23
  end
37
24
 
38
25
  opts.on '-d', '--data-directory=DIRECTORY', 'Solr data directory' do |d|
39
- data_dir = File.expand_path(d)
26
+ server.solr_data_dir = File.expand_path(d)
40
27
  end
41
28
 
42
29
  opts.on '-s', '--solr-home=HOME', 'Solr home directory (should contain conf/ directory)' do |s|
43
- solr_home = File.expand_path(s)
30
+ server.solr_home = File.expand_path(s)
44
31
  end
45
32
 
46
33
  opts.on '--pid-dir=PID_DIR', 'Directory for pid files' do |pd|
47
- pid_dir = File.expand_path(pd)
34
+ server.pid_dir = File.expand_path(pd)
48
35
  end
49
36
 
50
37
  opts.on '-l', '--log-level=LOG_LEVEL', 'Solr logging level' do |l|
51
- log_level = l
38
+ server.log_level = l
52
39
  end
53
40
 
54
41
  opts.on '--log-file=LOG_FILE', 'Path to Solr log file' do |lf|
55
- log_file = File.expand_path(lf)
42
+ server.log_file = File.expand_path(lf)
56
43
  end
57
44
 
58
45
  opts.on '--max-memory=MEMORY', 'Specify the maximum size of the memory allocation pool' do |mm|
59
- max_memory = mm
46
+ server.max_memory = mm
60
47
  end
61
48
 
62
49
  opts.on '--min-memory=MEMORY', 'Specify the initial size of the memory allocation pool' do |mm|
63
- min_memory = mm
50
+ server.min_memory = mm
64
51
  end
65
52
  end.parse!
66
53
 
67
- options = { :dir_mode => :normal, :dir => pid_dir }
68
-
69
- def logging_properties( log_file, log_level )
70
- temp_file = Tempfile.new 'logging.properties'
71
- temp_file << <<PROPERTIES
72
- .level = #{log_level}
73
- handlers = java.util.logging.FileHandler
74
- java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
75
- java.util.logging.FileHandler.pattern = #{log_file}
76
- PROPERTIES
77
- temp_file.flush
78
- temp_file.close
79
- temp_file.path
80
- end
81
-
82
- Daemons.run_proc('sunspot-solr', options) do
83
- FileUtils.cd(solr_install) do
84
- args = ['java']
85
- args << "-Xms#{min_memory}"
86
- args << "-Xmx#{max_memory}"
87
- args << "-Djetty.port=#{port}" if port
88
- args << "-Dsolr.data.dir=#{data_dir}" if data_dir
89
- args << "-Dsolr.solr.home=#{solr_home}" if solr_home
90
- args << "-Djava.util.logging.config.file=#{logging_properties(log_file, log_level)}" if log_file and log_level != 'OFF'
91
- args << '-jar' << File.join(solr_install, 'start.jar')
92
- STDERR.puts(args * ' ')
93
- Kernel.exec(*args)
54
+ begin
55
+ case ARGV[0]
56
+ when 'start'
57
+ server.start
58
+ when 'run'
59
+ server.run
60
+ when 'stop'
61
+ server.stop
62
+ when 'restart'
63
+ server.stop
64
+ server.start
65
+ else
66
+ abort("Usage: sunspot-solr (start|stop|run)")
94
67
  end
68
+ rescue Sunspot::Server::ServerError => e
69
+ abort(e.message)
95
70
  end
@@ -0,0 +1,71 @@
1
+ types: !omap
2
+ - text:
3
+ class: TextField
4
+ suffix: text
5
+ omit_norms: false
6
+ tokenizer: StandardTokenizerFactory
7
+ filters:
8
+ - StandardFilterFactory
9
+ - LowerCaseFilterFactory
10
+ invariants:
11
+ multiValued: true
12
+ - boolean:
13
+ class: BoolField
14
+ suffix: b
15
+ - date:
16
+ class: DateField
17
+ suffix: d
18
+ - rand:
19
+ class: RandomSortField
20
+ - sdouble:
21
+ class: SortableDoubleField
22
+ suffix: e
23
+ - sfloat:
24
+ class: SortableFloatField
25
+ suffix: f
26
+ - sint:
27
+ class: SortableIntField
28
+ suffix: i
29
+ - slong:
30
+ class: SortableLongField
31
+ suffix: l
32
+ - string:
33
+ class: StrField
34
+ suffix: s
35
+ - tint:
36
+ class: TrieIntField
37
+ suffix: it
38
+ - tfloat:
39
+ class: TrieFloatField
40
+ suffix: ft
41
+ - tdouble:
42
+ class: TrieDoubleField
43
+ - tdate:
44
+ class: TrieDateField
45
+ suffix: dt
46
+ fixed: !omap
47
+ - id:
48
+ type: string
49
+ attributes: [stored]
50
+ - type:
51
+ type: string
52
+ attributes: [multiValued]
53
+ - class_name:
54
+ type: string
55
+ - text:
56
+ type: string
57
+ attributes: [multiValued]
58
+ - lat:
59
+ type: tdouble
60
+ attributes: [stored]
61
+ - lng:
62
+ type: tdouble
63
+ attributes: [stored]
64
+ - 'random_*':
65
+ type: rand
66
+ - '_local*':
67
+ type: tdouble
68
+
69
+ variants: !omap
70
+ - multiValued: m
71
+ - stored: s
@@ -2,16 +2,6 @@ module Sunspot
2
2
  # The Sunspot::Configuration module provides a factory method for Sunspot
3
3
  # configuration objects. Available properties are:
4
4
  #
5
- # Sunspot.config.http_client::
6
- # The client to use for HTTP communication with Solr. Available options are
7
- # :net_http, which is the default and uses Ruby's built-in pure-Ruby HTTP
8
- # library; and :curb, which uses Ruby's libcurl bindings and requires
9
- # installation of the 'curb' gem.
10
- # Sunspot.config.xml_builder::
11
- # The library use to build XML messages sent to Solr. As of this writing the
12
- # options are :builder and :libxml - the latter is faster but less portable,
13
- # as it is native code. Check the documentation for RSolr::Message::Adapter
14
- # for more information.
15
5
  # Sunspot.config.solr.url::
16
6
  # The URL at which to connect to Solr
17
7
  # (default: 'http://localhost:8983/solr')
@@ -38,10 +38,91 @@ module Sunspot
38
38
  order_by(:random)
39
39
  end
40
40
 
41
- # Request facets on the given field names. If the last argument is a hash,
42
- # the given options will be applied to all specified fields. See
43
- # Sunspot::Search#facet and Sunspot::Facet for information on what is
44
- # returned.
41
+ #
42
+ # Request a facet on the search query. A facet is a feature of Solr that
43
+ # determines the number of documents that match the existing search *and*
44
+ # an additional criterion. This allows you to build powerful drill-down
45
+ # interfaces for search, at each step presenting the searcher with a set
46
+ # of refinements that are known to return results.
47
+ #
48
+ # In Sunspot, each facet returns zero or more rows, each of which
49
+ # represents a particular criterion conjoined with the actual query being
50
+ # performed. For _field_ _facets_, each row represents a particular value
51
+ # for a given field. For _query_ _facets_, each row represents an
52
+ # arbitrary scope; the facet itself is just a means of logically grouping
53
+ # the scopes.
54
+ #
55
+ # === Examples
56
+ #
57
+ # ==== Field Facets
58
+ #
59
+ # A field facet is specified by passing one or more Symbol arguments to
60
+ # this method:
61
+ #
62
+ # Sunspot.search(Post) do
63
+ # with(:blog_id, 1)
64
+ # facet(:category_id)
65
+ # end
66
+ #
67
+ # The facet specified above will have a row for each category_id that is
68
+ # present in a document which also has a blog_id of 1.
69
+ #
70
+ # ==== Multiselect Facets
71
+ #
72
+ # In certain circumstances, it is beneficial to exclude certain query
73
+ # scopes from a facet; the most common example is multi-select faceting,
74
+ # where the user has selected a certain value, but the facet should still
75
+ # show all options that would be available if they had not:
76
+ #
77
+ # Sunspot.search(Post) do
78
+ # with(:blog_id, 1)
79
+ # category_filter = with(:category_id, 2)
80
+ # facet(:category_id, :exclude => category_filter)
81
+ # end
82
+ #
83
+ # Although the results of the above search will be restricted to those
84
+ # with a category_id of 2, the category_id facet will operate as if a
85
+ # category had not been selected, allowing the user to select additional
86
+ # categories (which will presumably be ORed together).
87
+ #
88
+ # <strong>As far as I can tell, Solr only supports multi-select with
89
+ # field facets; if +:exclude+ is passed to a query facet, this method will
90
+ # raise an error. Also, the +:only+ and +:extra+ options use query
91
+ # faceting under the hood, so these can't be used with +:extra+ either.
92
+ # </strong>
93
+ #
94
+ # ==== Query Facets
95
+ #
96
+ # A query facet is a collection of arbitrary scopes, each of which
97
+ # represents a row. This is specified by passing a block into the #facet
98
+ # method; the block then contains one or more +row+ blocks, each of which
99
+ # creates a query facet row. The +row+ blocks follow the usual Sunspot
100
+ # scope DSL.
101
+ #
102
+ # For example, a query facet can be used to facet over a set of ranges:
103
+ #
104
+ # Sunspot.search(Post) do
105
+ # facet(:average_rating) do
106
+ # row(1.0..2.0) do
107
+ # with(:average_rating, 1.0..2.0)
108
+ # end
109
+ # row(2.0..3.0) do
110
+ # with(:average_rating, 2.0..3.0)
111
+ # end
112
+ # row(3.0..4.0) do
113
+ # with(:average_rating, 3.0..4.0)
114
+ # end
115
+ # row(4.0..5.0) do
116
+ # with(:average_rating, 4.0..5.0)
117
+ # end
118
+ # end
119
+ # end
120
+ #
121
+ # Note that the arguments to the +facet+ and +row+ methods simply provide
122
+ # labels for the facet and its rows, so that they can be retrieved and
123
+ # identified from the Search object. They are not passed to Solr and no
124
+ # semantic meaning is attached to them. The label for +facet+ should be
125
+ # a symbol; the label for +row+ can be whatever you'd like.
45
126
  #
46
127
  # ==== Parameters
47
128
  #
@@ -58,12 +139,29 @@ module Sunspot
58
139
  # :zeros<Boolean>::
59
140
  # Return facet rows for which there are no matches (equivalent to
60
141
  # :minimum_count => 0). Default is false.
142
+ # :exclude<Object,Array>::
143
+ # Exclude one or more filters when performing the faceting (see
144
+ # Multiselect Faceting above). The object given for this argument should
145
+ # be the return value(s) of a scoping method (+with+, +any_of+,
146
+ # +all_of+, etc.). <strong>Only can be used for field facets that do not
147
+ # use the +:extra+ or +:only+ options.</strong>
148
+ # :name<Symbol>::
149
+ # Give a custom name to a field facet. The main use case for this option
150
+ # is for requesting the same field facet multiple times, using different
151
+ # filter exclusions (see Multiselect Faceting above). If you pass this
152
+ # option, it is also the argument that should be passed to Search#facet
153
+ # when retrieving the facet result.
154
+ # :only<Array>::
155
+ # Only return facet rows for the given values. Useful if you are only
156
+ # interested in faceting on a subset of values for a given field.
157
+ # <strong>Only applies to field facets.</strong>
61
158
  # :extra<Symbol,Array>::
62
159
  # One or more of :any and :none. :any returns a facet row with a count
63
160
  # of all matching documents that have some value for this field. :none
64
161
  # returns a facet row with a count of all matching documents that have
65
162
  # no value for this field. The facet row(s) corresponding to the extras
66
- # have a value of the symbol passed.
163
+ # have a value of the symbol passed. <strong>Only applies to field
164
+ # facets.</strong>
67
165
  #
68
166
  def facet(*field_names, &block)
69
167
  options = Sunspot::Util.extract_options_from(field_names)
@@ -75,12 +173,24 @@ module Sunspot
75
173
  "wrong number of arguments (#{field_names.length} for 1)"
76
174
  )
77
175
  end
176
+ if options.has_key?(:exclude)
177
+ raise(
178
+ ArgumentError,
179
+ "can't use :exclude with query facets"
180
+ )
181
+ end
78
182
  search_facet = @search.add_query_facet(field_names.first, options)
79
183
  Sunspot::Util.instance_eval_or_call(
80
184
  QueryFacet.new(@query, @setup, search_facet),
81
185
  &block
82
186
  )
83
187
  elsif options[:only]
188
+ if options.has_key?(:exclude)
189
+ raise(
190
+ ArgumentError,
191
+ "can't use :exclude with :only (see documentation)"
192
+ )
193
+ end
84
194
  field_names.each do |field_name|
85
195
  field = @setup.field(field_name)
86
196
  search_facet = @search.add_field_facet(field, options)
@@ -97,7 +207,7 @@ module Sunspot
97
207
  field = @setup.field(field_name)
98
208
  facet =
99
209
  if options[:time_range]
100
- unless field.type == Sunspot::Type::TimeType
210
+ unless field.type.is_a?(Sunspot::Type::TimeType)
101
211
  raise(
102
212
  ArgumentError,
103
213
  ':time_range can only be specified for Date or Time fields'
@@ -106,11 +216,17 @@ module Sunspot
106
216
  search_facet = @search.add_date_facet(field, options)
107
217
  Sunspot::Query::DateFieldFacet.new(field, options)
108
218
  else
109
- search_facet = @search.add_field_facet(field)
219
+ search_facet = @search.add_field_facet(field, options)
110
220
  Sunspot::Query::FieldFacet.new(field, options)
111
221
  end
112
222
  @query.add_field_facet(facet)
113
223
  Util.Array(options[:extra]).each do |extra|
224
+ if options.has_key?(:exclude)
225
+ raise(
226
+ ArgumentError,
227
+ "can't use :exclude with :extra (see documentation)"
228
+ )
229
+ end
114
230
  extra_facet = Sunspot::Query::QueryFacet.new
115
231
  case extra
116
232
  when :any