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.
- checksums.yaml +7 -0
- data/.circleci/config.yml +99 -0
- data/.github/actions/test/action.yml +46 -0
- data/.github/workflows/ci.yml +75 -0
- data/.gitignore +18 -0
- data/.travis.yml +36 -0
- data/Appraisals +71 -0
- data/CHANGELOG.markdown +782 -0
- data/Gemfile +18 -0
- data/LICENCE +1 -1
- data/Procfile.support +2 -0
- data/README.textile +91 -136
- data/Rakefile +26 -0
- data/bin/console +15 -0
- data/bin/loadsphinx +99 -0
- data/bin/testmatrix +48 -0
- data/lib/thinking/sphinx.rb +3 -0
- data/lib/thinking-sphinx.rb +3 -0
- data/lib/thinking_sphinx/active_record/association.rb +19 -0
- data/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb +44 -0
- data/lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb +40 -0
- data/lib/thinking_sphinx/active_record/association_proxy.rb +34 -0
- data/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb +52 -0
- data/lib/thinking_sphinx/active_record/attribute/type.rb +106 -0
- data/lib/thinking_sphinx/active_record/attribute/values.rb +20 -0
- data/lib/thinking_sphinx/active_record/attribute.rb +22 -0
- data/lib/thinking_sphinx/active_record/base.rb +91 -0
- data/lib/thinking_sphinx/active_record/callbacks/association_delta_callbacks.rb +21 -0
- data/lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb +27 -0
- data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +66 -0
- data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +78 -0
- data/lib/thinking_sphinx/active_record/column.rb +44 -0
- data/lib/thinking_sphinx/active_record/column_sql_presenter.rb +54 -0
- data/lib/thinking_sphinx/active_record/database_adapters/abstract_adapter.rb +19 -0
- data/lib/thinking_sphinx/active_record/database_adapters/mysql_adapter.rb +51 -0
- data/lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb +47 -0
- data/lib/thinking_sphinx/active_record/database_adapters.rb +59 -0
- data/lib/thinking_sphinx/active_record/depolymorph/association_reflection.rb +32 -0
- data/lib/thinking_sphinx/active_record/depolymorph/base_reflection.rb +32 -0
- data/lib/thinking_sphinx/active_record/depolymorph/conditions_reflection.rb +40 -0
- data/lib/thinking_sphinx/active_record/depolymorph/overridden_reflection.rb +50 -0
- data/lib/thinking_sphinx/active_record/depolymorph/scoped_reflection.rb +26 -0
- data/lib/thinking_sphinx/active_record/field.rb +18 -0
- data/lib/thinking_sphinx/active_record/filter_reflection.rb +18 -0
- data/lib/thinking_sphinx/active_record/index.rb +71 -0
- data/lib/thinking_sphinx/active_record/interpreter.rb +77 -0
- data/lib/thinking_sphinx/active_record/join_association.rb +17 -0
- data/lib/thinking_sphinx/active_record/log_subscriber.rb +37 -0
- data/lib/thinking_sphinx/active_record/polymorpher.rb +64 -0
- data/lib/thinking_sphinx/active_record/property.rb +30 -0
- data/lib/thinking_sphinx/active_record/property_query.rb +149 -0
- data/lib/thinking_sphinx/active_record/property_sql_presenter.rb +89 -0
- data/lib/thinking_sphinx/active_record/simple_many_query.rb +37 -0
- data/lib/thinking_sphinx/active_record/source_joins.rb +68 -0
- data/lib/thinking_sphinx/active_record/sql_builder/clause_builder.rb +29 -0
- data/lib/thinking_sphinx/active_record/sql_builder/query.rb +59 -0
- data/lib/thinking_sphinx/active_record/sql_builder/statement.rb +147 -0
- data/lib/thinking_sphinx/active_record/sql_builder.rb +107 -0
- data/lib/thinking_sphinx/active_record/sql_source/template.rb +55 -0
- data/lib/thinking_sphinx/active_record/sql_source.rb +173 -0
- data/lib/thinking_sphinx/active_record.rb +39 -301
- data/lib/thinking_sphinx/attribute_types.rb +72 -0
- data/lib/thinking_sphinx/batched_search.rb +28 -0
- data/lib/thinking_sphinx/callbacks/appender.rb +63 -0
- data/lib/thinking_sphinx/callbacks.rb +44 -0
- data/lib/thinking_sphinx/capistrano/v2.rb +60 -0
- data/lib/thinking_sphinx/capistrano/v3.rb +104 -0
- data/lib/thinking_sphinx/capistrano.rb +10 -0
- data/lib/thinking_sphinx/commander.rb +27 -0
- data/lib/thinking_sphinx/commands/base.rb +53 -0
- data/lib/thinking_sphinx/commands/clear_real_time.rb +22 -0
- data/lib/thinking_sphinx/commands/clear_sql.rb +18 -0
- data/lib/thinking_sphinx/commands/configure.rb +15 -0
- data/lib/thinking_sphinx/commands/index_real_time.rb +15 -0
- data/lib/thinking_sphinx/commands/index_sql.rb +25 -0
- data/lib/thinking_sphinx/commands/merge.rb +27 -0
- data/lib/thinking_sphinx/commands/merge_and_update.rb +57 -0
- data/lib/thinking_sphinx/commands/prepare.rb +15 -0
- data/lib/thinking_sphinx/commands/rotate.rb +13 -0
- data/lib/thinking_sphinx/commands/running.rb +15 -0
- data/lib/thinking_sphinx/commands/start_attached.rb +22 -0
- data/lib/thinking_sphinx/commands/start_detached.rb +21 -0
- data/lib/thinking_sphinx/commands/stop.rb +24 -0
- data/lib/thinking_sphinx/commands.rb +20 -0
- data/lib/thinking_sphinx/configuration/consistent_ids.rb +35 -0
- data/lib/thinking_sphinx/configuration/defaults.rb +7 -0
- data/lib/thinking_sphinx/configuration/distributed_indices.rb +31 -0
- data/lib/thinking_sphinx/configuration/duplicate_names.rb +36 -0
- data/lib/thinking_sphinx/configuration/minimum_fields.rb +36 -0
- data/lib/thinking_sphinx/configuration.rb +196 -269
- data/lib/thinking_sphinx/connection/client.rb +74 -0
- data/lib/thinking_sphinx/connection/jruby.rb +58 -0
- data/lib/thinking_sphinx/connection/mri.rb +26 -0
- data/lib/thinking_sphinx/connection.rb +73 -0
- data/lib/thinking_sphinx/core/field.rb +11 -0
- data/lib/thinking_sphinx/core/index.rb +110 -0
- data/lib/thinking_sphinx/core/interpreter.rb +25 -0
- data/lib/thinking_sphinx/core/property.rb +15 -0
- data/lib/thinking_sphinx/core/settings.rb +11 -0
- data/lib/thinking_sphinx/core.rb +11 -0
- data/lib/thinking_sphinx/deletion.rb +70 -0
- data/lib/thinking_sphinx/deltas/default_delta.rb +57 -66
- data/lib/thinking_sphinx/deltas/delete_job.rb +27 -0
- data/lib/thinking_sphinx/deltas/index_job.rb +28 -0
- data/lib/thinking_sphinx/deltas.rb +52 -27
- data/lib/thinking_sphinx/distributed/index.rb +46 -0
- data/lib/thinking_sphinx/distributed.rb +7 -0
- data/lib/thinking_sphinx/errors.rb +96 -0
- data/lib/thinking_sphinx/excerpter.rb +36 -19
- data/lib/thinking_sphinx/facet.rb +29 -122
- data/lib/thinking_sphinx/facet_search.rb +132 -125
- data/lib/thinking_sphinx/float_formatter.rb +35 -0
- data/lib/thinking_sphinx/frameworks/plain.rb +10 -0
- data/lib/thinking_sphinx/frameworks/rails.rb +11 -0
- data/lib/thinking_sphinx/frameworks.rb +11 -0
- data/lib/thinking_sphinx/guard/file.rb +28 -0
- data/lib/thinking_sphinx/guard/files.rb +40 -0
- data/lib/thinking_sphinx/guard/none.rb +7 -0
- data/lib/thinking_sphinx/guard.rb +9 -0
- data/lib/thinking_sphinx/hooks/guard_presence.rb +34 -0
- data/lib/thinking_sphinx/index.rb +50 -92
- data/lib/thinking_sphinx/index_set.rb +96 -0
- data/lib/thinking_sphinx/indexing_strategies/all_at_once.rb +9 -0
- data/lib/thinking_sphinx/indexing_strategies/one_at_a_time.rb +16 -0
- data/lib/thinking_sphinx/interfaces/base.rb +13 -0
- data/lib/thinking_sphinx/interfaces/daemon.rb +27 -0
- data/lib/thinking_sphinx/interfaces/real_time.rb +46 -0
- data/lib/thinking_sphinx/interfaces/sql.rb +53 -0
- data/lib/thinking_sphinx/interfaces.rb +10 -0
- data/lib/thinking_sphinx/logger.rb +9 -0
- data/lib/thinking_sphinx/masks/group_enumerators_mask.rb +30 -0
- data/lib/thinking_sphinx/masks/pagination_mask.rb +63 -0
- data/lib/thinking_sphinx/masks/scopes_mask.rb +56 -0
- data/lib/thinking_sphinx/masks/weight_enumerator_mask.rb +17 -0
- data/lib/thinking_sphinx/masks.rb +10 -0
- data/lib/thinking_sphinx/middlewares/active_record_translator.rb +103 -0
- data/lib/thinking_sphinx/middlewares/geographer.rb +94 -0
- data/lib/thinking_sphinx/middlewares/glazier.rb +52 -0
- data/lib/thinking_sphinx/middlewares/ids_only.rb +15 -0
- data/lib/thinking_sphinx/middlewares/inquirer.rb +64 -0
- data/lib/thinking_sphinx/middlewares/middleware.rb +11 -0
- data/lib/thinking_sphinx/middlewares/sphinxql.rb +256 -0
- data/lib/thinking_sphinx/middlewares/stale_id_checker.rb +47 -0
- data/lib/thinking_sphinx/middlewares/stale_id_filter.rb +48 -0
- data/lib/thinking_sphinx/middlewares/valid_options.rb +25 -0
- data/lib/thinking_sphinx/middlewares.rb +35 -0
- data/lib/thinking_sphinx/panes/attributes_pane.rb +11 -0
- data/lib/thinking_sphinx/panes/distance_pane.rb +15 -0
- data/lib/thinking_sphinx/panes/excerpts_pane.rb +43 -0
- data/lib/thinking_sphinx/panes/weight_pane.rb +11 -0
- data/lib/thinking_sphinx/panes.rb +10 -0
- data/lib/thinking_sphinx/processor.rb +71 -0
- data/lib/thinking_sphinx/query.rb +11 -0
- data/lib/thinking_sphinx/railtie.rb +38 -0
- data/lib/thinking_sphinx/rake_interface.rb +34 -0
- data/lib/thinking_sphinx/real_time/attribute.rb +27 -0
- data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +60 -0
- data/lib/thinking_sphinx/real_time/field.rb +9 -0
- data/lib/thinking_sphinx/real_time/index/template.rb +52 -0
- data/lib/thinking_sphinx/real_time/index.rb +102 -0
- data/lib/thinking_sphinx/real_time/interpreter.rb +54 -0
- data/lib/thinking_sphinx/real_time/populator.rb +46 -0
- data/lib/thinking_sphinx/real_time/processor.rb +36 -0
- data/lib/thinking_sphinx/real_time/property.rb +21 -0
- data/lib/thinking_sphinx/real_time/transcribe_instance.rb +38 -0
- data/lib/thinking_sphinx/real_time/transcriber.rb +89 -0
- data/lib/thinking_sphinx/real_time/translator.rb +39 -0
- data/lib/thinking_sphinx/real_time.rb +40 -0
- data/lib/thinking_sphinx/scopes.rb +34 -0
- data/lib/thinking_sphinx/search/batch_inquirer.rb +23 -0
- data/lib/thinking_sphinx/search/context.rb +31 -0
- data/lib/thinking_sphinx/search/glaze.rb +39 -0
- data/lib/thinking_sphinx/search/merger.rb +34 -0
- data/lib/thinking_sphinx/search/query.rb +33 -0
- data/lib/thinking_sphinx/search/stale_ids_exception.rb +15 -0
- data/lib/thinking_sphinx/search.rb +166 -704
- data/lib/thinking_sphinx/settings.rb +128 -0
- data/lib/thinking_sphinx/sinatra.rb +7 -0
- data/lib/thinking_sphinx/subscribers/populator_subscriber.rb +48 -0
- data/lib/thinking_sphinx/tasks.rb +70 -150
- data/lib/thinking_sphinx/test.rb +56 -0
- data/lib/thinking_sphinx/utf8.rb +18 -0
- data/lib/thinking_sphinx/wildcard.rb +42 -0
- data/lib/thinking_sphinx/with_output.rb +13 -0
- data/lib/thinking_sphinx.rb +83 -185
- data/spec/acceptance/association_scoping_spec.rb +65 -0
- data/spec/acceptance/attribute_access_spec.rb +58 -0
- data/spec/acceptance/attribute_updates_spec.rb +18 -0
- data/spec/acceptance/batch_searching_spec.rb +23 -0
- data/spec/acceptance/big_integers_spec.rb +61 -0
- data/spec/acceptance/excerpts_spec.rb +50 -0
- data/spec/acceptance/facets_spec.rb +141 -0
- data/spec/acceptance/geosearching_spec.rb +70 -0
- data/spec/acceptance/grouping_by_attributes_spec.rb +79 -0
- data/spec/acceptance/index_options_spec.rb +154 -0
- data/spec/acceptance/indexing_spec.rb +38 -0
- data/spec/acceptance/merging_spec.rb +90 -0
- data/spec/acceptance/paginating_search_results_spec.rb +42 -0
- data/spec/acceptance/real_time_updates_spec.rb +115 -0
- data/spec/acceptance/remove_deleted_records_spec.rb +99 -0
- data/spec/acceptance/search_counts_spec.rb +20 -0
- data/spec/acceptance/search_for_just_ids_spec.rb +21 -0
- data/spec/acceptance/searching_across_models_spec.rb +47 -0
- data/spec/acceptance/searching_across_schemas_spec.rb +40 -0
- data/spec/acceptance/searching_on_fields_spec.rb +59 -0
- data/spec/acceptance/searching_with_filters_spec.rb +159 -0
- data/spec/acceptance/searching_with_sti_spec.rb +76 -0
- data/spec/acceptance/searching_within_a_model_spec.rb +117 -0
- data/spec/acceptance/sorting_search_results_spec.rb +50 -0
- data/spec/acceptance/spec_helper.rb +6 -0
- data/spec/acceptance/specifying_sql_spec.rb +516 -0
- data/spec/acceptance/sphinx_scopes_spec.rb +87 -0
- data/spec/acceptance/sql_deltas_spec.rb +78 -0
- data/spec/acceptance/support/database_cleaner.rb +13 -0
- data/spec/acceptance/support/sphinx_controller.rb +62 -0
- data/spec/acceptance/support/sphinx_helpers.rb +45 -0
- data/spec/acceptance/suspended_deltas_spec.rb +56 -0
- data/spec/fixtures/database.yml +4 -0
- data/spec/internal/app/indices/admin_person_index.rb +9 -0
- data/spec/internal/app/indices/album_index.rb +9 -0
- data/spec/internal/app/indices/animal_index.rb +5 -0
- data/spec/internal/app/indices/article_index.rb +31 -0
- data/spec/internal/app/indices/bird_index.rb +6 -0
- data/spec/internal/app/indices/book_index.rb +11 -0
- data/spec/internal/app/indices/car_index.rb +7 -0
- data/spec/internal/app/indices/city_index.rb +9 -0
- data/spec/internal/app/indices/colour_index.rb +7 -0
- data/spec/internal/app/indices/product_index.rb +27 -0
- data/spec/internal/app/indices/tee_index.rb +6 -0
- data/spec/internal/app/indices/user_index.rb +9 -0
- data/spec/internal/app/models/admin/person.rb +9 -0
- data/spec/internal/app/models/album.rb +25 -0
- data/spec/internal/app/models/animal.rb +5 -0
- data/spec/internal/app/models/article.rb +9 -0
- data/spec/internal/app/models/bird.rb +5 -0
- data/spec/internal/app/models/book.rb +18 -0
- data/spec/internal/app/models/car.rb +7 -0
- data/spec/internal/app/models/categorisation.rb +15 -0
- data/spec/internal/app/models/category.rb +6 -0
- data/spec/internal/app/models/city.rb +7 -0
- data/spec/internal/app/models/colour.rb +7 -0
- data/spec/internal/app/models/event.rb +5 -0
- data/spec/internal/app/models/flightless_bird.rb +4 -0
- data/spec/internal/app/models/genre.rb +5 -0
- data/spec/internal/app/models/hardcover.rb +5 -0
- data/spec/internal/app/models/mammal.rb +4 -0
- data/spec/internal/app/models/manufacturer.rb +5 -0
- data/spec/internal/app/models/product.rb +8 -0
- data/spec/internal/app/models/tag.rb +6 -0
- data/{features/support → spec/internal/app}/models/tagging.rb +3 -1
- data/spec/internal/app/models/tee.rb +10 -0
- data/spec/internal/app/models/tweet.rb +5 -0
- data/spec/internal/app/models/user.rb +10 -0
- data/spec/internal/config/database.yml +17 -0
- data/spec/internal/db/schema.rb +115 -0
- data/spec/internal/tmp/.gitkeep +0 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/json_column.rb +35 -0
- data/spec/support/multi_schema.rb +50 -0
- data/spec/support/mysql.rb +25 -0
- data/spec/support/sphinx_yaml_helpers.rb +16 -0
- data/spec/thinking_sphinx/active_record/association_spec.rb +14 -0
- data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +165 -0
- data/spec/thinking_sphinx/active_record/base_spec.rb +131 -0
- data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +128 -0
- data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +176 -0
- data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +91 -0
- data/spec/thinking_sphinx/active_record/column_spec.rb +72 -0
- data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +39 -0
- data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +33 -0
- data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +70 -0
- data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +66 -0
- data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +128 -0
- data/spec/thinking_sphinx/active_record/field_spec.rb +51 -0
- data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +207 -0
- data/spec/thinking_sphinx/active_record/index_spec.rb +220 -0
- data/spec/thinking_sphinx/active_record/interpreter_spec.rb +329 -0
- data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +87 -0
- data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +264 -0
- data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +662 -0
- data/spec/thinking_sphinx/active_record/sql_source_spec.rb +507 -0
- data/spec/thinking_sphinx/attribute_types_spec.rb +52 -0
- data/spec/thinking_sphinx/commands/clear_real_time_spec.rb +46 -0
- data/spec/thinking_sphinx/commands/clear_sql_spec.rb +52 -0
- data/spec/thinking_sphinx/commands/configure_spec.rb +31 -0
- data/spec/thinking_sphinx/commands/index_real_time_spec.rb +33 -0
- data/spec/thinking_sphinx/commands/index_sql_spec.rb +86 -0
- data/spec/thinking_sphinx/commands/merge_and_update_spec.rb +106 -0
- data/spec/thinking_sphinx/commands/merge_spec.rb +48 -0
- data/spec/thinking_sphinx/commands/prepare_spec.rb +31 -0
- data/spec/thinking_sphinx/commands/running_spec.rb +30 -0
- data/spec/thinking_sphinx/commands/start_detached_spec.rb +67 -0
- data/spec/thinking_sphinx/commands/stop_spec.rb +63 -0
- data/spec/thinking_sphinx/configuration/minimum_fields_spec.rb +60 -0
- data/spec/thinking_sphinx/configuration_spec.rb +582 -0
- data/spec/thinking_sphinx/connection/mri_spec.rb +49 -0
- data/spec/thinking_sphinx/connection_spec.rb +87 -0
- data/spec/thinking_sphinx/deletion_spec.rb +57 -0
- data/spec/thinking_sphinx/deltas/default_delta_spec.rb +123 -0
- data/spec/thinking_sphinx/deltas_spec.rb +77 -0
- data/spec/thinking_sphinx/errors_spec.rb +103 -0
- data/spec/thinking_sphinx/excerpter_spec.rb +53 -0
- data/spec/thinking_sphinx/facet_search_spec.rb +133 -0
- data/spec/thinking_sphinx/hooks/guard_presence_spec.rb +30 -0
- data/spec/thinking_sphinx/index_set_spec.rb +132 -0
- data/spec/thinking_sphinx/index_spec.rb +140 -0
- data/spec/thinking_sphinx/interfaces/daemon_spec.rb +60 -0
- data/spec/thinking_sphinx/interfaces/real_time_spec.rb +109 -0
- data/spec/thinking_sphinx/interfaces/sql_spec.rb +122 -0
- data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +123 -0
- data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +139 -0
- data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +180 -0
- data/spec/thinking_sphinx/middlewares/geographer_spec.rb +102 -0
- data/spec/thinking_sphinx/middlewares/glazier_spec.rb +65 -0
- data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +72 -0
- data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +401 -0
- data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +50 -0
- data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +113 -0
- data/spec/thinking_sphinx/middlewares/valid_options_spec.rb +51 -0
- data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +23 -0
- data/spec/thinking_sphinx/panes/distance_pane_spec.rb +43 -0
- data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +53 -0
- data/spec/thinking_sphinx/panes/weight_pane_spec.rb +22 -0
- data/spec/thinking_sphinx/rake_interface_spec.rb +39 -0
- data/spec/thinking_sphinx/real_time/attribute_spec.rb +64 -0
- data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +238 -0
- data/spec/thinking_sphinx/real_time/field_spec.rb +69 -0
- data/spec/thinking_sphinx/real_time/index_spec.rb +230 -0
- data/spec/thinking_sphinx/real_time/interpreter_spec.rb +203 -0
- data/spec/thinking_sphinx/real_time/transcribe_instance_spec.rb +35 -0
- data/spec/thinking_sphinx/real_time/transcriber_spec.rb +109 -0
- data/spec/thinking_sphinx/real_time/translator_spec.rb +17 -0
- data/spec/thinking_sphinx/scopes_spec.rb +51 -0
- data/spec/thinking_sphinx/search/glaze_spec.rb +79 -0
- data/spec/thinking_sphinx/search/query_spec.rb +87 -0
- data/spec/thinking_sphinx/search_spec.rb +214 -0
- data/spec/thinking_sphinx/wildcard_spec.rb +53 -0
- data/spec/thinking_sphinx_spec.rb +44 -0
- data/thinking-sphinx.gemspec +42 -0
- metadata +656 -243
- data/VERSION.yml +0 -5
- data/features/alternate_primary_key.feature +0 -27
- data/features/attribute_transformation.feature +0 -22
- data/features/attribute_updates.feature +0 -33
- data/features/datetime_deltas.feature +0 -66
- data/features/delayed_delta_indexing.feature +0 -37
- data/features/deleting_instances.feature +0 -64
- data/features/direct_attributes.feature +0 -11
- data/features/excerpts.feature +0 -13
- data/features/extensible_delta_indexing.feature +0 -9
- data/features/facets.feature +0 -76
- data/features/facets_across_model.feature +0 -29
- data/features/handling_edits.feature +0 -92
- data/features/retry_stale_indexes.feature +0 -24
- data/features/searching_across_models.feature +0 -20
- data/features/searching_by_model.feature +0 -175
- data/features/searching_with_find_arguments.feature +0 -56
- data/features/sphinx_detection.feature +0 -25
- data/features/sphinx_scopes.feature +0 -35
- data/features/step_definitions/alpha_steps.rb +0 -3
- data/features/step_definitions/beta_steps.rb +0 -7
- data/features/step_definitions/common_steps.rb +0 -178
- data/features/step_definitions/datetime_delta_steps.rb +0 -15
- data/features/step_definitions/delayed_delta_indexing_steps.rb +0 -7
- data/features/step_definitions/extensible_delta_indexing_steps.rb +0 -7
- data/features/step_definitions/facet_steps.rb +0 -92
- data/features/step_definitions/find_arguments_steps.rb +0 -36
- data/features/step_definitions/gamma_steps.rb +0 -15
- data/features/step_definitions/scope_steps.rb +0 -11
- data/features/step_definitions/search_steps.rb +0 -89
- data/features/step_definitions/sphinx_steps.rb +0 -31
- data/features/sti_searching.feature +0 -14
- data/features/support/database.example.yml +0 -3
- data/features/support/database.yml +0 -5
- data/features/support/db/active_record.rb +0 -40
- data/features/support/db/database.yml +0 -5
- data/features/support/db/fixtures/alphas.rb +0 -10
- data/features/support/db/fixtures/authors.rb +0 -1
- data/features/support/db/fixtures/betas.rb +0 -10
- data/features/support/db/fixtures/boxes.rb +0 -9
- data/features/support/db/fixtures/categories.rb +0 -1
- data/features/support/db/fixtures/cats.rb +0 -3
- data/features/support/db/fixtures/comments.rb +0 -24
- data/features/support/db/fixtures/delayed_betas.rb +0 -10
- data/features/support/db/fixtures/developers.rb +0 -29
- data/features/support/db/fixtures/dogs.rb +0 -3
- data/features/support/db/fixtures/extensible_betas.rb +0 -10
- data/features/support/db/fixtures/gammas.rb +0 -10
- data/features/support/db/fixtures/people.rb +0 -1001
- data/features/support/db/fixtures/posts.rb +0 -6
- data/features/support/db/fixtures/robots.rb +0 -14
- data/features/support/db/fixtures/tags.rb +0 -27
- data/features/support/db/fixtures/thetas.rb +0 -10
- data/features/support/db/migrations/create_alphas.rb +0 -7
- data/features/support/db/migrations/create_animals.rb +0 -5
- data/features/support/db/migrations/create_authors.rb +0 -3
- data/features/support/db/migrations/create_authors_posts.rb +0 -6
- data/features/support/db/migrations/create_betas.rb +0 -5
- data/features/support/db/migrations/create_boxes.rb +0 -5
- data/features/support/db/migrations/create_categories.rb +0 -3
- data/features/support/db/migrations/create_comments.rb +0 -10
- data/features/support/db/migrations/create_delayed_betas.rb +0 -17
- data/features/support/db/migrations/create_developers.rb +0 -9
- data/features/support/db/migrations/create_extensible_betas.rb +0 -5
- data/features/support/db/migrations/create_gammas.rb +0 -3
- data/features/support/db/migrations/create_people.rb +0 -13
- data/features/support/db/migrations/create_posts.rb +0 -5
- data/features/support/db/migrations/create_robots.rb +0 -4
- data/features/support/db/migrations/create_taggings.rb +0 -5
- data/features/support/db/migrations/create_tags.rb +0 -4
- data/features/support/db/migrations/create_thetas.rb +0 -5
- data/features/support/db/mysql.rb +0 -3
- data/features/support/db/postgresql.rb +0 -3
- data/features/support/env.rb +0 -18
- data/features/support/lib/generic_delta_handler.rb +0 -8
- data/features/support/models/alpha.rb +0 -10
- data/features/support/models/animal.rb +0 -5
- data/features/support/models/author.rb +0 -3
- data/features/support/models/beta.rb +0 -8
- data/features/support/models/box.rb +0 -8
- data/features/support/models/cat.rb +0 -3
- data/features/support/models/category.rb +0 -4
- data/features/support/models/comment.rb +0 -10
- data/features/support/models/delayed_beta.rb +0 -7
- data/features/support/models/developer.rb +0 -16
- data/features/support/models/dog.rb +0 -3
- data/features/support/models/extensible_beta.rb +0 -9
- data/features/support/models/gamma.rb +0 -5
- data/features/support/models/person.rb +0 -23
- data/features/support/models/post.rb +0 -20
- data/features/support/models/robot.rb +0 -12
- data/features/support/models/tag.rb +0 -3
- data/features/support/models/theta.rb +0 -7
- data/features/support/post_database.rb +0 -43
- data/lib/cucumber/thinking_sphinx/internal_world.rb +0 -125
- data/lib/cucumber/thinking_sphinx/sql_logger.rb +0 -20
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +0 -48
- data/lib/thinking_sphinx/active_record/delta.rb +0 -87
- data/lib/thinking_sphinx/active_record/has_many_association.rb +0 -28
- data/lib/thinking_sphinx/active_record/scopes.rb +0 -39
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +0 -42
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +0 -54
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +0 -143
- data/lib/thinking_sphinx/association.rb +0 -164
- data/lib/thinking_sphinx/attribute.rb +0 -341
- data/lib/thinking_sphinx/class_facet.rb +0 -15
- data/lib/thinking_sphinx/core/array.rb +0 -7
- data/lib/thinking_sphinx/core/string.rb +0 -15
- data/lib/thinking_sphinx/deltas/datetime_delta.rb +0 -50
- data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +0 -24
- data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +0 -27
- data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +0 -26
- data/lib/thinking_sphinx/deltas/delayed_delta.rb +0 -30
- data/lib/thinking_sphinx/deploy/capistrano.rb +0 -100
- data/lib/thinking_sphinx/field.rb +0 -82
- data/lib/thinking_sphinx/index/builder.rb +0 -286
- data/lib/thinking_sphinx/index/faux_column.rb +0 -110
- data/lib/thinking_sphinx/property.rb +0 -162
- data/lib/thinking_sphinx/rails_additions.rb +0 -150
- data/lib/thinking_sphinx/search_methods.rb +0 -421
- data/lib/thinking_sphinx/source/internal_properties.rb +0 -46
- data/lib/thinking_sphinx/source/sql.rb +0 -128
- data/lib/thinking_sphinx/source.rb +0 -150
- data/rails/init.rb +0 -14
- data/spec/lib/thinking_sphinx/active_record/delta_spec.rb +0 -130
- data/spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb +0 -49
- data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +0 -96
- data/spec/lib/thinking_sphinx/active_record_spec.rb +0 -353
- data/spec/lib/thinking_sphinx/association_spec.rb +0 -239
- data/spec/lib/thinking_sphinx/attribute_spec.rb +0 -507
- data/spec/lib/thinking_sphinx/configuration_spec.rb +0 -268
- data/spec/lib/thinking_sphinx/core/array_spec.rb +0 -9
- data/spec/lib/thinking_sphinx/core/string_spec.rb +0 -9
- data/spec/lib/thinking_sphinx/deltas/job_spec.rb +0 -32
- data/spec/lib/thinking_sphinx/excerpter_spec.rb +0 -57
- data/spec/lib/thinking_sphinx/facet_search_spec.rb +0 -176
- data/spec/lib/thinking_sphinx/facet_spec.rb +0 -333
- data/spec/lib/thinking_sphinx/field_spec.rb +0 -154
- data/spec/lib/thinking_sphinx/index/builder_spec.rb +0 -455
- data/spec/lib/thinking_sphinx/index/faux_column_spec.rb +0 -30
- data/spec/lib/thinking_sphinx/index_spec.rb +0 -45
- data/spec/lib/thinking_sphinx/rails_additions_spec.rb +0 -203
- data/spec/lib/thinking_sphinx/search_methods_spec.rb +0 -152
- data/spec/lib/thinking_sphinx/search_spec.rb +0 -1101
- data/spec/lib/thinking_sphinx/source_spec.rb +0 -227
- data/spec/lib/thinking_sphinx_spec.rb +0 -162
- data/tasks/distribution.rb +0 -53
- data/tasks/rails.rake +0 -1
- data/tasks/testing.rb +0 -72
- data/vendor/after_commit/LICENSE +0 -20
- data/vendor/after_commit/README +0 -16
- data/vendor/after_commit/Rakefile +0 -22
- data/vendor/after_commit/init.rb +0 -8
- data/vendor/after_commit/lib/after_commit/active_record.rb +0 -114
- data/vendor/after_commit/lib/after_commit/connection_adapters.rb +0 -103
- data/vendor/after_commit/lib/after_commit.rb +0 -45
- data/vendor/after_commit/test/after_commit_test.rb +0 -53
- data/vendor/delayed_job/lib/delayed/job.rb +0 -251
- data/vendor/delayed_job/lib/delayed/message_sending.rb +0 -7
- data/vendor/delayed_job/lib/delayed/performable_method.rb +0 -55
- data/vendor/delayed_job/lib/delayed/worker.rb +0 -54
- data/vendor/riddle/lib/riddle/client/filter.rb +0 -53
- data/vendor/riddle/lib/riddle/client/message.rb +0 -66
- data/vendor/riddle/lib/riddle/client/response.rb +0 -84
- data/vendor/riddle/lib/riddle/client.rb +0 -635
- data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +0 -48
- data/vendor/riddle/lib/riddle/configuration/index.rb +0 -142
- data/vendor/riddle/lib/riddle/configuration/indexer.rb +0 -19
- data/vendor/riddle/lib/riddle/configuration/remote_index.rb +0 -17
- data/vendor/riddle/lib/riddle/configuration/searchd.rb +0 -25
- data/vendor/riddle/lib/riddle/configuration/section.rb +0 -43
- data/vendor/riddle/lib/riddle/configuration/source.rb +0 -23
- data/vendor/riddle/lib/riddle/configuration/sql_source.rb +0 -34
- data/vendor/riddle/lib/riddle/configuration/xml_source.rb +0 -28
- data/vendor/riddle/lib/riddle/configuration.rb +0 -33
- data/vendor/riddle/lib/riddle/controller.rb +0 -53
- data/vendor/riddle/lib/riddle.rb +0 -30
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ThinkingSphinx
|
|
4
|
+
module Masks; end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'thinking_sphinx/masks/scopes_mask'
|
|
8
|
+
|
|
9
|
+
describe ThinkingSphinx::Masks::ScopesMask do
|
|
10
|
+
let(:search) { double('search', :options => {}, :per_page => 20,
|
|
11
|
+
:populated? => false) }
|
|
12
|
+
let(:mask) { ThinkingSphinx::Masks::ScopesMask.new search }
|
|
13
|
+
|
|
14
|
+
before :each do
|
|
15
|
+
allow(FileUtils).to receive_messages :mkdir_p => true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe '#search' do
|
|
19
|
+
it "replaces the query if one is supplied" do
|
|
20
|
+
expect(search).to receive(:query=).with('bar')
|
|
21
|
+
|
|
22
|
+
mask.search('bar')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "keeps the existing query when only options are offered" do
|
|
26
|
+
expect(search).not_to receive(:query=)
|
|
27
|
+
|
|
28
|
+
mask.search :with => {:foo => :bar}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "merges conditions" do
|
|
32
|
+
search.options[:conditions] = {:foo => 'bar'}
|
|
33
|
+
|
|
34
|
+
mask.search :conditions => {:baz => 'qux'}
|
|
35
|
+
|
|
36
|
+
expect(search.options[:conditions]).to eq({:foo => 'bar', :baz => 'qux'})
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "merges filters" do
|
|
40
|
+
search.options[:with] = {:foo => :bar}
|
|
41
|
+
|
|
42
|
+
mask.search :with => {:baz => :qux}
|
|
43
|
+
|
|
44
|
+
expect(search.options[:with]).to eq({:foo => :bar, :baz => :qux})
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "merges exclusive filters" do
|
|
48
|
+
search.options[:without] = {:foo => :bar}
|
|
49
|
+
|
|
50
|
+
mask.search :without => {:baz => :qux}
|
|
51
|
+
|
|
52
|
+
expect(search.options[:without]).to eq({:foo => :bar, :baz => :qux})
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "appends excluded ids" do
|
|
56
|
+
search.options[:without_ids] = [1, 3]
|
|
57
|
+
|
|
58
|
+
mask.search :without_ids => [5, 7]
|
|
59
|
+
|
|
60
|
+
expect(search.options[:without_ids]).to eq([1, 3, 5, 7])
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "replaces the retry_stale option" do
|
|
64
|
+
search.options[:retry_stale] = true
|
|
65
|
+
|
|
66
|
+
mask.search :retry_stale => 6
|
|
67
|
+
|
|
68
|
+
expect(search.options[:retry_stale]).to eq(6)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "returns the original search object" do
|
|
72
|
+
expect(mask.search.object_id).to eq(search.object_id)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe '#search_for_ids' do
|
|
77
|
+
it "replaces the query if one is supplied" do
|
|
78
|
+
expect(search).to receive(:query=).with('bar')
|
|
79
|
+
|
|
80
|
+
mask.search_for_ids('bar')
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "keeps the existing query when only options are offered" do
|
|
84
|
+
expect(search).not_to receive(:query=)
|
|
85
|
+
|
|
86
|
+
mask.search_for_ids :with => {:foo => :bar}
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "merges conditions" do
|
|
90
|
+
search.options[:conditions] = {:foo => 'bar'}
|
|
91
|
+
|
|
92
|
+
mask.search_for_ids :conditions => {:baz => 'qux'}
|
|
93
|
+
|
|
94
|
+
expect(search.options[:conditions]).to eq({:foo => 'bar', :baz => 'qux'})
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "merges filters" do
|
|
98
|
+
search.options[:with] = {:foo => :bar}
|
|
99
|
+
|
|
100
|
+
mask.search_for_ids :with => {:baz => :qux}
|
|
101
|
+
|
|
102
|
+
expect(search.options[:with]).to eq({:foo => :bar, :baz => :qux})
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "merges exclusive filters" do
|
|
106
|
+
search.options[:without] = {:foo => :bar}
|
|
107
|
+
|
|
108
|
+
mask.search_for_ids :without => {:baz => :qux}
|
|
109
|
+
|
|
110
|
+
expect(search.options[:without]).to eq({:foo => :bar, :baz => :qux})
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "appends excluded ids" do
|
|
114
|
+
search.options[:without_ids] = [1, 3]
|
|
115
|
+
|
|
116
|
+
mask.search_for_ids :without_ids => [5, 7]
|
|
117
|
+
|
|
118
|
+
expect(search.options[:without_ids]).to eq([1, 3, 5, 7])
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "replaces the retry_stale option" do
|
|
122
|
+
search.options[:retry_stale] = true
|
|
123
|
+
|
|
124
|
+
mask.search_for_ids :retry_stale => 6
|
|
125
|
+
|
|
126
|
+
expect(search.options[:retry_stale]).to eq(6)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it "adds the ids_only option" do
|
|
130
|
+
mask.search_for_ids
|
|
131
|
+
|
|
132
|
+
expect(search.options[:ids_only]).to be_truthy
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "returns the original search object" do
|
|
136
|
+
expect(mask.search_for_ids.object_id).to eq(search.object_id)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ThinkingSphinx
|
|
4
|
+
module Middlewares; end
|
|
5
|
+
class Search; end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
require 'thinking_sphinx/middlewares/middleware'
|
|
9
|
+
require 'thinking_sphinx/middlewares/active_record_translator'
|
|
10
|
+
require 'thinking_sphinx/search/stale_ids_exception'
|
|
11
|
+
|
|
12
|
+
describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
|
|
13
|
+
let(:app) { double('app', :call => true) }
|
|
14
|
+
let(:middleware) {
|
|
15
|
+
ThinkingSphinx::Middlewares::ActiveRecordTranslator.new app }
|
|
16
|
+
let(:context) { {:raw => [], :results => [] } }
|
|
17
|
+
let(:model) { double('model', :primary_key => :id) }
|
|
18
|
+
let(:search) { double('search', :options => {}) }
|
|
19
|
+
let(:configuration) { double('configuration', :settings => {:primary_key => :id}) }
|
|
20
|
+
|
|
21
|
+
def raw_result(id, model_name)
|
|
22
|
+
{'sphinx_internal_id' => id, 'sphinx_internal_class' => model_name}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe '#call' do
|
|
26
|
+
before :each do
|
|
27
|
+
allow(context).to receive_messages :search => search
|
|
28
|
+
allow(context).to receive_messages :configuration => configuration
|
|
29
|
+
allow(model).to receive_messages :unscoped => model
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "translates records to ActiveRecord objects" do
|
|
33
|
+
model_name = double('article', :constantize => model)
|
|
34
|
+
instance = double('instance', :id => 24)
|
|
35
|
+
allow(model).to receive_messages :where => [instance]
|
|
36
|
+
|
|
37
|
+
context[:results] << raw_result(24, model_name)
|
|
38
|
+
|
|
39
|
+
middleware.call [context]
|
|
40
|
+
|
|
41
|
+
expect(context[:results]).to eq([instance])
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "only queries the model once for the given search results" do
|
|
45
|
+
model_name = double('article', :constantize => model)
|
|
46
|
+
instance_a = double('instance', :id => 24)
|
|
47
|
+
instance_b = double('instance', :id => 42)
|
|
48
|
+
context[:results] << raw_result(24, model_name)
|
|
49
|
+
context[:results] << raw_result(42, model_name)
|
|
50
|
+
|
|
51
|
+
expect(model).to receive(:where).once.and_return([instance_a, instance_b])
|
|
52
|
+
|
|
53
|
+
middleware.call [context]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "handles multiple models" do
|
|
57
|
+
article_model = double('article model', :primary_key => :id)
|
|
58
|
+
article_name = double('article name', :constantize => article_model)
|
|
59
|
+
article = double('article instance', :id => 24)
|
|
60
|
+
|
|
61
|
+
user_model = double('user model', :primary_key => :id)
|
|
62
|
+
user_name = double('user name', :constantize => user_model)
|
|
63
|
+
user = double('user instance', :id => 12)
|
|
64
|
+
|
|
65
|
+
allow(article_model).to receive_messages :unscoped => article_model
|
|
66
|
+
allow(user_model).to receive_messages :unscoped => user_model
|
|
67
|
+
|
|
68
|
+
context[:results] << raw_result(24, article_name)
|
|
69
|
+
context[:results] << raw_result(12, user_name)
|
|
70
|
+
|
|
71
|
+
expect(article_model).to receive(:where).once.and_return([article])
|
|
72
|
+
expect(user_model).to receive(:where).once.and_return([user])
|
|
73
|
+
|
|
74
|
+
middleware.call [context]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "sorts the results according to Sphinx order, not database order" do
|
|
78
|
+
model_name = double('article', :constantize => model)
|
|
79
|
+
instance_1 = double('instance 1', :id => 1)
|
|
80
|
+
instance_2 = double('instance 2', :id => 2)
|
|
81
|
+
|
|
82
|
+
context[:results] << raw_result(2, model_name)
|
|
83
|
+
context[:results] << raw_result(1, model_name)
|
|
84
|
+
|
|
85
|
+
allow(model).to receive_messages(:where => [instance_1, instance_2])
|
|
86
|
+
|
|
87
|
+
middleware.call [context]
|
|
88
|
+
|
|
89
|
+
expect(context[:results]).to eq([instance_2, instance_1])
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "returns objects in database order if a SQL order clause is supplied" do
|
|
93
|
+
model_name = double('article', :constantize => model)
|
|
94
|
+
instance_1 = double('instance 1', :id => 1)
|
|
95
|
+
instance_2 = double('instance 2', :id => 2)
|
|
96
|
+
|
|
97
|
+
context[:results] << raw_result(2, model_name)
|
|
98
|
+
context[:results] << raw_result(1, model_name)
|
|
99
|
+
|
|
100
|
+
allow(model).to receive_messages(:order => model, :where => [instance_1, instance_2])
|
|
101
|
+
search.options[:sql] = {:order => 'name DESC'}
|
|
102
|
+
|
|
103
|
+
middleware.call [context]
|
|
104
|
+
|
|
105
|
+
expect(context[:results]).to eq([instance_1, instance_2])
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "handles model without primary key" do
|
|
109
|
+
no_primary_key_model = double('no primary key model')
|
|
110
|
+
allow(no_primary_key_model).to receive_messages :unscoped => no_primary_key_model
|
|
111
|
+
model_name = double('article', :constantize => no_primary_key_model)
|
|
112
|
+
instance = double('instance', :id => 1)
|
|
113
|
+
allow(no_primary_key_model).to receive_messages :where => [instance]
|
|
114
|
+
|
|
115
|
+
context[:results] << raw_result(1, model_name)
|
|
116
|
+
|
|
117
|
+
middleware.call [context]
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
context 'SQL options' do
|
|
121
|
+
let(:relation) { double('relation', :where => []) }
|
|
122
|
+
let(:model_name) { double('article', :constantize => model) }
|
|
123
|
+
|
|
124
|
+
before :each do
|
|
125
|
+
allow(model).to receive_messages :unscoped => relation
|
|
126
|
+
|
|
127
|
+
context[:results] << raw_result(1, model_name)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it "passes through SQL include options to the relation" do
|
|
131
|
+
search.options[:sql] = {:include => :association}
|
|
132
|
+
|
|
133
|
+
expect(relation).to receive(:includes).with(:association).
|
|
134
|
+
and_return(relation)
|
|
135
|
+
|
|
136
|
+
middleware.call [context]
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "passes through SQL join options to the relation" do
|
|
140
|
+
search.options[:sql] = {:joins => :association}
|
|
141
|
+
|
|
142
|
+
expect(relation).to receive(:joins).with(:association).and_return(relation)
|
|
143
|
+
|
|
144
|
+
middleware.call [context]
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it "passes through SQL order options to the relation" do
|
|
148
|
+
search.options[:sql] = {:order => 'name DESC'}
|
|
149
|
+
|
|
150
|
+
expect(relation).to receive(:order).with('name DESC').and_return(relation)
|
|
151
|
+
|
|
152
|
+
middleware.call [context]
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it "passes through SQL select options to the relation" do
|
|
156
|
+
search.options[:sql] = {:select => :column}
|
|
157
|
+
|
|
158
|
+
expect(relation).to receive(:select).with(:column).and_return(relation)
|
|
159
|
+
|
|
160
|
+
middleware.call [context]
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it "passes through SQL group options to the relation" do
|
|
164
|
+
search.options[:sql] = {:group => :column}
|
|
165
|
+
|
|
166
|
+
expect(relation).to receive(:group).with(:column).and_return(relation)
|
|
167
|
+
|
|
168
|
+
middleware.call [context]
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it "passes through SQL options defined by model to the relation" do
|
|
172
|
+
search.options[:sql] = {model_name => {:joins => :association}}
|
|
173
|
+
|
|
174
|
+
expect(relation).to receive(:joins).with(:association).and_return(relation)
|
|
175
|
+
|
|
176
|
+
middleware.call [context]
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ThinkingSphinx
|
|
4
|
+
module Middlewares; end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'thinking_sphinx/middlewares/middleware'
|
|
8
|
+
require 'thinking_sphinx/middlewares/geographer'
|
|
9
|
+
require 'thinking_sphinx/float_formatter'
|
|
10
|
+
|
|
11
|
+
describe ThinkingSphinx::Middlewares::Geographer do
|
|
12
|
+
let(:app) { double('app', :call => true) }
|
|
13
|
+
let(:middleware) { ThinkingSphinx::Middlewares::Geographer.new app }
|
|
14
|
+
let(:context) { {:sphinxql => sphinx_sql, :indices => [], :panes => []} }
|
|
15
|
+
let(:sphinx_sql) { double('sphinx_sql') }
|
|
16
|
+
let(:search) { double('search', :options => {}) }
|
|
17
|
+
|
|
18
|
+
before :each do
|
|
19
|
+
stub_const 'ThinkingSphinx::Panes::DistancePane', double
|
|
20
|
+
|
|
21
|
+
allow(context).to receive_messages :search => search
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe '#call' do
|
|
25
|
+
context 'no geodistance location provided' do
|
|
26
|
+
before :each do
|
|
27
|
+
search.options[:geo] = nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "doesn't add anything if :geo is nil" do
|
|
31
|
+
expect(sphinx_sql).not_to receive(:prepend_values)
|
|
32
|
+
|
|
33
|
+
middleware.call [context]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context 'geodistance location provided' do
|
|
38
|
+
before :each do
|
|
39
|
+
search.options[:geo] = [0.1, 0.2]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "adds the geodist function when given a :geo option" do
|
|
43
|
+
expect(sphinx_sql).to receive(:prepend_values).
|
|
44
|
+
with('GEODIST(0.1, 0.2, lat, lng) AS geodist').
|
|
45
|
+
and_return(sphinx_sql)
|
|
46
|
+
|
|
47
|
+
middleware.call [context]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "adds the distance pane" do
|
|
51
|
+
allow(sphinx_sql).to receive_messages :prepend_values => sphinx_sql
|
|
52
|
+
|
|
53
|
+
middleware.call [context]
|
|
54
|
+
|
|
55
|
+
expect(context[:panes]).to include(ThinkingSphinx::Panes::DistancePane)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "respects :latitude_attr and :longitude_attr options" do
|
|
59
|
+
search.options[:latitude_attr] = 'side_to_side'
|
|
60
|
+
search.options[:longitude_attr] = 'up_or_down'
|
|
61
|
+
|
|
62
|
+
expect(sphinx_sql).to receive(:prepend_values).
|
|
63
|
+
with('GEODIST(0.1, 0.2, side_to_side, up_or_down) AS geodist').
|
|
64
|
+
and_return(sphinx_sql)
|
|
65
|
+
|
|
66
|
+
middleware.call [context]
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "uses latitude if any index has that but not lat as an attribute" do
|
|
70
|
+
context[:indices] << double('index',
|
|
71
|
+
:unique_attribute_names => ['latitude'], :name => 'an_index')
|
|
72
|
+
|
|
73
|
+
expect(sphinx_sql).to receive(:prepend_values).
|
|
74
|
+
with('GEODIST(0.1, 0.2, latitude, lng) AS geodist').
|
|
75
|
+
and_return(sphinx_sql)
|
|
76
|
+
|
|
77
|
+
middleware.call [context]
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "uses latitude if any index has that but not lat as an attribute" do
|
|
81
|
+
context[:indices] << double('index',
|
|
82
|
+
:unique_attribute_names => ['longitude'], :name => 'an_index')
|
|
83
|
+
|
|
84
|
+
expect(sphinx_sql).to receive(:prepend_values).
|
|
85
|
+
with('GEODIST(0.1, 0.2, lat, longitude) AS geodist').
|
|
86
|
+
and_return(sphinx_sql)
|
|
87
|
+
|
|
88
|
+
middleware.call [context]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "handles very small values" do
|
|
92
|
+
search.options[:geo] = [0.0000001, 0.00000000002]
|
|
93
|
+
|
|
94
|
+
expect(sphinx_sql).to receive(:prepend_values).
|
|
95
|
+
with('GEODIST(0.0000001, 0.00000000002, lat, lng) AS geodist').
|
|
96
|
+
and_return(sphinx_sql)
|
|
97
|
+
|
|
98
|
+
middleware.call [context]
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ThinkingSphinx
|
|
4
|
+
module Middlewares; end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'thinking_sphinx/middlewares/middleware'
|
|
8
|
+
require 'thinking_sphinx/middlewares/glazier'
|
|
9
|
+
|
|
10
|
+
describe ThinkingSphinx::Middlewares::Glazier do
|
|
11
|
+
let(:app) { double('app', :call => true) }
|
|
12
|
+
let(:middleware) { ThinkingSphinx::Middlewares::Glazier.new app }
|
|
13
|
+
let(:context) { {:results => [result], :indices => [index],
|
|
14
|
+
:meta => {}, :raw => [raw_result], :panes => []} }
|
|
15
|
+
let(:result) { double 'result', :id => 10, :class => model }
|
|
16
|
+
let(:model) { double 'model', :name => 'Article' }
|
|
17
|
+
let(:index) { double 'index', :name => 'foo_core', :model => model,
|
|
18
|
+
:primary_key => :id }
|
|
19
|
+
let(:search) { double 'search', :options => {} }
|
|
20
|
+
let(:glazed_result) { double 'glazed result' }
|
|
21
|
+
let(:raw_result) {
|
|
22
|
+
{'sphinx_internal_class' => 'Article', 'sphinx_internal_id' => 10} }
|
|
23
|
+
|
|
24
|
+
describe '#call' do
|
|
25
|
+
before :each do
|
|
26
|
+
stub_const 'ThinkingSphinx::Search::Glaze', double(:new => glazed_result)
|
|
27
|
+
|
|
28
|
+
allow(context).to receive_messages :search => search
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context 'No panes provided' do
|
|
32
|
+
before :each do
|
|
33
|
+
context[:panes].clear
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "leaves the results as they are" do
|
|
37
|
+
middleware.call [context]
|
|
38
|
+
|
|
39
|
+
expect(context[:results]).to eq([result])
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context 'Panes provided' do
|
|
44
|
+
let(:pane_class) { double('pane class') }
|
|
45
|
+
|
|
46
|
+
before :each do
|
|
47
|
+
context[:panes] << pane_class
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "replaces each result with a glazed version" do
|
|
51
|
+
middleware.call [context]
|
|
52
|
+
|
|
53
|
+
expect(context[:results]).to eq([glazed_result])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "creates a glazed result for each result" do
|
|
57
|
+
expect(ThinkingSphinx::Search::Glaze).to receive(:new).
|
|
58
|
+
with(context, result, raw_result, [pane_class]).
|
|
59
|
+
and_return(glazed_result)
|
|
60
|
+
|
|
61
|
+
middleware.call [context]
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ThinkingSphinx
|
|
4
|
+
module Middlewares; end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'thinking_sphinx/middlewares/middleware'
|
|
8
|
+
require 'thinking_sphinx/middlewares/inquirer'
|
|
9
|
+
|
|
10
|
+
describe ThinkingSphinx::Middlewares::Inquirer do
|
|
11
|
+
let(:app) { double('app', :call => true) }
|
|
12
|
+
let(:middleware) { ThinkingSphinx::Middlewares::Inquirer.new app }
|
|
13
|
+
let(:context) { {:sphinxql => sphinx_sql} }
|
|
14
|
+
let(:sphinx_sql) { double('sphinx_sql',
|
|
15
|
+
:to_sql => 'SELECT * FROM index') }
|
|
16
|
+
let(:batch_inquirer) { double('batcher', :append_query => true,
|
|
17
|
+
:results => [[:raw], [{'Variable_name' => 'meta', 'Value' => 'value'}]]) }
|
|
18
|
+
|
|
19
|
+
before :each do
|
|
20
|
+
batch_class = double
|
|
21
|
+
allow(batch_class).to receive(:new).and_return(batch_inquirer)
|
|
22
|
+
|
|
23
|
+
stub_const 'Riddle::Query', double(:meta => 'SHOW META')
|
|
24
|
+
stub_const 'ThinkingSphinx::Search::BatchInquirer', batch_class
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe '#call' do
|
|
28
|
+
it "passes through the SphinxQL from a Riddle::Query::Select object" do
|
|
29
|
+
expect(batch_inquirer).to receive(:append_query).with('SELECT * FROM index')
|
|
30
|
+
expect(batch_inquirer).to receive(:append_query).with('SHOW META')
|
|
31
|
+
|
|
32
|
+
middleware.call [context]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "sets up the raw results" do
|
|
36
|
+
middleware.call [context]
|
|
37
|
+
|
|
38
|
+
expect(context[:raw]).to eq([:raw])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "sets up the meta results as a hash" do
|
|
42
|
+
middleware.call [context]
|
|
43
|
+
|
|
44
|
+
expect(context[:meta]).to eq({'meta' => 'value'})
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "uses the raw values as the initial results" do
|
|
48
|
+
middleware.call [context]
|
|
49
|
+
|
|
50
|
+
expect(context[:results]).to eq([:raw])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context "with mysql2 result" do
|
|
54
|
+
class FakeResult
|
|
55
|
+
include Enumerable
|
|
56
|
+
def each; [{"fake" => "value"}].each { |m| yield m }; end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
let(:batch_inquirer) { double('batcher', :append_query => true,
|
|
60
|
+
:results => [
|
|
61
|
+
FakeResult.new, [{'Variable_name' => 'meta', 'Value' => 'value'}]
|
|
62
|
+
])
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
it "converts the results into an array" do
|
|
66
|
+
middleware.call [context]
|
|
67
|
+
|
|
68
|
+
expect(context[:results]).to be_a Array
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|