kuahyeow-sunspot 0.9.8 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/History.txt +38 -0
  2. data/README.rdoc +40 -3
  3. data/TODO +10 -8
  4. data/VERSION.yml +2 -2
  5. data/bin/sunspot-configure-solr +22 -28
  6. data/bin/sunspot-solr +50 -29
  7. data/lib/sunspot.rb +8 -18
  8. data/lib/sunspot/adapters.rb +1 -1
  9. data/lib/sunspot/composite_setup.rb +13 -15
  10. data/lib/sunspot/configuration.rb +21 -0
  11. data/lib/sunspot/data_extractor.rb +3 -0
  12. data/lib/sunspot/dsl.rb +2 -1
  13. data/lib/sunspot/dsl/field_query.rb +33 -6
  14. data/lib/sunspot/dsl/fields.rb +14 -1
  15. data/lib/sunspot/dsl/fulltext.rb +168 -0
  16. data/lib/sunspot/dsl/query.rb +82 -5
  17. data/lib/sunspot/dsl/query_facet.rb +3 -3
  18. data/lib/sunspot/dsl/restriction.rb +7 -7
  19. data/lib/sunspot/dsl/scope.rb +17 -10
  20. data/lib/sunspot/dsl/search.rb +2 -2
  21. data/lib/sunspot/facet.rb +12 -39
  22. data/lib/sunspot/facet_data.rb +169 -0
  23. data/lib/sunspot/facet_row.rb +5 -27
  24. data/lib/sunspot/field.rb +50 -26
  25. data/lib/sunspot/field_factory.rb +15 -0
  26. data/lib/sunspot/indexer.rb +6 -0
  27. data/lib/sunspot/instantiated_facet.rb +7 -6
  28. data/lib/sunspot/instantiated_facet_row.rb +16 -1
  29. data/lib/sunspot/query.rb +2 -187
  30. data/lib/sunspot/query/boost_query.rb +20 -0
  31. data/lib/sunspot/query/connective.rb +98 -35
  32. data/lib/sunspot/query/dismax.rb +73 -0
  33. data/lib/sunspot/query/field_facet.rb +3 -23
  34. data/lib/sunspot/query/fulltext_base_query.rb +47 -0
  35. data/lib/sunspot/query/highlighting.rb +43 -0
  36. data/lib/sunspot/query/local.rb +24 -0
  37. data/lib/sunspot/query/pagination.rb +3 -4
  38. data/lib/sunspot/query/query.rb +93 -0
  39. data/lib/sunspot/query/query_facet.rb +15 -9
  40. data/lib/sunspot/query/query_facet_row.rb +3 -3
  41. data/lib/sunspot/query/query_field_facet.rb +20 -0
  42. data/lib/sunspot/query/restriction.rb +36 -15
  43. data/lib/sunspot/query/scope.rb +3 -159
  44. data/lib/sunspot/query/sort.rb +84 -15
  45. data/lib/sunspot/query/text_field_boost.rb +15 -0
  46. data/lib/sunspot/schema.rb +7 -25
  47. data/lib/sunspot/search.rb +63 -45
  48. data/lib/sunspot/search/highlight.rb +38 -0
  49. data/lib/sunspot/search/hit.rb +50 -3
  50. data/lib/sunspot/session.rb +40 -11
  51. data/lib/sunspot/setup.rb +47 -10
  52. data/lib/sunspot/text_field_setup.rb +29 -0
  53. data/lib/sunspot/type.rb +4 -4
  54. data/lib/sunspot/util.rb +27 -1
  55. data/solr/solr/conf/schema.xml +54 -40
  56. data/solr/solr/conf/solrconfig.xml +30 -0
  57. data/solr/solr/lib/geoapi-nogenerics-2.1-M2.jar +0 -0
  58. data/solr/solr/lib/gt2-referencing-2.3.1.jar +0 -0
  59. data/solr/solr/lib/jsr108-0.01.jar +0 -0
  60. data/solr/solr/lib/locallucene.jar +0 -0
  61. data/solr/solr/lib/localsolr.jar +0 -0
  62. data/spec/api/indexer/attributes_spec.rb +100 -0
  63. data/spec/api/indexer/batch_spec.rb +46 -0
  64. data/spec/api/indexer/dynamic_fields_spec.rb +33 -0
  65. data/spec/api/indexer/fixed_fields_spec.rb +57 -0
  66. data/spec/api/indexer/fulltext_spec.rb +43 -0
  67. data/spec/api/indexer/removal_spec.rb +46 -0
  68. data/spec/api/indexer/spec_helper.rb +1 -0
  69. data/spec/api/indexer_spec.rb +1 -308
  70. data/spec/api/query/connectives_spec.rb +162 -0
  71. data/spec/api/query/dsl_spec.rb +12 -0
  72. data/spec/api/query/dynamic_fields_spec.rb +149 -0
  73. data/spec/api/query/faceting_spec.rb +272 -0
  74. data/spec/api/query/fulltext_spec.rb +193 -0
  75. data/spec/api/query/highlighting_spec.rb +138 -0
  76. data/spec/api/query/local_spec.rb +54 -0
  77. data/spec/api/query/ordering_pagination_spec.rb +95 -0
  78. data/spec/api/query/scope_spec.rb +266 -0
  79. data/spec/api/query/spec_helper.rb +1 -0
  80. data/spec/api/query/text_field_scoping_spec.rb +30 -0
  81. data/spec/api/query/types_spec.rb +20 -0
  82. data/spec/api/search/dynamic_fields_spec.rb +27 -0
  83. data/spec/api/search/faceting_spec.rb +206 -0
  84. data/spec/api/search/highlighting_spec.rb +65 -0
  85. data/spec/api/search/hits_spec.rb +62 -0
  86. data/spec/api/search/results_spec.rb +52 -0
  87. data/spec/api/search/search_spec.rb +23 -0
  88. data/spec/api/search/spec_helper.rb +1 -0
  89. data/spec/api/session_spec.rb +11 -5
  90. data/spec/api/spec_helper.rb +1 -1
  91. data/spec/helpers/indexer_helper.rb +29 -0
  92. data/spec/helpers/query_helper.rb +13 -0
  93. data/spec/helpers/search_helper.rb +78 -0
  94. data/spec/integration/faceting_spec.rb +1 -1
  95. data/spec/integration/highlighting_spec.rb +22 -0
  96. data/spec/integration/keyword_search_spec.rb +65 -0
  97. data/spec/integration/local_search_spec.rb +56 -0
  98. data/spec/integration/scoped_search_spec.rb +15 -1
  99. data/spec/integration/spec_helper.rb +7 -1
  100. data/spec/mocks/connection.rb +24 -2
  101. data/spec/mocks/photo.rb +1 -1
  102. data/spec/mocks/post.rb +5 -3
  103. data/spec/mocks/super_class.rb +2 -0
  104. data/spec/spec_helper.rb +13 -0
  105. data/tasks/gemspec.rake +20 -8
  106. data/tasks/schema.rake +1 -1
  107. data/tasks/spec.rake +1 -1
  108. data/templates/schema.xml.erb +36 -0
  109. metadata +118 -52
  110. data/lib/sunspot/date_facet.rb +0 -36
  111. data/lib/sunspot/date_facet_row.rb +0 -17
  112. data/lib/sunspot/query/base_query.rb +0 -94
  113. data/lib/sunspot/query/dynamic_query.rb +0 -69
  114. data/lib/sunspot/query/field_query.rb +0 -57
  115. data/lib/sunspot/query_facet.rb +0 -33
  116. data/lib/sunspot/query_facet_row.rb +0 -21
  117. data/spec/api/build_search_spec.rb +0 -1018
  118. data/spec/api/query_spec.rb +0 -153
  119. data/spec/api/search_retrieval_spec.rb +0 -335
  120. data/templates/schema.xml.haml +0 -24
