thinking-sphinx 3.1.4 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (347) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +99 -0
  3. data/.github/actions/test/action.yml +46 -0
  4. data/.github/workflows/ci.yml +75 -0
  5. data/.gitignore +7 -2
  6. data/.travis.yml +31 -16
  7. data/Appraisals +68 -12
  8. data/CHANGELOG.markdown +782 -0
  9. data/Gemfile +13 -4
  10. data/Procfile.support +2 -0
  11. data/README.textile +41 -27
  12. data/Rakefile +2 -0
  13. data/bin/console +15 -0
  14. data/bin/loadsphinx +99 -0
  15. data/bin/testmatrix +48 -0
  16. data/lib/thinking/sphinx.rb +2 -0
  17. data/lib/thinking-sphinx.rb +2 -0
  18. data/lib/thinking_sphinx/active_record/association.rb +2 -0
  19. data/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb +3 -1
  20. data/lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb +2 -0
  21. data/lib/thinking_sphinx/active_record/association_proxy.rb +3 -2
  22. data/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb +3 -1
  23. data/lib/thinking_sphinx/active_record/attribute/type.rb +20 -4
  24. data/lib/thinking_sphinx/active_record/attribute/values.rb +2 -0
  25. data/lib/thinking_sphinx/active_record/attribute.rb +2 -0
  26. data/lib/thinking_sphinx/active_record/base.rb +43 -11
  27. data/lib/thinking_sphinx/active_record/callbacks/association_delta_callbacks.rb +21 -0
  28. data/lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb +15 -9
  29. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +20 -5
  30. data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +18 -4
  31. data/lib/thinking_sphinx/active_record/column.rb +2 -0
  32. data/lib/thinking_sphinx/active_record/column_sql_presenter.rb +7 -1
  33. data/lib/thinking_sphinx/active_record/database_adapters/abstract_adapter.rb +2 -0
  34. data/lib/thinking_sphinx/active_record/database_adapters/mysql_adapter.rb +9 -1
  35. data/lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb +2 -0
  36. data/lib/thinking_sphinx/active_record/database_adapters.rb +3 -1
  37. data/lib/thinking_sphinx/active_record/depolymorph/association_reflection.rb +32 -0
  38. data/lib/thinking_sphinx/active_record/depolymorph/base_reflection.rb +32 -0
  39. data/lib/thinking_sphinx/active_record/depolymorph/conditions_reflection.rb +40 -0
  40. data/lib/thinking_sphinx/active_record/depolymorph/overridden_reflection.rb +50 -0
  41. data/lib/thinking_sphinx/active_record/depolymorph/scoped_reflection.rb +26 -0
  42. data/lib/thinking_sphinx/active_record/field.rb +2 -0
  43. data/lib/thinking_sphinx/active_record/filter_reflection.rb +13 -71
  44. data/lib/thinking_sphinx/active_record/index.rb +7 -5
  45. data/lib/thinking_sphinx/active_record/interpreter.rb +6 -4
  46. data/lib/thinking_sphinx/active_record/join_association.rb +5 -1
  47. data/lib/thinking_sphinx/active_record/log_subscriber.rb +22 -3
  48. data/lib/thinking_sphinx/active_record/polymorpher.rb +2 -0
  49. data/lib/thinking_sphinx/active_record/property.rb +2 -0
  50. data/lib/thinking_sphinx/active_record/property_query.rb +4 -1
  51. data/lib/thinking_sphinx/active_record/property_sql_presenter.rb +2 -0
  52. data/lib/thinking_sphinx/active_record/simple_many_query.rb +2 -0
  53. data/lib/thinking_sphinx/active_record/source_joins.rb +68 -0
  54. data/lib/thinking_sphinx/active_record/sql_builder/clause_builder.rb +2 -0
  55. data/lib/thinking_sphinx/active_record/sql_builder/query.rb +13 -0
  56. data/lib/thinking_sphinx/active_record/sql_builder/statement.rb +2 -0
  57. data/lib/thinking_sphinx/active_record/sql_builder.rb +5 -18
  58. data/lib/thinking_sphinx/active_record/sql_source/template.rb +5 -3
  59. data/lib/thinking_sphinx/active_record/sql_source.rb +35 -9
  60. data/lib/thinking_sphinx/active_record.rb +14 -1
  61. data/lib/thinking_sphinx/attribute_types.rb +72 -0
  62. data/lib/thinking_sphinx/batched_search.rb +2 -0
  63. data/lib/thinking_sphinx/callbacks/appender.rb +63 -0
  64. data/lib/thinking_sphinx/callbacks.rb +29 -0
  65. data/lib/thinking_sphinx/capistrano/v2.rb +2 -0
  66. data/lib/thinking_sphinx/capistrano/v3.rb +2 -0
  67. data/lib/thinking_sphinx/capistrano.rb +2 -0
  68. data/lib/thinking_sphinx/commander.rb +27 -0
  69. data/lib/thinking_sphinx/commands/base.rb +53 -0
  70. data/lib/thinking_sphinx/commands/clear_real_time.rb +22 -0
  71. data/lib/thinking_sphinx/commands/clear_sql.rb +18 -0
  72. data/lib/thinking_sphinx/commands/configure.rb +15 -0
  73. data/lib/thinking_sphinx/commands/index_real_time.rb +15 -0
  74. data/lib/thinking_sphinx/commands/index_sql.rb +25 -0
  75. data/lib/thinking_sphinx/commands/merge.rb +27 -0
  76. data/lib/thinking_sphinx/commands/merge_and_update.rb +57 -0
  77. data/lib/thinking_sphinx/commands/prepare.rb +15 -0
  78. data/lib/thinking_sphinx/commands/rotate.rb +13 -0
  79. data/lib/thinking_sphinx/commands/running.rb +15 -0
  80. data/lib/thinking_sphinx/commands/start_attached.rb +22 -0
  81. data/lib/thinking_sphinx/commands/start_detached.rb +21 -0
  82. data/lib/thinking_sphinx/commands/stop.rb +24 -0
  83. data/lib/thinking_sphinx/commands.rb +20 -0
  84. data/lib/thinking_sphinx/configuration/consistent_ids.rb +2 -0
  85. data/lib/thinking_sphinx/configuration/defaults.rb +2 -0
  86. data/lib/thinking_sphinx/configuration/distributed_indices.rb +3 -1
  87. data/lib/thinking_sphinx/configuration/duplicate_names.rb +36 -0
  88. data/lib/thinking_sphinx/configuration/minimum_fields.rb +17 -12
  89. data/lib/thinking_sphinx/configuration.rb +90 -74
  90. data/lib/thinking_sphinx/connection/client.rb +74 -0
  91. data/lib/thinking_sphinx/connection/jruby.rb +58 -0
  92. data/lib/thinking_sphinx/connection/mri.rb +26 -0
  93. data/lib/thinking_sphinx/connection.rb +13 -114
  94. data/lib/thinking_sphinx/core/field.rb +2 -0
  95. data/lib/thinking_sphinx/core/index.rb +22 -2
  96. data/lib/thinking_sphinx/core/interpreter.rb +2 -0
  97. data/lib/thinking_sphinx/core/property.rb +2 -0
  98. data/lib/thinking_sphinx/core/settings.rb +2 -0
  99. data/lib/thinking_sphinx/core.rb +2 -0
  100. data/lib/thinking_sphinx/deletion.rb +33 -13
  101. data/lib/thinking_sphinx/deltas/default_delta.rb +3 -1
  102. data/lib/thinking_sphinx/deltas/delete_job.rb +16 -4
  103. data/lib/thinking_sphinx/deltas/index_job.rb +14 -2
  104. data/lib/thinking_sphinx/deltas.rb +2 -0
  105. data/lib/thinking_sphinx/distributed/index.rb +25 -3
  106. data/lib/thinking_sphinx/distributed.rb +2 -0
  107. data/lib/thinking_sphinx/errors.rb +47 -3
  108. data/lib/thinking_sphinx/excerpter.rb +2 -0
  109. data/lib/thinking_sphinx/facet.rb +4 -3
  110. data/lib/thinking_sphinx/facet_search.rb +4 -2
  111. data/lib/thinking_sphinx/float_formatter.rb +2 -0
  112. data/lib/thinking_sphinx/frameworks/plain.rb +2 -0
  113. data/lib/thinking_sphinx/frameworks/rails.rb +2 -0
  114. data/lib/thinking_sphinx/frameworks.rb +2 -0
  115. data/lib/thinking_sphinx/guard/file.rb +3 -1
  116. data/lib/thinking_sphinx/guard/files.rb +2 -0
  117. data/lib/thinking_sphinx/guard/none.rb +7 -0
  118. data/lib/thinking_sphinx/guard.rb +3 -0
  119. data/lib/thinking_sphinx/hooks/guard_presence.rb +34 -0
  120. data/lib/thinking_sphinx/index.rb +2 -0
  121. data/lib/thinking_sphinx/index_set.rb +27 -4
  122. data/lib/thinking_sphinx/indexing_strategies/all_at_once.rb +9 -0
  123. data/lib/thinking_sphinx/indexing_strategies/one_at_a_time.rb +16 -0
  124. data/lib/thinking_sphinx/interfaces/base.rb +13 -0
  125. data/lib/thinking_sphinx/interfaces/daemon.rb +27 -0
  126. data/lib/thinking_sphinx/interfaces/real_time.rb +46 -0
  127. data/lib/thinking_sphinx/interfaces/sql.rb +53 -0
  128. data/lib/thinking_sphinx/interfaces.rb +10 -0
  129. data/lib/thinking_sphinx/logger.rb +2 -0
  130. data/lib/thinking_sphinx/masks/group_enumerators_mask.rb +6 -4
  131. data/lib/thinking_sphinx/masks/pagination_mask.rb +2 -0
  132. data/lib/thinking_sphinx/masks/scopes_mask.rb +8 -0
  133. data/lib/thinking_sphinx/masks/weight_enumerator_mask.rb +3 -1
  134. data/lib/thinking_sphinx/masks.rb +2 -0
  135. data/lib/thinking_sphinx/middlewares/active_record_translator.rb +32 -9
  136. data/lib/thinking_sphinx/middlewares/geographer.rb +2 -0
  137. data/lib/thinking_sphinx/middlewares/glazier.rb +14 -1
  138. data/lib/thinking_sphinx/middlewares/ids_only.rb +2 -0
  139. data/lib/thinking_sphinx/middlewares/inquirer.rb +3 -1
  140. data/lib/thinking_sphinx/middlewares/middleware.rb +2 -0
  141. data/lib/thinking_sphinx/middlewares/sphinxql.rb +18 -16
  142. data/lib/thinking_sphinx/middlewares/stale_id_checker.rb +3 -1
  143. data/lib/thinking_sphinx/middlewares/stale_id_filter.rb +4 -2
  144. data/lib/thinking_sphinx/middlewares/valid_options.rb +25 -0
  145. data/lib/thinking_sphinx/middlewares.rb +7 -3
  146. data/lib/thinking_sphinx/panes/attributes_pane.rb +2 -0
  147. data/lib/thinking_sphinx/panes/distance_pane.rb +2 -0
  148. data/lib/thinking_sphinx/panes/excerpts_pane.rb +2 -0
  149. data/lib/thinking_sphinx/panes/weight_pane.rb +3 -1
  150. data/lib/thinking_sphinx/panes.rb +2 -0
  151. data/lib/thinking_sphinx/processor.rb +71 -0
  152. data/lib/thinking_sphinx/query.rb +2 -0
  153. data/lib/thinking_sphinx/railtie.rb +29 -2
  154. data/lib/thinking_sphinx/rake_interface.rb +14 -69
  155. data/lib/thinking_sphinx/real_time/attribute.rb +9 -1
  156. data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +17 -7
  157. data/lib/thinking_sphinx/real_time/field.rb +2 -0
  158. data/lib/thinking_sphinx/real_time/index/template.rb +19 -1
  159. data/lib/thinking_sphinx/real_time/index.rb +11 -5
  160. data/lib/thinking_sphinx/real_time/interpreter.rb +10 -6
  161. data/lib/thinking_sphinx/real_time/populator.rb +12 -14
  162. data/lib/thinking_sphinx/real_time/processor.rb +36 -0
  163. data/lib/thinking_sphinx/real_time/property.rb +3 -5
  164. data/lib/thinking_sphinx/real_time/transcribe_instance.rb +38 -0
  165. data/lib/thinking_sphinx/real_time/transcriber.rb +63 -15
  166. data/lib/thinking_sphinx/real_time/translator.rb +39 -0
  167. data/lib/thinking_sphinx/real_time.rb +22 -1
  168. data/lib/thinking_sphinx/scopes.rb +6 -0
  169. data/lib/thinking_sphinx/search/batch_inquirer.rb +2 -0
  170. data/lib/thinking_sphinx/search/context.rb +11 -0
  171. data/lib/thinking_sphinx/search/glaze.rb +2 -0
  172. data/lib/thinking_sphinx/search/merger.rb +2 -0
  173. data/lib/thinking_sphinx/search/query.rb +9 -1
  174. data/lib/thinking_sphinx/search/stale_ids_exception.rb +7 -3
  175. data/lib/thinking_sphinx/search.rb +30 -2
  176. data/lib/thinking_sphinx/settings.rb +128 -0
  177. data/lib/thinking_sphinx/sinatra.rb +3 -1
  178. data/lib/thinking_sphinx/subscribers/populator_subscriber.rb +19 -5
  179. data/lib/thinking_sphinx/tasks.rb +55 -28
  180. data/lib/thinking_sphinx/test.rb +3 -1
  181. data/lib/thinking_sphinx/utf8.rb +2 -0
  182. data/lib/thinking_sphinx/wildcard.rb +3 -1
  183. data/lib/thinking_sphinx/with_output.rb +13 -0
  184. data/lib/thinking_sphinx.rb +35 -4
  185. data/spec/acceptance/association_scoping_spec.rb +7 -5
  186. data/spec/acceptance/attribute_access_spec.rb +29 -12
  187. data/spec/acceptance/attribute_updates_spec.rb +5 -3
  188. data/spec/acceptance/batch_searching_spec.rb +6 -4
  189. data/spec/acceptance/big_integers_spec.rb +9 -7
  190. data/spec/acceptance/excerpts_spec.rb +11 -10
  191. data/spec/acceptance/facets_spec.rb +29 -16
  192. data/spec/acceptance/geosearching_spec.rb +22 -10
  193. data/spec/acceptance/grouping_by_attributes_spec.rb +30 -28
  194. data/spec/acceptance/index_options_spec.rb +18 -16
  195. data/spec/acceptance/indexing_spec.rb +5 -3
  196. data/spec/acceptance/merging_spec.rb +90 -0
  197. data/spec/acceptance/paginating_search_results_spec.rb +21 -3
  198. data/spec/acceptance/real_time_updates_spec.rb +103 -5
  199. data/spec/acceptance/remove_deleted_records_spec.rb +64 -8
  200. data/spec/acceptance/search_counts_spec.rb +4 -2
  201. data/spec/acceptance/search_for_just_ids_spec.rb +4 -2
  202. data/spec/acceptance/searching_across_models_spec.rb +15 -6
  203. data/spec/acceptance/searching_across_schemas_spec.rb +12 -10
  204. data/spec/acceptance/searching_on_fields_spec.rb +11 -9
  205. data/spec/acceptance/searching_with_filters_spec.rb +35 -20
  206. data/spec/acceptance/searching_with_sti_spec.rb +11 -9
  207. data/spec/acceptance/searching_within_a_model_spec.rb +44 -17
  208. data/spec/acceptance/sorting_search_results_spec.rb +21 -19
  209. data/spec/acceptance/spec_helper.rb +2 -13
  210. data/spec/acceptance/specifying_sql_spec.rb +118 -62
  211. data/spec/acceptance/sphinx_scopes_spec.rb +30 -21
  212. data/spec/acceptance/sql_deltas_spec.rb +35 -9
  213. data/spec/acceptance/support/database_cleaner.rb +3 -1
  214. data/spec/acceptance/support/sphinx_controller.rb +25 -9
  215. data/spec/acceptance/support/sphinx_helpers.rb +17 -2
  216. data/spec/acceptance/suspended_deltas_spec.rb +14 -12
  217. data/spec/fixtures/database.yml +1 -1
  218. data/spec/internal/app/indices/admin_person_index.rb +6 -0
  219. data/spec/internal/app/indices/album_index.rb +9 -0
  220. data/spec/internal/app/indices/animal_index.rb +2 -0
  221. data/spec/internal/app/indices/article_index.rb +10 -3
  222. data/spec/internal/app/indices/bird_index.rb +2 -0
  223. data/spec/internal/app/indices/book_index.rb +4 -1
  224. data/spec/internal/app/indices/car_index.rb +2 -0
  225. data/spec/internal/app/indices/city_index.rb +2 -0
  226. data/spec/internal/app/indices/colour_index.rb +7 -0
  227. data/spec/internal/app/indices/product_index.rb +3 -2
  228. data/spec/internal/app/indices/tee_index.rb +3 -1
  229. data/spec/internal/app/indices/user_index.rb +2 -0
  230. data/spec/internal/app/models/admin/person.rb +6 -0
  231. data/spec/internal/app/models/album.rb +25 -0
  232. data/spec/internal/app/models/animal.rb +3 -0
  233. data/spec/internal/app/models/article.rb +4 -0
  234. data/spec/internal/app/models/bird.rb +3 -0
  235. data/spec/internal/app/models/book.rb +9 -5
  236. data/spec/internal/app/models/car.rb +3 -1
  237. data/spec/internal/app/models/categorisation.rb +10 -1
  238. data/spec/internal/app/models/category.rb +2 -0
  239. data/spec/internal/app/models/city.rb +4 -0
  240. data/spec/internal/app/models/colour.rb +4 -0
  241. data/spec/internal/app/models/event.rb +2 -0
  242. data/spec/internal/app/models/flightless_bird.rb +2 -0
  243. data/spec/internal/app/models/genre.rb +2 -0
  244. data/spec/internal/app/models/hardcover.rb +2 -0
  245. data/spec/internal/app/models/mammal.rb +2 -0
  246. data/spec/internal/app/models/manufacturer.rb +2 -0
  247. data/spec/internal/app/models/product.rb +3 -1
  248. data/spec/internal/app/models/tag.rb +2 -0
  249. data/spec/internal/app/models/tagging.rb +2 -0
  250. data/spec/internal/app/models/tee.rb +7 -0
  251. data/spec/internal/app/models/tweet.rb +2 -0
  252. data/spec/internal/app/models/user.rb +4 -0
  253. data/spec/internal/config/database.yml +12 -1
  254. data/spec/internal/db/schema.rb +13 -1
  255. data/spec/spec_helper.rb +12 -1
  256. data/spec/support/json_column.rb +35 -0
  257. data/spec/support/multi_schema.rb +5 -1
  258. data/spec/support/mysql.rb +25 -0
  259. data/spec/support/sphinx_yaml_helpers.rb +8 -1
  260. data/spec/thinking_sphinx/active_record/association_spec.rb +3 -1
  261. data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +43 -38
  262. data/spec/thinking_sphinx/active_record/base_spec.rb +31 -29
  263. data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +81 -10
  264. data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +56 -29
  265. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +27 -10
  266. data/spec/thinking_sphinx/active_record/column_spec.rb +15 -13
  267. data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +39 -0
  268. data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +7 -5
  269. data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +26 -12
  270. data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +15 -13
  271. data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +50 -48
  272. data/spec/thinking_sphinx/active_record/field_spec.rb +9 -7
  273. data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +113 -80
  274. data/spec/thinking_sphinx/active_record/index_spec.rb +41 -37
  275. data/spec/thinking_sphinx/active_record/interpreter_spec.rb +62 -59
  276. data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +16 -14
  277. data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +69 -67
  278. data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +146 -154
  279. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +185 -109
  280. data/spec/thinking_sphinx/attribute_types_spec.rb +52 -0
  281. data/spec/thinking_sphinx/commands/clear_real_time_spec.rb +46 -0
  282. data/spec/thinking_sphinx/commands/clear_sql_spec.rb +52 -0
  283. data/spec/thinking_sphinx/commands/configure_spec.rb +31 -0
  284. data/spec/thinking_sphinx/commands/index_real_time_spec.rb +33 -0
  285. data/spec/thinking_sphinx/commands/index_sql_spec.rb +86 -0
  286. data/spec/thinking_sphinx/commands/merge_and_update_spec.rb +106 -0
  287. data/spec/thinking_sphinx/commands/merge_spec.rb +48 -0
  288. data/spec/thinking_sphinx/commands/prepare_spec.rb +31 -0
  289. data/spec/thinking_sphinx/commands/running_spec.rb +30 -0
  290. data/spec/thinking_sphinx/commands/start_detached_spec.rb +67 -0
  291. data/spec/thinking_sphinx/commands/stop_spec.rb +63 -0
  292. data/spec/thinking_sphinx/configuration/minimum_fields_spec.rb +60 -0
  293. data/spec/thinking_sphinx/configuration_spec.rb +247 -94
  294. data/spec/thinking_sphinx/connection/mri_spec.rb +49 -0
  295. data/spec/thinking_sphinx/connection_spec.rb +15 -13
  296. data/spec/thinking_sphinx/deletion_spec.rb +17 -17
  297. data/spec/thinking_sphinx/deltas/default_delta_spec.rb +28 -21
  298. data/spec/thinking_sphinx/deltas_spec.rb +14 -12
  299. data/spec/thinking_sphinx/errors_spec.rb +59 -27
  300. data/spec/thinking_sphinx/excerpter_spec.rb +12 -9
  301. data/spec/thinking_sphinx/facet_search_spec.rb +24 -22
  302. data/spec/thinking_sphinx/hooks/guard_presence_spec.rb +30 -0
  303. data/spec/thinking_sphinx/index_set_spec.rb +59 -18
  304. data/spec/thinking_sphinx/index_spec.rb +28 -26
  305. data/spec/thinking_sphinx/interfaces/daemon_spec.rb +60 -0
  306. data/spec/thinking_sphinx/interfaces/real_time_spec.rb +109 -0
  307. data/spec/thinking_sphinx/interfaces/sql_spec.rb +122 -0
  308. data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +22 -20
  309. data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +20 -18
  310. data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +45 -21
  311. data/spec/thinking_sphinx/middlewares/geographer_spec.rb +11 -9
  312. data/spec/thinking_sphinx/middlewares/glazier_spec.rb +12 -9
  313. data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +9 -7
  314. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +60 -58
  315. data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +7 -4
  316. data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +39 -17
  317. data/spec/thinking_sphinx/middlewares/valid_options_spec.rb +51 -0
  318. data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +3 -1
  319. data/spec/thinking_sphinx/panes/distance_pane_spec.rb +6 -4
  320. data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +8 -6
  321. data/spec/thinking_sphinx/panes/weight_pane_spec.rb +4 -2
  322. data/spec/thinking_sphinx/rake_interface_spec.rb +17 -235
  323. data/spec/thinking_sphinx/real_time/attribute_spec.rb +15 -13
  324. data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +114 -28
  325. data/spec/thinking_sphinx/real_time/field_spec.rb +16 -14
  326. data/spec/thinking_sphinx/real_time/index_spec.rb +83 -32
  327. data/spec/thinking_sphinx/real_time/interpreter_spec.rb +44 -42
  328. data/spec/thinking_sphinx/real_time/transcribe_instance_spec.rb +35 -0
  329. data/spec/thinking_sphinx/real_time/transcriber_spec.rb +109 -0
  330. data/spec/thinking_sphinx/real_time/translator_spec.rb +17 -0
  331. data/spec/thinking_sphinx/scopes_spec.rb +11 -5
  332. data/spec/thinking_sphinx/search/glaze_spec.rb +17 -15
  333. data/spec/thinking_sphinx/search/query_spec.rb +19 -10
  334. data/spec/thinking_sphinx/search_spec.rb +30 -28
  335. data/spec/thinking_sphinx/wildcard_spec.rb +18 -11
  336. data/spec/thinking_sphinx_spec.rb +10 -7
  337. data/thinking-sphinx.gemspec +17 -10
  338. metadata +157 -49
  339. data/HISTORY +0 -248
  340. data/gemfiles/.gitignore +0 -1
  341. data/gemfiles/rails_3_2.gemfile +0 -11
  342. data/gemfiles/rails_4_0.gemfile +0 -11
  343. data/gemfiles/rails_4_1.gemfile +0 -11
  344. data/gemfiles/rails_4_2.gemfile +0 -11
  345. data/lib/thinking_sphinx/controller.rb +0 -10
  346. data/lib/thinking_sphinx/middlewares/utf8.rb +0 -27
  347. data/lib/thinking_sphinx/sphinxql.rb +0 -23
