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,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe ThinkingSphinx::Connection::MRI do
|
|
4
|
+
subject { described_class.new :host => "127.0.0.1", :port => 9306 }
|
|
5
|
+
|
|
6
|
+
let(:client) { double :client, :query => "result", :next_result => false }
|
|
7
|
+
|
|
8
|
+
before :each do
|
|
9
|
+
allow(Mysql2::Client).to receive(:new).and_return(client)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
after :each do
|
|
13
|
+
ThinkingSphinx::Configuration.reset
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "#execute" do
|
|
17
|
+
it "sends the query to the client" do
|
|
18
|
+
subject.execute "SELECT QUERY"
|
|
19
|
+
|
|
20
|
+
expect(client).to have_received(:query).with("SELECT QUERY")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "returns a result" do
|
|
24
|
+
expect(subject.execute("SELECT QUERY")).to eq("result")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "with long queries" do
|
|
28
|
+
let(:maximum) { (2 ** 23) - 5 }
|
|
29
|
+
let(:query) { String.new "SELECT * FROM book_core WHERE MATCH('')" }
|
|
30
|
+
let(:difference) { maximum - query.length }
|
|
31
|
+
|
|
32
|
+
it 'does not allow overly long queries' do
|
|
33
|
+
expect {
|
|
34
|
+
subject.execute(query.insert(-3, 'a' * (difference + 5)))
|
|
35
|
+
}.to raise_error(ThinkingSphinx::QueryLengthError)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'does not allow queries longer than specified in the settings' do
|
|
39
|
+
ThinkingSphinx::Configuration.reset
|
|
40
|
+
|
|
41
|
+
write_configuration('maximum_statement_length' => maximum - 5)
|
|
42
|
+
|
|
43
|
+
expect {
|
|
44
|
+
subject.execute(query.insert(-3, 'a' * (difference)))
|
|
45
|
+
}.to raise_error(ThinkingSphinx::QueryLengthError)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end if RUBY_PLATFORM != 'java'
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::Connection do
|
|
@@ -8,9 +10,9 @@ describe ThinkingSphinx::Connection do
|
|
|
8
10
|
let(:translated_error) { ThinkingSphinx::SphinxError.new }
|
|
9
11
|
|
|
10
12
|
before :each do
|
|
11
|
-
ThinkingSphinx::Connection.
|
|
12
|
-
ThinkingSphinx::SphinxError.
|
|
13
|
-
pool.
|
|
13
|
+
allow(ThinkingSphinx::Connection).to receive_messages :pool => pool
|
|
14
|
+
allow(ThinkingSphinx::SphinxError).to receive_messages :new_from_mysql => translated_error
|
|
15
|
+
allow(pool).to receive(:take).and_yield(connection)
|
|
14
16
|
|
|
15
17
|
error.statement = 'SELECT * FROM article_core'
|
|
16
18
|
translated_error.statement = 'SELECT * FROM article_core'
|
|
@@ -18,41 +20,41 @@ describe ThinkingSphinx::Connection do
|
|
|
18
20
|
|
|
19
21
|
it "yields a connection from the pool" do
|
|
20
22
|
ThinkingSphinx::Connection.take do |c|
|
|
21
|
-
c.
|
|
23
|
+
expect(c).to eq(connection)
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
it "retries errors once" do
|
|
26
28
|
tries = 0
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
expect {
|
|
29
31
|
ThinkingSphinx::Connection.take do |c|
|
|
30
32
|
tries += 1
|
|
31
33
|
raise error if tries < 2
|
|
32
34
|
end
|
|
33
|
-
}.
|
|
35
|
+
}.not_to raise_error
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
it "retries errors twice" do
|
|
37
39
|
tries = 0
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
expect {
|
|
40
42
|
ThinkingSphinx::Connection.take do |c|
|
|
41
43
|
tries += 1
|
|
42
44
|
raise error if tries < 3
|
|
43
45
|
end
|
|
44
|
-
}.
|
|
46
|
+
}.not_to raise_error
|
|
45
47
|
end
|
|
46
48
|
|
|
47
49
|
it "raises a translated error if it fails three times" do
|
|
48
50
|
tries = 0
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
expect {
|
|
51
53
|
ThinkingSphinx::Connection.take do |c|
|
|
52
54
|
tries += 1
|
|
53
55
|
raise error if tries < 4
|
|
54
56
|
end
|
|
55
|
-
}.
|
|
57
|
+
}.to raise_error(ThinkingSphinx::SphinxError)
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
[ThinkingSphinx::SyntaxError, ThinkingSphinx::ParseError].each do |klass|
|
|
@@ -60,9 +62,9 @@ describe ThinkingSphinx::Connection do
|
|
|
60
62
|
let(:translated_error) { klass.new }
|
|
61
63
|
|
|
62
64
|
it "raises the error" do
|
|
63
|
-
|
|
65
|
+
expect {
|
|
64
66
|
ThinkingSphinx::Connection.take { |c| raise error }
|
|
65
|
-
}.
|
|
67
|
+
}.to raise_error(klass)
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
it "does not yield the connection more than once" do
|
|
@@ -77,7 +79,7 @@ describe ThinkingSphinx::Connection do
|
|
|
77
79
|
#
|
|
78
80
|
end
|
|
79
81
|
|
|
80
|
-
yields.
|
|
82
|
+
expect(yields).to eq(1)
|
|
81
83
|
end
|
|
82
84
|
end
|
|
83
85
|
end
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::Deletion do
|
|
4
6
|
describe '.perform' do
|
|
5
7
|
let(:connection) { double('connection', :execute => nil) }
|
|
6
8
|
let(:index) { double('index', :name => 'foo_core',
|
|
7
|
-
:
|
|
9
|
+
:type => 'plain', :distributed? => false) }
|
|
8
10
|
|
|
9
11
|
before :each do
|
|
10
|
-
ThinkingSphinx::Connection.
|
|
11
|
-
Riddle::Query.
|
|
12
|
+
allow(ThinkingSphinx::Connection).to receive(:take).and_yield(connection)
|
|
13
|
+
allow(Riddle::Query).to receive_messages :update => 'UPDATE STATEMENT'
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
context 'index is SQL-backed' do
|
|
15
17
|
it "updates the deleted flag to false" do
|
|
16
|
-
connection.
|
|
17
|
-
UPDATE foo_core
|
|
18
|
-
|
|
19
|
-
WHERE id IN (14)
|
|
20
|
-
SQL
|
|
18
|
+
expect(connection).to receive(:execute).with(
|
|
19
|
+
'UPDATE foo_core SET sphinx_deleted = 1 WHERE sphinx_internal_id IN (7)'
|
|
20
|
+
)
|
|
21
21
|
|
|
22
22
|
ThinkingSphinx::Deletion.perform index, 7
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it "doesn't care about Sphinx errors" do
|
|
26
|
-
connection.
|
|
26
|
+
allow(connection).to receive(:execute).
|
|
27
27
|
and_raise(ThinkingSphinx::ConnectionError.new(''))
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
expect {
|
|
30
30
|
ThinkingSphinx::Deletion.perform index, 7
|
|
31
|
-
}.
|
|
31
|
+
}.not_to raise_error
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
context "index is real-time" do
|
|
36
36
|
before :each do
|
|
37
|
-
index.
|
|
37
|
+
allow(index).to receive_messages :type => 'rt'
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it "deletes the record to false" do
|
|
41
|
-
connection.
|
|
42
|
-
with('DELETE FROM foo_core WHERE
|
|
41
|
+
expect(connection).to receive(:execute).
|
|
42
|
+
with('DELETE FROM foo_core WHERE sphinx_internal_id IN (7)')
|
|
43
43
|
|
|
44
44
|
ThinkingSphinx::Deletion.perform index, 7
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
it "doesn't care about Sphinx errors" do
|
|
48
|
-
connection.
|
|
48
|
+
allow(connection).to receive(:execute).
|
|
49
49
|
and_raise(ThinkingSphinx::ConnectionError.new(''))
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
expect {
|
|
52
52
|
ThinkingSphinx::Deletion.perform index, 7
|
|
53
|
-
}.
|
|
53
|
+
}.not_to raise_error
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::Deltas::DefaultDelta do
|
|
@@ -9,11 +11,11 @@ describe ThinkingSphinx::Deltas::DefaultDelta do
|
|
|
9
11
|
describe '#clause' do
|
|
10
12
|
context 'for a delta source' do
|
|
11
13
|
before :each do
|
|
12
|
-
adapter.
|
|
14
|
+
allow(adapter).to receive_messages :boolean_value => 't'
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
it "limits results to those flagged as deltas" do
|
|
16
|
-
delta.clause(true).
|
|
18
|
+
expect(delta.clause(true)).to eq("articles.delta = t")
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
end
|
|
@@ -21,46 +23,46 @@ describe ThinkingSphinx::Deltas::DefaultDelta do
|
|
|
21
23
|
describe '#delete' do
|
|
22
24
|
let(:connection) { double('connection', :execute => nil) }
|
|
23
25
|
let(:index) { double('index', :name => 'foo_core',
|
|
24
|
-
:
|
|
26
|
+
:document_id_for_instance => 14) }
|
|
25
27
|
let(:instance) { double('instance', :id => 7) }
|
|
26
28
|
|
|
27
29
|
before :each do
|
|
28
|
-
ThinkingSphinx::Connection.
|
|
29
|
-
Riddle::Query.
|
|
30
|
+
allow(ThinkingSphinx::Connection).to receive(:take).and_yield(connection)
|
|
31
|
+
allow(Riddle::Query).to receive_messages :update => 'UPDATE STATEMENT'
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
it "updates the deleted flag to false" do
|
|
33
|
-
connection.
|
|
35
|
+
expect(connection).to receive(:execute).with('UPDATE STATEMENT')
|
|
34
36
|
|
|
35
37
|
delta.delete index, instance
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
it "builds the update query for the given index" do
|
|
39
|
-
Riddle::Query.
|
|
41
|
+
expect(Riddle::Query).to receive(:update).
|
|
40
42
|
with('foo_core', anything, anything).and_return('')
|
|
41
43
|
|
|
42
44
|
delta.delete index, instance
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
it "builds the update query for the sphinx document id" do
|
|
46
|
-
Riddle::Query.
|
|
48
|
+
expect(Riddle::Query).to receive(:update).
|
|
47
49
|
with(anything, 14, anything).and_return('')
|
|
48
50
|
|
|
49
51
|
delta.delete index, instance
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
it "builds the update query for setting sphinx_deleted to true" do
|
|
53
|
-
Riddle::Query.
|
|
55
|
+
expect(Riddle::Query).to receive(:update).
|
|
54
56
|
with(anything, anything, :sphinx_deleted => true).and_return('')
|
|
55
57
|
|
|
56
58
|
delta.delete index, instance
|
|
57
59
|
end
|
|
58
60
|
|
|
59
61
|
it "doesn't care about Sphinx errors" do
|
|
60
|
-
connection.
|
|
62
|
+
allow(connection).to receive(:execute).
|
|
61
63
|
and_raise(ThinkingSphinx::ConnectionError.new(''))
|
|
62
64
|
|
|
63
|
-
|
|
65
|
+
expect { delta.delete index, instance }.not_to raise_error
|
|
64
66
|
end
|
|
65
67
|
end
|
|
66
68
|
|
|
@@ -68,13 +70,18 @@ describe ThinkingSphinx::Deltas::DefaultDelta do
|
|
|
68
70
|
let(:config) { double('config', :controller => controller,
|
|
69
71
|
:settings => {}) }
|
|
70
72
|
let(:controller) { double('controller') }
|
|
73
|
+
let(:commander) { double('commander', :call => true) }
|
|
71
74
|
|
|
72
75
|
before :each do
|
|
73
|
-
ThinkingSphinx::
|
|
76
|
+
stub_const 'ThinkingSphinx::Commander', commander
|
|
77
|
+
|
|
78
|
+
allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
|
|
74
79
|
end
|
|
75
80
|
|
|
76
81
|
it "indexes the given index" do
|
|
77
|
-
|
|
82
|
+
expect(commander).to receive(:call).with(
|
|
83
|
+
:index_sql, config, :indices => ['foo_delta'], :verbose => false
|
|
84
|
+
)
|
|
78
85
|
|
|
79
86
|
delta.index double('index', :name => 'foo_delta')
|
|
80
87
|
end
|
|
@@ -82,9 +89,9 @@ describe ThinkingSphinx::Deltas::DefaultDelta do
|
|
|
82
89
|
|
|
83
90
|
describe '#reset_query' do
|
|
84
91
|
it "updates the table to set delta flags to false" do
|
|
85
|
-
adapter.
|
|
86
|
-
delta.reset_query.
|
|
87
|
-
|
|
92
|
+
allow(adapter).to receive(:boolean_value) { |value| value ? 't' : 'f' }
|
|
93
|
+
expect(delta.reset_query).
|
|
94
|
+
to eq('UPDATE articles SET delta = f WHERE delta = t')
|
|
88
95
|
end
|
|
89
96
|
end
|
|
90
97
|
|
|
@@ -92,7 +99,7 @@ describe ThinkingSphinx::Deltas::DefaultDelta do
|
|
|
92
99
|
let(:instance) { double('instance') }
|
|
93
100
|
|
|
94
101
|
it "sets instance's delta flag to true" do
|
|
95
|
-
instance.
|
|
102
|
+
expect(instance).to receive(:delta=).with(true)
|
|
96
103
|
|
|
97
104
|
delta.toggle(instance)
|
|
98
105
|
end
|
|
@@ -102,15 +109,15 @@ describe ThinkingSphinx::Deltas::DefaultDelta do
|
|
|
102
109
|
let(:instance) { double('instance') }
|
|
103
110
|
|
|
104
111
|
it "returns the delta flag value when true" do
|
|
105
|
-
instance.
|
|
112
|
+
allow(instance).to receive_messages :delta? => true
|
|
106
113
|
|
|
107
|
-
delta.toggled?(instance).
|
|
114
|
+
expect(delta.toggled?(instance)).to be_truthy
|
|
108
115
|
end
|
|
109
116
|
|
|
110
117
|
it "returns the delta flag value when false" do
|
|
111
|
-
instance.
|
|
118
|
+
allow(instance).to receive_messages :delta? => false
|
|
112
119
|
|
|
113
|
-
delta.toggled?(instance).
|
|
120
|
+
expect(delta.toggled?(instance)).to be_falsey
|
|
114
121
|
end
|
|
115
122
|
end
|
|
116
123
|
end
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::Deltas do
|
|
4
6
|
describe '.processor_for' do
|
|
5
7
|
it "returns the default processor class when given true" do
|
|
6
|
-
ThinkingSphinx::Deltas.processor_for(true).
|
|
7
|
-
|
|
8
|
+
expect(ThinkingSphinx::Deltas.processor_for(true)).
|
|
9
|
+
to eq(ThinkingSphinx::Deltas::DefaultDelta)
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
it "returns the class when given one" do
|
|
11
13
|
klass = Class.new
|
|
12
|
-
ThinkingSphinx::Deltas.processor_for(klass).
|
|
14
|
+
expect(ThinkingSphinx::Deltas.processor_for(klass)).to eq(klass)
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
it "instantiates a class from the name as a string" do
|
|
16
|
-
ThinkingSphinx::Deltas.
|
|
17
|
-
processor_for('ThinkingSphinx::Deltas::DefaultDelta').
|
|
18
|
-
|
|
18
|
+
expect(ThinkingSphinx::Deltas.
|
|
19
|
+
processor_for('ThinkingSphinx::Deltas::DefaultDelta')).
|
|
20
|
+
to eq(ThinkingSphinx::Deltas::DefaultDelta)
|
|
19
21
|
end
|
|
20
22
|
end
|
|
21
23
|
|
|
@@ -29,7 +31,7 @@ describe ThinkingSphinx::Deltas do
|
|
|
29
31
|
let(:processor) { double('processor', :index => true) }
|
|
30
32
|
|
|
31
33
|
before :each do
|
|
32
|
-
ThinkingSphinx::Configuration.
|
|
34
|
+
allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
it "executes the given block" do
|
|
@@ -39,12 +41,12 @@ describe ThinkingSphinx::Deltas do
|
|
|
39
41
|
variable = :bar
|
|
40
42
|
end
|
|
41
43
|
|
|
42
|
-
variable.
|
|
44
|
+
expect(variable).to eq(:bar)
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
it "suspends deltas within the block" do
|
|
46
48
|
ThinkingSphinx::Deltas.suspend :user do
|
|
47
|
-
ThinkingSphinx::Deltas.
|
|
49
|
+
expect(ThinkingSphinx::Deltas).to be_suspended
|
|
48
50
|
end
|
|
49
51
|
end
|
|
50
52
|
|
|
@@ -53,11 +55,11 @@ describe ThinkingSphinx::Deltas do
|
|
|
53
55
|
#
|
|
54
56
|
end
|
|
55
57
|
|
|
56
|
-
ThinkingSphinx::Deltas.
|
|
58
|
+
expect(ThinkingSphinx::Deltas).not_to be_suspended
|
|
57
59
|
end
|
|
58
60
|
|
|
59
61
|
it "processes the delta indices for the given reference" do
|
|
60
|
-
processor.
|
|
62
|
+
expect(processor).to receive(:index).with(delta_index)
|
|
61
63
|
|
|
62
64
|
ThinkingSphinx::Deltas.suspend :user do
|
|
63
65
|
#
|
|
@@ -65,7 +67,7 @@ describe ThinkingSphinx::Deltas do
|
|
|
65
67
|
end
|
|
66
68
|
|
|
67
69
|
it "does not process the core indices for the given reference" do
|
|
68
|
-
processor.
|
|
70
|
+
expect(processor).not_to receive(:index).with(core_index)
|
|
69
71
|
|
|
70
72
|
ThinkingSphinx::Deltas.suspend :user do
|
|
71
73
|
#
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::SphinxError do
|
|
@@ -6,66 +8,96 @@ describe ThinkingSphinx::SphinxError do
|
|
|
6
8
|
:backtrace => ['foo', 'bar'] }
|
|
7
9
|
|
|
8
10
|
it "translates syntax errors" do
|
|
9
|
-
error.
|
|
11
|
+
allow(error).to receive_messages :message => 'index foo: syntax error: something is wrong'
|
|
10
12
|
|
|
11
|
-
ThinkingSphinx::SphinxError.new_from_mysql(error).
|
|
12
|
-
|
|
13
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
|
|
14
|
+
to be_a(ThinkingSphinx::SyntaxError)
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
it "translates parse errors" do
|
|
16
|
-
error.
|
|
18
|
+
allow(error).to receive_messages :message => 'index foo: parse error: something is wrong'
|
|
19
|
+
|
|
20
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
|
|
21
|
+
to be_a(ThinkingSphinx::ParseError)
|
|
22
|
+
end
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
it "translates 'query is non-computable' errors" do
|
|
25
|
+
allow(error).to receive_messages :message => 'index model_core: query is non-computable (single NOT operator)'
|
|
26
|
+
|
|
27
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
|
|
28
|
+
to be_a(ThinkingSphinx::ParseError)
|
|
20
29
|
end
|
|
21
30
|
|
|
22
31
|
it "translates query errors" do
|
|
23
|
-
error.
|
|
32
|
+
allow(error).to receive_messages :message => 'index foo: query error: something is wrong'
|
|
24
33
|
|
|
25
|
-
ThinkingSphinx::SphinxError.new_from_mysql(error).
|
|
26
|
-
|
|
34
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
|
|
35
|
+
to be_a(ThinkingSphinx::QueryError)
|
|
27
36
|
end
|
|
28
37
|
|
|
29
38
|
it "translates connection errors" do
|
|
30
|
-
error.
|
|
39
|
+
allow(error).to receive_messages :message => "Can't connect to MySQL server on '127.0.0.1' (61)"
|
|
40
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
|
|
41
|
+
to be_a(ThinkingSphinx::ConnectionError)
|
|
42
|
+
|
|
43
|
+
allow(error).to receive_messages :message => "Communications link failure"
|
|
44
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
|
|
45
|
+
to be_a(ThinkingSphinx::ConnectionError)
|
|
46
|
+
|
|
47
|
+
allow(error).to receive_messages :message => "Lost connection to MySQL server"
|
|
48
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
|
|
49
|
+
to be_a(ThinkingSphinx::ConnectionError)
|
|
50
|
+
|
|
51
|
+
# MariaDB has removed mention of MySQL in error messages:
|
|
52
|
+
allow(error).to receive_messages :message => "Can't connect to server on '127.0.0.1' (61)"
|
|
53
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
|
|
54
|
+
to be_a(ThinkingSphinx::ConnectionError)
|
|
55
|
+
|
|
56
|
+
allow(error).to receive_messages :message => "Lost connection to server"
|
|
57
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
|
|
58
|
+
to be_a(ThinkingSphinx::ConnectionError)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'translates out-of-bounds errors' do
|
|
62
|
+
allow(error).to receive_messages :message => "offset out of bounds (offset=1001, max_matches=1000)"
|
|
31
63
|
|
|
32
|
-
ThinkingSphinx::SphinxError.new_from_mysql(error).
|
|
33
|
-
|
|
64
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
|
|
65
|
+
to be_a(ThinkingSphinx::OutOfBoundsError)
|
|
34
66
|
end
|
|
35
67
|
|
|
36
68
|
it 'prefixes the connection error message' do
|
|
37
|
-
error.
|
|
69
|
+
allow(error).to receive_messages :message => "Can't connect to MySQL server on '127.0.0.1' (61)"
|
|
38
70
|
|
|
39
|
-
ThinkingSphinx::SphinxError.new_from_mysql(error).message.
|
|
40
|
-
|
|
71
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error).message).
|
|
72
|
+
to eq("Error connecting to Sphinx via the MySQL protocol. Can't connect to MySQL server on '127.0.0.1' (61)")
|
|
41
73
|
end
|
|
42
74
|
|
|
43
75
|
it "translates jdbc connection errors" do
|
|
44
|
-
error.
|
|
76
|
+
allow(error).to receive_messages :message => "Communications link failure"
|
|
45
77
|
|
|
46
|
-
ThinkingSphinx::SphinxError.new_from_mysql(error).
|
|
47
|
-
|
|
78
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
|
|
79
|
+
to be_a(ThinkingSphinx::ConnectionError)
|
|
48
80
|
end
|
|
49
81
|
|
|
50
82
|
it 'prefixes the jdbc connection error message' do
|
|
51
|
-
error.
|
|
83
|
+
allow(error).to receive_messages :message => "Communications link failure"
|
|
52
84
|
|
|
53
|
-
ThinkingSphinx::SphinxError.new_from_mysql(error).message.
|
|
54
|
-
|
|
85
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error).message).
|
|
86
|
+
to eq("Error connecting to Sphinx via the MySQL protocol. Communications link failure")
|
|
55
87
|
end
|
|
56
88
|
|
|
57
89
|
it "defaults to sphinx errors" do
|
|
58
|
-
error.
|
|
90
|
+
allow(error).to receive_messages :message => 'index foo: unknown error: something is wrong'
|
|
59
91
|
|
|
60
|
-
ThinkingSphinx::SphinxError.new_from_mysql(error).
|
|
61
|
-
|
|
92
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error)).
|
|
93
|
+
to be_a(ThinkingSphinx::SphinxError)
|
|
62
94
|
end
|
|
63
95
|
|
|
64
96
|
it "keeps the original error's backtrace" do
|
|
65
|
-
error.
|
|
97
|
+
allow(error).to receive_messages :message => 'index foo: unknown error: something is wrong'
|
|
66
98
|
|
|
67
|
-
ThinkingSphinx::SphinxError.new_from_mysql(error).
|
|
68
|
-
backtrace.
|
|
99
|
+
expect(ThinkingSphinx::SphinxError.new_from_mysql(error).
|
|
100
|
+
backtrace).to eq(error.backtrace)
|
|
69
101
|
end
|
|
70
102
|
end
|
|
71
103
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe ThinkingSphinx::Excerpter do
|
|
@@ -7,13 +9,13 @@ describe ThinkingSphinx::Excerpter do
|
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
before :each do
|
|
10
|
-
ThinkingSphinx::Connection.
|
|
11
|
-
Riddle::Query.
|
|
12
|
+
allow(ThinkingSphinx::Connection).to receive(:take).and_yield(connection)
|
|
13
|
+
allow(Riddle::Query).to receive_messages :snippets => 'CALL SNIPPETS'
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
describe '#excerpt!' do
|
|
15
17
|
it "generates a snippets call" do
|
|
16
|
-
Riddle::Query.
|
|
18
|
+
expect(Riddle::Query).to receive(:snippets).
|
|
17
19
|
with('all of the words', 'index', 'all words',
|
|
18
20
|
ThinkingSphinx::Excerpter::DefaultOptions).
|
|
19
21
|
and_return('CALL SNIPPETS')
|
|
@@ -25,26 +27,27 @@ describe ThinkingSphinx::Excerpter do
|
|
|
25
27
|
excerpter = ThinkingSphinx::Excerpter.new('index', 'all words',
|
|
26
28
|
:before_match => '<b>', :chunk_separator => ' -- ')
|
|
27
29
|
|
|
28
|
-
Riddle::Query.
|
|
29
|
-
with('all of the words', 'index', 'all words',
|
|
30
|
+
expect(Riddle::Query).to receive(:snippets).
|
|
31
|
+
with('all of the words', 'index', 'all words', {
|
|
30
32
|
:before_match => '<b>', :after_match => '</span>',
|
|
31
|
-
:chunk_separator => ' -- '
|
|
33
|
+
:chunk_separator => ' -- '
|
|
34
|
+
}).
|
|
32
35
|
and_return('CALL SNIPPETS')
|
|
33
36
|
|
|
34
37
|
excerpter.excerpt!('all of the words')
|
|
35
38
|
end
|
|
36
39
|
|
|
37
40
|
it "sends the snippets call to Sphinx" do
|
|
38
|
-
connection.
|
|
41
|
+
expect(connection).to receive(:execute).with('CALL SNIPPETS').
|
|
39
42
|
and_return([{'snippet' => ''}])
|
|
40
43
|
|
|
41
44
|
excerpter.excerpt!('all of the words')
|
|
42
45
|
end
|
|
43
46
|
|
|
44
47
|
it "returns the first value returned by Sphinx" do
|
|
45
|
-
connection.
|
|
48
|
+
allow(connection).to receive_messages :execute => [{'snippet' => 'some highlighted words'}]
|
|
46
49
|
|
|
47
|
-
excerpter.excerpt!('all of the words').
|
|
50
|
+
expect(excerpter.excerpt!('all of the words')).to eq('some highlighted words')
|
|
48
51
|
end
|
|
49
52
|
end
|
|
50
53
|
end
|