diff --git a/api/Gemfile b/api/Gemfile index b166c174f1..ae9c74712b 100644 --- a/api/Gemfile +++ b/api/Gemfile @@ -45,8 +45,6 @@ gem "dry-transaction" gem "dry-types" gem "dry-validation" gem "dux", "~> 0.8.0" -gem "elasticsearch", "~> 7.0" -gem "elasticsearch-dsl", "~> 0.1.10" gem "equalizer" gem "faker", "~> 3.2.1" gem "fast_jsonapi", git: "https://github.com/ManifoldScholar/fast_jsonapi.git", branch: "master" @@ -107,7 +105,6 @@ gem "rolify", "~> 5.1" gem "rubyzip", "~> 2.3.1" gem "scanf", "~> 1.0.0" gem "scenic", "~> 1.4" -gem "searchkick", "5.2.4" gem "shrine", "~> 3.5.0" gem "shrine-google_cloud_storage", "~> 3.3" gem "shrine-tus", "~> 2.0" diff --git a/api/Gemfile.lock b/api/Gemfile.lock index 2728378bb2..b0ae1fc8bf 100644 --- a/api/Gemfile.lock +++ b/api/Gemfile.lock @@ -261,15 +261,6 @@ GEM zeitwerk (~> 2.6) dux (0.8.0) yard_types - elasticsearch (7.17.9) - elasticsearch-api (= 7.17.9) - elasticsearch-transport (= 7.17.9) - elasticsearch-api (7.17.9) - multi_json - elasticsearch-dsl (0.1.10) - elasticsearch-transport (7.17.9) - faraday (~> 1) - multi_json equalizer (0.0.11) errbase (0.2.2) erubi (1.12.0) @@ -671,9 +662,6 @@ GEM scenic (1.7.0) activerecord (>= 4.0.0) railties (>= 4.0.0) - searchkick (5.2.4) - activemodel (>= 5.2) - hashie shrine (3.5.0) content_disposition (~> 1.0) down (~> 5.1) @@ -851,8 +839,6 @@ DEPENDENCIES dry-types dry-validation dux (~> 0.8.0) - elasticsearch (~> 7.0) - elasticsearch-dsl (~> 0.1.10) equalizer factory_bot_rails (~> 6.2) faker (~> 3.2.1) @@ -928,7 +914,6 @@ DEPENDENCIES rubyzip (~> 2.3.1) scanf (~> 1.0.0) scenic (~> 1.4) - searchkick (= 5.2.4) shrine (~> 3.5.0) shrine-google_cloud_storage (~> 3.3) shrine-tus (~> 2.0) diff --git a/api/app/services/filtering/applicator.rb b/api/app/services/filtering/applicator.rb index 8320495841..0005d1bd80 100644 --- a/api/app/services/filtering/applicator.rb +++ b/api/app/services/filtering/applicator.rb @@ -22,9 +22,7 @@ class Applicator maybe_scope_by_param: "filtering.maybe_scope_by_param", ] - define_model_callbacks :database_filters, :searchkick_filters - - around_searchkick_filters :nullify_current_scope! + define_model_callbacks :database_filters # @return [Filtering::Config] attr_reader :config @@ -46,11 +44,7 @@ def call filter_with_database! - if should_filter_with_searchkick? - @ids = @filtered_scope.distinct.reorder(nil).pluck(:id) - - filter_with_searchkick! - elsif should_apply_pagination? + if should_apply_pagination? @results = @filtered_scope.page(params[:page]).per(params[:per_page]) else @results = @filtered_scope.all @@ -79,26 +73,6 @@ def filter_with_database! @filtered_scope = filter_with_database.apply_filtering_loads end - # This will sieve the results from {#filter_with_database!} and - # check to make sure our page isn't something absurd. If the :page - # provided exceeds the total pages of search results, it will re-run - # the search with the last page instead. - # - # @note This step only runs if {#should_filter_with_searchkick?}. - # @see #exceeds_total_pages? - # @return [void] - def filter_with_searchkick! - @results = filter_with_searchkick - - return unless exceeds_total_pages?(@results) - - params[:page] = results.total_pages - - @results = filter_with_searchkick - end - - # @!endgroup - # @!group Filtering Actions # @return [ActiveRecord::Relation] @@ -108,15 +82,6 @@ def filter_with_database end end - # @return [Searchkick::Relation] - def filter_with_searchkick - run_callbacks :searchkick_filters do - apply_searchkick_filters - end - end - - # @!endgroup - # @!group Database Filtering # @return [ActiveRecord::Relation] @@ -152,26 +117,12 @@ def apply_database_filter(query, key, value) # Match a certain pattern of param keys that conform to a scope on the # model that take the provided user as their argument. # - # @param [String] key - def param_requires_user?(key) + # @param [String] , elasticsearch: true def param_requires_user?(key) key.start_with?("with_") && key.end_with?("_ability", "_role") end # @!endgroup - # @!group Searchkick Filtering - - # @return [Searchkick::Relation] - def apply_searchkick_filters - filter = Search::FilterScope.new do |f| - f.where :id, @ids - f.typeahead params[:typeahead], model::TYPEAHEAD_ATTRIBUTES - f.paginate params[:page], params[:per_page] unless skip_pagination - end - - model.lookup search_query, filter - end - # @return [ActiveRecord::Relation] def maybe_apply_default_order return yield unless should_apply_default_order? @@ -216,14 +167,6 @@ def should_apply_pagination? !skip_pagination && params[:page].present? end - def should_filter_with_searchkick? - return false unless params.key?(:keyword) - return false if has_keyword_scope? - return false unless @filtered_scope.exists? - - return true - end - # @!endgroup # @param [Searchkick::Relation] results diff --git a/api/app/services/search/advanced_dsl.rb b/api/app/services/search/advanced_dsl.rb index a2ab886dbe..7222810201 100644 --- a/api/app/services/search/advanced_dsl.rb +++ b/api/app/services/search/advanced_dsl.rb @@ -13,10 +13,6 @@ module AdvancedDSL # @see #each_analyzer_and_fuzzy_value ANALYZER_FUZZIES = ANALYZERS.product([true, false]).freeze - included do - include Elasticsearch::DSL - end - # @param [<#to_hash>] queries # @return [Hash] def extracted_bool_should(*queries) diff --git a/api/app/services/search/query.rb b/api/app/services/search/query.rb index 6dfdda5773..af3bec9aea 100644 --- a/api/app/services/search/query.rb +++ b/api/app/services/search/query.rb @@ -44,8 +44,8 @@ def perform_search # We call `#blank?` to ensure the results are eager-loaded to trigger an exception where necessary. # This is necessary because newer versions of Searchkick lazy-load the results and we want to know about them now. - Searchkick.search(searchkick_options).tap(&:blank?) - rescue Searchkick::InvalidQueryError => e + # Searchkick.search(searchkick_options).tap(&:blank?) + rescue InvalidQueryError => e raise e if raise_search_errors return empty_resultset @@ -97,7 +97,7 @@ def empty_resultset fake_options = inputs.slice(:per_page).merge(page: page_number) - Searchkick::Results.new nil, fake_response, fake_options + # Searchkick::Results.new nil, fake_response, fake_options end end end diff --git a/api/config/initializers/20_configuration.rb b/api/config/initializers/20_configuration.rb index 3c393dadd3..9f67a98be7 100644 --- a/api/config/initializers/20_configuration.rb +++ b/api/config/initializers/20_configuration.rb @@ -13,7 +13,6 @@ class ConfigMash < Hashie::Mash m.domain ||= "manifold.lvh" if Rails.env.development? || Rails.env.test? m.url ||= ENV["CLIENT_URL"] || "#{ssl_enabled ? 'https' : 'http'}://#{m.domain}" m.api_url ||= ENV["CLIENT_BROWSER_API_URL"] || m.url -m.elastic_search_url ||= ENV["ELASTICSEARCH_URL"] m.mammoth_path ||= ENV["MAMMOTH_PATH"] || Rails.root.join("..", "client/node_modules/mammoth/bin/mammoth") m.url_options = { diff --git a/api/config/initializers/30_monkeypatches.rb b/api/config/initializers/30_monkeypatches.rb index 2be1242f5e..4e327e6beb 100644 --- a/api/config/initializers/30_monkeypatches.rb +++ b/api/config/initializers/30_monkeypatches.rb @@ -1,7 +1,6 @@ require Rails.root.join("lib", "patches", "better_interactions").to_s require Rails.root.join("lib", "patches", "metadown_custom_renderer").to_s require Rails.root.join("lib", "patches", "better_enums").to_s -require Rails.root.join("lib", "patches", "elasticsearch-dsl").to_s require Rails.root.join("lib", "patches", "for_shrine").to_s require Rails.root.join("lib", "patches", "friendly_id_uniqueness").to_s require Rails.root.join("lib", "patches", "ahoy").to_s diff --git a/api/config/initializers/searchkick.rb b/api/config/initializers/searchkick.rb deleted file mode 100644 index 719aedebb8..0000000000 --- a/api/config/initializers/searchkick.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -Searchkick.search_method_name = :lookup -Searchkick.redis = ManifoldEnv.redis.build_connection_pool("searchkick") - -# We do not want searchkick to fill up sidekiq with needless retries. -Searchkick::ReindexV2Job.discard_on Searchkick::ImportError, ActiveJob::DeserializationError, ActiveRecord::RecordNotFound diff --git a/api/spec/models/event_spec.rb b/api/spec/models/event_spec.rb index a1c38fdb7f..877f3cd95e 100644 --- a/api/spec/models/event_spec.rb +++ b/api/spec/models/event_spec.rb @@ -18,7 +18,7 @@ expect(FactoryBot.create(:event)).to be_valid end - context "can be searched", :elasticsearch do + context "can be searched" do it "by title" do @event_a = FactoryBot.create(:event, subject_title: "Aquemini") diff --git a/api/spec/models/project_spec.rb b/api/spec/models/project_spec.rb index 7274c62b5a..9554c88a4e 100644 --- a/api/spec/models/project_spec.rb +++ b/api/spec/models/project_spec.rb @@ -107,7 +107,7 @@ expect(project.uncollected_resources.count).to be 2 end - context "can be searched", :elasticsearch do + context "can be searched" do it "by title" do @project_a = FactoryBot.create(:project, title: "Bartholomew Smarts", featured: true) @project_b = FactoryBot.create(:project, title: "Rambo Smarts", featured: true) diff --git a/api/spec/models/user_spec.rb b/api/spec/models/user_spec.rb index 8e2f3d7260..641d3c4764 100644 --- a/api/spec/models/user_spec.rb +++ b/api/spec/models/user_spec.rb @@ -143,7 +143,7 @@ end end - context "can be searched", :elasticsearch do + context "can be searched" do let(:first) { "189274891457612" } let(:last) { "HIOUFHAOASJDFIO" } let(:email) { "#{first}@#{last}.com" } diff --git a/api/spec/rails_helper.rb b/api/spec/rails_helper.rb index 840ab7568a..493769b251 100644 --- a/api/spec/rails_helper.rb +++ b/api/spec/rails_helper.rb @@ -209,18 +209,7 @@ /googleapis\.com/ ] - # config.around(:each, elasticsearch: true) do |example| - # WebMock.allow_net_connect! - # Searchkick.callbacks(nil) do - # example.run - # end - # WebMock.disable_net_connect!(allow: allowed_net_connect) - # end - - # Allow elastic search for tests tagged with elasticsearch - config.around(:example) do |example| - disable_web_connect = !example.metadata[:elasticsearch] if disable_web_connect WebMock.disable_net_connect!(allow: allowed_net_connect) diff --git a/api/spec/requests/api/v1/search_results_spec.rb b/api/spec/requests/api/v1/search_results_spec.rb index f56e45029c..f97542743f 100644 --- a/api/spec/requests/api/v1/search_results_spec.rb +++ b/api/spec/requests/api/v1/search_results_spec.rb @@ -1,13 +1,12 @@ require "swagger_helper" RSpec.describe "Search Results", type: :request do - context "can search a project", :elasticsearch do + context "can search a project" do let!(:keyword) { "bananas" } let!(:text_resource) { FactoryBot.create(:text) } let!(:project_resource) { FactoryBot.create(:project, title: keyword, texts: [text_resource]) } around(:example) do |example| - WebMock.disable_net_connect!(allow: [/127\.0\.0\.1:2?9200/, /localhost:2?9200/, /elasticsearch:9200/]) Journal.reindex Text.reindex Resource.reindex diff --git a/api/spec/requests/projects_spec.rb b/api/spec/requests/projects_spec.rb index fb54a3118a..15dbe9364a 100644 --- a/api/spec/requests/projects_spec.rb +++ b/api/spec/requests/projects_spec.rb @@ -11,7 +11,7 @@ end end - describe "it allows searching by keyword", :elasticsearch do + describe "it allows searching by keyword" do before(:each) do FactoryBot.create(:project, title: "foo") path = api_v1_projects_path(params: { filter: { keyword: "foo" } }) diff --git a/api/spec/requests/search_results_spec.rb b/api/spec/requests/search_results_spec.rb index 871bd5e772..4b40d68455 100644 --- a/api/spec/requests/search_results_spec.rb +++ b/api/spec/requests/search_results_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe "Search Results API", elasticsearch: true, type: :request do +RSpec.describe "Search Results API", type: :request do let_it_be(:bovary, refind: true) { FactoryBot.create :project, title: "Madame Bovary", description: "The force will be with you, always" } let_it_be(:babble, refind: true) { FactoryBot.create :project, title: "Madame Babble", description: "Peace be with you" } diff --git a/api/spec/serializers/project_serializer_spec.rb b/api/spec/serializers/project_serializer_spec.rb index d70ca384ed..f0a885811c 100644 --- a/api/spec/serializers/project_serializer_spec.rb +++ b/api/spec/serializers/project_serializer_spec.rb @@ -4,7 +4,7 @@ it_behaves_like "a serializer", partial_by_default: true it_behaves_like "a collaborative serializer" - describe "when the collection is search results", elasticsearch: true do + describe "when the collection is search results" do let(:object) do FactoryBot.create(:project, title: "test") Project.filtered(keyword: "test") diff --git a/api/spec/serializers/search_result_serializer_spec.rb b/api/spec/serializers/search_result_serializer_spec.rb index cf68fb3e6f..f5c03a25a0 100644 --- a/api/spec/serializers/search_result_serializer_spec.rb +++ b/api/spec/serializers/search_result_serializer_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe V1::SearchResultSerializer, elasticsearch: true do +RSpec.describe V1::SearchResultSerializer do let(:subject) { described_class.new(object) } let(:factory) { described_class.to_s.demodulize.gsub("Serializer", "").underscore.to_sym } diff --git a/api/spec/services/search/query_builder_spec.rb b/api/spec/services/search/query_builder_spec.rb index 10cdee6029..b3cb865677 100644 --- a/api/spec/services/search/query_builder_spec.rb +++ b/api/spec/services/search/query_builder_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe Search::QueryBuilder, elasticsearch: true, interaction: true do +RSpec.describe Search::QueryBuilder, interaction: true do let(:options) { Search::Options.new } let(:phrases) { [] } let(:needle) { nil } diff --git a/api/spec/services/search/query_spec.rb b/api/spec/services/search/query_spec.rb index a1e7abcccb..5288315606 100644 --- a/api/spec/services/search/query_spec.rb +++ b/api/spec/services/search/query_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe Search::Query, elasticsearch: true, interaction: true do +RSpec.describe Search::Query, interaction: true do let!(:bovary) { FactoryBot.create :project, title: "Madame Bovary", description: "The force will be with you, always" } let!(:babble) { FactoryBot.create :project, title: "Madame Babble", description: "Peace be with you" } @@ -49,7 +49,7 @@ def expect_the_search_results it "should raise an error" do perform_within_expectation! valid: false, raises: true do |e| - e.to raise_error(Searchkick::InvalidQueryError) + e.to raise_error(InvalidQueryError) end end end @@ -67,7 +67,7 @@ def expect_the_search_results it "should raise an error" do perform_within_expectation! valid: false, raises: true do |e| - e.to raise_error(Searchkick::InvalidQueryError) + e.to raise_error(InvalidQueryError) end end end diff --git a/api/spec/support/contexts/elasticsearch.rb b/api/spec/support/contexts/elasticsearch.rb deleted file mode 100644 index b2bffc0700..0000000000 --- a/api/spec/support/contexts/elasticsearch.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_context "elasticsearch", elasticsearch: true do - before(:all) do - WebMock.disable_net_connect!(allow: [/127\.0\.0\.1:2?9200/, /localhost:2?9200/, /elasticsearch:9200/]) - Journal.reindex - Text.reindex - Resource.reindex - Annotation.reindex - TextSection.reindex - end -end - -RSpec.configure do |config| - config.include_context "elasticsearch", elasticsearch: true -end