@@ -1,3 +1,41 @@
1
+ == 0.10.2 2009-10-09
2
+ * Add Sunspot.config.xml_builder option, which is passed to RSolr
3
+
4
+ == 0.10.1 2009-10-08
5
+ * Fix directory bugs in sunspot-solr executable
6
+
7
+ == 0.10.0 2009-10-08
8
+ * Support for geographical search using LocalSolr
9
+ * Support for keyword highlighting, with custom deferred formatting
10
+ * New fulltext DSL for specifying advanced dismax options
11
+ * Support boost queries
12
+ * Support for search-time field boost
13
+ * Support for phrase fields
14
+ * Support for prefix queries
15
+ * Set default search-time field boost in setup
16
+ * Restrict field facet to a set of desired values
17
+ * Query facets support all facet options
18
+ * Allow scoping by text fields
19
+ * Support executing searches repeatedly
20
+ * Allow setting of Solr URL for integration tests in environment variable
21
+ * Add support for master/slave configurations
22
+ * Added logging options to sunspot-solr executable
23
+ * Added default solr config file location to Sunspot::Configuration
24
+ * Informative, non-firehose Search#inspect
25
+ * No longer require arguments to #paginate
26
+ * Silently ignore keyword calls with nil/blank/whitespace keywords
27
+ * Don't require that all searched types have a referenced field
28
+ * Correct backwards ranges
29
+ * Raise descriptive error if no types passed to search
30
+ * Handle empty query facets, query facet rows, and connectives
31
+ * Quote values in range restrictions if they contain spaces
32
+ * Fix bug in Sunspot::Util.full_const_get
33
+ * Remove support for :other option in time faceting
34
+ * Remove order_by_random() method
35
+ * Removed options and Query from public API
36
+ * Use built-in optparse instead of optiflag in bin/sunspot-solr
37
+ * Remove dependency on haml and use erb since it is only used to generate one file
38
+
1
39
  == 0.9.0 2009-07-21
