thinking-sphinx 3.1.4 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.circleci/config.yml +99 -0
- data/.github/actions/test/action.yml +46 -0
- data/.github/workflows/ci.yml +75 -0
- data/.gitignore +7 -2
- data/.travis.yml +31 -16
- data/Appraisals +68 -12
- data/CHANGELOG.markdown +782 -0
- data/Gemfile +13 -4
- data/Procfile.support +2 -0
- data/README.textile +41 -27
- data/Rakefile +2 -0
- data/bin/console +15 -0
- data/bin/loadsphinx +99 -0
- data/bin/testmatrix +48 -0
- data/lib/thinking/sphinx.rb +2 -0
- data/lib/thinking-sphinx.rb +2 -0
- data/lib/thinking_sphinx/active_record/association.rb +2 -0
- data/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb +3 -1
- data/lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb +2 -0
- data/lib/thinking_sphinx/active_record/association_proxy.rb +3 -2
- data/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb +3 -1
- data/lib/thinking_sphinx/active_record/attribute/type.rb +20 -4
- data/lib/thinking_sphinx/active_record/attribute/values.rb +2 -0
- data/lib/thinking_sphinx/active_record/attribute.rb +2 -0
- data/lib/thinking_sphinx/active_record/base.rb +43 -11
- data/lib/thinking_sphinx/active_record/callbacks/association_delta_callbacks.rb +21 -0
- data/lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb +15 -9
- data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +20 -5
- data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +18 -4
- data/lib/thinking_sphinx/active_record/column.rb +2 -0
- data/lib/thinking_sphinx/active_record/column_sql_presenter.rb +7 -1
- data/lib/thinking_sphinx/active_record/database_adapters/abstract_adapter.rb +2 -0
- data/lib/thinking_sphinx/active_record/database_adapters/mysql_adapter.rb +9 -1
- data/lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb +2 -0
- data/lib/thinking_sphinx/active_record/database_adapters.rb +3 -1
- 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 +2 -0
- data/lib/thinking_sphinx/active_record/filter_reflection.rb +13 -71
- data/lib/thinking_sphinx/active_record/index.rb +7 -5
- data/lib/thinking_sphinx/active_record/interpreter.rb +6 -4
- data/lib/thinking_sphinx/active_record/join_association.rb +5 -1
- data/lib/thinking_sphinx/active_record/log_subscriber.rb +22 -3
- data/lib/thinking_sphinx/active_record/polymorpher.rb +2 -0
- data/lib/thinking_sphinx/active_record/property.rb +2 -0
- data/lib/thinking_sphinx/active_record/property_query.rb +4 -1
- data/lib/thinking_sphinx/active_record/property_sql_presenter.rb +2 -0
- data/lib/thinking_sphinx/active_record/simple_many_query.rb +2 -0
- data/lib/thinking_sphinx/active_record/source_joins.rb +68 -0
- data/lib/thinking_sphinx/active_record/sql_builder/clause_builder.rb +2 -0
- data/lib/thinking_sphinx/active_record/sql_builder/query.rb +13 -0
- data/lib/thinking_sphinx/active_record/sql_builder/statement.rb +2 -0
- data/lib/thinking_sphinx/active_record/sql_builder.rb +5 -18
- data/lib/thinking_sphinx/active_record/sql_source/template.rb +5 -3
- data/lib/thinking_sphinx/active_record/sql_source.rb +35 -9
- data/lib/thinking_sphinx/active_record.rb +14 -1
- data/lib/thinking_sphinx/attribute_types.rb +72 -0
- data/lib/thinking_sphinx/batched_search.rb +2 -0
- data/lib/thinking_sphinx/callbacks/appender.rb +63 -0
- data/lib/thinking_sphinx/callbacks.rb +29 -0
- data/lib/thinking_sphinx/capistrano/v2.rb +2 -0
- data/lib/thinking_sphinx/capistrano/v3.rb +2 -0
- data/lib/thinking_sphinx/capistrano.rb +2 -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 +2 -0
- data/lib/thinking_sphinx/configuration/defaults.rb +2 -0
- data/lib/thinking_sphinx/configuration/distributed_indices.rb +3 -1
- data/lib/thinking_sphinx/configuration/duplicate_names.rb +36 -0
- data/lib/thinking_sphinx/configuration/minimum_fields.rb +17 -12
- data/lib/thinking_sphinx/configuration.rb +90 -74
- 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 +13 -114
- data/lib/thinking_sphinx/core/field.rb +2 -0
- data/lib/thinking_sphinx/core/index.rb +22 -2
- data/lib/thinking_sphinx/core/interpreter.rb +2 -0
- data/lib/thinking_sphinx/core/property.rb +2 -0
- data/lib/thinking_sphinx/core/settings.rb +2 -0
- data/lib/thinking_sphinx/core.rb +2 -0
- data/lib/thinking_sphinx/deletion.rb +33 -13
- data/lib/thinking_sphinx/deltas/default_delta.rb +3 -1
- data/lib/thinking_sphinx/deltas/delete_job.rb +16 -4
- data/lib/thinking_sphinx/deltas/index_job.rb +14 -2
- data/lib/thinking_sphinx/deltas.rb +2 -0
- data/lib/thinking_sphinx/distributed/index.rb +25 -3
- data/lib/thinking_sphinx/distributed.rb +2 -0
- data/lib/thinking_sphinx/errors.rb +47 -3
- data/lib/thinking_sphinx/excerpter.rb +2 -0
- data/lib/thinking_sphinx/facet.rb +4 -3
- data/lib/thinking_sphinx/facet_search.rb +4 -2
- data/lib/thinking_sphinx/float_formatter.rb +2 -0
- data/lib/thinking_sphinx/frameworks/plain.rb +2 -0
- data/lib/thinking_sphinx/frameworks/rails.rb +2 -0
- data/lib/thinking_sphinx/frameworks.rb +2 -0
- data/lib/thinking_sphinx/guard/file.rb +3 -1
- data/lib/thinking_sphinx/guard/files.rb +2 -0
- data/lib/thinking_sphinx/guard/none.rb +7 -0
- data/lib/thinking_sphinx/guard.rb +3 -0
- data/lib/thinking_sphinx/hooks/guard_presence.rb +34 -0
- data/lib/thinking_sphinx/index.rb +2 -0
- data/lib/thinking_sphinx/index_set.rb +27 -4
- 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 +2 -0
- data/lib/thinking_sphinx/masks/group_enumerators_mask.rb +6 -4
- data/lib/thinking_sphinx/masks/pagination_mask.rb +2 -0
- data/lib/thinking_sphinx/masks/scopes_mask.rb +8 -0
- data/lib/thinking_sphinx/masks/weight_enumerator_mask.rb +3 -1
- data/lib/thinking_sphinx/masks.rb +2 -0
- data/lib/thinking_sphinx/middlewares/active_record_translator.rb +32 -9
- data/lib/thinking_sphinx/middlewares/geographer.rb +2 -0
- data/lib/thinking_sphinx/middlewares/glazier.rb +14 -1
- data/lib/thinking_sphinx/middlewares/ids_only.rb +2 -0
- data/lib/thinking_sphinx/middlewares/inquirer.rb +3 -1
- data/lib/thinking_sphinx/middlewares/middleware.rb +2 -0
- data/lib/thinking_sphinx/middlewares/sphinxql.rb +18 -16
- data/lib/thinking_sphinx/middlewares/stale_id_checker.rb +3 -1
- data/lib/thinking_sphinx/middlewares/stale_id_filter.rb +4 -2
- data/lib/thinking_sphinx/middlewares/valid_options.rb +25 -0
- data/lib/thinking_sphinx/middlewares.rb +7 -3
- data/lib/thinking_sphinx/panes/attributes_pane.rb +2 -0
- data/lib/thinking_sphinx/panes/distance_pane.rb +2 -0
- data/lib/thinking_sphinx/panes/excerpts_pane.rb +2 -0
- data/lib/thinking_sphinx/panes/weight_pane.rb +3 -1
- data/lib/thinking_sphinx/panes.rb +2 -0
- data/lib/thinking_sphinx/processor.rb +71 -0
- data/lib/thinking_sphinx/query.rb +2 -0
- data/lib/thinking_sphinx/railtie.rb +29 -2
- data/lib/thinking_sphinx/rake_interface.rb +14 -69
- data/lib/thinking_sphinx/real_time/attribute.rb +9 -1
- data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +17 -7
- data/lib/thinking_sphinx/real_time/field.rb +2 -0
- data/lib/thinking_sphinx/real_time/index/template.rb +19 -1
- data/lib/thinking_sphinx/real_time/index.rb +11 -5
- data/lib/thinking_sphinx/real_time/interpreter.rb +10 -6
- data/lib/thinking_sphinx/real_time/populator.rb +12 -14
- data/lib/thinking_sphinx/real_time/processor.rb +36 -0
- data/lib/thinking_sphinx/real_time/property.rb +3 -5
- data/lib/thinking_sphinx/real_time/transcribe_instance.rb +38 -0
- data/lib/thinking_sphinx/real_time/transcriber.rb +63 -15
- data/lib/thinking_sphinx/real_time/translator.rb +39 -0
- data/lib/thinking_sphinx/real_time.rb +22 -1
- data/lib/thinking_sphinx/scopes.rb +6 -0
- data/lib/thinking_sphinx/search/batch_inquirer.rb +2 -0
- data/lib/thinking_sphinx/search/context.rb +11 -0
- data/lib/thinking_sphinx/search/glaze.rb +2 -0
- data/lib/thinking_sphinx/search/merger.rb +2 -0
- data/lib/thinking_sphinx/search/query.rb +9 -1
- data/lib/thinking_sphinx/search/stale_ids_exception.rb +7 -3
- data/lib/thinking_sphinx/search.rb +30 -2
- data/lib/thinking_sphinx/settings.rb +128 -0
- data/lib/thinking_sphinx/sinatra.rb +3 -1
- data/lib/thinking_sphinx/subscribers/populator_subscriber.rb +19 -5
- data/lib/thinking_sphinx/tasks.rb +55 -28
- data/lib/thinking_sphinx/test.rb +3 -1
- data/lib/thinking_sphinx/utf8.rb +2 -0
- data/lib/thinking_sphinx/wildcard.rb +3 -1
- data/lib/thinking_sphinx/with_output.rb +13 -0
- data/lib/thinking_sphinx.rb +35 -4
- data/spec/acceptance/association_scoping_spec.rb +7 -5
- data/spec/acceptance/attribute_access_spec.rb +29 -12
- data/spec/acceptance/attribute_updates_spec.rb +5 -3
- data/spec/acceptance/batch_searching_spec.rb +6 -4
- data/spec/acceptance/big_integers_spec.rb +9 -7
- data/spec/acceptance/excerpts_spec.rb +11 -10
- data/spec/acceptance/facets_spec.rb +29 -16
- data/spec/acceptance/geosearching_spec.rb +22 -10
- data/spec/acceptance/grouping_by_attributes_spec.rb +30 -28
- data/spec/acceptance/index_options_spec.rb +18 -16
- data/spec/acceptance/indexing_spec.rb +5 -3
- data/spec/acceptance/merging_spec.rb +90 -0
- data/spec/acceptance/paginating_search_results_spec.rb +21 -3
- data/spec/acceptance/real_time_updates_spec.rb +103 -5
- data/spec/acceptance/remove_deleted_records_spec.rb +64 -8
- data/spec/acceptance/search_counts_spec.rb +4 -2
- data/spec/acceptance/search_for_just_ids_spec.rb +4 -2
- data/spec/acceptance/searching_across_models_spec.rb +15 -6
- data/spec/acceptance/searching_across_schemas_spec.rb +12 -10
- data/spec/acceptance/searching_on_fields_spec.rb +11 -9
- data/spec/acceptance/searching_with_filters_spec.rb +35 -20
- data/spec/acceptance/searching_with_sti_spec.rb +11 -9
- data/spec/acceptance/searching_within_a_model_spec.rb +44 -17
- data/spec/acceptance/sorting_search_results_spec.rb +21 -19
- data/spec/acceptance/spec_helper.rb +2 -13
- data/spec/acceptance/specifying_sql_spec.rb +118 -62
- data/spec/acceptance/sphinx_scopes_spec.rb +30 -21
- data/spec/acceptance/sql_deltas_spec.rb +35 -9
- data/spec/acceptance/support/database_cleaner.rb +3 -1
- data/spec/acceptance/support/sphinx_controller.rb +25 -9
- data/spec/acceptance/support/sphinx_helpers.rb +17 -2
- data/spec/acceptance/suspended_deltas_spec.rb +14 -12
- data/spec/fixtures/database.yml +1 -1
- data/spec/internal/app/indices/admin_person_index.rb +6 -0
- data/spec/internal/app/indices/album_index.rb +9 -0
- data/spec/internal/app/indices/animal_index.rb +2 -0
- data/spec/internal/app/indices/article_index.rb +10 -3
- data/spec/internal/app/indices/bird_index.rb +2 -0
- data/spec/internal/app/indices/book_index.rb +4 -1
- data/spec/internal/app/indices/car_index.rb +2 -0
- data/spec/internal/app/indices/city_index.rb +2 -0
- data/spec/internal/app/indices/colour_index.rb +7 -0
- data/spec/internal/app/indices/product_index.rb +3 -2
- data/spec/internal/app/indices/tee_index.rb +3 -1
- data/spec/internal/app/indices/user_index.rb +2 -0
- data/spec/internal/app/models/admin/person.rb +6 -0
- data/spec/internal/app/models/album.rb +25 -0
- data/spec/internal/app/models/animal.rb +3 -0
- data/spec/internal/app/models/article.rb +4 -0
- data/spec/internal/app/models/bird.rb +3 -0
- data/spec/internal/app/models/book.rb +9 -5
- data/spec/internal/app/models/car.rb +3 -1
- data/spec/internal/app/models/categorisation.rb +10 -1
- data/spec/internal/app/models/category.rb +2 -0
- data/spec/internal/app/models/city.rb +4 -0
- data/spec/internal/app/models/colour.rb +4 -0
- data/spec/internal/app/models/event.rb +2 -0
- data/spec/internal/app/models/flightless_bird.rb +2 -0
- data/spec/internal/app/models/genre.rb +2 -0
- data/spec/internal/app/models/hardcover.rb +2 -0
- data/spec/internal/app/models/mammal.rb +2 -0
- data/spec/internal/app/models/manufacturer.rb +2 -0
- data/spec/internal/app/models/product.rb +3 -1
- data/spec/internal/app/models/tag.rb +2 -0
- data/spec/internal/app/models/tagging.rb +2 -0
- data/spec/internal/app/models/tee.rb +7 -0
- data/spec/internal/app/models/tweet.rb +2 -0
- data/spec/internal/app/models/user.rb +4 -0
- data/spec/internal/config/database.yml +12 -1
- data/spec/internal/db/schema.rb +13 -1
- data/spec/spec_helper.rb +12 -1
- data/spec/support/json_column.rb +35 -0
- data/spec/support/multi_schema.rb +5 -1
- data/spec/support/mysql.rb +25 -0
- data/spec/support/sphinx_yaml_helpers.rb +8 -1
- data/spec/thinking_sphinx/active_record/association_spec.rb +3 -1
- data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +43 -38
- data/spec/thinking_sphinx/active_record/base_spec.rb +31 -29
- data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +81 -10
- data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +56 -29
- data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +27 -10
- data/spec/thinking_sphinx/active_record/column_spec.rb +15 -13
- 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 +7 -5
- data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +26 -12
- data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +15 -13
- data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +50 -48
- data/spec/thinking_sphinx/active_record/field_spec.rb +9 -7
- data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +113 -80
- data/spec/thinking_sphinx/active_record/index_spec.rb +41 -37
- data/spec/thinking_sphinx/active_record/interpreter_spec.rb +62 -59
- data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +16 -14
- data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +69 -67
- data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +146 -154
- data/spec/thinking_sphinx/active_record/sql_source_spec.rb +185 -109
- 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 +247 -94
- data/spec/thinking_sphinx/connection/mri_spec.rb +49 -0
- data/spec/thinking_sphinx/connection_spec.rb +15 -13
- data/spec/thinking_sphinx/deletion_spec.rb +17 -17
- data/spec/thinking_sphinx/deltas/default_delta_spec.rb +28 -21
- data/spec/thinking_sphinx/deltas_spec.rb +14 -12
- data/spec/thinking_sphinx/errors_spec.rb +59 -27
- data/spec/thinking_sphinx/excerpter_spec.rb +12 -9
- data/spec/thinking_sphinx/facet_search_spec.rb +24 -22
- data/spec/thinking_sphinx/hooks/guard_presence_spec.rb +30 -0
- data/spec/thinking_sphinx/index_set_spec.rb +59 -18
- data/spec/thinking_sphinx/index_spec.rb +28 -26
- 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 +22 -20
- data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +20 -18
- data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +45 -21
- data/spec/thinking_sphinx/middlewares/geographer_spec.rb +11 -9
- data/spec/thinking_sphinx/middlewares/glazier_spec.rb +12 -9
- data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +9 -7
- data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +60 -58
- data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +7 -4
- data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +39 -17
- data/spec/thinking_sphinx/middlewares/valid_options_spec.rb +51 -0
- data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +3 -1
- data/spec/thinking_sphinx/panes/distance_pane_spec.rb +6 -4
- data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +8 -6
- data/spec/thinking_sphinx/panes/weight_pane_spec.rb +4 -2
- data/spec/thinking_sphinx/rake_interface_spec.rb +17 -235
- data/spec/thinking_sphinx/real_time/attribute_spec.rb +15 -13
- data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +114 -28
- data/spec/thinking_sphinx/real_time/field_spec.rb +16 -14
- data/spec/thinking_sphinx/real_time/index_spec.rb +83 -32
- data/spec/thinking_sphinx/real_time/interpreter_spec.rb +44 -42
- 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 +11 -5
- data/spec/thinking_sphinx/search/glaze_spec.rb +17 -15
- data/spec/thinking_sphinx/search/query_spec.rb +19 -10
- data/spec/thinking_sphinx/search_spec.rb +30 -28
- data/spec/thinking_sphinx/wildcard_spec.rb +18 -11
- data/spec/thinking_sphinx_spec.rb +10 -7
- data/thinking-sphinx.gemspec +17 -10
- metadata +157 -49
- data/HISTORY +0 -248
- data/gemfiles/.gitignore +0 -1
- data/gemfiles/rails_3_2.gemfile +0 -11
- data/gemfiles/rails_4_0.gemfile +0 -11
- data/gemfiles/rails_4_1.gemfile +0 -11
- data/gemfiles/rails_4_2.gemfile +0 -11
- data/lib/thinking_sphinx/controller.rb +0 -10
- data/lib/thinking_sphinx/middlewares/utf8.rb +0 -27
- data/lib/thinking_sphinx/sphinxql.rb +0 -23
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ThinkingSphinx
|
|
2
4
|
module Middlewares; end
|
|
3
5
|
end
|
|
@@ -10,11 +12,12 @@ describe ThinkingSphinx::Middlewares::Glazier do
|
|
|
10
12
|
let(:middleware) { ThinkingSphinx::Middlewares::Glazier.new app }
|
|
11
13
|
let(:context) { {:results => [result], :indices => [index],
|
|
12
14
|
:meta => {}, :raw => [raw_result], :panes => []} }
|
|
13
|
-
let(:result) { double
|
|
14
|
-
|
|
15
|
-
let(:index) { double
|
|
16
|
-
|
|
17
|
-
let(:
|
|
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' }
|
|
18
21
|
let(:raw_result) {
|
|
19
22
|
{'sphinx_internal_class' => 'Article', 'sphinx_internal_id' => 10} }
|
|
20
23
|
|
|
@@ -22,7 +25,7 @@ describe ThinkingSphinx::Middlewares::Glazier do
|
|
|
22
25
|
before :each do
|
|
23
26
|
stub_const 'ThinkingSphinx::Search::Glaze', double(:new => glazed_result)
|
|
24
27
|
|
|
25
|
-
context.
|
|
28
|
+
allow(context).to receive_messages :search => search
|
|
26
29
|
end
|
|
27
30
|
|
|
28
31
|
context 'No panes provided' do
|
|
@@ -33,7 +36,7 @@ describe ThinkingSphinx::Middlewares::Glazier do
|
|
|
33
36
|
it "leaves the results as they are" do
|
|
34
37
|
middleware.call [context]
|
|
35
38
|
|
|
36
|
-
context[:results].
|
|
39
|
+
expect(context[:results]).to eq([result])
|
|
37
40
|
end
|
|
38
41
|
end
|
|
39
42
|
|
|
@@ -47,11 +50,11 @@ describe ThinkingSphinx::Middlewares::Glazier do
|
|
|
47
50
|
it "replaces each result with a glazed version" do
|
|
48
51
|
middleware.call [context]
|
|
49
52
|
|
|
50
|
-
context[:results].
|
|
53
|
+
expect(context[:results]).to eq([glazed_result])
|
|
51
54
|
end
|
|
52
55
|
|
|
53
56
|
it "creates a glazed result for each result" do
|
|
54
|
-
ThinkingSphinx::Search::Glaze.
|
|
57
|
+
expect(ThinkingSphinx::Search::Glaze).to receive(:new).
|
|
55
58
|
with(context, result, raw_result, [pane_class]).
|
|
56
59
|
and_return(glazed_result)
|
|
57
60
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ThinkingSphinx
|
|
2
4
|
module Middlewares; end
|
|
3
5
|
end
|
|
@@ -16,7 +18,7 @@ describe ThinkingSphinx::Middlewares::Inquirer do
|
|
|
16
18
|
|
|
17
19
|
before :each do
|
|
18
20
|
batch_class = double
|
|
19
|
-
batch_class.
|
|
21
|
+
allow(batch_class).to receive(:new).and_return(batch_inquirer)
|
|
20
22
|
|
|
21
23
|
stub_const 'Riddle::Query', double(:meta => 'SHOW META')
|
|
22
24
|
stub_const 'ThinkingSphinx::Search::BatchInquirer', batch_class
|
|
@@ -24,8 +26,8 @@ describe ThinkingSphinx::Middlewares::Inquirer do
|
|
|
24
26
|
|
|
25
27
|
describe '#call' do
|
|
26
28
|
it "passes through the SphinxQL from a Riddle::Query::Select object" do
|
|
27
|
-
batch_inquirer.
|
|
28
|
-
batch_inquirer.
|
|
29
|
+
expect(batch_inquirer).to receive(:append_query).with('SELECT * FROM index')
|
|
30
|
+
expect(batch_inquirer).to receive(:append_query).with('SHOW META')
|
|
29
31
|
|
|
30
32
|
middleware.call [context]
|
|
31
33
|
end
|
|
@@ -33,19 +35,19 @@ describe ThinkingSphinx::Middlewares::Inquirer do
|
|
|
33
35
|
it "sets up the raw results" do
|
|
34
36
|
middleware.call [context]
|
|
35
37
|
|
|
36
|
-
context[:raw].
|
|
38
|
+
expect(context[:raw]).to eq([:raw])
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
it "sets up the meta results as a hash" do
|
|
40
42
|
middleware.call [context]
|
|
41
43
|
|
|
42
|
-
context[:meta].
|
|
44
|
+
expect(context[:meta]).to eq({'meta' => 'value'})
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
it "uses the raw values as the initial results" do
|
|
46
48
|
middleware.call [context]
|
|
47
49
|
|
|
48
|
-
context[:results].
|
|
50
|
+
expect(context[:results]).to eq([:raw])
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
context "with mysql2 result" do
|
|
@@ -63,7 +65,7 @@ describe ThinkingSphinx::Middlewares::Inquirer do
|
|
|
63
65
|
it "converts the results into an array" do
|
|
64
66
|
middleware.call [context]
|
|
65
67
|
|
|
66
|
-
context[:results].
|
|
68
|
+
expect(context[:results]).to be_a Array
|
|
67
69
|
end
|
|
68
70
|
end
|
|
69
71
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ThinkingSphinx
|
|
2
4
|
module Middlewares; end
|
|
3
5
|
end
|
|
@@ -16,7 +18,6 @@ require 'active_support/core_ext/string/inflections'
|
|
|
16
18
|
require 'thinking_sphinx/middlewares/middleware'
|
|
17
19
|
require 'thinking_sphinx/middlewares/sphinxql'
|
|
18
20
|
require 'thinking_sphinx/errors'
|
|
19
|
-
require 'thinking_sphinx/sphinxql'
|
|
20
21
|
|
|
21
22
|
describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
22
23
|
let(:app) { double('app', :call => true) }
|
|
@@ -30,13 +31,13 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
30
31
|
let(:query) { double('query') }
|
|
31
32
|
let(:configuration) { double('configuration', :settings => {},
|
|
32
33
|
index_set_class: set_class) }
|
|
33
|
-
let(:set_class) { double(:new => index_set) }
|
|
34
|
+
let(:set_class) { double(:new => index_set, :reference_name => :article) }
|
|
34
35
|
|
|
35
36
|
before :each do
|
|
36
37
|
stub_const 'Riddle::Query::Select', double(:new => sphinx_sql)
|
|
37
38
|
stub_const 'ThinkingSphinx::Search::Query', double(:new => query)
|
|
38
39
|
|
|
39
|
-
context.
|
|
40
|
+
allow(context).to receive_messages :search => search, :configuration => configuration
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
describe '#call' do
|
|
@@ -46,7 +47,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
46
47
|
double('index', :name => 'user_core', :options => {})
|
|
47
48
|
]
|
|
48
49
|
|
|
49
|
-
sphinx_sql.
|
|
50
|
+
expect(sphinx_sql).to receive(:from).with('`article_core`', '`user_core`').
|
|
50
51
|
and_return(sphinx_sql)
|
|
51
52
|
|
|
52
53
|
middleware.call [context]
|
|
@@ -57,10 +58,10 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
57
58
|
:name => 'User')
|
|
58
59
|
search.options[:classes] = [klass]
|
|
59
60
|
search.options[:indices] = ['user_core']
|
|
60
|
-
index_set.first.
|
|
61
|
+
allow(index_set.first).to receive_messages :reference => :user
|
|
61
62
|
|
|
62
|
-
set_class.
|
|
63
|
-
with(:classes => [klass], :indices => ['user_core']).
|
|
63
|
+
expect(set_class).to receive(:new).
|
|
64
|
+
with({ :classes => [klass], :indices => ['user_core'] }).
|
|
64
65
|
and_return(index_set)
|
|
65
66
|
|
|
66
67
|
middleware.call [context]
|
|
@@ -75,19 +76,19 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
75
76
|
end
|
|
76
77
|
|
|
77
78
|
it "generates a Sphinx query from the provided keyword and conditions" do
|
|
78
|
-
search.
|
|
79
|
+
allow(search).to receive_messages :query => 'tasty'
|
|
79
80
|
search.options[:conditions] = {:title => 'pancakes'}
|
|
80
81
|
|
|
81
|
-
ThinkingSphinx::Search::Query.
|
|
82
|
+
expect(ThinkingSphinx::Search::Query).to receive(:new).
|
|
82
83
|
with('tasty', {:title => 'pancakes'}, anything).and_return(query)
|
|
83
84
|
|
|
84
85
|
middleware.call [context]
|
|
85
86
|
end
|
|
86
87
|
|
|
87
88
|
it "matches on the generated query" do
|
|
88
|
-
query.
|
|
89
|
+
allow(query).to receive_messages :to_s => 'waffles'
|
|
89
90
|
|
|
90
|
-
sphinx_sql.
|
|
91
|
+
expect(sphinx_sql).to receive(:matching).with('waffles')
|
|
91
92
|
|
|
92
93
|
middleware.call [context]
|
|
93
94
|
end
|
|
@@ -95,15 +96,15 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
95
96
|
it "requests a starred query if the :star option is set to true" do
|
|
96
97
|
search.options[:star] = true
|
|
97
98
|
|
|
98
|
-
ThinkingSphinx::Search::Query.
|
|
99
|
+
expect(ThinkingSphinx::Search::Query).to receive(:new).
|
|
99
100
|
with(anything, anything, true).and_return(query)
|
|
100
101
|
|
|
101
102
|
middleware.call [context]
|
|
102
103
|
end
|
|
103
104
|
|
|
104
105
|
it "doesn't append a field condition by default" do
|
|
105
|
-
ThinkingSphinx::Search::Query.
|
|
106
|
-
conditions[:sphinx_internal_class_name].
|
|
106
|
+
expect(ThinkingSphinx::Search::Query).to receive(:new) do |query, conditions, star|
|
|
107
|
+
expect(conditions[:sphinx_internal_class_name]).to be_nil
|
|
107
108
|
query
|
|
108
109
|
end
|
|
109
110
|
|
|
@@ -113,12 +114,13 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
113
114
|
it "doesn't append a field condition if all classes match index references" do
|
|
114
115
|
model = double('model', :connection => double,
|
|
115
116
|
:ancestors => [ActiveRecord::Base], :name => 'Animal')
|
|
116
|
-
index_set.first.
|
|
117
|
+
allow(index_set.first).to receive_messages :reference => :animal
|
|
118
|
+
allow(set_class).to receive_messages(:reference_name => :animal)
|
|
117
119
|
|
|
118
120
|
search.options[:classes] = [model]
|
|
119
121
|
|
|
120
|
-
ThinkingSphinx::Search::Query.
|
|
121
|
-
conditions[:sphinx_internal_class_name].
|
|
122
|
+
expect(ThinkingSphinx::Search::Query).to receive(:new) do |query, conditions, star|
|
|
123
|
+
expect(conditions[:sphinx_internal_class_name]).to be_nil
|
|
122
124
|
query
|
|
123
125
|
end
|
|
124
126
|
|
|
@@ -132,19 +134,19 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
132
134
|
def self.name; 'Cat'; end
|
|
133
135
|
def self.inheritance_column; 'type'; end
|
|
134
136
|
end
|
|
135
|
-
supermodel.
|
|
137
|
+
allow(supermodel).to receive_messages :connection => db_connection, :column_names => ['type']
|
|
136
138
|
submodel = Class.new(supermodel) do
|
|
137
139
|
def self.name; 'Lion'; end
|
|
138
140
|
def self.inheritance_column; 'type'; end
|
|
139
141
|
def self.table_name; 'cats'; end
|
|
140
142
|
end
|
|
141
|
-
submodel.
|
|
143
|
+
allow(submodel).to receive_messages :connection => db_connection, :column_names => ['type'],
|
|
142
144
|
:descendants => []
|
|
143
|
-
index_set.first.
|
|
145
|
+
allow(index_set.first).to receive_messages :reference => :cat
|
|
144
146
|
|
|
145
147
|
search.options[:classes] = [submodel]
|
|
146
148
|
|
|
147
|
-
ThinkingSphinx::Search::Query.
|
|
149
|
+
expect(ThinkingSphinx::Search::Query).to receive(:new).with(anything,
|
|
148
150
|
hash_including(:sphinx_internal_class_name => '(Lion)'), anything).
|
|
149
151
|
and_return(query)
|
|
150
152
|
|
|
@@ -158,19 +160,19 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
158
160
|
def self.name; 'Animals::Cat'; end
|
|
159
161
|
def self.inheritance_column; 'type'; end
|
|
160
162
|
end
|
|
161
|
-
supermodel.
|
|
163
|
+
allow(supermodel).to receive_messages :connection => db_connection, :column_names => ['type']
|
|
162
164
|
submodel = Class.new(supermodel) do
|
|
163
165
|
def self.name; 'Animals::Lion'; end
|
|
164
166
|
def self.inheritance_column; 'type'; end
|
|
165
167
|
def self.table_name; 'cats'; end
|
|
166
168
|
end
|
|
167
|
-
submodel.
|
|
169
|
+
allow(submodel).to receive_messages :connection => db_connection, :column_names => ['type'],
|
|
168
170
|
:descendants => []
|
|
169
|
-
index_set.first.
|
|
171
|
+
allow(index_set.first).to receive_messages :reference => :"animals/cat"
|
|
170
172
|
|
|
171
173
|
search.options[:classes] = [submodel]
|
|
172
174
|
|
|
173
|
-
ThinkingSphinx::Search::Query.
|
|
175
|
+
expect(ThinkingSphinx::Search::Query).to receive(:new).with(anything,
|
|
174
176
|
hash_including(:sphinx_internal_class_name => '("Animals::Lion")'), anything).
|
|
175
177
|
and_return(query)
|
|
176
178
|
|
|
@@ -180,12 +182,12 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
180
182
|
it "does not query the database for subclasses if :skip_sti is set to true" do
|
|
181
183
|
model = double('model', :connection => double,
|
|
182
184
|
:ancestors => [ActiveRecord::Base], :name => 'Animal')
|
|
183
|
-
index_set.first.
|
|
185
|
+
allow(index_set.first).to receive_messages :reference => :animal
|
|
184
186
|
|
|
185
187
|
search.options[:classes] = [model]
|
|
186
188
|
search.options[:skip_sti] = true
|
|
187
189
|
|
|
188
|
-
model.connection.
|
|
190
|
+
expect(model.connection).not_to receive(:select_values)
|
|
189
191
|
|
|
190
192
|
middleware.call [context]
|
|
191
193
|
end
|
|
@@ -197,15 +199,15 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
197
199
|
def self.name; 'Cat'; end
|
|
198
200
|
def self.inheritance_column; 'type'; end
|
|
199
201
|
end
|
|
200
|
-
supermodel.
|
|
202
|
+
allow(supermodel).to receive_messages :connection => db_connection, :column_names => ['type']
|
|
201
203
|
submodel = Class.new(supermodel) do
|
|
202
204
|
def self.name; 'Lion'; end
|
|
203
205
|
def self.inheritance_column; 'type'; end
|
|
204
206
|
def self.table_name; 'cats'; end
|
|
205
207
|
end
|
|
206
|
-
submodel.
|
|
208
|
+
allow(submodel).to receive_messages :connection => db_connection, :column_names => ['type'],
|
|
207
209
|
:descendants => []
|
|
208
|
-
index_set.first.
|
|
210
|
+
allow(index_set.first).to receive_messages :reference => :cat
|
|
209
211
|
|
|
210
212
|
search.options[:classes] = [submodel]
|
|
211
213
|
|
|
@@ -213,7 +215,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
213
215
|
end
|
|
214
216
|
|
|
215
217
|
it "filters out deleted values by default" do
|
|
216
|
-
sphinx_sql.
|
|
218
|
+
expect(sphinx_sql).to receive(:where).with({ :sphinx_deleted => false }).
|
|
217
219
|
and_return(sphinx_sql)
|
|
218
220
|
|
|
219
221
|
middleware.call [context]
|
|
@@ -222,7 +224,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
222
224
|
it "appends boolean attribute filters to the query" do
|
|
223
225
|
search.options[:with] = {:visible => true}
|
|
224
226
|
|
|
225
|
-
sphinx_sql.
|
|
227
|
+
expect(sphinx_sql).to receive(:where).with(hash_including(:visible => true)).
|
|
226
228
|
and_return(sphinx_sql)
|
|
227
229
|
|
|
228
230
|
middleware.call [context]
|
|
@@ -231,7 +233,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
231
233
|
it "appends exclusive filters to the query" do
|
|
232
234
|
search.options[:without] = {:tag_ids => [2, 4, 8]}
|
|
233
235
|
|
|
234
|
-
sphinx_sql.
|
|
236
|
+
expect(sphinx_sql).to receive(:where_not).
|
|
235
237
|
with(hash_including(:tag_ids => [2, 4, 8])).and_return(sphinx_sql)
|
|
236
238
|
|
|
237
239
|
middleware.call [context]
|
|
@@ -240,7 +242,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
240
242
|
it "appends the without_ids option as an exclusive filter" do
|
|
241
243
|
search.options[:without_ids] = [1, 4, 9]
|
|
242
244
|
|
|
243
|
-
sphinx_sql.
|
|
245
|
+
expect(sphinx_sql).to receive(:where_not).
|
|
244
246
|
with(hash_including(:sphinx_internal_id => [1, 4, 9])).
|
|
245
247
|
and_return(sphinx_sql)
|
|
246
248
|
|
|
@@ -250,8 +252,8 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
250
252
|
it "appends MVA matches with all values" do
|
|
251
253
|
search.options[:with_all] = {:tag_ids => [1, 7]}
|
|
252
254
|
|
|
253
|
-
sphinx_sql.
|
|
254
|
-
with(:tag_ids => [1, 7]).and_return(sphinx_sql)
|
|
255
|
+
expect(sphinx_sql).to receive(:where_all).
|
|
256
|
+
with({ :tag_ids => [1, 7] }).and_return(sphinx_sql)
|
|
255
257
|
|
|
256
258
|
middleware.call [context]
|
|
257
259
|
end
|
|
@@ -259,8 +261,8 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
259
261
|
it "appends MVA matches without all of the given values" do
|
|
260
262
|
search.options[:without_all] = {:tag_ids => [1, 7]}
|
|
261
263
|
|
|
262
|
-
sphinx_sql.
|
|
263
|
-
with(:tag_ids => [1, 7]).and_return(sphinx_sql)
|
|
264
|
+
expect(sphinx_sql).to receive(:where_not_all).
|
|
265
|
+
with({ :tag_ids => [1, 7] }).and_return(sphinx_sql)
|
|
264
266
|
|
|
265
267
|
middleware.call [context]
|
|
266
268
|
end
|
|
@@ -268,7 +270,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
268
270
|
it "appends order clauses to the query" do
|
|
269
271
|
search.options[:order] = 'created_at ASC'
|
|
270
272
|
|
|
271
|
-
sphinx_sql.
|
|
273
|
+
expect(sphinx_sql).to receive(:order_by).with('created_at ASC').
|
|
272
274
|
and_return(sphinx_sql)
|
|
273
275
|
|
|
274
276
|
middleware.call [context]
|
|
@@ -277,7 +279,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
277
279
|
it "presumes attributes given as symbols should be sorted ascendingly" do
|
|
278
280
|
search.options[:order] = :updated_at
|
|
279
281
|
|
|
280
|
-
sphinx_sql.
|
|
282
|
+
expect(sphinx_sql).to receive(:order_by).with('updated_at ASC').
|
|
281
283
|
and_return(sphinx_sql)
|
|
282
284
|
|
|
283
285
|
middleware.call [context]
|
|
@@ -285,10 +287,10 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
285
287
|
|
|
286
288
|
it "appends a group by clause to the query" do
|
|
287
289
|
search.options[:group_by] = :foreign_id
|
|
288
|
-
search.
|
|
289
|
-
sphinx_sql.
|
|
290
|
+
allow(search).to receive_messages :masks => []
|
|
291
|
+
allow(sphinx_sql).to receive_messages :values => sphinx_sql
|
|
290
292
|
|
|
291
|
-
sphinx_sql.
|
|
293
|
+
expect(sphinx_sql).to receive(:group_by).with('foreign_id').
|
|
292
294
|
and_return(sphinx_sql)
|
|
293
295
|
|
|
294
296
|
middleware.call [context]
|
|
@@ -297,24 +299,24 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
297
299
|
it "appends a sort within group clause to the query" do
|
|
298
300
|
search.options[:order_group_by] = :title
|
|
299
301
|
|
|
300
|
-
sphinx_sql.
|
|
302
|
+
expect(sphinx_sql).to receive(:order_within_group_by).with('title ASC').
|
|
301
303
|
and_return(sphinx_sql)
|
|
302
304
|
|
|
303
305
|
middleware.call [context]
|
|
304
306
|
end
|
|
305
307
|
|
|
306
308
|
it "uses the provided offset" do
|
|
307
|
-
search.
|
|
309
|
+
allow(search).to receive_messages :offset => 50
|
|
308
310
|
|
|
309
|
-
sphinx_sql.
|
|
311
|
+
expect(sphinx_sql).to receive(:offset).with(50).and_return(sphinx_sql)
|
|
310
312
|
|
|
311
313
|
middleware.call [context]
|
|
312
314
|
end
|
|
313
315
|
|
|
314
316
|
it "uses the provided limit" do
|
|
315
|
-
search.
|
|
317
|
+
allow(search).to receive_messages :per_page => 24
|
|
316
318
|
|
|
317
|
-
sphinx_sql.
|
|
319
|
+
expect(sphinx_sql).to receive(:limit).with(24).and_return(sphinx_sql)
|
|
318
320
|
|
|
319
321
|
middleware.call [context]
|
|
320
322
|
end
|
|
@@ -322,7 +324,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
322
324
|
it "adds the provided select statement" do
|
|
323
325
|
search.options[:select] = 'foo as bar'
|
|
324
326
|
|
|
325
|
-
sphinx_sql.
|
|
327
|
+
expect(sphinx_sql).to receive(:values).with('foo as bar').
|
|
326
328
|
and_return(sphinx_sql)
|
|
327
329
|
|
|
328
330
|
middleware.call [context]
|
|
@@ -331,7 +333,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
331
333
|
it "adds the provided group-best count" do
|
|
332
334
|
search.options[:group_best] = 5
|
|
333
335
|
|
|
334
|
-
sphinx_sql.
|
|
336
|
+
expect(sphinx_sql).to receive(:group_best).with(5).and_return(sphinx_sql)
|
|
335
337
|
|
|
336
338
|
middleware.call [context]
|
|
337
339
|
end
|
|
@@ -339,7 +341,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
339
341
|
it "adds the provided having clause" do
|
|
340
342
|
search.options[:having] = 'foo > 1'
|
|
341
343
|
|
|
342
|
-
sphinx_sql.
|
|
344
|
+
expect(sphinx_sql).to receive(:having).with('foo > 1').and_return(sphinx_sql)
|
|
343
345
|
|
|
344
346
|
middleware.call [context]
|
|
345
347
|
end
|
|
@@ -347,8 +349,8 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
347
349
|
it "uses any provided field weights" do
|
|
348
350
|
search.options[:field_weights] = {:title => 3}
|
|
349
351
|
|
|
350
|
-
sphinx_sql.
|
|
351
|
-
options[:field_weights].
|
|
352
|
+
expect(sphinx_sql).to receive(:with_options) do |options|
|
|
353
|
+
expect(options[:field_weights]).to eq({:title => 3})
|
|
352
354
|
sphinx_sql
|
|
353
355
|
end
|
|
354
356
|
|
|
@@ -358,7 +360,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
358
360
|
it "uses index-defined field weights if they're available" do
|
|
359
361
|
index_set.first.options[:field_weights] = {:title => 3}
|
|
360
362
|
|
|
361
|
-
sphinx_sql.
|
|
363
|
+
expect(sphinx_sql).to receive(:with_options).with(
|
|
362
364
|
hash_including(:field_weights => {:title => 3})
|
|
363
365
|
).and_return(sphinx_sql)
|
|
364
366
|
|
|
@@ -368,7 +370,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
368
370
|
it "uses index-defined max matches if it's available" do
|
|
369
371
|
index_set.first.options[:max_matches] = 100
|
|
370
372
|
|
|
371
|
-
sphinx_sql.
|
|
373
|
+
expect(sphinx_sql).to receive(:with_options).with(
|
|
372
374
|
hash_including(:max_matches => 100)
|
|
373
375
|
).and_return(sphinx_sql)
|
|
374
376
|
|
|
@@ -378,7 +380,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
378
380
|
it "uses configuration-level max matches if set" do
|
|
379
381
|
configuration.settings['max_matches'] = 120
|
|
380
382
|
|
|
381
|
-
sphinx_sql.
|
|
383
|
+
expect(sphinx_sql).to receive(:with_options).with(
|
|
382
384
|
hash_including(:max_matches => 120)
|
|
383
385
|
).and_return(sphinx_sql)
|
|
384
386
|
|
|
@@ -388,8 +390,8 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
|
|
|
388
390
|
it "uses any given ranker option" do
|
|
389
391
|
search.options[:ranker] = 'proximity'
|
|
390
392
|
|
|
391
|
-
sphinx_sql.
|
|
392
|
-
options[:ranker].
|
|
393
|
+
expect(sphinx_sql).to receive(:with_options) do |options|
|
|
394
|
+
expect(options[:ranker]).to eq('proximity')
|
|
393
395
|
sphinx_sql
|
|
394
396
|
end
|
|
395
397
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ThinkingSphinx
|
|
2
4
|
module Middlewares; end
|
|
3
5
|
class Search; end
|
|
@@ -25,7 +27,7 @@ describe ThinkingSphinx::Middlewares::StaleIdChecker do
|
|
|
25
27
|
context[:results] << double('instance', :id => 24)
|
|
26
28
|
context[:results] << double('instance', :id => 42)
|
|
27
29
|
|
|
28
|
-
app.
|
|
30
|
+
expect(app).to receive(:call)
|
|
29
31
|
|
|
30
32
|
middleware.call [context]
|
|
31
33
|
end
|
|
@@ -37,10 +39,11 @@ describe ThinkingSphinx::Middlewares::StaleIdChecker do
|
|
|
37
39
|
context[:results] << double('instance', :id => 24)
|
|
38
40
|
context[:results] << nil
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
expect {
|
|
41
43
|
middleware.call [context]
|
|
42
|
-
}.
|
|
43
|
-
err.ids.
|
|
44
|
+
}.to raise_error(ThinkingSphinx::Search::StaleIdsException) { |err|
|
|
45
|
+
expect(err.ids).to eq([42])
|
|
46
|
+
expect(err.context).to eq(context)
|
|
44
47
|
}
|
|
45
48
|
end
|
|
46
49
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ThinkingSphinx
|
|
2
4
|
module Middlewares; end
|
|
3
5
|
class Search; end
|
|
@@ -15,22 +17,22 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
|
|
|
15
17
|
|
|
16
18
|
describe '#call' do
|
|
17
19
|
before :each do
|
|
18
|
-
context.
|
|
20
|
+
allow(context).to receive_messages :search => search
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
context 'one stale ids exception' do
|
|
22
24
|
before :each do
|
|
23
|
-
app.
|
|
25
|
+
allow(app).to receive(:call) do
|
|
24
26
|
@calls ||= 0
|
|
25
27
|
@calls += 1
|
|
26
|
-
raise ThinkingSphinx::Search::StaleIdsException
|
|
28
|
+
raise ThinkingSphinx::Search::StaleIdsException.new([12], context) if @calls == 1
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
it "appends the ids to the without_ids filter" do
|
|
31
33
|
middleware.call [context]
|
|
32
34
|
|
|
33
|
-
search.options[:without_ids].
|
|
35
|
+
expect(search.options[:without_ids]).to eq([12])
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
it "respects existing without_ids filters" do
|
|
@@ -38,24 +40,24 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
|
|
|
38
40
|
|
|
39
41
|
middleware.call [context]
|
|
40
42
|
|
|
41
|
-
search.options[:without_ids].
|
|
43
|
+
expect(search.options[:without_ids]).to eq([11, 12])
|
|
42
44
|
end
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
context 'two stale ids exceptions' do
|
|
46
48
|
before :each do
|
|
47
|
-
app.
|
|
49
|
+
allow(app).to receive(:call) do
|
|
48
50
|
@calls ||= 0
|
|
49
51
|
@calls += 1
|
|
50
|
-
raise ThinkingSphinx::Search::StaleIdsException
|
|
51
|
-
raise ThinkingSphinx::Search::StaleIdsException
|
|
52
|
+
raise ThinkingSphinx::Search::StaleIdsException.new([12], context) if @calls == 1
|
|
53
|
+
raise ThinkingSphinx::Search::StaleIdsException.new([13], context) if @calls == 2
|
|
52
54
|
end
|
|
53
55
|
end
|
|
54
56
|
|
|
55
57
|
it "appends the ids to the without_ids filter" do
|
|
56
58
|
middleware.call [context]
|
|
57
59
|
|
|
58
|
-
search.options[:without_ids].
|
|
60
|
+
expect(search.options[:without_ids]).to eq([12, 13])
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
it "respects existing without_ids filters" do
|
|
@@ -63,29 +65,49 @@ describe ThinkingSphinx::Middlewares::StaleIdFilter do
|
|
|
63
65
|
|
|
64
66
|
middleware.call [context]
|
|
65
67
|
|
|
66
|
-
search.options[:without_ids].
|
|
68
|
+
expect(search.options[:without_ids]).to eq([11, 12, 13])
|
|
67
69
|
end
|
|
68
70
|
end
|
|
69
71
|
|
|
70
72
|
context 'three stale ids exceptions' do
|
|
71
73
|
before :each do
|
|
72
|
-
app.
|
|
74
|
+
allow(app).to receive(:call) do
|
|
73
75
|
@calls ||= 0
|
|
74
76
|
@calls += 1
|
|
75
77
|
|
|
76
|
-
raise ThinkingSphinx::Search::StaleIdsException
|
|
77
|
-
raise ThinkingSphinx::Search::StaleIdsException
|
|
78
|
-
raise ThinkingSphinx::Search::StaleIdsException
|
|
78
|
+
raise ThinkingSphinx::Search::StaleIdsException.new([12], context) if @calls == 1
|
|
79
|
+
raise ThinkingSphinx::Search::StaleIdsException.new([13], context) if @calls == 2
|
|
80
|
+
raise ThinkingSphinx::Search::StaleIdsException.new([14], context) if @calls == 3
|
|
79
81
|
end
|
|
80
82
|
end
|
|
81
83
|
|
|
82
84
|
it "raises the final stale ids exceptions" do
|
|
83
|
-
|
|
85
|
+
expect {
|
|
84
86
|
middleware.call [context]
|
|
85
|
-
}.
|
|
86
|
-
err.ids.
|
|
87
|
+
}.to raise_error(ThinkingSphinx::Search::StaleIdsException) { |err|
|
|
88
|
+
expect(err.ids).to eq([14])
|
|
87
89
|
}
|
|
88
90
|
end
|
|
89
91
|
end
|
|
92
|
+
|
|
93
|
+
context 'stale ids exceptions with multiple contexts' do
|
|
94
|
+
let(:context2) { {:raw => [], :results => []} }
|
|
95
|
+
let(:search2) { double('search2', :options => {}) }
|
|
96
|
+
before :each do
|
|
97
|
+
allow(context2).to receive_messages :search => search2
|
|
98
|
+
allow(app).to receive(:call) do
|
|
99
|
+
@calls ||= 0
|
|
100
|
+
@calls += 1
|
|
101
|
+
raise ThinkingSphinx::Search::StaleIdsException.new([12], context2) if @calls == 1
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "appends the ids to the without_ids filter in the correct context" do
|
|
106
|
+
middleware.call [context, context2]
|
|
107
|
+
expect(search.options[:without_ids]).to eq(nil)
|
|
108
|
+
expect(search2.options[:without_ids]).to eq([12])
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
90
112
|
end
|
|
91
113
|
end
|