thinking-sphinx 1.2.13 → 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 (517) hide show
  1. checksums.yaml +7 -0
  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 +18 -0
  6. data/.travis.yml +36 -0
  7. data/Appraisals +71 -0
  8. data/CHANGELOG.markdown +782 -0
  9. data/Gemfile +18 -0
  10. data/LICENCE +1 -1
  11. data/Procfile.support +2 -0
  12. data/README.textile +91 -136
  13. data/Rakefile +26 -0
  14. data/bin/console +15 -0
  15. data/bin/loadsphinx +99 -0
  16. data/bin/testmatrix +48 -0
  17. data/lib/thinking/sphinx.rb +3 -0
  18. data/lib/thinking-sphinx.rb +3 -0
  19. data/lib/thinking_sphinx/active_record/association.rb +19 -0
  20. data/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb +44 -0
  21. data/lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb +40 -0
  22. data/lib/thinking_sphinx/active_record/association_proxy.rb +34 -0
  23. data/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb +52 -0
  24. data/lib/thinking_sphinx/active_record/attribute/type.rb +106 -0
  25. data/lib/thinking_sphinx/active_record/attribute/values.rb +20 -0
  26. data/lib/thinking_sphinx/active_record/attribute.rb +22 -0
  27. data/lib/thinking_sphinx/active_record/base.rb +91 -0
  28. data/lib/thinking_sphinx/active_record/callbacks/association_delta_callbacks.rb +21 -0
  29. data/lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb +27 -0
  30. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +66 -0
  31. data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +78 -0
  32. data/lib/thinking_sphinx/active_record/column.rb +44 -0
  33. data/lib/thinking_sphinx/active_record/column_sql_presenter.rb +54 -0
  34. data/lib/thinking_sphinx/active_record/database_adapters/abstract_adapter.rb +19 -0
  35. data/lib/thinking_sphinx/active_record/database_adapters/mysql_adapter.rb +51 -0
  36. data/lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb +47 -0
  37. data/lib/thinking_sphinx/active_record/database_adapters.rb +59 -0
  38. data/lib/thinking_sphinx/active_record/depolymorph/association_reflection.rb +32 -0
  39. data/lib/thinking_sphinx/active_record/depolymorph/base_reflection.rb +32 -0
  40. data/lib/thinking_sphinx/active_record/depolymorph/conditions_reflection.rb +40 -0
  41. data/lib/thinking_sphinx/active_record/depolymorph/overridden_reflection.rb +50 -0
  42. data/lib/thinking_sphinx/active_record/depolymorph/scoped_reflection.rb +26 -0
  43. data/lib/thinking_sphinx/active_record/field.rb +18 -0
  44. data/lib/thinking_sphinx/active_record/filter_reflection.rb +18 -0
  45. data/lib/thinking_sphinx/active_record/index.rb +71 -0
  46. data/lib/thinking_sphinx/active_record/interpreter.rb +77 -0
  47. data/lib/thinking_sphinx/active_record/join_association.rb +17 -0
  48. data/lib/thinking_sphinx/active_record/log_subscriber.rb +37 -0
  49. data/lib/thinking_sphinx/active_record/polymorpher.rb +64 -0
  50. data/lib/thinking_sphinx/active_record/property.rb +30 -0
  51. data/lib/thinking_sphinx/active_record/property_query.rb +149 -0
  52. data/lib/thinking_sphinx/active_record/property_sql_presenter.rb +89 -0
  53. data/lib/thinking_sphinx/active_record/simple_many_query.rb +37 -0
  54. data/lib/thinking_sphinx/active_record/source_joins.rb +68 -0
  55. data/lib/thinking_sphinx/active_record/sql_builder/clause_builder.rb +29 -0
  56. data/lib/thinking_sphinx/active_record/sql_builder/query.rb +59 -0
  57. data/lib/thinking_sphinx/active_record/sql_builder/statement.rb +147 -0
  58. data/lib/thinking_sphinx/active_record/sql_builder.rb +107 -0
  59. data/lib/thinking_sphinx/active_record/sql_source/template.rb +55 -0
  60. data/lib/thinking_sphinx/active_record/sql_source.rb +173 -0
  61. data/lib/thinking_sphinx/active_record.rb +39 -301
  62. data/lib/thinking_sphinx/attribute_types.rb +72 -0
  63. data/lib/thinking_sphinx/batched_search.rb +28 -0
  64. data/lib/thinking_sphinx/callbacks/appender.rb +63 -0
  65. data/lib/thinking_sphinx/callbacks.rb +44 -0
  66. data/lib/thinking_sphinx/capistrano/v2.rb +60 -0
  67. data/lib/thinking_sphinx/capistrano/v3.rb +104 -0
  68. data/lib/thinking_sphinx/capistrano.rb +10 -0
  69. data/lib/thinking_sphinx/commander.rb +27 -0
  70. data/lib/thinking_sphinx/commands/base.rb +53 -0
  71. data/lib/thinking_sphinx/commands/clear_real_time.rb +22 -0
  72. data/lib/thinking_sphinx/commands/clear_sql.rb +18 -0
  73. data/lib/thinking_sphinx/commands/configure.rb +15 -0
  74. data/lib/thinking_sphinx/commands/index_real_time.rb +15 -0
  75. data/lib/thinking_sphinx/commands/index_sql.rb +25 -0
  76. data/lib/thinking_sphinx/commands/merge.rb +27 -0
  77. data/lib/thinking_sphinx/commands/merge_and_update.rb +57 -0
  78. data/lib/thinking_sphinx/commands/prepare.rb +15 -0
  79. data/lib/thinking_sphinx/commands/rotate.rb +13 -0
  80. data/lib/thinking_sphinx/commands/running.rb +15 -0
  81. data/lib/thinking_sphinx/commands/start_attached.rb +22 -0
  82. data/lib/thinking_sphinx/commands/start_detached.rb +21 -0
  83. data/lib/thinking_sphinx/commands/stop.rb +24 -0
  84. data/lib/thinking_sphinx/commands.rb +20 -0
  85. data/lib/thinking_sphinx/configuration/consistent_ids.rb +35 -0
  86. data/lib/thinking_sphinx/configuration/defaults.rb +7 -0
  87. data/lib/thinking_sphinx/configuration/distributed_indices.rb +31 -0
  88. data/lib/thinking_sphinx/configuration/duplicate_names.rb +36 -0
  89. data/lib/thinking_sphinx/configuration/minimum_fields.rb +36 -0
  90. data/lib/thinking_sphinx/configuration.rb +196 -269
  91. data/lib/thinking_sphinx/connection/client.rb +74 -0
  92. data/lib/thinking_sphinx/connection/jruby.rb +58 -0
  93. data/lib/thinking_sphinx/connection/mri.rb +26 -0
  94. data/lib/thinking_sphinx/connection.rb +73 -0
  95. data/lib/thinking_sphinx/core/field.rb +11 -0
  96. data/lib/thinking_sphinx/core/index.rb +110 -0
  97. data/lib/thinking_sphinx/core/interpreter.rb +25 -0
  98. data/lib/thinking_sphinx/core/property.rb +15 -0
  99. data/lib/thinking_sphinx/core/settings.rb +11 -0
  100. data/lib/thinking_sphinx/core.rb +11 -0
  101. data/lib/thinking_sphinx/deletion.rb +70 -0
  102. data/lib/thinking_sphinx/deltas/default_delta.rb +57 -66
  103. data/lib/thinking_sphinx/deltas/delete_job.rb +27 -0
  104. data/lib/thinking_sphinx/deltas/index_job.rb +28 -0
  105. data/lib/thinking_sphinx/deltas.rb +52 -27
  106. data/lib/thinking_sphinx/distributed/index.rb +46 -0
  107. data/lib/thinking_sphinx/distributed.rb +7 -0
  108. data/lib/thinking_sphinx/errors.rb +96 -0
  109. data/lib/thinking_sphinx/excerpter.rb +36 -19
  110. data/lib/thinking_sphinx/facet.rb +29 -122
  111. data/lib/thinking_sphinx/facet_search.rb +132 -125
  112. data/lib/thinking_sphinx/float_formatter.rb +35 -0
  113. data/lib/thinking_sphinx/frameworks/plain.rb +10 -0
  114. data/lib/thinking_sphinx/frameworks/rails.rb +11 -0
  115. data/lib/thinking_sphinx/frameworks.rb +11 -0
  116. data/lib/thinking_sphinx/guard/file.rb +28 -0
  117. data/lib/thinking_sphinx/guard/files.rb +40 -0
  118. data/lib/thinking_sphinx/guard/none.rb +7 -0
  119. data/lib/thinking_sphinx/guard.rb +9 -0
  120. data/lib/thinking_sphinx/hooks/guard_presence.rb +34 -0
  121. data/lib/thinking_sphinx/index.rb +50 -92
  122. data/lib/thinking_sphinx/index_set.rb +96 -0
  123. data/lib/thinking_sphinx/indexing_strategies/all_at_once.rb +9 -0
  124. data/lib/thinking_sphinx/indexing_strategies/one_at_a_time.rb +16 -0
  125. data/lib/thinking_sphinx/interfaces/base.rb +13 -0
  126. data/lib/thinking_sphinx/interfaces/daemon.rb +27 -0
  127. data/lib/thinking_sphinx/interfaces/real_time.rb +46 -0
  128. data/lib/thinking_sphinx/interfaces/sql.rb +53 -0
  129. data/lib/thinking_sphinx/interfaces.rb +10 -0
  130. data/lib/thinking_sphinx/logger.rb +9 -0
  131. data/lib/thinking_sphinx/masks/group_enumerators_mask.rb +30 -0
  132. data/lib/thinking_sphinx/masks/pagination_mask.rb +63 -0
  133. data/lib/thinking_sphinx/masks/scopes_mask.rb +56 -0
  134. data/lib/thinking_sphinx/masks/weight_enumerator_mask.rb +17 -0
  135. data/lib/thinking_sphinx/masks.rb +10 -0
  136. data/lib/thinking_sphinx/middlewares/active_record_translator.rb +103 -0
  137. data/lib/thinking_sphinx/middlewares/geographer.rb +94 -0
  138. data/lib/thinking_sphinx/middlewares/glazier.rb +52 -0
  139. data/lib/thinking_sphinx/middlewares/ids_only.rb +15 -0
  140. data/lib/thinking_sphinx/middlewares/inquirer.rb +64 -0
  141. data/lib/thinking_sphinx/middlewares/middleware.rb +11 -0
  142. data/lib/thinking_sphinx/middlewares/sphinxql.rb +256 -0
  143. data/lib/thinking_sphinx/middlewares/stale_id_checker.rb +47 -0
  144. data/lib/thinking_sphinx/middlewares/stale_id_filter.rb +48 -0
  145. data/lib/thinking_sphinx/middlewares/valid_options.rb +25 -0
  146. data/lib/thinking_sphinx/middlewares.rb +35 -0
  147. data/lib/thinking_sphinx/panes/attributes_pane.rb +11 -0
  148. data/lib/thinking_sphinx/panes/distance_pane.rb +15 -0
  149. data/lib/thinking_sphinx/panes/excerpts_pane.rb +43 -0
  150. data/lib/thinking_sphinx/panes/weight_pane.rb +11 -0
  151. data/lib/thinking_sphinx/panes.rb +10 -0
  152. data/lib/thinking_sphinx/processor.rb +71 -0
  153. data/lib/thinking_sphinx/query.rb +11 -0
  154. data/lib/thinking_sphinx/railtie.rb +38 -0
  155. data/lib/thinking_sphinx/rake_interface.rb +34 -0
  156. data/lib/thinking_sphinx/real_time/attribute.rb +27 -0
  157. data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +60 -0
  158. data/lib/thinking_sphinx/real_time/field.rb +9 -0
  159. data/lib/thinking_sphinx/real_time/index/template.rb +52 -0
  160. data/lib/thinking_sphinx/real_time/index.rb +102 -0
  161. data/lib/thinking_sphinx/real_time/interpreter.rb +54 -0
  162. data/lib/thinking_sphinx/real_time/populator.rb +46 -0
  163. data/lib/thinking_sphinx/real_time/processor.rb +36 -0
  164. data/lib/thinking_sphinx/real_time/property.rb +21 -0
  165. data/lib/thinking_sphinx/real_time/transcribe_instance.rb +38 -0
  166. data/lib/thinking_sphinx/real_time/transcriber.rb +89 -0
  167. data/lib/thinking_sphinx/real_time/translator.rb +39 -0
  168. data/lib/thinking_sphinx/real_time.rb +40 -0
  169. data/lib/thinking_sphinx/scopes.rb +34 -0
  170. data/lib/thinking_sphinx/search/batch_inquirer.rb +23 -0
  171. data/lib/thinking_sphinx/search/context.rb +31 -0
  172. data/lib/thinking_sphinx/search/glaze.rb +39 -0
  173. data/lib/thinking_sphinx/search/merger.rb +34 -0
  174. data/lib/thinking_sphinx/search/query.rb +33 -0
  175. data/lib/thinking_sphinx/search/stale_ids_exception.rb +15 -0
  176. data/lib/thinking_sphinx/search.rb +166 -704
  177. data/lib/thinking_sphinx/settings.rb +128 -0
  178. data/lib/thinking_sphinx/sinatra.rb +7 -0
  179. data/lib/thinking_sphinx/subscribers/populator_subscriber.rb +48 -0
  180. data/lib/thinking_sphinx/tasks.rb +70 -150
  181. data/lib/thinking_sphinx/test.rb +56 -0
  182. data/lib/thinking_sphinx/utf8.rb +18 -0
  183. data/lib/thinking_sphinx/wildcard.rb +42 -0
  184. data/lib/thinking_sphinx/with_output.rb +13 -0
  185. data/lib/thinking_sphinx.rb +83 -185
  186. data/spec/acceptance/association_scoping_spec.rb +65 -0
  187. data/spec/acceptance/attribute_access_spec.rb +58 -0
  188. data/spec/acceptance/attribute_updates_spec.rb +18 -0
  189. data/spec/acceptance/batch_searching_spec.rb +23 -0
  190. data/spec/acceptance/big_integers_spec.rb +61 -0
  191. data/spec/acceptance/excerpts_spec.rb +50 -0
  192. data/spec/acceptance/facets_spec.rb +141 -0
  193. data/spec/acceptance/geosearching_spec.rb +70 -0
  194. data/spec/acceptance/grouping_by_attributes_spec.rb +79 -0
  195. data/spec/acceptance/index_options_spec.rb +154 -0
  196. data/spec/acceptance/indexing_spec.rb +38 -0
  197. data/spec/acceptance/merging_spec.rb +90 -0
  198. data/spec/acceptance/paginating_search_results_spec.rb +42 -0
  199. data/spec/acceptance/real_time_updates_spec.rb +115 -0
  200. data/spec/acceptance/remove_deleted_records_spec.rb +99 -0
  201. data/spec/acceptance/search_counts_spec.rb +20 -0
  202. data/spec/acceptance/search_for_just_ids_spec.rb +21 -0
  203. data/spec/acceptance/searching_across_models_spec.rb +47 -0
  204. data/spec/acceptance/searching_across_schemas_spec.rb +40 -0
  205. data/spec/acceptance/searching_on_fields_spec.rb +59 -0
  206. data/spec/acceptance/searching_with_filters_spec.rb +159 -0
  207. data/spec/acceptance/searching_with_sti_spec.rb +76 -0
  208. data/spec/acceptance/searching_within_a_model_spec.rb +117 -0
  209. data/spec/acceptance/sorting_search_results_spec.rb +50 -0
  210. data/spec/acceptance/spec_helper.rb +6 -0
  211. data/spec/acceptance/specifying_sql_spec.rb +516 -0
  212. data/spec/acceptance/sphinx_scopes_spec.rb +87 -0
  213. data/spec/acceptance/sql_deltas_spec.rb +78 -0
  214. data/spec/acceptance/support/database_cleaner.rb +13 -0
  215. data/spec/acceptance/support/sphinx_controller.rb +62 -0
  216. data/spec/acceptance/support/sphinx_helpers.rb +45 -0
  217. data/spec/acceptance/suspended_deltas_spec.rb +56 -0
  218. data/spec/fixtures/database.yml +4 -0
  219. data/spec/internal/app/indices/admin_person_index.rb +9 -0
  220. data/spec/internal/app/indices/album_index.rb +9 -0
  221. data/spec/internal/app/indices/animal_index.rb +5 -0
  222. data/spec/internal/app/indices/article_index.rb +31 -0
  223. data/spec/internal/app/indices/bird_index.rb +6 -0
  224. data/spec/internal/app/indices/book_index.rb +11 -0
  225. data/spec/internal/app/indices/car_index.rb +7 -0
  226. data/spec/internal/app/indices/city_index.rb +9 -0
  227. data/spec/internal/app/indices/colour_index.rb +7 -0
  228. data/spec/internal/app/indices/product_index.rb +27 -0
  229. data/spec/internal/app/indices/tee_index.rb +6 -0
  230. data/spec/internal/app/indices/user_index.rb +9 -0
  231. data/spec/internal/app/models/admin/person.rb +9 -0
  232. data/spec/internal/app/models/album.rb +25 -0
  233. data/spec/internal/app/models/animal.rb +5 -0
  234. data/spec/internal/app/models/article.rb +9 -0
  235. data/spec/internal/app/models/bird.rb +5 -0
  236. data/spec/internal/app/models/book.rb +18 -0
  237. data/spec/internal/app/models/car.rb +7 -0
  238. data/spec/internal/app/models/categorisation.rb +15 -0
  239. data/spec/internal/app/models/category.rb +6 -0
  240. data/spec/internal/app/models/city.rb +7 -0
  241. data/spec/internal/app/models/colour.rb +7 -0
  242. data/spec/internal/app/models/event.rb +5 -0
  243. data/spec/internal/app/models/flightless_bird.rb +4 -0
  244. data/spec/internal/app/models/genre.rb +5 -0
  245. data/spec/internal/app/models/hardcover.rb +5 -0
  246. data/spec/internal/app/models/mammal.rb +4 -0
  247. data/spec/internal/app/models/manufacturer.rb +5 -0
  248. data/spec/internal/app/models/product.rb +8 -0
  249. data/spec/internal/app/models/tag.rb +6 -0
  250. data/{features/support → spec/internal/app}/models/tagging.rb +3 -1
  251. data/spec/internal/app/models/tee.rb +10 -0
  252. data/spec/internal/app/models/tweet.rb +5 -0
  253. data/spec/internal/app/models/user.rb +10 -0
  254. data/spec/internal/config/database.yml +17 -0
  255. data/spec/internal/db/schema.rb +115 -0
  256. data/spec/internal/tmp/.gitkeep +0 -0
  257. data/spec/spec_helper.rb +29 -0
  258. data/spec/support/json_column.rb +35 -0
  259. data/spec/support/multi_schema.rb +50 -0
  260. data/spec/support/mysql.rb +25 -0
  261. data/spec/support/sphinx_yaml_helpers.rb +16 -0
  262. data/spec/thinking_sphinx/active_record/association_spec.rb +14 -0
  263. data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +165 -0
  264. data/spec/thinking_sphinx/active_record/base_spec.rb +131 -0
  265. data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +128 -0
  266. data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +176 -0
  267. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +91 -0
  268. data/spec/thinking_sphinx/active_record/column_spec.rb +72 -0
  269. data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +39 -0
  270. data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +33 -0
  271. data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +70 -0
  272. data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +66 -0
  273. data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +128 -0
  274. data/spec/thinking_sphinx/active_record/field_spec.rb +51 -0
  275. data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +207 -0
  276. data/spec/thinking_sphinx/active_record/index_spec.rb +220 -0
  277. data/spec/thinking_sphinx/active_record/interpreter_spec.rb +329 -0
  278. data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +87 -0
  279. data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +264 -0
  280. data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +662 -0
  281. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +507 -0
  282. data/spec/thinking_sphinx/attribute_types_spec.rb +52 -0
  283. data/spec/thinking_sphinx/commands/clear_real_time_spec.rb +46 -0
  284. data/spec/thinking_sphinx/commands/clear_sql_spec.rb +52 -0
  285. data/spec/thinking_sphinx/commands/configure_spec.rb +31 -0
  286. data/spec/thinking_sphinx/commands/index_real_time_spec.rb +33 -0
  287. data/spec/thinking_sphinx/commands/index_sql_spec.rb +86 -0
  288. data/spec/thinking_sphinx/commands/merge_and_update_spec.rb +106 -0
  289. data/spec/thinking_sphinx/commands/merge_spec.rb +48 -0
  290. data/spec/thinking_sphinx/commands/prepare_spec.rb +31 -0
  291. data/spec/thinking_sphinx/commands/running_spec.rb +30 -0
  292. data/spec/thinking_sphinx/commands/start_detached_spec.rb +67 -0
  293. data/spec/thinking_sphinx/commands/stop_spec.rb +63 -0
  294. data/spec/thinking_sphinx/configuration/minimum_fields_spec.rb +60 -0
  295. data/spec/thinking_sphinx/configuration_spec.rb +582 -0
  296. data/spec/thinking_sphinx/connection/mri_spec.rb +49 -0
  297. data/spec/thinking_sphinx/connection_spec.rb +87 -0
  298. data/spec/thinking_sphinx/deletion_spec.rb +57 -0
  299. data/spec/thinking_sphinx/deltas/default_delta_spec.rb +123 -0
  300. data/spec/thinking_sphinx/deltas_spec.rb +77 -0
  301. data/spec/thinking_sphinx/errors_spec.rb +103 -0
  302. data/spec/thinking_sphinx/excerpter_spec.rb +53 -0
  303. data/spec/thinking_sphinx/facet_search_spec.rb +133 -0
  304. data/spec/thinking_sphinx/hooks/guard_presence_spec.rb +30 -0
  305. data/spec/thinking_sphinx/index_set_spec.rb +132 -0
  306. data/spec/thinking_sphinx/index_spec.rb +140 -0
  307. data/spec/thinking_sphinx/interfaces/daemon_spec.rb +60 -0
  308. data/spec/thinking_sphinx/interfaces/real_time_spec.rb +109 -0
  309. data/spec/thinking_sphinx/interfaces/sql_spec.rb +122 -0
  310. data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +123 -0
  311. data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +139 -0
  312. data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +180 -0
  313. data/spec/thinking_sphinx/middlewares/geographer_spec.rb +102 -0
  314. data/spec/thinking_sphinx/middlewares/glazier_spec.rb +65 -0
  315. data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +72 -0
  316. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +401 -0
  317. data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +50 -0
  318. data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +113 -0
  319. data/spec/thinking_sphinx/middlewares/valid_options_spec.rb +51 -0
  320. data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +23 -0
  321. data/spec/thinking_sphinx/panes/distance_pane_spec.rb +43 -0
  322. data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +53 -0
  323. data/spec/thinking_sphinx/panes/weight_pane_spec.rb +22 -0
  324. data/spec/thinking_sphinx/rake_interface_spec.rb +39 -0
  325. data/spec/thinking_sphinx/real_time/attribute_spec.rb +64 -0
  326. data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +238 -0
  327. data/spec/thinking_sphinx/real_time/field_spec.rb +69 -0
  328. data/spec/thinking_sphinx/real_time/index_spec.rb +230 -0
  329. data/spec/thinking_sphinx/real_time/interpreter_spec.rb +203 -0
  330. data/spec/thinking_sphinx/real_time/transcribe_instance_spec.rb +35 -0
  331. data/spec/thinking_sphinx/real_time/transcriber_spec.rb +109 -0
  332. data/spec/thinking_sphinx/real_time/translator_spec.rb +17 -0
  333. data/spec/thinking_sphinx/scopes_spec.rb +51 -0
  334. data/spec/thinking_sphinx/search/glaze_spec.rb +79 -0
  335. data/spec/thinking_sphinx/search/query_spec.rb +87 -0
  336. data/spec/thinking_sphinx/search_spec.rb +214 -0
  337. data/spec/thinking_sphinx/wildcard_spec.rb +53 -0
  338. data/spec/thinking_sphinx_spec.rb +44 -0
  339. data/thinking-sphinx.gemspec +42 -0
  340. metadata +656 -243
  341. data/VERSION.yml +0 -5
  342. data/features/alternate_primary_key.feature +0 -27
  343. data/features/attribute_transformation.feature +0 -22
  344. data/features/attribute_updates.feature +0 -33
  345. data/features/datetime_deltas.feature +0 -66
  346. data/features/delayed_delta_indexing.feature +0 -37
  347. data/features/deleting_instances.feature +0 -64
  348. data/features/direct_attributes.feature +0 -11
  349. data/features/excerpts.feature +0 -13
  350. data/features/extensible_delta_indexing.feature +0 -9
  351. data/features/facets.feature +0 -76
  352. data/features/facets_across_model.feature +0 -29
  353. data/features/handling_edits.feature +0 -92
  354. data/features/retry_stale_indexes.feature +0 -24
  355. data/features/searching_across_models.feature +0 -20
  356. data/features/searching_by_model.feature +0 -175
  357. data/features/searching_with_find_arguments.feature +0 -56
  358. data/features/sphinx_detection.feature +0 -25
  359. data/features/sphinx_scopes.feature +0 -35
  360. data/features/step_definitions/alpha_steps.rb +0 -3
  361. data/features/step_definitions/beta_steps.rb +0 -7
  362. data/features/step_definitions/common_steps.rb +0 -178
  363. data/features/step_definitions/datetime_delta_steps.rb +0 -15
  364. data/features/step_definitions/delayed_delta_indexing_steps.rb +0 -7
  365. data/features/step_definitions/extensible_delta_indexing_steps.rb +0 -7
  366. data/features/step_definitions/facet_steps.rb +0 -92
  367. data/features/step_definitions/find_arguments_steps.rb +0 -36
  368. data/features/step_definitions/gamma_steps.rb +0 -15
  369. data/features/step_definitions/scope_steps.rb +0 -11
  370. data/features/step_definitions/search_steps.rb +0 -89
  371. data/features/step_definitions/sphinx_steps.rb +0 -31
  372. data/features/sti_searching.feature +0 -14
  373. data/features/support/database.example.yml +0 -3
  374. data/features/support/database.yml +0 -5
  375. data/features/support/db/active_record.rb +0 -40
  376. data/features/support/db/database.yml +0 -5
  377. data/features/support/db/fixtures/alphas.rb +0 -10
  378. data/features/support/db/fixtures/authors.rb +0 -1
  379. data/features/support/db/fixtures/betas.rb +0 -10
  380. data/features/support/db/fixtures/boxes.rb +0 -9
  381. data/features/support/db/fixtures/categories.rb +0 -1
  382. data/features/support/db/fixtures/cats.rb +0 -3
  383. data/features/support/db/fixtures/comments.rb +0 -24
  384. data/features/support/db/fixtures/delayed_betas.rb +0 -10
  385. data/features/support/db/fixtures/developers.rb +0 -29
  386. data/features/support/db/fixtures/dogs.rb +0 -3
  387. data/features/support/db/fixtures/extensible_betas.rb +0 -10
  388. data/features/support/db/fixtures/gammas.rb +0 -10
  389. data/features/support/db/fixtures/people.rb +0 -1001
  390. data/features/support/db/fixtures/posts.rb +0 -6
  391. data/features/support/db/fixtures/robots.rb +0 -14
  392. data/features/support/db/fixtures/tags.rb +0 -27
  393. data/features/support/db/fixtures/thetas.rb +0 -10
  394. data/features/support/db/migrations/create_alphas.rb +0 -7
  395. data/features/support/db/migrations/create_animals.rb +0 -5
  396. data/features/support/db/migrations/create_authors.rb +0 -3
  397. data/features/support/db/migrations/create_authors_posts.rb +0 -6
  398. data/features/support/db/migrations/create_betas.rb +0 -5
  399. data/features/support/db/migrations/create_boxes.rb +0 -5
  400. data/features/support/db/migrations/create_categories.rb +0 -3
  401. data/features/support/db/migrations/create_comments.rb +0 -10
  402. data/features/support/db/migrations/create_delayed_betas.rb +0 -17
  403. data/features/support/db/migrations/create_developers.rb +0 -9
  404. data/features/support/db/migrations/create_extensible_betas.rb +0 -5
  405. data/features/support/db/migrations/create_gammas.rb +0 -3
  406. data/features/support/db/migrations/create_people.rb +0 -13
  407. data/features/support/db/migrations/create_posts.rb +0 -5
  408. data/features/support/db/migrations/create_robots.rb +0 -4
  409. data/features/support/db/migrations/create_taggings.rb +0 -5
  410. data/features/support/db/migrations/create_tags.rb +0 -4
  411. data/features/support/db/migrations/create_thetas.rb +0 -5
  412. data/features/support/db/mysql.rb +0 -3
  413. data/features/support/db/postgresql.rb +0 -3
  414. data/features/support/env.rb +0 -18
  415. data/features/support/lib/generic_delta_handler.rb +0 -8
  416. data/features/support/models/alpha.rb +0 -10
  417. data/features/support/models/animal.rb +0 -5
  418. data/features/support/models/author.rb +0 -3
  419. data/features/support/models/beta.rb +0 -8
  420. data/features/support/models/box.rb +0 -8
  421. data/features/support/models/cat.rb +0 -3
  422. data/features/support/models/category.rb +0 -4
  423. data/features/support/models/comment.rb +0 -10
  424. data/features/support/models/delayed_beta.rb +0 -7
  425. data/features/support/models/developer.rb +0 -16
  426. data/features/support/models/dog.rb +0 -3
  427. data/features/support/models/extensible_beta.rb +0 -9
  428. data/features/support/models/gamma.rb +0 -5
  429. data/features/support/models/person.rb +0 -23
  430. data/features/support/models/post.rb +0 -20
  431. data/features/support/models/robot.rb +0 -12
  432. data/features/support/models/tag.rb +0 -3
  433. data/features/support/models/theta.rb +0 -7
  434. data/features/support/post_database.rb +0 -43
  435. data/lib/cucumber/thinking_sphinx/internal_world.rb +0 -125
  436. data/lib/cucumber/thinking_sphinx/sql_logger.rb +0 -20
  437. data/lib/thinking_sphinx/active_record/attribute_updates.rb +0 -48
  438. data/lib/thinking_sphinx/active_record/delta.rb +0 -87
  439. data/lib/thinking_sphinx/active_record/has_many_association.rb +0 -28
  440. data/lib/thinking_sphinx/active_record/scopes.rb +0 -39
  441. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +0 -42
  442. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +0 -54
  443. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +0 -143
  444. data/lib/thinking_sphinx/association.rb +0 -164
  445. data/lib/thinking_sphinx/attribute.rb +0 -341
  446. data/lib/thinking_sphinx/class_facet.rb +0 -15
  447. data/lib/thinking_sphinx/core/array.rb +0 -7
  448. data/lib/thinking_sphinx/core/string.rb +0 -15
  449. data/lib/thinking_sphinx/deltas/datetime_delta.rb +0 -50
  450. data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +0 -24
  451. data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +0 -27
  452. data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +0 -26
  453. data/lib/thinking_sphinx/deltas/delayed_delta.rb +0 -30
  454. data/lib/thinking_sphinx/deploy/capistrano.rb +0 -100
  455. data/lib/thinking_sphinx/field.rb +0 -82
  456. data/lib/thinking_sphinx/index/builder.rb +0 -286
  457. data/lib/thinking_sphinx/index/faux_column.rb +0 -110
  458. data/lib/thinking_sphinx/property.rb +0 -162
  459. data/lib/thinking_sphinx/rails_additions.rb +0 -150
  460. data/lib/thinking_sphinx/search_methods.rb +0 -421
  461. data/lib/thinking_sphinx/source/internal_properties.rb +0 -46
  462. data/lib/thinking_sphinx/source/sql.rb +0 -128
  463. data/lib/thinking_sphinx/source.rb +0 -150
  464. data/rails/init.rb +0 -14
  465. data/spec/lib/thinking_sphinx/active_record/delta_spec.rb +0 -130
  466. data/spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb +0 -49
  467. data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +0 -96
  468. data/spec/lib/thinking_sphinx/active_record_spec.rb +0 -353
  469. data/spec/lib/thinking_sphinx/association_spec.rb +0 -239
  470. data/spec/lib/thinking_sphinx/attribute_spec.rb +0 -507
  471. data/spec/lib/thinking_sphinx/configuration_spec.rb +0 -268
  472. data/spec/lib/thinking_sphinx/core/array_spec.rb +0 -9
  473. data/spec/lib/thinking_sphinx/core/string_spec.rb +0 -9
  474. data/spec/lib/thinking_sphinx/deltas/job_spec.rb +0 -32
  475. data/spec/lib/thinking_sphinx/excerpter_spec.rb +0 -57
  476. data/spec/lib/thinking_sphinx/facet_search_spec.rb +0 -176
  477. data/spec/lib/thinking_sphinx/facet_spec.rb +0 -333
  478. data/spec/lib/thinking_sphinx/field_spec.rb +0 -154
  479. data/spec/lib/thinking_sphinx/index/builder_spec.rb +0 -455
  480. data/spec/lib/thinking_sphinx/index/faux_column_spec.rb +0 -30
  481. data/spec/lib/thinking_sphinx/index_spec.rb +0 -45
  482. data/spec/lib/thinking_sphinx/rails_additions_spec.rb +0 -203
  483. data/spec/lib/thinking_sphinx/search_methods_spec.rb +0 -152
  484. data/spec/lib/thinking_sphinx/search_spec.rb +0 -1101
  485. data/spec/lib/thinking_sphinx/source_spec.rb +0 -227
  486. data/spec/lib/thinking_sphinx_spec.rb +0 -162
  487. data/tasks/distribution.rb +0 -53
  488. data/tasks/rails.rake +0 -1
  489. data/tasks/testing.rb +0 -72
  490. data/vendor/after_commit/LICENSE +0 -20
  491. data/vendor/after_commit/README +0 -16
  492. data/vendor/after_commit/Rakefile +0 -22
  493. data/vendor/after_commit/init.rb +0 -8
  494. data/vendor/after_commit/lib/after_commit/active_record.rb +0 -114
  495. data/vendor/after_commit/lib/after_commit/connection_adapters.rb +0 -103
  496. data/vendor/after_commit/lib/after_commit.rb +0 -45
  497. data/vendor/after_commit/test/after_commit_test.rb +0 -53
  498. data/vendor/delayed_job/lib/delayed/job.rb +0 -251
  499. data/vendor/delayed_job/lib/delayed/message_sending.rb +0 -7
  500. data/vendor/delayed_job/lib/delayed/performable_method.rb +0 -55
  501. data/vendor/delayed_job/lib/delayed/worker.rb +0 -54
  502. data/vendor/riddle/lib/riddle/client/filter.rb +0 -53
  503. data/vendor/riddle/lib/riddle/client/message.rb +0 -66
  504. data/vendor/riddle/lib/riddle/client/response.rb +0 -84
  505. data/vendor/riddle/lib/riddle/client.rb +0 -635
  506. data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +0 -48
  507. data/vendor/riddle/lib/riddle/configuration/index.rb +0 -142
  508. data/vendor/riddle/lib/riddle/configuration/indexer.rb +0 -19
  509. data/vendor/riddle/lib/riddle/configuration/remote_index.rb +0 -17
  510. data/vendor/riddle/lib/riddle/configuration/searchd.rb +0 -25
  511. data/vendor/riddle/lib/riddle/configuration/section.rb +0 -43
  512. data/vendor/riddle/lib/riddle/configuration/source.rb +0 -23
  513. data/vendor/riddle/lib/riddle/configuration/sql_source.rb +0 -34
  514. data/vendor/riddle/lib/riddle/configuration/xml_source.rb +0 -28
  515. data/vendor/riddle/lib/riddle/configuration.rb +0 -33
  516. data/vendor/riddle/lib/riddle/controller.rb +0 -53
  517. data/vendor/riddle/lib/riddle.rb +0 -30