data/Gemfile CHANGED
@@ -1,9 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
5
- gem 'mysql2', '~> 0.3.12b4', :platform => :ruby
6
- gem 'pg', '~> 0.16.0', :platform => :ruby
7
+ gem 'logger'
8
+ gem 'mysql2', '~> 0.5.0', :platform => :ruby
9
+ gem 'pg', '~> 0.18.4', :platform => :ruby
10
+
11
+ gem 'activerecord', '< 7' if RUBY_VERSION.to_f <= 2.4
7
12
 
8
- gem 'activerecord-jdbcmysql-adapter', '~> 1.3.4', :platform => :jruby
9
- gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.4', :platform => :jruby
13
+ if RUBY_PLATFORM == 'java'
14
+ gem 'jdbc-mysql', '5.1.35', :platform => :jruby
15
+ gem 'activerecord-jdbcmysql-adapter', '>= 1.3.23', :platform => :jruby
16
+ gem 'activerecord-jdbcpostgresql-adapter', '>= 1.3.23', :platform => :jruby
17
+ gem 'activerecord', '>= 3.2.22'
18
+ end
data/Procfile.support ADDED
@@ -0,0 +1,2 @@
1
+ postgres: postgres -D data/postgres -p ${POSTGRES_PORT:-5432}
2
+ mysql: $(brew --prefix mysql@5.7)/bin/mysqld --datadir=$(PWD)/data/mysql --port ${MYSQL_PORT:-3306} --socket=mysql.sock
data/README.textile CHANGED
@@ -1,59 +1,73 @@
1
1
  h1. Thinking Sphinx