2
40
  * Use Dismax parser for keyword search
3
41
  * Field and document boosting
@@ -10,6 +10,11 @@ features for indexing objects and searching for them.
10
10
  Sunspot is designed to be easily plugged in to any ORM, or even non-database-backed
11
11
  objects such as the filesystem.
12
12
 
13
+ This README is intended as a quick primer on what Sunspot is capable of; for
14
+ detailed treatment of Sunspot's full feature range, check out the wiki:
15
+ http://wiki.github.com/outoftime/sunspot
16
+
17
+
13
18
  === Features:
14
19
 
15
20
  * Define indexing strategy for each searchable class using intuitive block-based API
@@ -123,9 +128,7 @@ me so I can rectify the situation!
123
128
 
124
129
  1. RSolr
125
130
  2. Daemons
126
- 3. OptiFlag
127
- 4. Haml
128
- 5. Java
131
+ 4. Java
129
132
 
130
133
  Sunspot has been tested with MRI 1.8.6 and 1.8.7, REE 1.8.6, YARV 1.9.1, and
131
134
  JRuby 1.2.0
@@ -135,6 +138,35 @@ JRuby 1.2.0
135
138
  Please submit bug reports to
136
139
  http://outoftime.lighthouseapp.com/projects/20339-sunspot
137
140
 
141
+ == Contribution Guidelines
142
+
143
+ Contributions are very welcome - both new features, enhancements, and bug fixes.
144
+ Bug reports with a failing regression test are also lovely. In order to keep the
145
+ contribution process as organized and smooth as possible, please follow these
146
+ guidelines:
147
+
148
+ * Contributions should be submitted via Sunspot's Lighthouse account, with an
149
+ attached git patch. See below for how to create a git patch.
150
+ * Patches should not make any changes in your patch to the gemspec task other
151
+ than adding/removing dependencies (e.g., changing the name, version, email,
152
+ description, etc.)
153
+ * Patches should not include any changes to the gemspec itself.
154
+ * Document any new methods, options, arguments, etc.
155
+ * Write tests.
156
+ * As much as possible, follow the coding and testing styles you see in existing
157
+ code. One could accuse me of being nitpicky about this, but consistent code is
158
+ easier to read, maintain, and enhance.
159
+ * Don't make any massive changes to the structure of library or test code. If
160
+ you think something needs a huge refactor or rearrangement, shoot me a
161
+ message; trying to apply that kind of patch without warning opens the door to
162
+ a world of conflict hurt.
163
+
164
+ Here's how to create a Git patch - assuming you're pulling from the canonical
165
+ Sunspot repository at `upstream`:
166
+
167
+ git fetch upstream
168
+ git format-patch upstre
169
+
138
170
  == Further Reading
