warp-thinking-sphinx 1.2.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. data/LICENCE +20 -0
  2. data/README.textile +144 -0
  3. data/VERSION.yml +4 -0
  4. data/features/a.rb +17 -0
  5. data/features/alternate_primary_key.feature +27 -0
  6. data/features/attribute_transformation.feature +22 -0
  7. data/features/attribute_updates.feature +33 -0
  8. data/features/datetime_deltas.feature +66 -0
  9. data/features/delayed_delta_indexing.feature +37 -0
  10. data/features/deleting_instances.feature +64 -0
  11. data/features/direct_attributes.feature +11 -0
  12. data/features/excerpts.feature +13 -0
  13. data/features/extensible_delta_indexing.feature +9 -0
  14. data/features/facets.feature +76 -0
  15. data/features/facets_across_model.feature +29 -0
  16. data/features/handling_edits.feature +92 -0
  17. data/features/retry_stale_indexes.feature +24 -0
  18. data/features/searching_across_models.feature +20 -0
  19. data/features/searching_by_model.feature +175 -0
  20. data/features/searching_with_find_arguments.feature +56 -0
  21. data/features/sphinx_detection.feature +25 -0
  22. data/features/sphinx_scopes.feature +35 -0
  23. data/features/step_definitions/alpha_steps.rb +3 -0
  24. data/features/step_definitions/beta_steps.rb +7 -0
  25. data/features/step_definitions/common_steps.rb +178 -0
  26. data/features/step_definitions/datetime_delta_steps.rb +15 -0
  27. data/features/step_definitions/delayed_delta_indexing_steps.rb +7 -0
  28. data/features/step_definitions/extensible_delta_indexing_steps.rb +7 -0
  29. data/features/step_definitions/facet_steps.rb +92 -0
  30. data/features/step_definitions/find_arguments_steps.rb +36 -0
  31. data/features/step_definitions/gamma_steps.rb +15 -0
  32. data/features/step_definitions/scope_steps.rb +11 -0
  33. data/features/step_definitions/search_steps.rb +89 -0
  34. data/features/step_definitions/sphinx_steps.rb +31 -0
  35. data/features/sti_searching.feature +14 -0
  36. data/features/support/db/active_record.rb +40 -0
  37. data/features/support/db/database.example.yml +3 -0
  38. data/features/support/db/fixtures/alphas.rb +10 -0
  39. data/features/support/db/fixtures/authors.rb +1 -0
  40. data/features/support/db/fixtures/betas.rb +10 -0
  41. data/features/support/db/fixtures/boxes.rb +9 -0
  42. data/features/support/db/fixtures/categories.rb +1 -0
  43. data/features/support/db/fixtures/cats.rb +3 -0
  44. data/features/support/db/fixtures/comments.rb +24 -0
  45. data/features/support/db/fixtures/delayed_betas.rb +10 -0
  46. data/features/support/db/fixtures/developers.rb +29 -0
  47. data/features/support/db/fixtures/dogs.rb +3 -0
  48. data/features/support/db/fixtures/extensible_betas.rb +10 -0
  49. data/features/support/db/fixtures/gammas.rb +10 -0
  50. data/features/support/db/fixtures/people.rb +1001 -0
  51. data/features/support/db/fixtures/posts.rb +6 -0
  52. data/features/support/db/fixtures/robots.rb +14 -0
  53. data/features/support/db/fixtures/tags.rb +27 -0
  54. data/features/support/db/fixtures/thetas.rb +10 -0
  55. data/features/support/db/migrations/create_alphas.rb +7 -0
  56. data/features/support/db/migrations/create_animals.rb +5 -0
  57. data/features/support/db/migrations/create_authors.rb +3 -0
  58. data/features/support/db/migrations/create_authors_posts.rb +6 -0
  59. data/features/support/db/migrations/create_betas.rb +5 -0
  60. data/features/support/db/migrations/create_boxes.rb +5 -0
  61. data/features/support/db/migrations/create_categories.rb +3 -0
  62. data/features/support/db/migrations/create_comments.rb +10 -0
  63. data/features/support/db/migrations/create_delayed_betas.rb +17 -0
  64. data/features/support/db/migrations/create_developers.rb +9 -0
  65. data/features/support/db/migrations/create_extensible_betas.rb +5 -0
  66. data/features/support/db/migrations/create_gammas.rb +3 -0
  67. data/features/support/db/migrations/create_people.rb +13 -0
  68. data/features/support/db/migrations/create_posts.rb +5 -0
  69. data/features/support/db/migrations/create_robots.rb +5 -0
  70. data/features/support/db/migrations/create_taggings.rb +5 -0
  71. data/features/support/db/migrations/create_tags.rb +4 -0
  72. data/features/support/db/migrations/create_thetas.rb +5 -0
  73. data/features/support/db/mysql.rb +3 -0
  74. data/features/support/db/postgresql.rb +3 -0
  75. data/features/support/env.rb +6 -0
  76. data/features/support/lib/generic_delta_handler.rb +8 -0
  77. data/features/support/models/alpha.rb +10 -0
  78. data/features/support/models/animal.rb +5 -0
  79. data/features/support/models/author.rb +3 -0
  80. data/features/support/models/beta.rb +8 -0
  81. data/features/support/models/box.rb +8 -0
  82. data/features/support/models/cat.rb +3 -0
  83. data/features/support/models/category.rb +4 -0
  84. data/features/support/models/comment.rb +10 -0
  85. data/features/support/models/delayed_beta.rb +7 -0
  86. data/features/support/models/developer.rb +16 -0
  87. data/features/support/models/dog.rb +3 -0
  88. data/features/support/models/extensible_beta.rb +9 -0
  89. data/features/support/models/gamma.rb +5 -0
  90. data/features/support/models/person.rb +23 -0
  91. data/features/support/models/post.rb +20 -0
  92. data/features/support/models/robot.rb +8 -0
  93. data/features/support/models/tag.rb +3 -0
  94. data/features/support/models/tagging.rb +4 -0
  95. data/features/support/models/theta.rb +7 -0
  96. data/features/support/post_database.rb +43 -0
  97. data/features/support/z.rb +19 -0
  98. data/lib/thinking_sphinx.rb +212 -0
  99. data/lib/thinking_sphinx/active_record.rb +306 -0
  100. data/lib/thinking_sphinx/active_record/attribute_updates.rb +48 -0
  101. data/lib/thinking_sphinx/active_record/delta.rb +87 -0
  102. data/lib/thinking_sphinx/active_record/has_many_association.rb +28 -0
  103. data/lib/thinking_sphinx/active_record/scopes.rb +39 -0
  104. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +42 -0
  105. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +54 -0
  106. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +136 -0
  107. data/lib/thinking_sphinx/association.rb +243 -0
  108. data/lib/thinking_sphinx/attribute.rb +340 -0
  109. data/lib/thinking_sphinx/class_facet.rb +15 -0
  110. data/lib/thinking_sphinx/configuration.rb +282 -0
  111. data/lib/thinking_sphinx/core/array.rb +7 -0
  112. data/lib/thinking_sphinx/core/string.rb +15 -0
  113. data/lib/thinking_sphinx/deltas.rb +30 -0
  114. data/lib/thinking_sphinx/deltas/datetime_delta.rb +50 -0
  115. data/lib/thinking_sphinx/deltas/default_delta.rb +68 -0
  116. data/lib/thinking_sphinx/deltas/delayed_delta.rb +30 -0
  117. data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +24 -0
  118. data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +27 -0
  119. data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +26 -0
  120. data/lib/thinking_sphinx/deploy/capistrano.rb +100 -0
  121. data/lib/thinking_sphinx/excerpter.rb +22 -0
  122. data/lib/thinking_sphinx/facet.rb +125 -0
  123. data/lib/thinking_sphinx/facet_search.rb +134 -0
  124. data/lib/thinking_sphinx/field.rb +81 -0
  125. data/lib/thinking_sphinx/index.rb +99 -0
  126. data/lib/thinking_sphinx/index/builder.rb +286 -0
  127. data/lib/thinking_sphinx/index/faux_column.rb +110 -0
  128. data/lib/thinking_sphinx/property.rb +163 -0
  129. data/lib/thinking_sphinx/rails_additions.rb +150 -0
  130. data/lib/thinking_sphinx/search.rb +708 -0
  131. data/lib/thinking_sphinx/search_methods.rb +421 -0
  132. data/lib/thinking_sphinx/source.rb +152 -0
  133. data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
  134. data/lib/thinking_sphinx/source/sql.rb +127 -0
  135. data/lib/thinking_sphinx/tasks.rb +165 -0
  136. data/rails/init.rb +14 -0
  137. data/spec/lib/thinking_sphinx/active_record/delta_spec.rb +130 -0
  138. data/spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb +49 -0
  139. data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +96 -0
  140. data/spec/lib/thinking_sphinx/active_record_spec.rb +353 -0
  141. data/spec/lib/thinking_sphinx/association_spec.rb +239 -0
  142. data/spec/lib/thinking_sphinx/attribute_spec.rb +507 -0
  143. data/spec/lib/thinking_sphinx/configuration_spec.rb +268 -0
  144. data/spec/lib/thinking_sphinx/core/array_spec.rb +9 -0
  145. data/spec/lib/thinking_sphinx/core/string_spec.rb +9 -0
  146. data/spec/lib/thinking_sphinx/deltas/job_spec.rb +32 -0
  147. data/spec/lib/thinking_sphinx/excerpter_spec.rb +57 -0
  148. data/spec/lib/thinking_sphinx/facet_search_spec.rb +176 -0
  149. data/spec/lib/thinking_sphinx/facet_spec.rb +333 -0
  150. data/spec/lib/thinking_sphinx/field_spec.rb +154 -0
  151. data/spec/lib/thinking_sphinx/index/builder_spec.rb +455 -0
  152. data/spec/lib/thinking_sphinx/index/faux_column_spec.rb +30 -0
  153. data/spec/lib/thinking_sphinx/index_spec.rb +45 -0
  154. data/spec/lib/thinking_sphinx/rails_additions_spec.rb +203 -0
  155. data/spec/lib/thinking_sphinx/search_methods_spec.rb +152 -0
  156. data/spec/lib/thinking_sphinx/search_spec.rb +1101 -0
  157. data/spec/lib/thinking_sphinx/source_spec.rb +227 -0
  158. data/spec/lib/thinking_sphinx_spec.rb +162 -0
  159. data/tasks/distribution.rb +55 -0
  160. data/tasks/rails.rake +1 -0
  161. data/tasks/testing.rb +83 -0
  162. data/vendor/after_commit/LICENSE +20 -0
  163. data/vendor/after_commit/README +16 -0
  164. data/vendor/after_commit/Rakefile +22 -0
  165. data/vendor/after_commit/init.rb +8 -0
  166. data/vendor/after_commit/lib/after_commit.rb +45 -0
  167. data/vendor/after_commit/lib/after_commit/active_record.rb +114 -0
  168. data/vendor/after_commit/lib/after_commit/connection_adapters.rb +103 -0
  169. data/vendor/after_commit/test/after_commit_test.rb +53 -0
  170. data/vendor/delayed_job/lib/delayed/job.rb +251 -0
  171. data/vendor/delayed_job/lib/delayed/message_sending.rb +7 -0
  172. data/vendor/delayed_job/lib/delayed/performable_method.rb +55 -0
  173. data/vendor/delayed_job/lib/delayed/worker.rb +54 -0
  174. data/vendor/riddle/lib/riddle.rb +30 -0
  175. data/vendor/riddle/lib/riddle/client.rb +635 -0
  176. data/vendor/riddle/lib/riddle/client/filter.rb +53 -0
  177. data/vendor/riddle/lib/riddle/client/message.rb +66 -0
  178. data/vendor/riddle/lib/riddle/client/response.rb +84 -0
  179. data/vendor/riddle/lib/riddle/configuration.rb +33 -0
  180. data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +48 -0
  181. data/vendor/riddle/lib/riddle/configuration/index.rb +142 -0
  182. data/vendor/riddle/lib/riddle/configuration/indexer.rb +19 -0
  183. data/vendor/riddle/lib/riddle/configuration/remote_index.rb +17 -0
  184. data/vendor/riddle/lib/riddle/configuration/searchd.rb +25 -0
  185. data/vendor/riddle/lib/riddle/configuration/section.rb +43 -0
  186. data/vendor/riddle/lib/riddle/configuration/source.rb +23 -0
  187. data/vendor/riddle/lib/riddle/configuration/sql_source.rb +34 -0
  188. data/vendor/riddle/lib/riddle/configuration/xml_source.rb +28 -0
  189. data/vendor/riddle/lib/riddle/controller.rb +53 -0
  190. metadata +267 -0