2
2
 
3
- Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is v3.1.4.
3
+ Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is v6.0.0.
4
4
 
5
5
  h2. Upgrading
6
6
 
7
- Please refer to the release notes for any changes you need to make when upgrading:
7
+ Please refer to "the changelog":https://github.com/pat/thinking-sphinx/blob/develop/CHANGELOG.markdown and "release notes":https://github.com/pat/thinking-sphinx/releases for any changes you need to make when upgrading. The release notes in particular are quite good at covering breaking changes and more details for new features.
8
8
 
9
- * "v3.1.4":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.4
10
- * "v3.1.3":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.3
11
- * "v3.1.2":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.2
12
- * "v3.1.1":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.1
13
- * "v3.1.0":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.0
14
- * "v3.0.6":https://github.com/pat/thinking-sphinx/releases/tag/v3.0.6
15
-
16
- If you're upgrading from pre-v3, then the documentation has "pretty extensive notes":http://pat.github.io/thinking-sphinx/upgrading.html on what's changed.
9
+ The documentation also has more details on what's involved for upgrading from "v4 to v5":https://freelancing-gods.com/thinking-sphinx/v5/upgrading.html, "v3 to v4":https://freelancing-gods.com/thinking-sphinx/v4/upgrading.html, and "v1/v2 to v3":https://freelancing-gods.com/thinking-sphinx/v3/upgrading.html.
17
10
 