139
171
 
140
172
  * Sunspot Discussion: http://groups.google.com/group/ruby-sunspot
@@ -148,6 +180,11 @@ http://outoftime.lighthouseapp.com/projects/20339-sunspot
148
180
  * Peer Allan (peer.allan@gmail.com)
149
181
  * Dmitriy Dzema (dima@dzema.name)
150
182
  * Benjamin Krause (bk@benjaminkrause.com)
183
+ * Marcel de Graaf (marcel@slashdev.nl)
184
+ * Brandon Keepers (brandon@opensoul.org)
185
+ * Peter Berkenbosch (peterberkenbosch@me.com)
186
+ * Brian Atkinson
187
+ * Tom Coleman (tom@thesnail.org)
151
188
 
152
189
  == License
153
190
 
data/TODO CHANGED
@@ -1,9 +1,11 @@
1
- === 0.9.X ===
2
- * Deal with empty facet queries
3
- * Passing an integer into the second argument of dynamic_facet() when multiple facets are requested gives the wrong value
4
1
  === 0.10 ===
5
- * Highlighting
6
- * LocalSolr
7
- * Text field restrictions
8
- * Prefixes
9
- * Intelligently decide whether to instantiate all facet rows at once
2
+ * Wrap everything into :q parameter when local search performed
3
+ * Allow boosting without field constraints
4
+ * Allow coordinates to be specified with block in setup
5
+ === 0.11 ===
6
+ * Support all operations in batches. Make it smart.
7
+ * Don't use more than one commits when one is equivalent
8
+ * Preserve adds/deletes that are done after last commit
9
+ * Don't do adds and deletes for the same document out of order
10
+ * Don't do more than one add for the same document
11
+ * Do use as few requests as possible within those constraints
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 8
2
+ :minor: 10
3
+ :patch: 3
3
4
  :major: 0
4
- :minor: 9
@@ -1,39 +1,33 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- using_gems = false
4
- begin
5
- require 'fileutils'
6
- require 'optiflag'
7
- require File.join(File.dirname(__FILE__), '..', 'lib', 'sunspot', 'schema')
8
- rescue LoadError => e
9
- if using_gems
10
- raise(e)
11
- else
12
- using_gems = true
13
- require 'rubygems'
14
- retry
3
+ require 'fileutils'
4
+ require 'optparse'
5
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'sunspot', 'schema')
6
+
7
+ solr_directory = FileUtils.pwd
8
+
9
+ schema = Sunspot::Schema.new
10
+
11
+ OptionParser.new do |opts|
12
+ opts.banner = 'Usage: sunspot-configure-solr [options]'
13
+
14
+ opts.on '--tokenizer=TOKENIZER', 'Tokenizer class to use' do |tokenizer|
15
+ schema.tokenizer = tokenizer
15
16
  end
16
- end
17
17
 
18
- module ConfigureSolrFlags extend OptiFlagSet
19
- optional_flag 'tokenizer'
20
- optional_flag 'extra_filters'
21
- optional_flag 'dir'
22
- and_process!
23
- end
18
+ opts.on '--extra-filter=EXTRA_FILTER', 'Extra filters for tokenized text (you may specify this multiple times)' do |extra_filter|
19
+ schema.add_filter(extra_filter)
20
+ end
21
+
22
+ opts.on '--dir=CONF_DIR', 'Directory containing Solr configuration and schema' do |dir|
23
+ solr_directory = File.expand_path(dir)
24
+ end
25
+ end.parse!
24
26
 
25
- solr_directory = ARGV.flags.dir || FileUtils.pwd
26
27
  conf_directory = File.join(solr_directory, 'conf')
