Skip to content

Commit

Permalink
handle keyword search in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
starswan committed Nov 28, 2024
1 parent 21303b1 commit 120c6ec
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
10 changes: 1 addition & 9 deletions app/jobs/alert_email/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AlertEmail::Base < ApplicationJob
phases: ->(vacancy, value) { (vacancy.phases & value).any? },
working_patterns: ->(vacancy, value) { (vacancy.working_patterns & value).any? },
organisation_slug: ->(vacancy, value) { vacancy.organisations.map(&:slug).include?(value) },
keyword: ->(vacancy, value) { vacancy.searchable_content.include? value.downcase.strip }
}.freeze

def perform # rubocop:disable Metrics/AbcSize
Expand All @@ -24,7 +25,6 @@ def perform # rubocop:disable Metrics/AbcSize
subscriptions.find_each.reject { |sub| already_run_ids.include?(sub.id) }.each do |subscription|
scope = default_scope
criteria = subscription.search_criteria.symbolize_keys
scope, criteria = handle_keywords(scope, criteria)
scope, criteria = handle_location(scope, criteria)

vacancies = scope.select do |vacancy|
Expand All @@ -38,14 +38,6 @@ def perform # rubocop:disable Metrics/AbcSize

private

def handle_keywords(scope, criteria)
if criteria.key?(:keyword)
[scope.search_by_full_text(criteria[:keyword]), criteria.except(:keyword)]
else
[scope, criteria]
end
end

def handle_location(scope, criteria)
if criteria.key?(:location)
[scope.search_by_location(criteria[:location], criteria[:radius]), criteria.except(:location, :radius)]
Expand Down
4 changes: 2 additions & 2 deletions spec/jobs/send_daily_alert_email_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
RSpec.describe SendDailyAlertEmailJob do
subject(:job) { described_class.perform_later }

let(:mail) { double(:mail, deliver_later: nil) }

describe "#perform" do
let(:mail) { double(:mail, deliver_later: nil) }

context "with vacancies" do
before do
create(:vacancy, :published_slugged, contact_number: "1", ect_status: :ect_unsuitable, job_roles: %w[teacher], subjects: %w[English], phases: %w[secondary], working_patterns: %w[full_time])
Expand Down

0 comments on commit 120c6ec

Please sign in to comment.