18
11
  h2. Installation
19
12
 
20
13
  It's a gem, so install it like you would any other gem. You will also need to specify the mysql2 gem if you're using MRI, or jdbc-mysql if you're using JRuby:
21
14
 
22
- <pre><code>gem 'mysql2', '~> 0.3.18', :platform => :ruby
15
+ <pre><code>gem 'mysql2', '~> 0.4', :platform => :ruby
23
16
  gem 'jdbc-mysql', '~> 5.1.35', :platform => :jruby
24
- gem 'thinking-sphinx', '~> 3.1.4'</code></pre>
17
+ gem 'thinking-sphinx', '~> 6.0'</code></pre>
25
18
 
26
19
  The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.
27
20
 
28
- You'll also need to install Sphinx - this is covered in "the extended documentation":http://pat.github.io/thinking-sphinx/installing_sphinx.html.
21
+ You'll also need to install Sphinx - this is covered in "the extended documentation":https://freelancing-gods.com/thinking-sphinx/installing_sphinx.html.
29
22
 
30
23
  h2. Usage
31
24
 
32
- Begin by reading the "quick-start guide":http://pat.github.io/thinking-sphinx/quickstart.html, and beyond that, "the documentation":http://pat.github.io/thinking-sphinx/ should serve you pretty well.
25
+ Begin by reading the "quick-start guide":https://freelancing-gods.com/thinking-sphinx/quickstart.html, and beyond that, "the documentation":https://freelancing-gods.com/thinking-sphinx/ should serve you pretty well.
26
+
27
+ h2. Requirements
33
28
 