27
28
  schema_file = File.join(conf_directory, 'schema.xml')
28
- FileUtils.mkdir_p(conf_directory)
29
29
 
30
- schema = Sunspot::Schema.new
31
- schema.tokenizer = ARGV.flags.tokenizer if ARGV.flags.tokenizer
32
- if ARGV.flags.extra_filters
33
- for filter in ARGV.flags.extra_filters.split(',')
34
- schema.add_filter(filter)
35
- end
36
- end
30
+ FileUtils.mkdir_p(conf_directory)
37
31
 
38
32
  if File.exist?(schema_file)
39
33
  backup_file = File.join(conf_directory, "schema-#{File.mtime(schema_file).strftime('%Y%m%d%H%M%S')}.xml")
@@ -2,9 +2,10 @@
2
2
  using_gems = false
3
3
  begin
4
4
  require 'fileutils'
5
+ require 'tempfile'
5
6
  require 'tmpdir'
7
+ require 'optparse'
6
8
  require 'daemons'
7
- require 'optiflag'
8
9
  rescue LoadError => e
9
10
  if using_gems
10
11
  raise(e)
@@ -16,47 +17,67 @@ rescue LoadError => e
16
17
  end
17
18
 
18
19
  working_directory = FileUtils.pwd
19
- solr_home = File.join(File.dirname(__FILE__), '..', 'solr')
20
+ solr_install = File.expand_path(File.join(File.dirname(__FILE__), '..', 'solr'))
20
21
 
21
- module SolrFlags extend OptiFlagSet
22
- optional_flag 'p' do
23
- description 'Port on which to run Solr (default 8983)'
24
- long_form 'port'
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
+
29
+ OptionParser.new do |opts|
30
+ opts.banner = "Usage: sunspot-solr start [options]"
31
+
32
+ opts.on '-p', '--port=PORT', 'Port on which to run Solr (default 8983)' do |p|
33
+ port = p
25
34
  end
26
35
 
27
- optional_flag 'd' do
28
- description 'Solr data directory'
36
+ opts.on '-d', '--data-directory=DIRECTORY', 'Solr data directory' do |d|
37
+ data_dir = File.expand_path(d)
29
38
  end
30
39
 
31
- optional_flag 's' do
32
- description 'Solr home (should contain conf/ directory)'
40
+ opts.on '-s', '--solr-home=HOME', 'Solr home directory (should contain conf/ directory)' do |s|
41
+ solr_home = File.expand_path(s)
33
42
  end
34
43
 
35
- optional_flag 'pd' do
36
- long_form 'pid-dir'
37
- description 'Directory for pid files'
44
+ opts.on '--pid-dir=PID_DIR', 'Directory for pid files' do |pd|
45
+ pid_dir = File.expand_path(pd)
38
46
  end
39
47
 
40
- and_process!
41
- end
48
+ opts.on '-l', '--log-level=LOG_LEVEL', 'Solr logging level' do |l|
49
+ log_level = l
50
+ end
42
51
 
43
- port = ARGV.flags.p || '8983'
44
- data_dir = File.expand_path(ARGV.flags.d || File.join(Dir.tmpdir, 'solr_data'))
45
- home = File.expand_path(ARGV.flags.s) if ARGV.flags.s
46
- pid_dir = File.expand_path(ARGV.flags.pd || working_directory)
52
+ opts.on '--log-file=LOG_FILE', 'Path to Solr log file' do |lf|
53
+ log_file = File.expand_path(lf)
54
+ end
55
+ end.parse!
47
56
 
48
57
  options = { :dir_mode => :normal, :dir => pid_dir }
49
58
 
59
+ def logging_properties( log_file, log_level )
60
+ temp_file = Tempfile.new 'logging.properties'
61
+ temp_file << <<PROPERTIES
62
+ .level = #{log_level}
63
+ handlers = java.util.logging.FileHandler
64
+ java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
65
+ java.util.logging.FileHandler.pattern = #{log_file}
66
+ PROPERTIES
67
+ temp_file.flush
68
+ temp_file.close
69
+ temp_file.path
70
+ end
71
+
50
72
  Daemons.run_proc('sunspot-solr', options) do