@@ -0,0 +1,53 @@
1
+ module Riddle
2
+ class Client
3
+ # Used for querying Sphinx.
4
+ class Filter
5
+ attr_accessor :attribute, :values, :exclude
6
+
7
+ # Attribute name, values (which can be an array or a range), and whether
8
+ # the filter should be exclusive.
9
+ def initialize(attribute, values, exclude=false)
10
+ @attribute, @values, @exclude = attribute, values, exclude
11
+ end
12
+
13
+ def exclude?
14
+ self.exclude
15
+ end
16
+
17
+ # Returns the message for this filter to send to the Sphinx service
18
+ def query_message
19
+ message = Message.new
20
+
21
+ message.append_string self.attribute.to_s
22
+ case self.values
23
+ when Range
24
+ if self.values.first.is_a?(Float) && self.values.last.is_a?(Float)
25
+ message.append_int FilterTypes[:float_range]
26
+ message.append_floats self.values.first, self.values.last
27
+ else
28
+ message.append_int FilterTypes[:range]
29
+ message.append_ints self.values.first, self.values.last
30
+ end
31
+ when Array
32
+ message.append_int FilterTypes[:values]
33
+ message.append_int self.values.length
34
+ # using to_f is a hack from the php client - to workaround 32bit
35
+ # signed ints on x32 platforms
36
+ message.append_ints *self.values.collect { |val|
37
+ case val
38
+ when TrueClass
39
+ 1.0
40
+ when FalseClass
41
+ 0.0
42
+ else
43
+ val.to_f
44
+ end
45
+ }
46
+ end
47
+ message.append_int self.exclude? ? 1 : 0
48
+
49
+ message.to_s
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,66 @@
1
+ module Riddle
2
+ class Client
3
+ # This class takes care of the translation of ints, strings and arrays to
4
+ # the format required by the Sphinx service.
5
+ class Message
6
+ def initialize
7
+ @message = ""
8
+ @size_method = @message.respond_to?(:bytesize) ? :bytesize : :length
9
+ end
10
+
11
+ # Append raw data (only use if you know what you're doing)
12
+ def append(*args)
13
+ args.each { |arg| @message << arg }
14
+ end
15
+
16
+ # Append a string's length, then the string itself
17
+ def append_string(str)
18
+ string = str.respond_to?(:force_encoding) ?
19
+ str.dup.force_encoding('ASCII-8BIT') : str
20
+
21
+ @message << [string.send(@size_method)].pack('N') + string
22
+ end
23
+
24
+ # Append an integer
25
+ def append_int(int)
26
+ @message << [int].pack('N')
27
+ end
28
+
29
+ def append_64bit_int(int)
30
+ @message << [int >> 32, int & 0xFFFFFFFF].pack('NN')
31
+ end
32
+
33
+ # Append a float
34
+ def append_float(float)
35
+ @message << [float].pack('f').unpack('L*').pack("N")
36
+ end
37
+
38
+ # Append multiple integers
39
+ def append_ints(*ints)
40
+ ints.each { |int| append_int(int) }
41
+ end
42
+
43
+ def append_64bit_ints(*ints)
44
+ ints.each { |int| append_64bit_int(int) }
45
+ end
46
+
47
+ # Append multiple floats
48
+ def append_floats(*floats)
49
+ floats.each { |float| append_float(float) }
50
+ end
51
+
52
+ # Append an array of strings - first appends the length of the array,
53
+ # then each item's length and value.
54
+ def append_array(array)
55
+ append_int(array.length)
56
+
57
+ array.each { |item| append_string(item) }
58
+ end
59
+
60
+ # Returns the entire message
61
+ def to_s
62
+ @message
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,84 @@
1
+ module Riddle
2
+ class Client
3
+ # Used to interrogate responses from the Sphinx daemon. Keep in mind none
4
+ # of the methods here check whether the data they're grabbing are what the
5
+ # user expects - it just assumes the user knows what the data stream is
6
+ # made up of.
7
+ class Response
8
+ # Create with the data to interpret
9
+ def initialize(str)
10
+ @str = str
11
+ @marker = 0
12
+ end
13
+
14
+ # Return the next string value in the stream
15
+ def next
16
+ len = next_int
17
+ result = @str[@marker, len]
18
+ @marker += len
19
+
20
+ return result
21
+ end
22
+
23
+ # Return the next integer value from the stream
24
+ def next_int
25
+ int = @str[@marker, 4].unpack('N*').first
26
+ @marker += 4
27
+
28
+ return int
29
+ end
30
+
31
+ def next_64bit_int
32
+ high, low = @str[@marker, 8].unpack('N*N*')[0..1]
33
+ @marker += 8
34
+
35
+ return (high << 32) + low
36
+ end
37
+
38
+ # Return the next float value from the stream
39
+ def next_float
40
+ float = @str[@marker, 4].unpack('N*').pack('L').unpack('f*').first
41
+ @marker += 4
42
+
43
+ return float
44
+ end
45
+
46
+ # Returns an array of string items
47
+ def next_array
48
+ count = next_int
49
+ items = []
50
+ for i in 0...count
51
+ items << self.next
52
+ end
53
+
54
+ return items
55
+ end
56
+
57
+ # Returns an array of int items
58
+ def next_int_array
59
+ count = next_int
60
+ items = []
61
+ for i in 0...count
62
+ items << self.next_int
63
+ end
64
+
65
+ return items
66
+ end
67
+
68
+ def next_float_array
69
+ count = next_int
70
+ items = []
71
+ for i in 0...count
72
+ items << self.next_float
73
+ end
74
+
75
+ return items
76
+ end
77
+
78
+ # Returns the length of the streamed data
79
+ def length
80
+ @str.length
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,33 @@
1
+ require 'riddle/configuration/section'
2
+
3
+ require 'riddle/configuration/distributed_index'
4
+ require 'riddle/configuration/index'
5
+ require 'riddle/configuration/indexer'
6
+ require 'riddle/configuration/remote_index'
7
+ require 'riddle/configuration/searchd'
8
+ require 'riddle/configuration/source'
9
+ require 'riddle/configuration/sql_source'
10
+ require 'riddle/configuration/xml_source'
11
+
12
+ module Riddle
13
+ class Configuration
14
+ class ConfigurationError < StandardError #:nodoc:
15
+ end
16
+
17
+ attr_reader :indexes, :searchd
18
+ attr_accessor :indexer
19
+
20
+ def initialize
21
+ @indexer = Riddle::Configuration::Indexer.new
22
+ @searchd = Riddle::Configuration::Searchd.new
23
+ @indexes = []
24
+ end
25
+
26
+ def render
27
+ (
28
+ [@indexer.render, @searchd.render] +
29
+ @indexes.collect { |index| index.render }
30
+ ).join("\n")
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,48 @@
1
+ module Riddle
2
+ class Configuration
3
+ class DistributedIndex < Riddle::Configuration::Section
4
+ self.settings = [:type, :local, :agent, :agent_connect_timeout,
5
+ :agent_query_timeout]
6
+
7
+ attr_accessor :name, :local_indexes, :remote_indexes,
8
+ :agent_connect_timeout, :agent_query_timeout
9
+
10
+ def initialize(name)
11
+ @name = name
12
+ @local_indexes = []
13
+ @remote_indexes = []
14
+ end
15
+
16
+ def type
17
+ "distributed"
18
+ end
19
+
20
+ def local
21
+ self.local_indexes
22
+ end
23
+
24
+ def agent
25
+ agents = remote_indexes.collect { |index| index.remote }.uniq
26
+ agents.collect { |agent|
27
+ agent + ":" + remote_indexes.select { |index|
28
+ index.remote == agent
29
+ }.collect { |index| index.name }.join(",")
30
+ }
31
+ end
32
+
33
+ def render
34
+ raise ConfigurationError unless valid?
35
+
36
+ (
37
+ ["index #{name}", "{"] +
38
+ settings_body +
39
+ ["}", ""]
40
+ ).join("\n")
41
+ end
42
+
43
+ def valid?
44
+ @local_indexes.length > 0 || @remote_indexes.length > 0
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,142 @@
1
+ module Riddle
2
+ class Configuration
3
+ class Index < Riddle::Configuration::Section
4
+ self.settings = [:source, :path, :docinfo, :mlock, :morphology,
5
+ :stopwords, :wordforms, :exceptions, :min_word_len, :charset_type,
6
+ :charset_table, :ignore_chars, :min_prefix_len, :min_infix_len,
7
+ :prefix_fields, :infix_fields, :enable_star, :ngram_len, :ngram_chars,
8
+ :phrase_boundary, :phrase_boundary_step, :html_strip,
9
+ :html_index_attrs, :html_remove_elements, :preopen]
10
+
11
+ attr_accessor :name, :parent, :sources, :path, :docinfo, :mlock,
12
+ :morphologies, :stopword_files, :wordform_files, :exception_files,
13
+ :min_word_len, :charset_type, :charset_table, :ignore_characters,
14
+ :min_prefix_len, :min_infix_len, :prefix_field_names,
15
+ :infix_field_names, :enable_star, :ngram_len, :ngram_characters,
16
+ :phrase_boundaries, :phrase_boundary_step, :html_strip,
17
+ :html_index_attrs, :html_remove_element_tags, :preopen
18
+
19
+ def initialize(name, *sources)
20
+ @name = name
21
+ @sources = sources
22
+ @morphologies = []
23
+ @stopword_files = []
24
+ @wordform_files = []
25
+ @exception_files = []
26
+ @ignore_characters = []
27
+ @prefix_field_names = []
28
+ @infix_field_names = []
29
+ @ngram_characters = []
30
+ @phrase_boundaries = []
31
+ @html_remove_element_tags = []
32
+ end
33
+
34
+ def source
35
+ @sources.collect { |s| s.name }
36
+ end
37
+
38
+ def morphology
39
+ nil_join @morphologies, ", "
40
+ end
41
+
42
+ def morphology=(morphology)
43
+ @morphologies = nil_split morphology, /,\s?/
44
+ end
45
+
46
+ def stopwords
47
+ nil_join @stopword_files, " "
48
+ end
49
+
50
+ def stopwords=(stopwords)
51
+ @stopword_files = nil_split stopwords, ' '
52
+ end
53
+
54
+ def wordforms
55
+ nil_join @wordform_files, " "
56
+ end
57
+
58
+ def wordforms=(wordforms)
59
+ @wordform_files = nil_split wordforms, ' '
60
+ end
61
+
62
+ def exceptions
63
+ nil_join @exception_files, " "
64
+ end
65
+
66
+ def exceptions=(exceptions)
67
+ @exception_files = nil_split exceptions, ' '
68
+ end
69
+
70
+ def ignore_chars
71
+ nil_join @ignore_characters, ", "
72
+ end
73
+
74
+ def ignore_chars=(ignore_chars)
75
+ @ignore_characters = nil_split ignore_chars, /,\s?/
76
+ end
77
+
78
+ def prefix_fields
79
+ nil_join @prefix_field_names, ", "
80
+ end
81
+
82
+ def infix_fields
83
+ nil_join @infix_field_names, ", "
84
+ end
85
+
86
+ def ngram_chars
87
+ nil_join @ngram_characters, ", "
88
+ end
89
+
90
+ def ngram_chars=(ngram_chars)
91
+ @ngram_characters = nil_split ngram_chars, /,\s?/
92
+ end
93
+
94
+ def phrase_boundary
95
+ nil_join @phrase_boundaries, ", "
96
+ end
97
+
98
+ def phrase_boundary=(phrase_boundary)
99
+ @phrase_boundaries = nil_split phrase_boundary, /,\s?/
100
+ end
101
+
102
+ def html_remove_elements
103
+ nil_join @html_remove_element_tags, ", "
104
+ end
105
+
106
+ def html_remove_elements=(html_remove_elements)
107
+ @html_remove_element_tags = nil_split html_remove_elements, /,\s?/
108
+ end
109
+
110
+ def render
111
+ raise ConfigurationError, "#{@name} #{@sources.inspect} #{@path} #{@parent}" unless valid?
112
+
113
+ inherited_name = "#{name}"
114
+ inherited_name << " : #{parent}" if parent
115
+ (
116
+ @sources.collect { |s| s.render } +
117
+ ["index #{inherited_name}", "{"] +
118
+ settings_body +
119
+ ["}", ""]
120
+ ).join("\n")
121
+ end
122
+
123
+ def valid?
124
+ (!@name.nil?) && (!( @sources.length == 0 || @path.nil? ) || !@parent.nil?)
125
+ end
126
+
127
+ private
128
+
129
+ def nil_split(string, pattern)
130
+ (string || "").split(pattern)
131
+ end
132
+
133
+ def nil_join(array, delimiter)
134
+ if array.length == 0
135
+ nil
136
+ else
137
+ array.join(delimiter)
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,19 @@
1
+ module Riddle
2
+ class Configuration
3
+ class Indexer < Riddle::Configuration::Section
4
+ self.settings = [:mem_limit, :max_iops, :max_iosize]
5
+
6
+ attr_accessor *self.settings
7
+
8
+ def render
9
+ raise ConfigurationError unless valid?
10
+
11
+ (
12
+ ["indexer", "{"] +
13
+ settings_body +
14
+ ["}", ""]
15
+ ).join("\n")
16
+ end
17
+ end
18
+ end
19
+ end