34
- h3. Extending with Middleware, Glazes and Panes
29
+ The current release of Thinking Sphinx works with the following versions of its dependencies:
35
30
 
36
- These are covered in "a blog post":http://freelancing-gods.com/posts/rewriting_thinking_sphinx_middleware_glazes_and_panes.
31
+ |_. Library |_. Minimum |_. Tested Against |
32
+ | Ruby | v3.0 | v3.0..v4.0 |
33
+ | Sphinx | v2.2.11 | v2.2.11, v3.4.1 |
34
+ | Manticore | v2.8 | v4.0, v6.0 |
35
+ | ActiveRecord | v6.1 | v6.1..v8.1 |
37
36
 
38
- h2. Requirements
37
+ It _might_ work with older versions of Ruby (back to v2.7) and Rails (back to v5.0), but it's highly recommended to update to a supported release.
39
38
 
40
- h3. Sphinx
39
+ It should also work with JRuby, but the test environment for that in CI has been unreliable, hence that's not actively tested against at the moment.
41
40
 
42
- Thinking Sphinx v3 is currently built for Sphinx 2.0.5 or newer, and releases since v3.1.0 expect Sphinx 2.1.2 or newer by default.
41
+ h3. Sphinx or Manticore
42
+
43
+ If you're using Sphinx, v2.2.11 is recommended even though it's quite old, as it works well with PostgreSQL databases (but if you're using MySQL - or real-time indices - then v3.3.1 should also be fine).
44
+
45
+ If you're opting for Manticore instead, v2.8 or newer works, but v4 or newer is recommended as that's what is actively tested against. The v4.2 and 5.0 releases had bugs with facet searching, but that's been fixed in Manticore v6.0.
43
46
 
44
47
  h3. Rails and ActiveRecord
45
48
 
46
- Currently Thinking Sphinx 3 is built to support Rails/ActiveRecord 3.2 or newer. If you're using Sinatra and ActiveRecord instead of Rails, that's fine - just make sure you add the @:require => 'thinking_sphinx/sinatra'@ option when listing @thinking-sphinx@ in your Gemfile.
49
+ Currently Thinking Sphinx is built to support Rails/ActiveRecord 6.1 or newer. If you're using Sinatra and ActiveRecord instead of Rails, that's fine - just make sure you add the @:require => 'thinking_sphinx/sinatra'@ option when listing @thinking-sphinx@ in your Gemfile.
47
50
 
48
- Please note that if you're referring to polymorphic associations in your index definitions, you'll want to be using Rails/ActiveRecord 4.0 or newer. Supporting polymorphic associations and Rails/ActiveRecord 3.2 is problematic, and likely will not be addressed in the future.
51
+ The last releases for older Rails versions:
49
52
 
50
- If you want ActiveRecord 3.1 support, then refer to the 3.0.x releases of Thinking Sphinx. Anything older than that, then you're stuck with Thinking Sphinx v2.x (for Rails/ActiveRecord 3.0) or v1.x (Rails 2.3). Please note that these older versions are no longer actively supported.
53
+ |_. Rails Version |_. Thinking Sphinx Version |
54
+ | 6.0 | v5.6.0 |
55
+ | 5.2 | v5.6.0 |
56
+ | 5.1 | v5.6.0 |
57
+ | 5.0 | v5.6.0 |
58
+ | 4.2 | v5.6.0 |
59
+ | 4.1 | v4.4.1 |
60
+ | 4.0 | v4.4.1 |
61
+ | 3.2 | v4.4.1 |
62
+ | 3.1 | v3.0.6 |
63
+ | 3.0 | v2.1.0 |
64
+ | 2.3 | v1.5.0 |
51
65
 
52
- h3. Ruby
66
+ Please note that these older versions are no longer actively supported.
53
67
 
54
- You'll need either the standard Ruby (v1.9.3 or newer) or JRuby (1.7.9 or newer). I'm open to patches to improve Rubinius support (if required - it may work with it right now).
68
+ h3. Ruby
55
69
 
56
- JRuby is only supported as of Thinking Sphinx v3.1.0, and requires Sphinx 2.1.2 or newer.
70
+ You'll need either the standard Ruby (v3.0 or newer) or JRuby (9.1 or newer). The last release to support Ruby 2.4-2.7 is v5.6.0.
57
71
 
58
72
  h3. Database Versions
59
73
 
@@ -61,7 +75,7 @@ MySQL 5.x and Postgres 8.4 or better are supported.
61
75
 
62
76
  h2. Contributing
63
77
 
64
- Please note that this project now has a "Contributor Code of Conduct":http://contributor-covenant.org/version/1/0/0/. By participating in this project you agree to abide by its terms.
78
+ Please note that this project has a "Contributor Code of Conduct":http://contributor-covenant.org/version/1/0/0/. By participating in this project you agree to abide by its terms.
65
79
 
66
80
  To contribute, clone this repository and have a good look through the specs - you'll notice the distinction between acceptance tests that actually use Sphinx and go through the full stack, and unit tests (everything else) which use liberal test doubles to ensure they're only testing the behaviour of the class in question. I've found this leads to far better code design.
67
81
 
@@ -82,4 +96,4 @@ You can then run the unit tests with @rake spec:unit@, the acceptance tests with
82
96
 
83
97
  h2. Licence
84
98
 
85
- Copyright (c) 2007-2015, Thinking Sphinx is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to "all who have contributed patches":https://github.com/pat/thinking-sphinx/contributors.
99
+ Copyright (c) 2007-2026, Thinking Sphinx is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to "all who have contributed patches":https://github.com/pat/thinking-sphinx/contributors.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler'
2
4
  require 'appraisal'
3
5
 
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "thinking_sphinx"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/loadsphinx ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env bash
2
+
3
+ version=$1
4
+ engine=$2
5
+
6
+ set -e
7
+
8
+ load_sphinx () {
9
+ distro="xenial"
10
+
11
+ case $version in
12
+ 2.1.9)
13
+ url="http://sphinxsearch.com/files/sphinxsearch_2.1.9-release-0ubuntu11~trusty_amd64.deb"
14
+ format="deb"
15
+ distro="trusty";;
16
+ 2.2.11)
17
+ url="http://sphinxsearch.com/files/sphinxsearch_2.2.11-release-1~jessie_amd64.deb"
18
+ format="deb"
19
+ distro="trusty";;
20
+ 3.0.3)
21
+ url="http://sphinxsearch.com/files/sphinx-3.0.3-facc3fb-linux-amd64.tar.gz"
22
+ format="gz";;
23
+ 3.1.1)
24
+ url="http://sphinxsearch.com/files/sphinx-3.1.1-612d99f-linux-amd64.tar.gz"
25
+ format="gz";;
26
+ 3.2.1)
27
+ url="http://sphinxsearch.com/files/sphinx-3.2.1-f152e0b-linux-amd64.tar.gz"
28
+ format="gz";;
29
+ 3.3.1)
30
+ url="http://sphinxsearch.com/files/sphinx-3.3.1-b72d67b-linux-amd64.tar.gz"
31
+ format="gz";;
32
+ 3.4.1)
33
+ url="http://sphinxsearch.com/files/sphinx-3.4.1-efbcc65-linux-amd64.tar.gz"
34
+ format="gz";;
35
+ *)
36
+ echo "No Sphinx version $version available"
37
+ exit 1;;
38
+ esac
39
+
40
+ if [ "$distro" == "trusty" ]; then
41
+ curl --location http://launchpadlibrarian.net/247512886/libmysqlclient18_5.6.28-1ubuntu3_amd64.deb -o libmysql.deb
42
+ sudo apt-get install ./libmysql.deb
43
+ fi
44
+
45
+ if [ "$format" == "deb" ]; then
46
+ curl --location $url -o sphinx.deb
47
+ sudo apt-get install libodbc1
48
+ sudo dpkg -i ./sphinx.deb
49
+ sudo apt-get install -f
50
+ else
51
+ curl $url -o sphinx.tar.gz
52
+ tar -zxvf sphinx.tar.gz
53
+ sudo mv sphinx-$version/bin/* /usr/local/bin/.
54
+ fi
55
+ }
56
+
57
+ load_manticore () {
58
+ url="https://github.com/manticoresoftware/manticore/releases/download/$version/manticore_$version.deb"
59
+
60
+ case $version in
61
+ 2.6.4)
62
+ url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.6.4/manticore_2.6.4-180503-37308c3-release-stemmer.xenial_amd64-bin.deb";;
63
+ 2.7.5)
64
+ url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.7.5/manticore_2.7.5-181204-4a31c54-release-stemmer.xenial_amd64-bin.deb";;
65
+ 2.8.2)
66
+ url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.8.2/manticore_2.8.2-190402-4e81114d-release-stemmer.stretch_amd64-bin.deb";;
67
+ 3.4.2)
68
+ url="https://github.com/manticoresoftware/manticoresearch/releases/download/3.4.2/manticore_3.4.2-200410-6903305-release.xenial_amd64-bin.deb";;
69
+ 3.5.4)
70
+ url="https://repo.manticoresearch.com/repository/manticoresearch_focal/dists/focal/main/binary-amd64/manticore_3.5.4-210107-f70faec5_amd64.deb";;
71
+ 4.0.2)
72
+ url="https://repo.manticoresearch.com/repository/manticoresearch_focal/dists/focal/main/binary-amd64/manticore_4.0.2-210921-af497f245_amd64.deb";;
73
+ 4.2.0)
74
+ url="https://repo.manticoresearch.com/repository/manticoresearch_focal/dists/focal/main/binary-amd64/manticore_4.2.0-211223-15e927b28_amd64.deb";;
75
+ 6.0.0)
76
+ url="skipped";;
77
+ *)
78
+ echo "No Manticore version $version available"
79
+ exit 1;;
80
+ esac
81
+
82
+ if [ "$version" == "6.0.0" ]; then
83
+ curl --location https://repo.manticoresearch.com/manticore-repo.noarch.deb -o repo.deb
84
+ sudo dpkg -i repo.deb
85
+ sudo apt update
86
+ sudo apt install manticore
87
+ else
88
+ sudo apt-get install default-libmysqlclient-dev
89
+ curl --location $url -o manticore.deb
90
+ sudo dpkg -i ./manticore.deb
91
+ sudo apt-get install -f
92
+ fi
93
+ }
94
+
95
+ if [ "$engine" == "sphinx" ]; then
96
+ load_sphinx
97
+ else
98
+ load_manticore
99
+ fi
data/bin/testmatrix ADDED
@@ -0,0 +1,48 @@
1
+ #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+
6
+ RUBIES = %w[ 3.0 3.1 3.2 3.3 3.4 4.0 ]
7
+ DATABASES = %w[ mysql2 postgresql ]
8
+ SPHINX_ENGINES = {
9
+ "sphinx" => %w[ 2.2.11 3.4.1 ],
10
+ "manticore" => %w[ 4.0.2 6.0.0 ]
11
+ }.freeze
12
+ RAILS_VERSIONS = [
13
+ { version: '6_1', min_ruby: 2.7, max_ruby: 3.3 },
14
+ { version: '7_0', min_ruby: 2.7, max_ruby: 4.0 },
15
+ { version: '7_1', min_ruby: 2.7, max_ruby: 4.0 },
16
+ { version: '7_2', min_ruby: 3.1, max_ruby: 4.0 },
17
+ { version: '8_0', min_ruby: 3.2, max_ruby: 4.0 },
18
+ { version: '8_1', min_ruby: 3.2, max_ruby: 4.0 },
19
+ ].freeze
20
+
21
+ # Returns an array of hashes, with each hash being a valid testable
22
+ # combination:
23
+ output = []
24
+
25
+ RUBIES.each do |ruby|
26
+ DATABASES.each do |database|
27
+ SPHINX_ENGINES.each do |sphinx_engine, sphinx_versions|
28
+ sphinx_versions.each do |sphinx_version|
29
+ # Sphinx 3.4.1 doesn't play nicely with Postgres.
30
+ next if database == 'postgresql' && sphinx_engine == 'sphinx' && sphinx_version == '3.4.1'
31
+
32
+ RAILS_VERSIONS.each do |rails|
33
+ next unless ruby.to_f >= rails[:min_ruby] && ruby.to_f <= rails[:max_ruby]
34
+
35
+ output << {
36
+ ruby: ruby,
37
+ rails: rails[:version],
38
+ database: database,
39
+ sphinx_engine: sphinx_engine,
40
+ sphinx_version: sphinx_version
41
+ }
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ puts JSON.generate(output.compact)
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thinking_sphinx'
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thinking_sphinx'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ThinkingSphinx::ActiveRecord::Association
2
4
  def initialize(column)
3
5
  @column = column
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeFinder
2
4
  def initialize(association)
3
5
  @association = association
@@ -29,7 +31,7 @@ class ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeFinder
29
31
  @indices ||= begin
30
32
  configuration.preload_indices
31
33
  configuration.indices_for_references(
32
- *@association.klass.name.underscore.to_sym
34
+ *configuration.index_set_class.reference_name(@association.klass)
33
35
  ).reject &:distributed?
34
36
  end
35
37
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeMatcher
2
4
  def initialize(attribute, foreign_key)
3
5
  @attribute, @foreign_key = attribute, foreign_key.to_s
@@ -1,6 +1,6 @@
1
- module ThinkingSphinx::ActiveRecord::AssociationProxy
2
- extend ActiveSupport::Concern
1
+ # frozen_string_literal: true
3
2
 
3
+ module ThinkingSphinx::ActiveRecord::AssociationProxy
4
4
  def search(query = nil, options = {})
5
5
  perform_search super(*normalise_search_arguments(query, options))
6
6
  end
@@ -10,6 +10,7 @@ module ThinkingSphinx::ActiveRecord::AssociationProxy
10
10
  end
11
11
 
12
12
  private
13
+
13
14
  def normalise_search_arguments(query, options)
14
15
  query, options = nil, query if query.is_a?(Hash)
15
16
  options[:ignore_scopes] = true
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ThinkingSphinx::ActiveRecord::Attribute::SphinxPresenter
2
4
  SPHINX_TYPES = {
3
5
  :integer => :uint,
4
6
  :boolean => :bool,
5
- :timestamp => :timestamp,
7
+ :timestamp => :uint,
6
8
  :float => :float,
7
9
  :string => :string,
8
10
  :bigint => :bigint,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ThinkingSphinx::ActiveRecord::Attribute::Type
2
4
  UPDATEABLE_TYPES = [:integer, :timestamp, :boolean, :float]
3
5
 
@@ -41,7 +43,7 @@ class ThinkingSphinx::ActiveRecord::Attribute::Type
41
43
  end
42
44
 
43
45
  def big_integer?
44
- database_column.type == :integer && database_column.sql_type[/bigint/i]
46
+ type_symbol == :integer && database_column.sql_type[/bigint/i]
45
47
  end
46
48
 
47
49
  def column_name
@@ -72,19 +74,33 @@ class ThinkingSphinx::ActiveRecord::Attribute::Type
72
74
 
73
75
  def type_from_database
74
76
  raise ThinkingSphinx::MissingColumnError,
75
- "column #{column_name} does not exist" if database_column.nil?
77
+ "Cannot determine the database type of column #{column_name}, as it does not exist" if database_column.nil?
76
78
 
77
79
  return :bigint if big_integer?
78
80
 
79
- case database_column.type
81
+ case type_symbol
80
82
  when :datetime, :date
81
83
  :timestamp
82
84
  when :text
83
85
  :string
84
86
  when :decimal
85
87
  :float
88
+ when :integer, :boolean, :timestamp, :float, :string, :bigint, :json
89
+ type_symbol
86
90
  else
87
- database_column.type
91
+ raise ThinkingSphinx::UnknownAttributeType,
92
+ <<-ERROR
93
+ Unable to determine an equivalent Sphinx attribute type from #{database_column.type.class.name} for attribute #{attribute.name}. You may want to manually set the type.
94
+
95
+ e.g.
96
+ has my_column, :type => :integer
97
+ ERROR
88
98
  end
89
99
  end
100
+
101
+ def type_symbol
102
+ return database_column.type if database_column.type.is_a?(Symbol)
103
+
104
+ database_column.type.class.name.demodulize.downcase.to_sym
105
+ end
90
106
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ThinkingSphinx::ActiveRecord::Attribute::Values
2
4
  def initialize(attribute)
3
5
  @attribute = attribute
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ThinkingSphinx::ActiveRecord::Attribute <
2
4
  ThinkingSphinx::ActiveRecord::Property
3
5
 
@@ -1,35 +1,67 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ThinkingSphinx::ActiveRecord::Base
2
4
  extend ActiveSupport::Concern
3
5
 
4
6
  included do
5
- after_destroy ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks
6
- before_save ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
7
- after_update ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks
8
- after_commit ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
7
+ # Avoid method collisions for public Thinking Sphinx methods added to all
8
+ # ActiveRecord models. The `sphinx_`-prefixed versions will always exist,
9
+ # and the non-prefixed versions will be added if a method of that name
10
+ # doesn't already exist.
11
+ #
12
+ # If a method is overwritten later by something else, that's also fine - the
13
+ # prefixed versions will still be there.
14
+ class_module = ThinkingSphinx::ActiveRecord::Base::ClassMethods
15
+ class_module.public_instance_methods.each do |method_name|
16
+ short_method = method_name.to_s.delete_prefix("sphinx_").to_sym
17
+ next if methods.include?(short_method)
18
+
19
+ define_singleton_method(short_method, method(method_name))
20
+ end
21
+
22
+ if ActiveRecord::VERSION::STRING.to_i >= 5
23
+ [
24
+ ::ActiveRecord::Reflection::HasManyReflection,
25
+ ::ActiveRecord::Reflection::HasAndBelongsToManyReflection
26
+ ].each do |reflection_class|
27
+ reflection_class.include DefaultReflectionAssociations
28
+ end
29
+ else
30
+ ::ActiveRecord::Associations::CollectionProxy.include(
31
+ ThinkingSphinx::ActiveRecord::AssociationProxy
32
+ )
33
+ end
34
+ end
9
35
 
10
- ::ActiveRecord::Associations::CollectionProxy.send :include,
11
- ThinkingSphinx::ActiveRecord::AssociationProxy
36
+ module DefaultReflectionAssociations
37
+ def extensions
38
+ super + [ThinkingSphinx::ActiveRecord::AssociationProxy]
39
+ end
12
40
  end
13
41
 
14
42
  module ClassMethods
15
- def facets(query = nil, options = {})
43
+ def sphinx_facets(query = nil, options = {})
16
44
  merge_search ThinkingSphinx.facets, query, options
17
45
  end
18
46
 
19
- def search(query = nil, options = {})
47
+ def sphinx_search(query = nil, options = {})
20
48
  merge_search ThinkingSphinx.search, query, options
21
49
  end
22
50
 
23
- def search_count(query = nil, options = {})
24
- search(query, options).total_entries
51
+ def sphinx_search_count(query = nil, options = {})
52
+ search_for_ids(query, options).total_entries
25
53
  end
26
54
 
27
- def search_for_ids(query = nil, options = {})
55
+ def sphinx_search_for_ids(query = nil, options = {})
28
56
  ThinkingSphinx::Search::Merger.new(
29
57
  search(query, options)
30
58
  ).merge! nil, :ids_only => true
31
59
  end
32
60
 
61
+ def sphinx_search_none
62
+ merge_search ThinkingSphinx.search, nil, none: true
63
+ end
64
+
33
65
  private
34
66
 
35
67
  def default_sphinx_scope?
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ThinkingSphinx::ActiveRecord::Callbacks::AssociationDeltaCallbacks
4
+ def initialize(path)
5
+ @path = path
6
+ end
7
+
8
+ def after_commit(instance)
9
+ Array(objects_for(instance)).each do |object|
10
+ object.update :delta => true unless object.frozen?
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :path
17
+
18
+ def objects_for(instance)
19
+ path.inject(instance) { |object, method| object.send method }
20
+ end
21
+ end
@@ -1,21 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks <
2
4
  ThinkingSphinx::Callbacks
3
5
 
4
- callbacks :after_destroy
6
+ callbacks :after_commit, :after_destroy, :after_rollback
7
+
8
+ def after_commit
9
+ delete_from_sphinx
10
+ end
5
11
 
6
12
  def after_destroy
7
- return if instance.new_record?
13
+ delete_from_sphinx
14
+ end
8
15
 
9
- indices.each { |index|
10
- ThinkingSphinx::Deletion.perform index, instance.id
11
- }
16
+ def after_rollback
17
+ delete_from_sphinx
12
18
  end
13
19
 
14
20
  private
15
21
 
16
- def indices
17
- ThinkingSphinx::Configuration.instance.index_set_class.new(
18
- :classes => [instance.class]
19
- ).to_a
22
+ def delete_from_sphinx
23
+ return if ThinkingSphinx::Callbacks.suspended?
24
+
25
+ ThinkingSphinx::Processor.new(instance: instance).delete
20
26
  end
21
27
  end
@@ -1,12 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
2
4
  ThinkingSphinx::Callbacks
3
5
 
4
6
  callbacks :after_commit, :before_save
5
7
 
6
8
  def after_commit
7
- return unless delta_indices? && processors.any? { |processor|
8
- processor.toggled?(instance)
9
- } && !ThinkingSphinx::Deltas.suspended?
9
+ return unless !suspended? && delta_indices? && toggled?
10
10
 
11
11
  delta_indices.each do |index|
12
12
  index.delta_processor.index index
@@ -18,7 +18,8 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
18
18
  end
19
19
 
20
20
  def before_save
21
- return unless delta_indices?
21
+ return unless !ThinkingSphinx::Callbacks.suspended? && delta_indices? &&
22
+ new_or_changed?
22
23
 
23
24
  processors.each { |processor| processor.toggle instance }
24
25
  end
@@ -42,10 +43,24 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
42
43
  end
43
44
 
44
45
  def indices
45
- @indices ||= config.index_set_class.new :classes => [instance.class]
46
+ @indices ||= config.index_set_class.new(
47
+ :instances => [instance], :classes => [instance.class]
48
+ ).select { |index| index.type == "plain" }
49
+ end
50
+
51
+ def new_or_changed?
52
+ instance.new_record? || instance.changed?
46
53
  end
47
54
 
48
55
  def processors
49
56
  delta_indices.collect &:delta_processor
50
57
  end
58
+
59
+ def suspended?
60
+ ThinkingSphinx::Callbacks.suspended? || ThinkingSphinx::Deltas.suspended?
61
+ end
62
+
63
+ def toggled?
64
+ processors.any? { |processor| processor.toggled?(instance) }
65
+ end
51
66
  end