51
- FileUtils.cd(working_directory) do
52
- FileUtils.cd(solr_home) do
53
- args = ['java']
54
- args << "-Djetty.port=#{port}" if port
55
- args << "-Dsolr.data.dir=#{data_dir}" if data_dir
56
- args << "-Dsolr.solr.home=#{home}" if home
57
- args << '-jar' << 'start.jar'
58
- STDERR.puts(args * ' ')
59
- Kernel.exec(*args)
60
- end
73
+ FileUtils.cd(solr_install) do
74
+ args = ['java']
75
+ args << "-Djetty.port=#{port}" if port
76
+ args << "-Dsolr.data.dir=#{data_dir}" if data_dir
77
+ args << "-Dsolr.solr.home=#{solr_home}" if solr_home
78
+ args << "-Djava.util.logging.config.file=#{logging_properties(log_file, log_level)}" if log_file and log_level != 'OFF'
79
+ args << '-jar' << File.join(solr_install, 'start.jar')
80
+ STDERR.puts(args * ' ')
81
+ Kernel.exec(*args)
61
82
  end
62
83
  end
@@ -9,10 +9,10 @@ end
9
9
 
10
10
  require File.join(File.dirname(__FILE__), 'light_config')
11
11
 
12
- %w(util adapters configuration setup composite_setup field field_factory
13
- data_extractor indexer query search facet facet_row instantiated_facet
14
- instantiated_facet_row date_facet date_facet_row query_facet query_facet_row
15
- session type dsl).each do |filename|
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
16
  require File.join(File.dirname(__FILE__), 'sunspot', filename)
17
17
  end
18
18
 
@@ -36,6 +36,7 @@ module Sunspot
36
36
  UnrecognizedRestrictionError = Class.new(Exception)
37
37
  NoAdapterError = Class.new(Exception)
38
38
  NoSetupError = Class.new(Exception)
39
+ IllegalSearchError = Class.new(Exception)
39
40
 
40
41
  class <<self
41
42
  # Configures indexing and search for a given class.
@@ -222,18 +223,6 @@ module Sunspot
222
223
  # Zero, one, or more types to search for. If no types are passed, all
223
224
  # configured types will be searched.
224
225
  #
225
- # ==== Options (last argument, optional)
226
- #
227
- # :keywords<String>:: Fulltext search string
228
- # :conditions<Hash>::
229
- # Hash of key-value pairs to be used as restrictions. Keys are field
230
- # names. Scalar values are used as equality restrictions; arrays are used
231
- # as "any of" restrictions; and Ranges are used as range restrictions.
232
- # :order<String>:: order field and direction (e.g., 'updated_at desc')
233
- # :page<Integer>:: Page to start on for pagination
234
- # :per_page<Integer>::
235
- # Number of results to use per page. Ignored if :page is not specified.
236
- #
237
226
  # ==== Returns
238
227
  #
239
228
  # Sunspot::Search:: Object containing results, facets, count, etc.
@@ -242,9 +231,10 @@ module Sunspot
242
231
  # the following criteria:
243
232
  #
244
233
  # * They are not of type +text+.
245
- # * They are defined for all of the classes being searched
246
- # * They have the same data type for all of the classes being searched
234
+ # * They are defined for at least one of the classes being searched
235
+ # * They have the same data type for all of the classes being searched.
247
236
  # * They have the same multiple flag for all of the classes being searched.
237
+ # * They have the same stored flag for all of the classes being searched.
248
238
  #
249
239
  # The restrictions available are the constants defined in the
250
240
  # Sunspot::Restriction class. The standard restrictions are:
@@ -127,7 +127,7 @@ module Sunspot
127
127
  "No adapter is configured for #{original_class_name} or its superclasses. See the documentation for Sunspot::Adapters")
128
128
  end
129
129
 
130
- def index_id_for(class_name, id)
130
+ def index_id_for(class_name, id) #:nodoc:
131
131
  "#{class_name} #{id}"
