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
data/Gemfile
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
source 'https://rubygems.org'
|
|
2
4
|
|
|
3
5
|
gemspec
|
|
4
6
|
|
|
5
|
-
gem '
|
|
6
|
-
gem '
|
|
7
|
+
gem 'logger'
|
|
8
|
+
gem 'mysql2', '~> 0.5.0', :platform => :ruby
|
|
9
|
+
gem 'pg', '~> 0.18.4', :platform => :ruby
|
|
10
|
+
|
|
11
|
+
gem 'activerecord', '< 7' if RUBY_VERSION.to_f <= 2.4
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
gem '
|
|
13
|
+
if RUBY_PLATFORM == 'java'
|
|
14
|
+
gem 'jdbc-mysql', '5.1.35', :platform => :jruby
|
|
15
|
+
gem 'activerecord-jdbcmysql-adapter', '>= 1.3.23', :platform => :jruby
|
|
16
|
+
gem 'activerecord-jdbcpostgresql-adapter', '>= 1.3.23', :platform => :jruby
|
|
17
|
+
gem 'activerecord', '>= 3.2.22'
|
|
18
|
+
end
|
data/Procfile.support
ADDED
data/README.textile
CHANGED
|
@@ -1,59 +1,73 @@
|
|
|
1
1
|
h1. Thinking Sphinx
|
|
2
2
|
|
|
3
|
-
Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is
|
|
3
|
+
Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is v6.0.0.
|
|
4
4
|
|
|
5
5
|
h2. Upgrading
|
|
6
6
|
|
|
7
|
-
Please refer to the release notes for any changes you need to make when upgrading
|
|
7
|
+
Please refer to "the changelog":https://github.com/pat/thinking-sphinx/blob/develop/CHANGELOG.markdown and "release notes":https://github.com/pat/thinking-sphinx/releases for any changes you need to make when upgrading. The release notes in particular are quite good at covering breaking changes and more details for new features.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
* "v3.1.3":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.3
|
|
11
|
-
* "v3.1.2":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.2
|
|
12
|
-
* "v3.1.1":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.1
|
|
13
|
-
* "v3.1.0":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.0
|
|
14
|
-
* "v3.0.6":https://github.com/pat/thinking-sphinx/releases/tag/v3.0.6
|
|
15
|
-
|
|
16
|
-
If you're upgrading from pre-v3, then the documentation has "pretty extensive notes":http://pat.github.io/thinking-sphinx/upgrading.html on what's changed.
|
|
9
|
+
The documentation also has more details on what's involved for upgrading from "v4 to v5":https://freelancing-gods.com/thinking-sphinx/v5/upgrading.html, "v3 to v4":https://freelancing-gods.com/thinking-sphinx/v4/upgrading.html, and "v1/v2 to v3":https://freelancing-gods.com/thinking-sphinx/v3/upgrading.html.
|
|
17
10
|
|
|
18
11
|
h2. Installation
|
|
19
12
|
|
|
20
13
|
It's a gem, so install it like you would any other gem. You will also need to specify the mysql2 gem if you're using MRI, or jdbc-mysql if you're using JRuby:
|
|
21
14
|
|
|
22
|
-
<pre><code>gem 'mysql2', '~> 0.
|
|
15
|
+
<pre><code>gem 'mysql2', '~> 0.4', :platform => :ruby
|
|
23
16
|
gem 'jdbc-mysql', '~> 5.1.35', :platform => :jruby
|
|
24
|
-
gem 'thinking-sphinx', '~>
|
|
17
|
+
gem 'thinking-sphinx', '~> 6.0'</code></pre>
|
|
25
18
|
|
|
26
19
|
The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.
|
|
27
20
|
|
|
28
|
-
You'll also need to install Sphinx - this is covered in "the extended documentation":
|
|
21
|
+
You'll also need to install Sphinx - this is covered in "the extended documentation":https://freelancing-gods.com/thinking-sphinx/installing_sphinx.html.
|
|
29
22
|
|
|
30
23
|
h2. Usage
|
|
31
24
|
|
|
32
|
-
Begin by reading the "quick-start guide":
|
|
25
|
+
Begin by reading the "quick-start guide":https://freelancing-gods.com/thinking-sphinx/quickstart.html, and beyond that, "the documentation":https://freelancing-gods.com/thinking-sphinx/ should serve you pretty well.
|
|
26
|
+
|
|
27
|
+
h2. Requirements
|
|
33
28
|
|
|
34
|
-
|
|
29
|
+
The current release of Thinking Sphinx works with the following versions of its dependencies:
|
|
35
30
|
|
|
36
|
-
|
|
31
|
+
|_. Library |_. Minimum |_. Tested Against |
|
|
32
|
+
| Ruby | v3.0 | v3.0..v4.0 |
|
|
33
|
+
| Sphinx | v2.2.11 | v2.2.11, v3.4.1 |
|
|
34
|
+
| Manticore | v2.8 | v4.0, v6.0 |
|
|
35
|
+
| ActiveRecord | v6.1 | v6.1..v8.1 |
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
It _might_ work with older versions of Ruby (back to v2.7) and Rails (back to v5.0), but it's highly recommended to update to a supported release.
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
It should also work with JRuby, but the test environment for that in CI has been unreliable, hence that's not actively tested against at the moment.
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
h3. Sphinx or Manticore
|
|
42
|
+
|
|
43
|
+
If you're using Sphinx, v2.2.11 is recommended even though it's quite old, as it works well with PostgreSQL databases (but if you're using MySQL - or real-time indices - then v3.3.1 should also be fine).
|
|
44
|
+
|
|
45
|
+
If you're opting for Manticore instead, v2.8 or newer works, but v4 or newer is recommended as that's what is actively tested against. The v4.2 and 5.0 releases had bugs with facet searching, but that's been fixed in Manticore v6.0.
|
|
43
46
|
|
|
44
47
|
h3. Rails and ActiveRecord
|
|
45
48
|
|
|
46
|
-
Currently Thinking Sphinx
|
|
49
|
+
Currently Thinking Sphinx is built to support Rails/ActiveRecord 6.1 or newer. If you're using Sinatra and ActiveRecord instead of Rails, that's fine - just make sure you add the @:require => 'thinking_sphinx/sinatra'@ option when listing @thinking-sphinx@ in your Gemfile.
|
|
47
50
|
|
|
48
|
-
|
|
51
|
+
The last releases for older Rails versions:
|
|
49
52
|
|
|
50
|
-
|
|
53
|
+
|_. Rails Version |_. Thinking Sphinx Version |
|
|
54
|
+
| 6.0 | v5.6.0 |
|
|
55
|
+
| 5.2 | v5.6.0 |
|
|
56
|
+
| 5.1 | v5.6.0 |
|
|
57
|
+
| 5.0 | v5.6.0 |
|
|
58
|
+
| 4.2 | v5.6.0 |
|
|
59
|
+
| 4.1 | v4.4.1 |
|
|
60
|
+
| 4.0 | v4.4.1 |
|
|
61
|
+
| 3.2 | v4.4.1 |
|
|
62
|
+
| 3.1 | v3.0.6 |
|
|
63
|
+
| 3.0 | v2.1.0 |
|
|
64
|
+
| 2.3 | v1.5.0 |
|
|
51
65
|
|
|
52
|
-
|
|
66
|
+
Please note that these older versions are no longer actively supported.
|
|
53
67
|
|
|
54
|
-
|
|
68
|
+
h3. Ruby
|
|
55
69
|
|
|
56
|
-
|
|
70
|
+
You'll need either the standard Ruby (v3.0 or newer) or JRuby (9.1 or newer). The last release to support Ruby 2.4-2.7 is v5.6.0.
|
|
57
71
|
|
|
58
72
|
h3. Database Versions
|
|
59
73
|
|
|
@@ -61,7 +75,7 @@ MySQL 5.x and Postgres 8.4 or better are supported.
|
|
|
61
75
|
|
|
62
76
|
h2. Contributing
|
|
63
77
|
|
|
64
|
-
Please note that this project
|
|
78
|
+
Please note that this project has a "Contributor Code of Conduct":http://contributor-covenant.org/version/1/0/0/. By participating in this project you agree to abide by its terms.
|
|
65
79
|
|
|
66
80
|
To contribute, clone this repository and have a good look through the specs - you'll notice the distinction between acceptance tests that actually use Sphinx and go through the full stack, and unit tests (everything else) which use liberal test doubles to ensure they're only testing the behaviour of the class in question. I've found this leads to far better code design.
|
|
67
81
|
|
|
@@ -82,4 +96,4 @@ You can then run the unit tests with @rake spec:unit@, the acceptance tests with
|
|
|
82
96
|
|
|
83
97
|
h2. Licence
|
|
84
98
|
|
|
85
|
-
Copyright (c) 2007-
|
|
99
|
+
Copyright (c) 2007-2026, Thinking Sphinx is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to "all who have contributed patches":https://github.com/pat/thinking-sphinx/contributors.
|
data/Rakefile
CHANGED
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#! /usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "thinking_sphinx"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require "irb"
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/loadsphinx
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
version=$1
|
|
4
|
+
engine=$2
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
load_sphinx () {
|
|
9
|
+
distro="xenial"
|
|
10
|
+
|
|
11
|
+
case $version in
|
|
12
|
+
2.1.9)
|
|
13
|
+
url="http://sphinxsearch.com/files/sphinxsearch_2.1.9-release-0ubuntu11~trusty_amd64.deb"
|
|
14
|
+
format="deb"
|
|
15
|
+
distro="trusty";;
|
|
16
|
+
2.2.11)
|
|
17
|
+
url="http://sphinxsearch.com/files/sphinxsearch_2.2.11-release-1~jessie_amd64.deb"
|
|
18
|
+
format="deb"
|
|
19
|
+
distro="trusty";;
|
|
20
|
+
3.0.3)
|
|
21
|
+
url="http://sphinxsearch.com/files/sphinx-3.0.3-facc3fb-linux-amd64.tar.gz"
|
|
22
|
+
format="gz";;
|
|
23
|
+
3.1.1)
|
|
24
|
+
url="http://sphinxsearch.com/files/sphinx-3.1.1-612d99f-linux-amd64.tar.gz"
|
|
25
|
+
format="gz";;
|
|
26
|
+
3.2.1)
|
|
27
|
+
url="http://sphinxsearch.com/files/sphinx-3.2.1-f152e0b-linux-amd64.tar.gz"
|
|
28
|
+
format="gz";;
|
|
29
|
+
3.3.1)
|
|
30
|
+
url="http://sphinxsearch.com/files/sphinx-3.3.1-b72d67b-linux-amd64.tar.gz"
|
|
31
|
+
format="gz";;
|
|
32
|
+
3.4.1)
|
|
33
|
+
url="http://sphinxsearch.com/files/sphinx-3.4.1-efbcc65-linux-amd64.tar.gz"
|
|
34
|
+
format="gz";;
|
|
35
|
+
*)
|
|
36
|
+
echo "No Sphinx version $version available"
|
|
37
|
+
exit 1;;
|
|
38
|
+
esac
|
|
39
|
+
|
|
40
|
+
if [ "$distro" == "trusty" ]; then
|
|
41
|
+
curl --location http://launchpadlibrarian.net/247512886/libmysqlclient18_5.6.28-1ubuntu3_amd64.deb -o libmysql.deb
|
|
42
|
+
sudo apt-get install ./libmysql.deb
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
if [ "$format" == "deb" ]; then
|
|
46
|
+
curl --location $url -o sphinx.deb
|
|
47
|
+
sudo apt-get install libodbc1
|
|
48
|
+
sudo dpkg -i ./sphinx.deb
|
|
49
|
+
sudo apt-get install -f
|
|
50
|
+
else
|
|
51
|
+
curl $url -o sphinx.tar.gz
|
|
52
|
+
tar -zxvf sphinx.tar.gz
|
|
53
|
+
sudo mv sphinx-$version/bin/* /usr/local/bin/.
|
|
54
|
+
fi
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
load_manticore () {
|
|
58
|
+
url="https://github.com/manticoresoftware/manticore/releases/download/$version/manticore_$version.deb"
|
|
59
|
+
|
|
60
|
+
case $version in
|
|
61
|
+
2.6.4)
|
|
62
|
+
url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.6.4/manticore_2.6.4-180503-37308c3-release-stemmer.xenial_amd64-bin.deb";;
|
|
63
|
+
2.7.5)
|
|
64
|
+
url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.7.5/manticore_2.7.5-181204-4a31c54-release-stemmer.xenial_amd64-bin.deb";;
|
|
65
|
+
2.8.2)
|
|
66
|
+
url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.8.2/manticore_2.8.2-190402-4e81114d-release-stemmer.stretch_amd64-bin.deb";;
|
|
67
|
+
3.4.2)
|
|
68
|
+
url="https://github.com/manticoresoftware/manticoresearch/releases/download/3.4.2/manticore_3.4.2-200410-6903305-release.xenial_amd64-bin.deb";;
|
|
69
|
+
3.5.4)
|
|
70
|
+
url="https://repo.manticoresearch.com/repository/manticoresearch_focal/dists/focal/main/binary-amd64/manticore_3.5.4-210107-f70faec5_amd64.deb";;
|
|
71
|
+
4.0.2)
|
|
72
|
+
url="https://repo.manticoresearch.com/repository/manticoresearch_focal/dists/focal/main/binary-amd64/manticore_4.0.2-210921-af497f245_amd64.deb";;
|
|
73
|
+
4.2.0)
|
|
74
|
+
url="https://repo.manticoresearch.com/repository/manticoresearch_focal/dists/focal/main/binary-amd64/manticore_4.2.0-211223-15e927b28_amd64.deb";;
|
|
75
|
+
6.0.0)
|
|
76
|
+
url="skipped";;
|
|
77
|
+
*)
|
|
78
|
+
echo "No Manticore version $version available"
|
|
79
|
+
exit 1;;
|
|
80
|
+
esac
|
|
81
|
+
|
|
82
|
+
if [ "$version" == "6.0.0" ]; then
|
|
83
|
+
curl --location https://repo.manticoresearch.com/manticore-repo.noarch.deb -o repo.deb
|
|
84
|
+
sudo dpkg -i repo.deb
|
|
85
|
+
sudo apt update
|
|
86
|
+
sudo apt install manticore
|
|
87
|
+
else
|
|
88
|
+
sudo apt-get install default-libmysqlclient-dev
|
|
89
|
+
curl --location $url -o manticore.deb
|
|
90
|
+
sudo dpkg -i ./manticore.deb
|
|
91
|
+
sudo apt-get install -f
|
|
92
|
+
fi
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if [ "$engine" == "sphinx" ]; then
|
|
96
|
+
load_sphinx
|
|
97
|
+
else
|
|
98
|
+
load_manticore
|
|
99
|
+
fi
|
data/bin/testmatrix
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#! /usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
RUBIES = %w[ 3.0 3.1 3.2 3.3 3.4 4.0 ]
|
|
7
|
+
DATABASES = %w[ mysql2 postgresql ]
|
|
8
|
+
SPHINX_ENGINES = {
|
|
9
|
+
"sphinx" => %w[ 2.2.11 3.4.1 ],
|
|
10
|
+
"manticore" => %w[ 4.0.2 6.0.0 ]
|
|
11
|
+
}.freeze
|
|
12
|
+
RAILS_VERSIONS = [
|
|
13
|
+
{ version: '6_1', min_ruby: 2.7, max_ruby: 3.3 },
|
|
14
|
+
{ version: '7_0', min_ruby: 2.7, max_ruby: 4.0 },
|
|
15
|
+
{ version: '7_1', min_ruby: 2.7, max_ruby: 4.0 },
|
|
16
|
+
{ version: '7_2', min_ruby: 3.1, max_ruby: 4.0 },
|
|
17
|
+
{ version: '8_0', min_ruby: 3.2, max_ruby: 4.0 },
|
|
18
|
+
{ version: '8_1', min_ruby: 3.2, max_ruby: 4.0 },
|
|
19
|
+
].freeze
|
|
20
|
+
|
|
21
|
+
# Returns an array of hashes, with each hash being a valid testable
|
|
22
|
+
# combination:
|
|
23
|
+
output = []
|
|
24
|
+
|
|
25
|
+
RUBIES.each do |ruby|
|
|
26
|
+
DATABASES.each do |database|
|
|
27
|
+
SPHINX_ENGINES.each do |sphinx_engine, sphinx_versions|
|
|
28
|
+
sphinx_versions.each do |sphinx_version|
|
|
29
|
+
# Sphinx 3.4.1 doesn't play nicely with Postgres.
|
|
30
|
+
next if database == 'postgresql' && sphinx_engine == 'sphinx' && sphinx_version == '3.4.1'
|
|
31
|
+
|
|
32
|
+
RAILS_VERSIONS.each do |rails|
|
|
33
|
+
next unless ruby.to_f >= rails[:min_ruby] && ruby.to_f <= rails[:max_ruby]
|
|
34
|
+
|
|
35
|
+
output << {
|
|
36
|
+
ruby: ruby,
|
|
37
|
+
rails: rails[:version],
|
|
38
|
+
database: database,
|
|
39
|
+
sphinx_engine: sphinx_engine,
|
|
40
|
+
sphinx_version: sphinx_version
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
puts JSON.generate(output.compact)
|
data/lib/thinking/sphinx.rb
CHANGED
data/lib/thinking-sphinx.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeFinder
|
|
2
4
|
def initialize(association)
|
|
3
5
|
@association = association
|
|
@@ -29,7 +31,7 @@ class ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeFinder
|
|
|
29
31
|
@indices ||= begin
|
|
30
32
|
configuration.preload_indices
|
|
31
33
|
configuration.indices_for_references(
|
|
32
|
-
|
|
34
|
+
*configuration.index_set_class.reference_name(@association.klass)
|
|
33
35
|
).reject &:distributed?
|
|
34
36
|
end
|
|
35
37
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
extend ActiveSupport::Concern
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
3
|
+
module ThinkingSphinx::ActiveRecord::AssociationProxy
|
|
4
4
|
def search(query = nil, options = {})
|
|
5
5
|
perform_search super(*normalise_search_arguments(query, options))
|
|
6
6
|
end
|
|
@@ -10,6 +10,7 @@ module ThinkingSphinx::ActiveRecord::AssociationProxy
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
private
|
|
13
|
+
|
|
13
14
|
def normalise_search_arguments(query, options)
|
|
14
15
|
query, options = nil, query if query.is_a?(Hash)
|
|
15
16
|
options[:ignore_scopes] = true
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class ThinkingSphinx::ActiveRecord::Attribute::SphinxPresenter
|
|
2
4
|
SPHINX_TYPES = {
|
|
3
5
|
:integer => :uint,
|
|
4
6
|
:boolean => :bool,
|
|
5
|
-
:timestamp => :
|
|
7
|
+
:timestamp => :uint,
|
|
6
8
|
:float => :float,
|
|
7
9
|
:string => :string,
|
|
8
10
|
:bigint => :bigint,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class ThinkingSphinx::ActiveRecord::Attribute::Type
|
|
2
4
|
UPDATEABLE_TYPES = [:integer, :timestamp, :boolean, :float]
|
|
3
5
|
|
|
@@ -41,7 +43,7 @@ class ThinkingSphinx::ActiveRecord::Attribute::Type
|
|
|
41
43
|
end
|
|
42
44
|
|
|
43
45
|
def big_integer?
|
|
44
|
-
|
|
46
|
+
type_symbol == :integer && database_column.sql_type[/bigint/i]
|
|
45
47
|
end
|
|
46
48
|
|
|
47
49
|
def column_name
|
|
@@ -72,19 +74,33 @@ class ThinkingSphinx::ActiveRecord::Attribute::Type
|
|
|
72
74
|
|
|
73
75
|
def type_from_database
|
|
74
76
|
raise ThinkingSphinx::MissingColumnError,
|
|
75
|
-
"column #{column_name} does not exist" if database_column.nil?
|
|
77
|
+
"Cannot determine the database type of column #{column_name}, as it does not exist" if database_column.nil?
|
|
76
78
|
|
|
77
79
|
return :bigint if big_integer?
|
|
78
80
|
|
|
79
|
-
case
|
|
81
|
+
case type_symbol
|
|
80
82
|
when :datetime, :date
|
|
81
83
|
:timestamp
|
|
82
84
|
when :text
|
|
83
85
|
:string
|
|
84
86
|
when :decimal
|
|
85
87
|
:float
|
|
88
|
+
when :integer, :boolean, :timestamp, :float, :string, :bigint, :json
|
|
89
|
+
type_symbol
|
|
86
90
|
else
|
|
87
|
-
|
|
91
|
+
raise ThinkingSphinx::UnknownAttributeType,
|
|
92
|
+
<<-ERROR
|
|
93
|
+
Unable to determine an equivalent Sphinx attribute type from #{database_column.type.class.name} for attribute #{attribute.name}. You may want to manually set the type.
|
|
94
|
+
|
|
95
|
+
e.g.
|
|
96
|
+
has my_column, :type => :integer
|
|
97
|
+
ERROR
|
|
88
98
|
end
|
|
89
99
|
end
|
|
100
|
+
|
|
101
|
+
def type_symbol
|
|
102
|
+
return database_column.type if database_column.type.is_a?(Symbol)
|
|
103
|
+
|
|
104
|
+
database_column.type.class.name.demodulize.downcase.to_sym
|
|
105
|
+
end
|
|
90
106
|
end
|
|
@@ -1,35 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ThinkingSphinx::ActiveRecord::Base
|
|
2
4
|
extend ActiveSupport::Concern
|
|
3
5
|
|
|
4
6
|
included do
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
# Avoid method collisions for public Thinking Sphinx methods added to all
|
|
8
|
+
# ActiveRecord models. The `sphinx_`-prefixed versions will always exist,
|
|
9
|
+
# and the non-prefixed versions will be added if a method of that name
|
|
10
|
+
# doesn't already exist.
|
|
11
|
+
#
|
|
12
|
+
# If a method is overwritten later by something else, that's also fine - the
|
|
13
|
+
# prefixed versions will still be there.
|
|
14
|
+
class_module = ThinkingSphinx::ActiveRecord::Base::ClassMethods
|
|
15
|
+
class_module.public_instance_methods.each do |method_name|
|
|
16
|
+
short_method = method_name.to_s.delete_prefix("sphinx_").to_sym
|
|
17
|
+
next if methods.include?(short_method)
|
|
18
|
+
|
|
19
|
+
define_singleton_method(short_method, method(method_name))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
if ActiveRecord::VERSION::STRING.to_i >= 5
|
|
23
|
+
[
|
|
24
|
+
::ActiveRecord::Reflection::HasManyReflection,
|
|
25
|
+
::ActiveRecord::Reflection::HasAndBelongsToManyReflection
|
|
26
|
+
].each do |reflection_class|
|
|
27
|
+
reflection_class.include DefaultReflectionAssociations
|
|
28
|
+
end
|
|
29
|
+
else
|
|
30
|
+
::ActiveRecord::Associations::CollectionProxy.include(
|
|
31
|
+
ThinkingSphinx::ActiveRecord::AssociationProxy
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
9
35
|
|
|
10
|
-
|
|
11
|
-
|
|
36
|
+
module DefaultReflectionAssociations
|
|
37
|
+
def extensions
|
|
38
|
+
super + [ThinkingSphinx::ActiveRecord::AssociationProxy]
|
|
39
|
+
end
|
|
12
40
|
end
|
|
13
41
|
|
|
14
42
|
module ClassMethods
|
|
15
|
-
def
|
|
43
|
+
def sphinx_facets(query = nil, options = {})
|
|
16
44
|
merge_search ThinkingSphinx.facets, query, options
|
|
17
45
|
end
|
|
18
46
|
|
|
19
|
-
def
|
|
47
|
+
def sphinx_search(query = nil, options = {})
|
|
20
48
|
merge_search ThinkingSphinx.search, query, options
|
|
21
49
|
end
|
|
22
50
|
|
|
23
|
-
def
|
|
24
|
-
|
|
51
|
+
def sphinx_search_count(query = nil, options = {})
|
|
52
|
+
search_for_ids(query, options).total_entries
|
|
25
53
|
end
|
|
26
54
|
|
|
27
|
-
def
|
|
55
|
+
def sphinx_search_for_ids(query = nil, options = {})
|
|
28
56
|
ThinkingSphinx::Search::Merger.new(
|
|
29
57
|
search(query, options)
|
|
30
58
|
).merge! nil, :ids_only => true
|
|
31
59
|
end
|
|
32
60
|
|
|
61
|
+
def sphinx_search_none
|
|
62
|
+
merge_search ThinkingSphinx.search, nil, none: true
|
|
63
|
+
end
|
|
64
|
+
|
|
33
65
|
private
|
|
34
66
|
|
|
35
67
|
def default_sphinx_scope?
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class ThinkingSphinx::ActiveRecord::Callbacks::AssociationDeltaCallbacks
|
|
4
|
+
def initialize(path)
|
|
5
|
+
@path = path
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def after_commit(instance)
|
|
9
|
+
Array(objects_for(instance)).each do |object|
|
|
10
|
+
object.update :delta => true unless object.frozen?
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
attr_reader :path
|
|
17
|
+
|
|
18
|
+
def objects_for(instance)
|
|
19
|
+
path.inject(instance) { |object, method| object.send method }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -1,21 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks <
|
|
2
4
|
ThinkingSphinx::Callbacks
|
|
3
5
|
|
|
4
|
-
callbacks :after_destroy
|
|
6
|
+
callbacks :after_commit, :after_destroy, :after_rollback
|
|
7
|
+
|
|
8
|
+
def after_commit
|
|
9
|
+
delete_from_sphinx
|
|
10
|
+
end
|
|
5
11
|
|
|
6
12
|
def after_destroy
|
|
7
|
-
|
|
13
|
+
delete_from_sphinx
|
|
14
|
+
end
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
16
|
+
def after_rollback
|
|
17
|
+
delete_from_sphinx
|
|
12
18
|
end
|
|
13
19
|
|
|
14
20
|
private
|
|
15
21
|
|
|
16
|
-
def
|
|
17
|
-
ThinkingSphinx::
|
|
18
|
-
|
|
19
|
-
).
|
|
22
|
+
def delete_from_sphinx
|
|
23
|
+
return if ThinkingSphinx::Callbacks.suspended?
|
|
24
|
+
|
|
25
|
+
ThinkingSphinx::Processor.new(instance: instance).delete
|
|
20
26
|
end
|
|
21
27
|
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
|
|
2
4
|
ThinkingSphinx::Callbacks
|
|
3
5
|
|
|
4
6
|
callbacks :after_commit, :before_save
|
|
5
7
|
|
|
6
8
|
def after_commit
|
|
7
|
-
return unless
|
|
8
|
-
processor.toggled?(instance)
|
|
9
|
-
} && !ThinkingSphinx::Deltas.suspended?
|
|
9
|
+
return unless !suspended? && delta_indices? && toggled?
|
|
10
10
|
|
|
11
11
|
delta_indices.each do |index|
|
|
12
12
|
index.delta_processor.index index
|
|
@@ -18,7 +18,8 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def before_save
|
|
21
|
-
return unless delta_indices?
|
|
21
|
+
return unless !ThinkingSphinx::Callbacks.suspended? && delta_indices? &&
|
|
22
|
+
new_or_changed?
|
|
22
23
|
|
|
23
24
|
processors.each { |processor| processor.toggle instance }
|
|
24
25
|
end
|
|
@@ -42,10 +43,24 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
|
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
def indices
|
|
45
|
-
@indices ||= config.index_set_class.new
|
|
46
|
+
@indices ||= config.index_set_class.new(
|
|
47
|
+
:instances => [instance], :classes => [instance.class]
|
|
48
|
+
).select { |index| index.type == "plain" }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def new_or_changed?
|
|
52
|
+
instance.new_record? || instance.changed?
|
|
46
53
|
end
|
|
47
54
|
|
|
48
55
|
def processors
|
|
49
56
|
delta_indices.collect &:delta_processor
|
|
50
57
|
end
|
|
58
|
+
|
|
59
|
+
def suspended?
|
|
60
|
+
ThinkingSphinx::Callbacks.suspended? || ThinkingSphinx::Deltas.suspended?
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def toggled?
|
|
64
|
+
processors.any? { |processor| processor.toggled?(instance) }
|
|
65
|
+
end
|
|
51
66
|
end
|