@@ -1,1101 +0,0 @@
1
- require 'spec/spec_helper'
2
- require 'will_paginate/collection'
3
-
4
- describe ThinkingSphinx::Search do
5
- before :each do
6
- @config = ThinkingSphinx::Configuration.instance
7
- @client = Riddle::Client.new
8
-
9
- @config.stub!(:client => @client)
10
- @client.stub!(:query => {:matches => [], :total_found => 41, :total => 41})
11
- end
12
-
13
- it "not request results from the client if not accessing items" do
14
- @config.should_not_receive(:client)
15
-
16
- ThinkingSphinx::Search.new.class
17
- end
18
-
19
- it "should request results if access is required" do
20
- @config.should_receive(:client)
21
-
22
- ThinkingSphinx::Search.new.first
23
- end
24
-
25
- describe '#respond_to?' do
26
- it "should respond to Array methods" do
27
- ThinkingSphinx::Search.new.respond_to?(:each).should be_true
28
- end
29
-
30
- it "should respond to Search methods" do
31
- ThinkingSphinx::Search.new.respond_to?(:per_page).should be_true
32
- end
33
- end
34
-
35
- describe '#populated?' do
36
- before :each do
37
- @search = ThinkingSphinx::Search.new
38
- end
39
-
40
- it "should be false if the client request has not been made" do
41
- @search.populated?.should be_false
42
- end
43
-
44
- it "should be true once the client request has been made" do
45
- @search.first
46
- @search.populated?.should be_true
47
- end
48
- end
49
-
50
- describe '#results' do
51
- it "should populate search results before returning" do
52
- @search = ThinkingSphinx::Search.new
53
- @search.populated?.should be_false
54
-
55
- @search.results
56
- @search.populated?.should be_true
57
- end
58
- end
59
-
60
- describe '#method_missing' do
61
- before :each do
62
- Alpha.sphinx_scope(:by_name) { |name|
63
- {:conditions => {:name => name}}
64
- }
65
- Alpha.sphinx_scope(:ids_only) { {:ids_only => true} }
66
- end
67
-
68
- after :each do
69
- Alpha.remove_sphinx_scopes
70
- end
71
-
72
- it "should handle Array methods" do
73
- ThinkingSphinx::Search.new.private_methods.should be_an(Array)
74
- end
75
-
76
- it "should raise a NoMethodError exception if unknown method" do
77
- lambda {
78
- ThinkingSphinx::Search.new.foo
79
- }.should raise_error(NoMethodError)
80
- end
81
-
82
- it "should not request results from client if method does not exist" do
83
- @client.should_not_receive(:query)
84
-
85
- lambda {
86
- ThinkingSphinx::Search.new.foo
87
- }.should raise_error(NoMethodError)
88
- end
89
-
90
- it "should accept sphinx scopes" do
91
- search = ThinkingSphinx::Search.new(:classes => [Alpha])
92
-
93
- lambda {
94
- search.by_name('Pat')
95
- }.should_not raise_error(NoMethodError)
96
- end
97
-
98
- it "should return itself when using a sphinx scope" do
99
- search = ThinkingSphinx::Search.new(:classes => [Alpha])
100
- search.by_name('Pat').object_id.should == search.object_id
101
- end
102
-
103
- it "should keep the same search object when chaining multiple scopes" do
104
- search = ThinkingSphinx::Search.new(:classes => [Alpha])
105
- search.by_name('Pat').ids_only.object_id.should == search.object_id
106
- end
107
- end
108
-
109
- describe '.search' do
110
- it "return the output of ThinkingSphinx.search" do
111
- @results = [] # to confirm same object
112
- ThinkingSphinx.stub!(:search => @results)
113
-
114
- ThinkingSphinx::Search.search.object_id.should == @results.object_id
115
- end
116
- end
117
-
118
- describe '.search_for_ids' do
119
- it "return the output of ThinkingSphinx.search_for_ids" do
120
- @results = [] # to confirm same object
121
- ThinkingSphinx.stub!(:search_for_ids => @results)
122
-
123
- ThinkingSphinx::Search.search_for_ids.object_id.
124
- should == @results.object_id
125
- end
126
- end
127
-
128
- describe '.search_for_id' do
129
- it "return the output of ThinkingSphinx.search_for_ids" do
130
- @results = [] # to confirm same object
131
- ThinkingSphinx.stub!(:search_for_id => @results)
132
-
133
- ThinkingSphinx::Search.search_for_id.object_id.
134
- should == @results.object_id
135
- end
136
- end
137
-
138
- describe '.count' do
139
- it "return the output of ThinkingSphinx.search" do
140
- @results = [] # to confirm same object
141
- ThinkingSphinx.stub!(:count => @results)
142
-
143
- ThinkingSphinx::Search.count.object_id.should == @results.object_id
144
- end
145
- end
146
-
147
- describe '.facets' do
148
- it "return the output of ThinkingSphinx.facets" do
149
- @results = [] # to confirm same object
150
- ThinkingSphinx.stub!(:facets => @results)
151
-
152
- ThinkingSphinx::Search.facets.object_id.should == @results.object_id
153
- end
154
- end
155
-
156
- describe '#populate' do
157
- before :each do
158
- @alpha_a, @alpha_b = Alpha.new, Alpha.new
159
- @beta_a, @beta_b = Beta.new, Beta.new
160
-
161
- @alpha_a.stub! :id => 1, :read_attribute => 1
162
- @alpha_b.stub! :id => 2, :read_attribute => 2
163
- @beta_a.stub! :id => 1, :read_attribute => 1
164
- @beta_b.stub! :id => 2, :read_attribute => 2
165
-
166
- @client.stub! :query => {
167
- :matches => minimal_result_hashes(@alpha_a, @beta_b, @alpha_b, @beta_a)
168
- }
169
- Alpha.stub! :find => [@alpha_a, @alpha_b]
170
- Beta.stub! :find => [@beta_a, @beta_b]
171
- end
172
-
173
- it "should issue only one select per model" do
174
- Alpha.should_receive(:find).once.and_return([@alpha_a, @alpha_b])
175
- Beta.should_receive(:find).once.and_return([@beta_a, @beta_b])
176
-
177
- ThinkingSphinx::Search.new.first
178
- end
179
-
180
- it "should mix the results from different models" do
181
- search = ThinkingSphinx::Search.new
182
- search[0].should be_a(Alpha)
183
- search[1].should be_a(Beta)
184
- search[2].should be_a(Alpha)
185
- search[3].should be_a(Beta)
186
- end
187
-
188
- it "should maintain the Xoopit ordering for results" do
189
- search = ThinkingSphinx::Search.new
190
- search[0].id.should == 1
191
- search[1].id.should == 2
192
- search[2].id.should == 2
193
- search[3].id.should == 1
194
- end
195
-
196
- it "should use the requested classes to generate the index argument" do
197
- @client.should_receive(:query) do |query, index, comment|
198
- index.should == 'alpha_core,beta_core,beta_delta'
199
- end
200
-
201
- ThinkingSphinx::Search.new(:classes => [Alpha, Beta]).first
202
- end
203
-
204
- describe 'query' do
205
- it "should concatenate arguments with spaces" do
206
- @client.should_receive(:query) do |query, index, comment|
207
- query.should == 'two words'
208
- end
209
-
210
- ThinkingSphinx::Search.new('two', 'words').first
211
- end
212
-
213
- it "should append conditions to the query" do
214
- @client.should_receive(:query) do |query, index, comment|
215
- query.should == 'general @focused specific'
216
- end
217
-
218
- ThinkingSphinx::Search.new('general', :conditions => {
219
- :focused => 'specific'
220
- }).first
221
- end
222
-
223
- it "append multiple conditions together" do
224
- @client.should_receive(:query) do |query, index, comment|
225
- query.should match(/general.+@foo word/)
226
- query.should match(/general.+@bar word/)
227
- end
228
-
229
- ThinkingSphinx::Search.new('general', :conditions => {
230
- :foo => 'word', :bar => 'word'
231
- }).first
232
- end
233
-
234
- it "should apply stars if requested, and handle full extended syntax" do
235
- input = %{a b* c (d | e) 123 5&6 (f_f g) !h "i j" "k l"~10 "m n"/3 @o p -(q|r)}
236
- expected = %{*a* b* *c* (*d* | *e*) *123* *5*&*6* (*f_f* *g*) !*h* "i j" "k l"~10 "m n"/3 @o *p* -(*q*|*r*)}
237
-
238
- @client.should_receive(:query) do |query, index, comment|
239
- query.should == expected
240
- end
241
-
242
- ThinkingSphinx::Search.new(input, :star => true).first
243
- end
244
-
245
- it "should default to /\w+/ as token for auto-starring" do
246
- @client.should_receive(:query) do |query, index, comment|
247
- query.should == '*foo*@*bar*.*com*'
248
- end
249
-
250
- ThinkingSphinx::Search.new('foo@bar.com', :star => true).first
251
- end
252
-
253
- it "should honour custom star tokens" do
254
- @client.should_receive(:query) do |query, index, comment|
255
- query.should == '*foo@bar.com* -*foo-bar*'
256
- end
257
-
258
- ThinkingSphinx::Search.new(
259
- 'foo@bar.com -foo-bar', :star => /[\w@.-]+/u
260
- ).first
261
- end
262
- end
263
-
264
- describe 'comment' do
265
- it "should add comment if explicitly provided" do
266
- @client.should_receive(:query) do |query, index, comment|
267
- comment.should == 'custom log'
268
- end
269
-
270
- ThinkingSphinx::Search.new(:comment => 'custom log').first
271
- end
272
-
273
- it "should default to a blank comment" do
274
- @client.should_receive(:query) do |query, index, comment|
275
- comment.should == ''
276
- end
277
-
278
- ThinkingSphinx::Search.new.first
279
- end
280
- end
281
-
282
- describe 'match mode' do
283
- it "should default to :all" do
284
- ThinkingSphinx::Search.new.first
285
-
286
- @client.match_mode.should == :all
287
- end
288
-
289
- it "should default to :extended if conditions are supplied" do
290
- ThinkingSphinx::Search.new('general', :conditions => {
291
- :foo => 'word', :bar => 'word'
292
- }).first
293
-
294
- @client.match_mode.should == :extended
295
- end
296
-
297
- it "should use explicit match modes" do
298
- ThinkingSphinx::Search.new('general', :conditions => {
299
- :foo => 'word', :bar => 'word'
300
- }, :match_mode => :extended2).first
301
-
302
- @client.match_mode.should == :extended2
303
- end
304
- end
305
-
306
- describe 'pagination' do
307
- it "should set the limit using per_page" do
308
- ThinkingSphinx::Search.new(:per_page => 30).first
309
- @client.limit.should == 30
310
- end
311
-
312
- it "should set the offset if pagination is requested" do
313
- ThinkingSphinx::Search.new(:page => 3).first
314
- @client.offset.should == 40
315
- end
316
-
317
- it "should set the offset by the per_page value" do
318
- ThinkingSphinx::Search.new(:page => 3, :per_page => 30).first
319
- @client.offset.should == 60
320
- end
321
- end
322
-
323
- describe 'filters' do
324
- it "should filter out deleted values by default" do
325
- ThinkingSphinx::Search.new.first
326
-
327
- filter = @client.filters.last
328
- filter.values.should == [0]
329
- filter.attribute.should == 'sphinx_deleted'
330
- filter.exclude?.should be_false
331
- end
332
-
333
- it "should add class filters for explicit classes" do
334
- ThinkingSphinx::Search.new(:classes => [Alpha, Beta]).first
335
-
336
- filter = @client.filters.last
337
- filter.values.should == [Alpha.to_crc32, Beta.to_crc32]
338
- filter.attribute.should == 'class_crc'
339
- filter.exclude?.should be_false
340
- end
341
-
342
- it "should add class filters for subclasses of requested classes" do
343
- ThinkingSphinx::Search.new(:classes => [Person]).first
344
-
345
- filter = @client.filters.last
346
- filter.values.should == [
347
- Parent.to_crc32, Admin::Person.to_crc32,
348
- Child.to_crc32, Person.to_crc32
349
- ]
350
- filter.attribute.should == 'class_crc'
351
- filter.exclude?.should be_false
352
- end
353
-
354
- it "should append inclusive filters of integers" do
355
- ThinkingSphinx::Search.new(:with => {:int => 1}).first
356
-
357
- filter = @client.filters.last
358
- filter.values.should == [1]
359
- filter.attribute.should == 'int'
360
- filter.exclude?.should be_false
361
- end
362
-
363
- it "should append inclusive filters of floats" do
364
- ThinkingSphinx::Search.new(:with => {:float => 1.5}).first
365
-
366
- filter = @client.filters.last
367
- filter.values.should == [1.5]
368
- filter.attribute.should == 'float'
369
- filter.exclude?.should be_false
370
- end
371
-
372
- it "should append inclusive filters of booleans" do
373
- ThinkingSphinx::Search.new(:with => {:boolean => true}).first
374
-
375
- filter = @client.filters.last
376
- filter.values.should == [true]
377
- filter.attribute.should == 'boolean'
378
- filter.exclude?.should be_false
379
- end
380
-
381
- it "should append inclusive filters of arrays" do
382
- ThinkingSphinx::Search.new(:with => {:ints => [1, 2, 3]}).first
383
-
384
- filter = @client.filters.last
385
- filter.values.should == [1, 2, 3]
386
- filter.attribute.should == 'ints'
387
- filter.exclude?.should be_false
388
- end
389
-
390
- it "should treat nils in arrays as 0" do
391
- ThinkingSphinx::Search.new(:with => {:ints => [nil, 1, 2, 3]}).first
392
-
393
- filter = @client.filters.last
394
- filter.values.should == [0, 1, 2, 3]
395
- end
396
-
397
- it "should append inclusive filters of time ranges" do
398
- first, last = 1.week.ago, Time.now
399
- ThinkingSphinx::Search.new(:with => {
400
- :time => first..last
401
- }).first
402
-
403
- filter = @client.filters.last
404
- filter.values.should == (first.to_i..last.to_i)
405
- filter.attribute.should == 'time'
406
- filter.exclude?.should be_false
407
- end
408
-
409
- it "should append exclusive filters of integers" do
410
- ThinkingSphinx::Search.new(:without => {:int => 1}).first
411
-
412
- filter = @client.filters.last
413
- filter.values.should == [1]
414
- filter.attribute.should == 'int'
415
- filter.exclude?.should be_true
416
- end
417
-
418
- it "should append exclusive filters of floats" do
419
- ThinkingSphinx::Search.new(:without => {:float => 1.5}).first
420
-
421
- filter = @client.filters.last
422
- filter.values.should == [1.5]
423
- filter.attribute.should == 'float'
424
- filter.exclude?.should be_true
425
- end
426
-
427
- it "should append exclusive filters of booleans" do
428
- ThinkingSphinx::Search.new(:without => {:boolean => true}).first
429
-
430
- filter = @client.filters.last
431
- filter.values.should == [true]
432
- filter.attribute.should == 'boolean'
433
- filter.exclude?.should be_true
434
- end
435
-
436
- it "should append exclusive filters of arrays" do
437
- ThinkingSphinx::Search.new(:without => {:ints => [1, 2, 3]}).first
438
-
439
- filter = @client.filters.last
440
- filter.values.should == [1, 2, 3]
441
- filter.attribute.should == 'ints'
442
- filter.exclude?.should be_true
443
- end
444
-
445
- it "should append exclusive filters of time ranges" do
446
- first, last = 1.week.ago, Time.now
447
- ThinkingSphinx::Search.new(:without => {
448
- :time => first..last
449
- }).first
450
-
451
- filter = @client.filters.last
452
- filter.values.should == (first.to_i..last.to_i)
453
- filter.attribute.should == 'time'
454
- filter.exclude?.should be_true
455
- end
456
-
457
- it "should add separate filters for each item in a with_all value" do
458
- ThinkingSphinx::Search.new(:with_all => {:ints => [1, 2, 3]}).first
459
-
460
- filters = @client.filters[-3, 3]
461
- filters.each do |filter|
462
- filter.attribute.should == 'ints'
463
- filter.exclude?.should be_false
464
- end
465
-
466
- filters[0].values.should == [1]
467
- filters[1].values.should == [2]
468
- filters[2].values.should == [3]
469
- end
470
-
471
- it "should filter out specific ids using :without_ids" do
472
- ThinkingSphinx::Search.new(:without_ids => [4, 5, 6]).first
473
-
474
- filter = @client.filters.last
475
- filter.values.should == [4, 5, 6]
476
- filter.attribute.should == 'sphinx_internal_id'
477
- filter.exclude?.should be_true
478
- end
479
-
480
- describe 'in :conditions' do
481
- it "should add as filters for known attributes in :conditions option" do
482
- ThinkingSphinx::Search.new('general',
483
- :conditions => {:word => 'specific', :lat => 1.5},
484
- :classes => [Alpha]
485
- ).first
486
-
487
- filter = @client.filters.last
488
- filter.values.should == [1.5]
489
- filter.attribute.should == 'lat'
490
- filter.exclude?.should be_false
491
- end
492
-
493
- it "should not add the filter to the query string" do
494
- @client.should_receive(:query) do |query, index, comment|
495
- query.should == 'general @word specific'
496
- end
497
-
498
- ThinkingSphinx::Search.new('general',
499
- :conditions => {:word => 'specific', :lat => 1.5},
500
- :classes => [Alpha]
501
- ).first
502
- end
503
- end
504
- end
505
-
506
- describe 'sort mode' do
507
- it "should use :relevance as a default" do
508
- ThinkingSphinx::Search.new.first
509
- @client.sort_mode.should == :relevance
510
- end
511
-
512
- it "should use :attr_asc if a symbol is supplied to :order" do
513
- ThinkingSphinx::Search.new(:order => :created_at).first
514
- @client.sort_mode.should == :attr_asc
515
- end
516
-
517
- it "should use :attr_desc if :desc is the mode" do
518
- ThinkingSphinx::Search.new(
519
- :order => :created_at, :sort_mode => :desc
520
- ).first
521
- @client.sort_mode.should == :attr_desc
522
- end
523
-
524
- it "should use :extended if a string is supplied to :order" do
525
- ThinkingSphinx::Search.new(:order => "created_at ASC").first
526
- @client.sort_mode.should == :extended
527
- end
528
-
529
- it "should use :expr if explicitly requested" do
530
- ThinkingSphinx::Search.new(
531
- :order => "created_at ASC", :sort_mode => :expr
532
- ).first
533
- @client.sort_mode.should == :expr
534
- end
535
-
536
- it "should use :attr_desc if explicitly requested" do
537
- ThinkingSphinx::Search.new(
538
- :order => "created_at", :sort_mode => :desc
539
- ).first
540
- @client.sort_mode.should == :attr_desc
541
- end
542
- end
543
-
544
- describe 'sort by' do
545
- it "should presume order symbols are attributes" do
546
- ThinkingSphinx::Search.new(:order => :created_at).first
547
- @client.sort_by.should == 'created_at'
548
- end
549
-
550
- it "replace field names with their sortable attributes" do
551
- ThinkingSphinx::Search.new(:order => :name, :classes => [Alpha]).first
552
- @client.sort_by.should == 'name_sort'
553
- end
554
-
555
- it "should replace field names in strings" do
556
- ThinkingSphinx::Search.new(
557
- :order => "created_at ASC, name DESC", :classes => [Alpha]
558
- ).first
559
- @client.sort_by.should == 'created_at ASC, name_sort DESC'
560
- end
561
- end
562
-
563
- describe 'max matches' do
564
- it "should use the global setting by default" do
565
- ThinkingSphinx::Search.new.first
566
- @client.max_matches.should == 1000
567
- end
568
-
569
- it "should use explicit setting" do
570
- ThinkingSphinx::Search.new(:max_matches => 2000).first
571
- @client.max_matches.should == 2000
572
- end
573
- end
574
-
575
- describe 'field weights' do
576
- it "should set field weights as provided" do
577
- ThinkingSphinx::Search.new(
578
- :field_weights => {'foo' => 10, 'bar' => 5}
579
- ).first
580
-
581
- @client.field_weights.should == {
582
- 'foo' => 10, 'bar' => 5
583
- }
584
- end
585
-
586
- it "should use field weights set in the index" do
587
- ThinkingSphinx::Search.new(:classes => [Alpha]).first
588
-
589
- @client.field_weights.should == {'name' => 10}
590
- end
591
- end
592
-
593
- describe 'index weights' do
594
- it "should send index weights through to the client" do
595
- ThinkingSphinx::Search.new(:index_weights => {'foo' => 100}).first
596
- @client.index_weights.should == {'foo' => 100}
597
- end
598
-
599
- it "should convert classes to their core and delta index names" do
600
- ThinkingSphinx::Search.new(:index_weights => {Alpha => 100}).first
601
- @client.index_weights.should == {
602
- 'alpha_core' => 100,
603
- 'alpha_delta' => 100
604
- }
605
- end
606
- end
607
-
608
- describe 'grouping' do
609
- it "should convert group into group_by and group_function" do
610
- ThinkingSphinx::Search.new(:group => :edition).first
611
-
612
- @client.group_function.should == :attr
613
- @client.group_by.should == "edition"
614
- end
615
-
616
- it "should pass on explicit grouping arguments" do
617
- ThinkingSphinx::Search.new(
618
- :group_by => 'created_at',
619
- :group_function => :attr,
620
- :group_clause => 'clause',
621
- :group_distinct => 'distinct'
622
- ).first
623
-
624
- @client.group_by.should == 'created_at'
625
- @client.group_function.should == :attr
626
- @client.group_clause.should == 'clause'
627
- @client.group_distinct.should == 'distinct'
628
- end
629
- end
630
-
631
- describe 'anchor' do
632
- it "should detect lat and lng attributes on the given model" do
633
- ThinkingSphinx::Search.new(
634
- :geo => [1.0, -1.0],
635
- :classes => [Alpha]
636
- ).first
637
-
638
- @client.anchor[:latitude_attribute].should == 'lat'
639
- @client.anchor[:longitude_attribute].should == 'lng'
640
- end
641
-
642
- it "should detect lat and lon attributes on the given model" do
643
- ThinkingSphinx::Search.new(
644
- :geo => [1.0, -1.0],
645
- :classes => [Beta]
646
- ).first
647
-
648
- @client.anchor[:latitude_attribute].should == 'lat'
649
- @client.anchor[:longitude_attribute].should == 'lon'
650
- end
651
-
652
- it "should detect latitude and longitude attributes on the given model" do
653
- ThinkingSphinx::Search.new(
654
- :geo => [1.0, -1.0],
655
- :classes => [Person]
656
- ).first
657
-
658
- @client.anchor[:latitude_attribute].should == 'latitude'
659
- @client.anchor[:longitude_attribute].should == 'longitude'
660
- end
661
-
662
- it "should accept manually defined latitude and longitude attributes" do
663
- ThinkingSphinx::Search.new(
664
- :geo => [1.0, -1.0],
665
- :classes => [Alpha],
666
- :latitude_attr => :updown,
667
- :longitude_attr => :leftright
668
- ).first
669
-
670
- @client.anchor[:latitude_attribute].should == 'updown'
671
- @client.anchor[:longitude_attribute].should == 'leftright'
672
- end
673
-
674
- it "should accept manually defined latitude and longitude attributes in the given model" do
675
- ThinkingSphinx::Search.new(
676
- :geo => [1.0, -1.0],
677
- :classes => [Friendship]
678
- ).first
679
-
680
- @client.anchor[:latitude_attribute].should == 'person_id'
681
- @client.anchor[:longitude_attribute].should == 'person_id'
682
- end
683
-
684
- it "should accept geo array for geo-position values" do
685
- ThinkingSphinx::Search.new(
686
- :geo => [1.0, -1.0],
687
- :classes => [Alpha]
688
- ).first
689
-
690
- @client.anchor[:latitude].should == 1.0
691
- @client.anchor[:longitude].should == -1.0
692
- end
693
-
694
- it "should accept lat and lng options for geo-position values" do
695
- ThinkingSphinx::Search.new(
696
- :lat => 1.0,
697
- :lng => -1.0,
698
- :classes => [Alpha]
699
- ).first
700
-
701
- @client.anchor[:latitude].should == 1.0
702
- @client.anchor[:longitude].should == -1.0
703
- end
704
- end
705
-
706
- describe 'sql ordering' do
707
- before :each do
708
- @client.stub! :query => {
709
- :matches => minimal_result_hashes(@alpha_b, @alpha_a)
710
- }
711
- Alpha.stub! :find => [@alpha_a, @alpha_b]
712
- end
713
-
714
- it "shouldn't re-sort SQL results based on Sphinx information" do
715
- search = ThinkingSphinx::Search.new(
716
- :classes => [Alpha],
717
- :sql_order => 'id'
718
- )
719
- search.first.should == @alpha_a
720
- search.last.should == @alpha_b
721
- end
722
-
723
- it "should use the option for the ActiveRecord::Base#find calls" do
724
- Alpha.should_receive(:find) do |mode, options|
725
- options[:order].should == 'id'
726
- end
727
-
728
- ThinkingSphinx::Search.new(
729
- :classes => [Alpha],
730
- :sql_order => 'id'
731
- ).first
732
- end
733
- end
734
-
735
- context 'result objects' do
736
- describe '#excerpts' do
737
- before :each do
738
- @search = ThinkingSphinx::Search.new
739
- end
740
-
741
- it "should add excerpts method if objects don't already have one" do
742
- @search.first.should respond_to(:excerpts)
743
- end
744
-
745
- it "should return an instance of ThinkingSphinx::Excerpter" do
746
- @search.first.excerpts.should be_a(ThinkingSphinx::Excerpter)
747
- end
748
-
749
- it "should not add excerpts method if objects already have one" do
750
- @search.last.excerpts.should_not be_a(ThinkingSphinx::Excerpter)
751
- end
752
-
753
- it "should set up the excerpter with the instances and search" do
754
- ThinkingSphinx::Excerpter.should_receive(:new).with(@search, @alpha_a)
755
- ThinkingSphinx::Excerpter.should_receive(:new).with(@search, @alpha_b)
756
-
757
- @search.first
758
- end
759
- end
760
-
761
- describe '#sphinx_attributes' do
762
- before :each do
763
- @search = ThinkingSphinx::Search.new
764
- end
765
-
766
- it "should add sphinx_attributes method if objects don't already have one" do
767
- @search.last.should respond_to(:sphinx_attributes)
768
- end
769
-
770
- it "should return a hash" do
771
- @search.last.sphinx_attributes.should be_a(Hash)
772
- end
773
-
774
- it "should not add sphinx_attributes if objects have a method of that name already" do
775
- @search.first.sphinx_attributes.should_not be_a(Hash)
776
- end
777
-
778
- it "should pair sphinx_attributes with the correct hash" do
779
- hash = @search.last.sphinx_attributes
780
- hash['sphinx_internal_id'].should == @search.last.id
781
- hash['class_crc'].should == @search.last.class.to_crc32
782
- end
783
- end
784
- end
785
- end
786
-
787
- describe '#current_page' do
788
- it "should return 1 by default" do
789
- ThinkingSphinx::Search.new.current_page.should == 1
790
- end
791
-
792
- it "should handle string page values" do
793
- ThinkingSphinx::Search.new(:page => '2').current_page.should == 2
794
- end
795
-
796
- it "should handle empty string page values" do
797
- ThinkingSphinx::Search.new(:page => '').current_page.should == 1
798
- end
799
-
800
- it "should return the requested page" do
801
- ThinkingSphinx::Search.new(:page => 10).current_page.should == 10
802
- end
803
- end
804
-
805
- describe '#per_page' do
806
- it "should return 20 by default" do
807
- ThinkingSphinx::Search.new.per_page.should == 20
808
- end
809
-
810
- it "should allow for custom values" do
811
- ThinkingSphinx::Search.new(:per_page => 30).per_page.should == 30
812
- end
813
-
814
- it "should prioritise :limit over :per_page if given" do
815
- ThinkingSphinx::Search.new(
816
- :per_page => 30, :limit => 40
817
- ).per_page.should == 40
818
- end
819
- end
820
-
821
- describe '#total_pages' do
822
- it "should calculate the total pages depending on per_page and total_entries" do
823
- ThinkingSphinx::Search.new.total_pages.should == 3
824
- end
825
-
826
- it "should allow for custom per_page values" do
827
- ThinkingSphinx::Search.new(:per_page => 30).total_pages.should == 2
828
- end
829
-
830
- it "should not overstep the max_matches implied limit" do
831
- @client.stub!(:query => {
832
- :matches => [], :total_found => 41, :total => 40
833
- })
834
-
835
- ThinkingSphinx::Search.new.total_pages.should == 2
836
- end
837
- end
838
-
839
- describe '#next_page' do
840
- it "should return one more than the current page" do
841
- ThinkingSphinx::Search.new.next_page.should == 2
842
- end
843
-
844
- it "should return nil if on the last page" do
845
- ThinkingSphinx::Search.new(:page => 3).next_page.should be_nil
846
- end
847
- end
848
-
849
- describe '#previous_page' do
850
- it "should return one less than the current page" do
851
- ThinkingSphinx::Search.new(:page => 2).previous_page.should == 1
852
- end
853
-
854
- it "should return nil if on the first page" do
855
- ThinkingSphinx::Search.new.previous_page.should be_nil
856
- end
857
- end
858
-
859
- describe '#total_entries' do
860
- it "should return the total number of results, not just the amount on the page" do
861
- ThinkingSphinx::Search.new.total_entries.should == 41
862
- end
863
- end
864
-
865
- describe '#offset' do
866
- it "should default to 0" do
867
- ThinkingSphinx::Search.new.offset.should == 0
868
- end
869
-
870
- it "should increase by the per_page value for each page in" do
871
- ThinkingSphinx::Search.new(:per_page => 25, :page => 2).offset.should == 25
872
- end
873
- end
874
-
875
- describe '#indexes' do
876
- it "should default to '*'" do
877
- ThinkingSphinx::Search.new.indexes.should == '*'
878
- end
879
-
880
- it "should use given class to determine index name" do
881
- ThinkingSphinx::Search.new(:classes => [Alpha]).indexes.
882
- should == 'alpha_core'
883
- end
884
-
885
- it "should add both core and delta indexes for given classes" do
886
- ThinkingSphinx::Search.new(:classes => [Alpha, Beta]).indexes.
887
- should == 'alpha_core,beta_core,beta_delta'
888
- end
889
-
890
- it "should respect the :index option" do
891
- ThinkingSphinx::Search.new(:classes => [Alpha], :index => '*').indexes.
892
- should == '*'
893
- end
894
- end
895
-
896
- describe '.each_with_groupby_and_count' do
897
- before :each do
898
- @alpha = Alpha.new
899
- @alpha.stub!(:id => 1, :read_attribute => 1)
900
-
901
- @client.stub! :query => {
902
- :matches => [{
903
- :attributes => {
904
- 'sphinx_internal_id' => @alpha.id,
905
- 'class_crc' => Alpha.to_crc32,
906
- '@groupby' => 101,
907
- '@count' => 5
908
- }
909
- }]
910
- }
911
- Alpha.stub!(:find => [@alpha])
912
- end
913
-
914
- it "should yield the match, group and count" do
915
- search = ThinkingSphinx::Search.new
916
- search.each_with_groupby_and_count do |obj, group, count|
917
- obj.should == @alpha
918
- group.should == 101
919
- count.should == 5
920
- end
921
- end
922
-
923
- it "should be aliased to each_with_group_and_count" do
924
- search = ThinkingSphinx::Search.new
925
- search.each_with_group_and_count do |obj, group, count|
926
- obj.should == @alpha
927
- group.should == 101
928
- count.should == 5
929
- end
930
- end
931
- end
932
-
933
- describe '.each_with_weighting' do
934
- before :each do
935
- @alpha = Alpha.new
936
- @alpha.stub!(:id => 1, :read_attribute => 1)
937
-
938
- @client.stub! :query => {
939
- :matches => [{
940
- :attributes => {
941
- 'sphinx_internal_id' => @alpha.id,
942
- 'class_crc' => Alpha.to_crc32
943
- }, :weight => 12
944
- }]
945
- }
946
- Alpha.stub!(:find => [@alpha])
947
- end
948
-
949
- it "should yield the match and weight" do
950
- search = ThinkingSphinx::Search.new
951
- search.each_with_weighting do |obj, weight|
952
- obj.should == @alpha
953
- weight.should == 12
954
- end
955
- end
956
- end
957
-
958
- describe '.each_with_*' do
959
- before :each do
960
- @alpha = Alpha.new
961
- @alpha.stub!(:id => 1, :read_attribute => 1)
962
-
963
- @client.stub! :query => {
964
- :matches => [{
965
- :attributes => {
966
- 'sphinx_internal_id' => @alpha.id,
967
- 'class_crc' => Alpha.to_crc32,
968
- '@geodist' => 101,
969
- '@groupby' => 102,
970
- '@count' => 103
971
- }, :weight => 12
972
- }]
973
- }
974
- Alpha.stub!(:find => [@alpha])
975
-
976
- @search = ThinkingSphinx::Search.new
977
- end
978
-
979
- it "should yield geodist if requested" do
980
- @search.each_with_geodist do |obj, distance|
981
- obj.should == @alpha
982
- distance.should == 101
983
- end
984
- end
985
-
986
- it "should yield count if requested" do
987
- @search.each_with_count do |obj, count|
988
- obj.should == @alpha
989
- count.should == 103
990
- end
991
- end
992
-
993
- it "should yield groupby if requested" do
994
- @search.each_with_groupby do |obj, group|
995
- obj.should == @alpha
996
- group.should == 102
997
- end
998
- end
999
-
1000
- it "should still use the array's each_with_index" do
1001
- @search.each_with_index do |obj, index|
1002
- obj.should == @alpha
1003
- index.should == 0
1004
- end
1005
- end
1006
- end
1007
-
1008
- describe '#excerpt_for' do
1009
- before :each do
1010
- @client.stub!(:excerpts => ['excerpted string'])
1011
- @client.stub!(:query => {
1012
- :matches => [],
1013
- :words => {'one' => {}, 'two' => {}}
1014
- })
1015
- @search = ThinkingSphinx::Search.new(:classes => [Alpha])
1016
- end
1017
-
1018
- it "should return the Sphinx excerpt value" do
1019
- @search.excerpt_for('string').should == 'excerpted string'
1020
- end
1021
-
1022
- it "should use the given model's core index" do
1023
- @client.should_receive(:excerpts) do |options|
1024
- options[:index].should == 'alpha_core'
1025
- end
1026
-
1027
- @search.excerpt_for('string')
1028
- end
1029
-
1030
- it "should optionally take a second argument to allow for multi-model searches" do
1031
- @client.should_receive(:excerpts) do |options|
1032
- options[:index].should == 'beta_core'
1033
- end
1034
-
1035
- @search.excerpt_for('string', Beta)
1036
- end
1037
-
1038
- it "should join the words together" do
1039
- @client.should_receive(:excerpts) do |options|
1040
- options[:words].should == @search.results[:words].keys.join(' ')
1041
- end
1042
-
1043
- @search.excerpt_for('string', Beta)
1044
- end
1045
-
1046
- it "should use the correct index in STI situations" do
1047
- @client.should_receive(:excerpts) do |options|
1048
- options[:index].should == 'person_core'
1049
- end
1050
-
1051
- @search.excerpt_for('string', Parent)
1052
- end
1053
- end
1054
-
1055
- describe '#search' do
1056
- before :each do
1057
- @search = ThinkingSphinx::Search.new('word',
1058
- :conditions => {:field => 'field'},
1059
- :with => {:int => 5}
1060
- )
1061
- end
1062
-
1063
- it "should return itself" do
1064
- @search.search.object_id.should == @search.object_id
1065
- end
1066
-
1067
- it "should merge in arguments" do
1068
- @client.should_receive(:query) do |query, index, comments|
1069
- query.should == 'word more @field field'
1070
- end
1071
-
1072
- @search.search('more').first
1073
- end
1074
-
1075
- it "should merge conditions" do
1076
- @client.should_receive(:query) do |query, index, comments|
1077
- query.should match(/@name plato/)
1078
- query.should match(/@field field/)
1079
- end
1080
-
1081
- @search.search(:conditions => {:name => 'plato'}).first
1082
- end
1083
-
1084
- it "should merge filters" do
1085
- @search.search(:with => {:float => 1.5}).first
1086
-
1087
- @client.filters.detect { |filter|
1088
- filter.attribute == 'float'
1089
- }.should_not be_nil
1090
- @client.filters.detect { |filter|
1091
- filter.attribute == 'int'
1092
- }.should_not be_nil
1093
- end
1094
- end
1095
- end
1096
-
1097
- describe ThinkingSphinx::Search, "playing nice with Search model" do
1098
- it "should not conflict with models called Search" do
1099
- lambda { Search.find(:all) }.should_not raise_error
1100
- end
1101
- end