132
132
  end
133
133
 
@@ -48,7 +48,7 @@ module Sunspot
48
48
  # UnrecognizedFieldError::
49
49
  # If no field with that name is configured for any of the enclosed types.
50
50
  #
51
- def text_field(field_name)
51
+ def text_fields(field_name)
52
52
  text_fields_hash[field_name.to_sym] || raise(
53
53
  UnrecognizedFieldError,
54
54
  "No text field configured for #{@types * ', '} with name '#{field_name}'"
@@ -104,8 +104,8 @@ module Sunspot
104
104
  #
105
105
  # Array:: Text fields configured for the enclosed types
106
106
  #
107
- def text_fields
108
- @text_fields ||= text_fields_hash.values
107
+ def all_text_fields
108
+ @text_fields ||= text_fields_hash.values.map { |set| set.to_a }.flatten
109
109
  end
110
110
 
111
111
  private
@@ -121,8 +121,8 @@ module Sunspot
121
121
  def text_fields_hash
122
122
  @text_fields_hash ||=
123
123
  setups.inject({}) do |hash, setup|
124
- setup.text_fields.each do |text_field|
125
- hash[text_field.name] ||= text_field
124
+ setup.all_text_fields.each do |text_field|
125
+ (hash[text_field.name] ||= Set.new) << text_field
126
126
  end
127
127
  hash
128
128
  end
@@ -141,21 +141,19 @@ module Sunspot
141
141
  def fields_hash
142
142
  @fields_hash ||=
143
143
  begin
144
- fields_hash = @types.inject({}) do |hash, type|
144
+ field_sets_hash = Hash.new { |h, k| h[k] = Set.new }
145
+ @types.each do |type|
145
146
  Setup.for(type).fields.each do |field|
146
- (hash[field.name.to_sym] ||= {})[type.name] = field
147
+ field_sets_hash[field.name.to_sym] << field
147
148
  end
148
- hash
149
149
  end
150
- fields_hash.each_pair do |field_name, field_configurations_hash|
151
- if @types.any? { |type| field_configurations_hash[type.name].nil? } # at least one type doesn't have this field configured
152
- fields_hash.delete(field_name)
153
- elsif field_configurations_hash.values.map { |configuration| configuration.indexed_name }.uniq.length != 1 # fields with this name have different configs
154
- fields_hash.delete(field_name)
155
- else
156
- fields_hash[field_name] = field_configurations_hash.values.first
150
+ fields_hash = {}
151
+ field_sets_hash.each_pair do |field_name, set|
152
+ if set.length == 1
153
+ fields_hash[field_name] = set.to_a.first
157
154
  end
158
155
  end
156
+ fields_hash
159
157
  end
160
158
  end
161
159
 
@@ -7,6 +7,11 @@ module Sunspot
7
7
  # :net_http, which is the default and uses Ruby's built-in pure-Ruby HTTP
8
8
  # library; and :curb, which uses Ruby's libcurl bindings and requires
9
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.
10
15
  # Sunspot.config.solr.url::
11
16
  # The URL at which to connect to Solr
12
17
  # (default: 'http://localhost:8983/solr')
@@ -25,14 +30,30 @@ module Sunspot
25
30
  def build #:nodoc:
26
31
  LightConfig.build do
27
32
  http_client :net_http
33
+ xml_builder :builder
34
+
28
35
  solr do
29
36
  url 'http://127.0.0.1:8983/solr'
30
37
  end
38
+ master_solr do
39
+ url nil
40
+ end
31
41
  pagination do
32
42
  default_per_page 30
33
43
  end
34
44
  end
35
45
  end
46
+
47
+ # Location for the default solr configuration files,
48
+ # required for bootstrapping a new solr installation
49
+ #
50
+ # ==== Returns
51
+ #
52
+ # String:: Directory with default solr config files
53
+ #
54
+ def solr_default_configuration_location
55
+ File.join( File.dirname(__FILE__), '../../solr/solr/conf' )
56
+ end
36
57
  end
37
58
  end
38
59
  end