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
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe ThinkingSphinx::Interfaces::SQL do
|
|
6
|
+
let(:interface) { ThinkingSphinx::Interfaces::SQL.new(
|
|
7
|
+
configuration, {:verbose => true}, stream
|
|
8
|
+
) }
|
|
9
|
+
let(:commander) { double :call => true }
|
|
10
|
+
let(:configuration) { double 'configuration', :preload_indices => true,
|
|
11
|
+
:render => true, :indices => [double(:index, :type => 'plain')] }
|
|
12
|
+
let(:stream) { double :puts => nil }
|
|
13
|
+
|
|
14
|
+
before :each do
|
|
15
|
+
stub_const 'ThinkingSphinx::Commander', commander
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe '#clear' do
|
|
19
|
+
let(:users_index) { double(:type => 'plain') }
|
|
20
|
+
let(:parts_index) { double(:type => 'plain') }
|
|
21
|
+
let(:rt_index) { double(:type => 'rt') }
|
|
22
|
+
|
|
23
|
+
before :each do
|
|
24
|
+
allow(configuration).to receive(:indices).
|
|
25
|
+
and_return([users_index, parts_index, rt_index])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "invokes the clear_sql command" do
|
|
29
|
+
expect(commander).to receive(:call).with(
|
|
30
|
+
:clear_sql,
|
|
31
|
+
configuration,
|
|
32
|
+
{:verbose => true, :indices => [users_index, parts_index]},
|
|
33
|
+
stream
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
interface.clear
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe '#index' do
|
|
41
|
+
it "invokes the prepare command" do
|
|
42
|
+
expect(commander).to receive(:call).with(
|
|
43
|
+
:prepare, configuration, {:verbose => true}, stream
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
interface.index
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "renders the configuration to a file by default" do
|
|
50
|
+
expect(commander).to receive(:call).with(
|
|
51
|
+
:configure, configuration, {:verbose => true}, stream
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
interface.index
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "does not render the configuration if requested" do
|
|
58
|
+
expect(commander).not_to receive(:call).with(
|
|
59
|
+
:configure, configuration, {:verbose => true}, stream
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
interface.index false
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "executes the index command" do
|
|
66
|
+
expect(commander).to receive(:call).with(
|
|
67
|
+
:index_sql, configuration, {:verbose => true, :indices => nil}, stream
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
interface.index
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
context "with options[:index_names]" do
|
|
74
|
+
let(:users_index) { double(:name => 'users', :type => 'plain') }
|
|
75
|
+
let(:parts_index) { double(:name => 'parts', :type => 'plain') }
|
|
76
|
+
let(:rt_index) { double(:type => 'rt') }
|
|
77
|
+
let(:interface) { ThinkingSphinx::Interfaces::SQL.new(
|
|
78
|
+
configuration, {:index_names => ['users']}, stream
|
|
79
|
+
) }
|
|
80
|
+
|
|
81
|
+
before :each do
|
|
82
|
+
allow(configuration).to receive(:indices).
|
|
83
|
+
and_return([users_index, parts_index, rt_index])
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'invokes the index command for matching indices' do
|
|
87
|
+
expect(commander).to receive(:call).with(
|
|
88
|
+
:index_sql,
|
|
89
|
+
configuration,
|
|
90
|
+
{:index_names => ['users'], :indices => ['users']},
|
|
91
|
+
stream
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
interface.index
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe '#merge' do
|
|
100
|
+
it "invokes the merge command" do
|
|
101
|
+
expect(commander).to receive(:call).with(
|
|
102
|
+
:merge_and_update, configuration, {:verbose => true}, stream
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
interface.merge
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context "with options[:index_names]" do
|
|
109
|
+
let(:interface) { ThinkingSphinx::Interfaces::SQL.new(
|
|
110
|
+
configuration, {:index_names => ['users']}, stream
|
|
111
|
+
) }
|
|
112
|
+
|
|
113
|
+
it 'invokes the merge command with the index_names option' do
|
|
114
|
+
expect(commander).to receive(:call).with(
|
|
115
|
+
:merge_and_update, configuration, {:index_names => ['users']}, stream
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
interface.merge
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ThinkingSphinx
|
|
2
4
|
module Masks; end
|
|
3
5
|
end
|
|
@@ -12,13 +14,13 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
|
12
14
|
|
|
13
15
|
describe '#first_page?' do
|
|
14
16
|
it "returns true when on the first page" do
|
|
15
|
-
mask.
|
|
17
|
+
expect(mask).to be_first_page
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
it "returns false on other pages" do
|
|
19
|
-
search.
|
|
21
|
+
allow(search).to receive_messages :current_page => 2
|
|
20
22
|
|
|
21
|
-
mask.
|
|
23
|
+
expect(mask).not_to be_first_page
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
|
|
@@ -28,13 +30,13 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
it "is true when there's no more pages" do
|
|
31
|
-
search.
|
|
33
|
+
allow(search).to receive_messages :current_page => 3
|
|
32
34
|
|
|
33
|
-
mask.
|
|
35
|
+
expect(mask).to be_last_page
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
it "is false when there's still more pages" do
|
|
37
|
-
mask.
|
|
39
|
+
expect(mask).not_to be_last_page
|
|
38
40
|
end
|
|
39
41
|
end
|
|
40
42
|
|
|
@@ -44,13 +46,13 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
|
44
46
|
end
|
|
45
47
|
|
|
46
48
|
it "should return one more than the current page" do
|
|
47
|
-
mask.next_page.
|
|
49
|
+
expect(mask.next_page).to eq(2)
|
|
48
50
|
end
|
|
49
51
|
|
|
50
52
|
it "should return nil if on the last page" do
|
|
51
|
-
search.
|
|
53
|
+
allow(search).to receive_messages :current_page => 3
|
|
52
54
|
|
|
53
|
-
mask.next_page.
|
|
55
|
+
expect(mask.next_page).to be_nil
|
|
54
56
|
end
|
|
55
57
|
end
|
|
56
58
|
|
|
@@ -60,13 +62,13 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
|
60
62
|
end
|
|
61
63
|
|
|
62
64
|
it "is true when there is a second page" do
|
|
63
|
-
mask.next_page
|
|
65
|
+
expect(mask.next_page?).to be_truthy
|
|
64
66
|
end
|
|
65
67
|
|
|
66
68
|
it "is false when there's no more pages" do
|
|
67
|
-
search.
|
|
69
|
+
allow(search).to receive_messages :current_page => 3
|
|
68
70
|
|
|
69
|
-
mask.next_page
|
|
71
|
+
expect(mask.next_page?).to be_falsey
|
|
70
72
|
end
|
|
71
73
|
end
|
|
72
74
|
|
|
@@ -76,13 +78,13 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
|
76
78
|
end
|
|
77
79
|
|
|
78
80
|
it "should return one less than the current page" do
|
|
79
|
-
search.
|
|
81
|
+
allow(search).to receive_messages :current_page => 2
|
|
80
82
|
|
|
81
|
-
mask.previous_page.
|
|
83
|
+
expect(mask.previous_page).to eq(1)
|
|
82
84
|
end
|
|
83
85
|
|
|
84
86
|
it "should return nil if on the first page" do
|
|
85
|
-
mask.previous_page.
|
|
87
|
+
expect(mask.previous_page).to be_nil
|
|
86
88
|
end
|
|
87
89
|
end
|
|
88
90
|
|
|
@@ -92,7 +94,7 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
|
92
94
|
end
|
|
93
95
|
|
|
94
96
|
it "returns the total found from the search request metadata" do
|
|
95
|
-
mask.total_entries.
|
|
97
|
+
expect(mask.total_entries).to eq(12)
|
|
96
98
|
end
|
|
97
99
|
end
|
|
98
100
|
|
|
@@ -103,19 +105,19 @@ describe ThinkingSphinx::Masks::PaginationMask do
|
|
|
103
105
|
end
|
|
104
106
|
|
|
105
107
|
it "uses the total available from the search request metadata" do
|
|
106
|
-
mask.total_pages.
|
|
108
|
+
expect(mask.total_pages).to eq(2)
|
|
107
109
|
end
|
|
108
110
|
|
|
109
111
|
it "should allow for custom per_page values" do
|
|
110
|
-
search.
|
|
112
|
+
allow(search).to receive_messages :per_page => 40
|
|
111
113
|
|
|
112
|
-
mask.total_pages.
|
|
114
|
+
expect(mask.total_pages).to eq(1)
|
|
113
115
|
end
|
|
114
116
|
|
|
115
117
|
it "should return 0 if there is no index and therefore no results" do
|
|
116
118
|
search.meta.clear
|
|
117
119
|
|
|
118
|
-
mask.total_pages.
|
|
120
|
+
expect(mask.total_pages).to eq(0)
|
|
119
121
|
end
|
|
120
122
|
end
|
|
121
123
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ThinkingSphinx
|
|
2
4
|
module Masks; end
|
|
3
5
|
end
|
|
@@ -10,18 +12,18 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
|
10
12
|
let(:mask) { ThinkingSphinx::Masks::ScopesMask.new search }
|
|
11
13
|
|
|
12
14
|
before :each do
|
|
13
|
-
FileUtils.
|
|
15
|
+
allow(FileUtils).to receive_messages :mkdir_p => true
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
describe '#search' do
|
|
17
19
|
it "replaces the query if one is supplied" do
|
|
18
|
-
search.
|
|
20
|
+
expect(search).to receive(:query=).with('bar')
|
|
19
21
|
|
|
20
22
|
mask.search('bar')
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
it "keeps the existing query when only options are offered" do
|
|
24
|
-
search.
|
|
26
|
+
expect(search).not_to receive(:query=)
|
|
25
27
|
|
|
26
28
|
mask.search :with => {:foo => :bar}
|
|
27
29
|
end
|
|
@@ -31,7 +33,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
|
31
33
|
|
|
32
34
|
mask.search :conditions => {:baz => 'qux'}
|
|
33
35
|
|
|
34
|
-
search.options[:conditions].
|
|
36
|
+
expect(search.options[:conditions]).to eq({:foo => 'bar', :baz => 'qux'})
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
it "merges filters" do
|
|
@@ -39,7 +41,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
|
39
41
|
|
|
40
42
|
mask.search :with => {:baz => :qux}
|
|
41
43
|
|
|
42
|
-
search.options[:with].
|
|
44
|
+
expect(search.options[:with]).to eq({:foo => :bar, :baz => :qux})
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
it "merges exclusive filters" do
|
|
@@ -47,7 +49,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
|
47
49
|
|
|
48
50
|
mask.search :without => {:baz => :qux}
|
|
49
51
|
|
|
50
|
-
search.options[:without].
|
|
52
|
+
expect(search.options[:without]).to eq({:foo => :bar, :baz => :qux})
|
|
51
53
|
end
|
|
52
54
|
|
|
53
55
|
it "appends excluded ids" do
|
|
@@ -55,7 +57,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
|
55
57
|
|
|
56
58
|
mask.search :without_ids => [5, 7]
|
|
57
59
|
|
|
58
|
-
search.options[:without_ids].
|
|
60
|
+
expect(search.options[:without_ids]).to eq([1, 3, 5, 7])
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
it "replaces the retry_stale option" do
|
|
@@ -63,23 +65,23 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
|
63
65
|
|
|
64
66
|
mask.search :retry_stale => 6
|
|
65
67
|
|
|
66
|
-
search.options[:retry_stale].
|
|
68
|
+
expect(search.options[:retry_stale]).to eq(6)
|
|
67
69
|
end
|
|
68
70
|
|
|
69
71
|
it "returns the original search object" do
|
|
70
|
-
mask.search.object_id.
|
|
72
|
+
expect(mask.search.object_id).to eq(search.object_id)
|
|
71
73
|
end
|
|
72
74
|
end
|
|
73
75
|
|
|
74
76
|
describe '#search_for_ids' do
|
|
75
77
|
it "replaces the query if one is supplied" do
|
|
76
|
-
search.
|
|
78
|
+
expect(search).to receive(:query=).with('bar')
|
|
77
79
|
|
|
78
80
|
mask.search_for_ids('bar')
|
|
79
81
|
end
|
|
80
82
|
|
|
81
83
|
it "keeps the existing query when only options are offered" do
|
|
82
|
-
search.
|
|
84
|
+
expect(search).not_to receive(:query=)
|
|
83
85
|
|
|
84
86
|
mask.search_for_ids :with => {:foo => :bar}
|
|
85
87
|
end
|
|
@@ -89,7 +91,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
|
89
91
|
|
|
90
92
|
mask.search_for_ids :conditions => {:baz => 'qux'}
|
|
91
93
|
|
|
92
|
-
search.options[:conditions].
|
|
94
|
+
expect(search.options[:conditions]).to eq({:foo => 'bar', :baz => 'qux'})
|
|
93
95
|
end
|
|
94
96
|
|
|
95
97
|
it "merges filters" do
|
|
@@ -97,7 +99,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
|
97
99
|
|
|
98
100
|
mask.search_for_ids :with => {:baz => :qux}
|
|
99
101
|
|
|
100
|
-
search.options[:with].
|
|
102
|
+
expect(search.options[:with]).to eq({:foo => :bar, :baz => :qux})
|
|
101
103
|
end
|
|
102
104
|
|
|
103
105
|
it "merges exclusive filters" do
|
|
@@ -105,7 +107,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
|
105
107
|
|
|
106
108
|
mask.search_for_ids :without => {:baz => :qux}
|
|
107
109
|
|
|
108
|
-
search.options[:without].
|
|
110
|
+
expect(search.options[:without]).to eq({:foo => :bar, :baz => :qux})
|
|
109
111
|
end
|
|
110
112
|
|
|
111
113
|
it "appends excluded ids" do
|
|
@@ -113,7 +115,7 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
|
113
115
|
|
|
114
116
|
mask.search_for_ids :without_ids => [5, 7]
|
|
115
117
|
|
|
116
|
-
search.options[:without_ids].
|
|
118
|
+
expect(search.options[:without_ids]).to eq([1, 3, 5, 7])
|
|
117
119
|
end
|
|
118
120
|
|
|
119
121
|
it "replaces the retry_stale option" do
|
|
@@ -121,17 +123,17 @@ describe ThinkingSphinx::Masks::ScopesMask do
|
|
|
121
123
|
|
|
122
124
|
mask.search_for_ids :retry_stale => 6
|
|
123
125
|
|
|
124
|
-
search.options[:retry_stale].
|
|
126
|
+
expect(search.options[:retry_stale]).to eq(6)
|
|
125
127
|
end
|
|
126
128
|
|
|
127
129
|
it "adds the ids_only option" do
|
|
128
130
|
mask.search_for_ids
|
|
129
131
|
|
|
130
|
-
search.options[:ids_only].
|
|
132
|
+
expect(search.options[:ids_only]).to be_truthy
|
|
131
133
|
end
|
|
132
134
|
|
|
133
135
|
it "returns the original search object" do
|
|
134
|
-
mask.search_for_ids.object_id.
|
|
136
|
+
expect(mask.search_for_ids.object_id).to eq(search.object_id)
|
|
135
137
|
end
|
|
136
138
|
end
|
|
137
139
|
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
|
|
@@ -11,9 +13,10 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
|
|
|
11
13
|
let(:app) { double('app', :call => true) }
|
|
12
14
|
let(:middleware) {
|
|
13
15
|
ThinkingSphinx::Middlewares::ActiveRecordTranslator.new app }
|
|
14
|
-
let(:context) { {:raw => [], :results => []} }
|
|
16
|
+
let(:context) { {:raw => [], :results => [] } }
|
|
15
17
|
let(:model) { double('model', :primary_key => :id) }
|
|
16
18
|
let(:search) { double('search', :options => {}) }
|
|
19
|
+
let(:configuration) { double('configuration', :settings => {:primary_key => :id}) }
|
|
17
20
|
|
|
18
21
|
def raw_result(id, model_name)
|
|
19
22
|
{'sphinx_internal_id' => id, 'sphinx_internal_class' => model_name}
|
|
@@ -21,20 +24,21 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
|
|
|
21
24
|
|
|
22
25
|
describe '#call' do
|
|
23
26
|
before :each do
|
|
24
|
-
context.
|
|
25
|
-
|
|
27
|
+
allow(context).to receive_messages :search => search
|
|
28
|
+
allow(context).to receive_messages :configuration => configuration
|
|
29
|
+
allow(model).to receive_messages :unscoped => model
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
it "translates records to ActiveRecord objects" do
|
|
29
33
|
model_name = double('article', :constantize => model)
|
|
30
34
|
instance = double('instance', :id => 24)
|
|
31
|
-
model.
|
|
35
|
+
allow(model).to receive_messages :where => [instance]
|
|
32
36
|
|
|
33
37
|
context[:results] << raw_result(24, model_name)
|
|
34
38
|
|
|
35
39
|
middleware.call [context]
|
|
36
40
|
|
|
37
|
-
context[:results].
|
|
41
|
+
expect(context[:results]).to eq([instance])
|
|
38
42
|
end
|
|
39
43
|
|
|
40
44
|
it "only queries the model once for the given search results" do
|
|
@@ -44,7 +48,7 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
|
|
|
44
48
|
context[:results] << raw_result(24, model_name)
|
|
45
49
|
context[:results] << raw_result(42, model_name)
|
|
46
50
|
|
|
47
|
-
model.
|
|
51
|
+
expect(model).to receive(:where).once.and_return([instance_a, instance_b])
|
|
48
52
|
|
|
49
53
|
middleware.call [context]
|
|
50
54
|
end
|
|
@@ -58,14 +62,14 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
|
|
|
58
62
|
user_name = double('user name', :constantize => user_model)
|
|
59
63
|
user = double('user instance', :id => 12)
|
|
60
64
|
|
|
61
|
-
article_model.
|
|
62
|
-
user_model.
|
|
65
|
+
allow(article_model).to receive_messages :unscoped => article_model
|
|
66
|
+
allow(user_model).to receive_messages :unscoped => user_model
|
|
63
67
|
|
|
64
68
|
context[:results] << raw_result(24, article_name)
|
|
65
69
|
context[:results] << raw_result(12, user_name)
|
|
66
70
|
|
|
67
|
-
article_model.
|
|
68
|
-
user_model.
|
|
71
|
+
expect(article_model).to receive(:where).once.and_return([article])
|
|
72
|
+
expect(user_model).to receive(:where).once.and_return([user])
|
|
69
73
|
|
|
70
74
|
middleware.call [context]
|
|
71
75
|
end
|
|
@@ -78,11 +82,11 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
|
|
|
78
82
|
context[:results] << raw_result(2, model_name)
|
|
79
83
|
context[:results] << raw_result(1, model_name)
|
|
80
84
|
|
|
81
|
-
model.
|
|
85
|
+
allow(model).to receive_messages(:where => [instance_1, instance_2])
|
|
82
86
|
|
|
83
87
|
middleware.call [context]
|
|
84
88
|
|
|
85
|
-
context[:results].
|
|
89
|
+
expect(context[:results]).to eq([instance_2, instance_1])
|
|
86
90
|
end
|
|
87
91
|
|
|
88
92
|
it "returns objects in database order if a SQL order clause is supplied" do
|
|
@@ -93,28 +97,40 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
|
|
|
93
97
|
context[:results] << raw_result(2, model_name)
|
|
94
98
|
context[:results] << raw_result(1, model_name)
|
|
95
99
|
|
|
96
|
-
model.
|
|
100
|
+
allow(model).to receive_messages(:order => model, :where => [instance_1, instance_2])
|
|
97
101
|
search.options[:sql] = {:order => 'name DESC'}
|
|
98
102
|
|
|
99
103
|
middleware.call [context]
|
|
100
104
|
|
|
101
|
-
context[:results].
|
|
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]
|
|
102
118
|
end
|
|
103
119
|
|
|
104
120
|
context 'SQL options' do
|
|
105
121
|
let(:relation) { double('relation', :where => []) }
|
|
122
|
+
let(:model_name) { double('article', :constantize => model) }
|
|
106
123
|
|
|
107
124
|
before :each do
|
|
108
|
-
model.
|
|
125
|
+
allow(model).to receive_messages :unscoped => relation
|
|
109
126
|
|
|
110
|
-
model_name = double('article', :constantize => model)
|
|
111
127
|
context[:results] << raw_result(1, model_name)
|
|
112
128
|
end
|
|
113
129
|
|
|
114
130
|
it "passes through SQL include options to the relation" do
|
|
115
131
|
search.options[:sql] = {:include => :association}
|
|
116
132
|
|
|
117
|
-
relation.
|
|
133
|
+
expect(relation).to receive(:includes).with(:association).
|
|
118
134
|
and_return(relation)
|
|
119
135
|
|
|
120
136
|
middleware.call [context]
|
|
@@ -123,7 +139,7 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
|
|
|
123
139
|
it "passes through SQL join options to the relation" do
|
|
124
140
|
search.options[:sql] = {:joins => :association}
|
|
125
141
|
|
|
126
|
-
relation.
|
|
142
|
+
expect(relation).to receive(:joins).with(:association).and_return(relation)
|
|
127
143
|
|
|
128
144
|
middleware.call [context]
|
|
129
145
|
end
|
|
@@ -131,7 +147,7 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
|
|
|
131
147
|
it "passes through SQL order options to the relation" do
|
|
132
148
|
search.options[:sql] = {:order => 'name DESC'}
|
|
133
149
|
|
|
134
|
-
relation.
|
|
150
|
+
expect(relation).to receive(:order).with('name DESC').and_return(relation)
|
|
135
151
|
|
|
136
152
|
middleware.call [context]
|
|
137
153
|
end
|
|
@@ -139,7 +155,7 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
|
|
|
139
155
|
it "passes through SQL select options to the relation" do
|
|
140
156
|
search.options[:sql] = {:select => :column}
|
|
141
157
|
|
|
142
|
-
relation.
|
|
158
|
+
expect(relation).to receive(:select).with(:column).and_return(relation)
|
|
143
159
|
|
|
144
160
|
middleware.call [context]
|
|
145
161
|
end
|
|
@@ -147,7 +163,15 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
|
|
|
147
163
|
it "passes through SQL group options to the relation" do
|
|
148
164
|
search.options[:sql] = {:group => :column}
|
|
149
165
|
|
|
150
|
-
relation.
|
|
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)
|
|
151
175
|
|
|
152
176
|
middleware.call [context]
|
|
153
177
|
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,7 @@ describe ThinkingSphinx::Middlewares::Geographer do
|
|
|
16
18
|
before :each do
|
|
17
19
|
stub_const 'ThinkingSphinx::Panes::DistancePane', double
|
|
18
20
|
|
|
19
|
-
context.
|
|
21
|
+
allow(context).to receive_messages :search => search
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
describe '#call' do
|
|
@@ -26,7 +28,7 @@ describe ThinkingSphinx::Middlewares::Geographer do
|
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
it "doesn't add anything if :geo is nil" do
|
|
29
|
-
sphinx_sql.
|
|
31
|
+
expect(sphinx_sql).not_to receive(:prepend_values)
|
|
30
32
|
|
|
31
33
|
middleware.call [context]
|
|
32
34
|
end
|
|
@@ -38,7 +40,7 @@ describe ThinkingSphinx::Middlewares::Geographer do
|
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
it "adds the geodist function when given a :geo option" do
|
|
41
|
-
sphinx_sql.
|
|
43
|
+
expect(sphinx_sql).to receive(:prepend_values).
|
|
42
44
|
with('GEODIST(0.1, 0.2, lat, lng) AS geodist').
|
|
43
45
|
and_return(sphinx_sql)
|
|
44
46
|
|
|
@@ -46,18 +48,18 @@ describe ThinkingSphinx::Middlewares::Geographer do
|
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
it "adds the distance pane" do
|
|
49
|
-
sphinx_sql.
|
|
51
|
+
allow(sphinx_sql).to receive_messages :prepend_values => sphinx_sql
|
|
50
52
|
|
|
51
53
|
middleware.call [context]
|
|
52
54
|
|
|
53
|
-
context[:panes].
|
|
55
|
+
expect(context[:panes]).to include(ThinkingSphinx::Panes::DistancePane)
|
|
54
56
|
end
|
|
55
57
|
|
|
56
58
|
it "respects :latitude_attr and :longitude_attr options" do
|
|
57
59
|
search.options[:latitude_attr] = 'side_to_side'
|
|
58
60
|
search.options[:longitude_attr] = 'up_or_down'
|
|
59
61
|
|
|
60
|
-
sphinx_sql.
|
|
62
|
+
expect(sphinx_sql).to receive(:prepend_values).
|
|
61
63
|
with('GEODIST(0.1, 0.2, side_to_side, up_or_down) AS geodist').
|
|
62
64
|
and_return(sphinx_sql)
|
|
63
65
|
|
|
@@ -68,7 +70,7 @@ describe ThinkingSphinx::Middlewares::Geographer do
|
|
|
68
70
|
context[:indices] << double('index',
|
|
69
71
|
:unique_attribute_names => ['latitude'], :name => 'an_index')
|
|
70
72
|
|
|
71
|
-
sphinx_sql.
|
|
73
|
+
expect(sphinx_sql).to receive(:prepend_values).
|
|
72
74
|
with('GEODIST(0.1, 0.2, latitude, lng) AS geodist').
|
|
73
75
|
and_return(sphinx_sql)
|
|
74
76
|
|
|
@@ -79,7 +81,7 @@ describe ThinkingSphinx::Middlewares::Geographer do
|
|
|
79
81
|
context[:indices] << double('index',
|
|
80
82
|
:unique_attribute_names => ['longitude'], :name => 'an_index')
|
|
81
83
|
|
|
82
|
-
sphinx_sql.
|
|
84
|
+
expect(sphinx_sql).to receive(:prepend_values).
|
|
83
85
|
with('GEODIST(0.1, 0.2, lat, longitude) AS geodist').
|
|
84
86
|
and_return(sphinx_sql)
|
|
85
87
|
|
|
@@ -89,7 +91,7 @@ describe ThinkingSphinx::Middlewares::Geographer do
|
|
|
89
91
|
it "handles very small values" do
|
|
90
92
|
search.options[:geo] = [0.0000001, 0.00000000002]
|
|
91
93
|
|
|
92
|
-
sphinx_sql.
|
|
94
|
+
expect(sphinx_sql).to receive(:prepend_values).
|
|
93
95
|
with('GEODIST(0.0000001, 0.00000000002, lat, lng) AS geodist').
|
|
94
96
|
and_return(sphinx_sql)
|
|
95
97
|
|