Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
15 changes: 0 additions & 15 deletions api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
63 changes: 3 additions & 60 deletions api/app/services/filtering/applicator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions api/app/services/search/advanced_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions api/app/services/search/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion api/config/initializers/20_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
1 change: 0 additions & 1 deletion api/config/initializers/30_monkeypatches.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 0 additions & 7 deletions api/config/initializers/searchkick.rb

This file was deleted.

2 changes: 1 addition & 1 deletion api/spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion api/spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion api/spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
11 changes: 0 additions & 11 deletions api/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions api/spec/requests/api/v1/search_results_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion api/spec/requests/projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" } })
Expand Down
2 changes: 1 addition & 1 deletion api/spec/requests/search_results_spec.rb
Original file line number Diff line number Diff line change
@@ -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" }

Expand Down
2 changes: 1 addition & 1 deletion api/spec/serializers/project_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion api/spec/serializers/search_result_serializer_spec.rb
Original file line number Diff line number Diff line change
@@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion api/spec/services/search/query_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
6 changes: 3 additions & 3 deletions api/spec/services/search/query_spec.rb
Original file line number Diff line number Diff line change
@@ -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" }

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 0 additions & 16 deletions api/spec/support/contexts/elasticsearch.rb

This file was deleted.