Skip to content

Commit

Permalink
add searchkick and elasticsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Nov 26, 2024
1 parent af1ada0 commit 4e62e25
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 40 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ PORT=3006
MAILCATCHER_HTTP=3086
SECRET_KEY_BASE=don't forget to set this to some thing strong in production
NODE_OPTIONS=--openssl-legacy-provider
ELASTIC_SEARCH_URL=http://elasticsearch:9200
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ gem 'alma', '~> 0.3.3'
gem 'primo', git: 'https://github.com/tulibraries/primo.git', branch: 'main'

## SEARCH - USING ELASTIC SEARCH
gem 'elasticsearch-model', '0.1.9'
gem 'elasticsearch-rails', '0.1.9'
gem 'searchkick'
gem 'elasticsearch'

## DUMP DATA INTO YML FILE ##
# rake db:data:dump_dir dir=../tmp/db_june_2017
Expand Down
12 changes: 5 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ GEM
elasticsearch-api (= 8.16.0)
elasticsearch-api (8.16.0)
multi_json
elasticsearch-model (0.1.9)
activesupport (> 3)
elasticsearch (> 0.4)
hashie
elasticsearch-rails (0.1.9)
em-websocket (0.5.3)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0)
Expand Down Expand Up @@ -344,6 +339,9 @@ GEM
sprockets-rails
tilt
scrub_rb (1.0.1)
searchkick (5.4.0)
activemodel (>= 6.1)
hashie
shellany (0.0.1)
shoulda-context (2.0.0)
shoulda-matchers (5.3.0)
Expand Down Expand Up @@ -398,8 +396,7 @@ DEPENDENCIES
caxlsx_rails (= 0.6.3)
database_cleaner (~> 2.0, >= 2.0.1)
devise
elasticsearch-model (= 0.1.9)
elasticsearch-rails (= 0.1.9)
elasticsearch
email_validator (~> 2.2, >= 2.2.3)
exception_notification (~> 4.5)
factory_girl_rails (= 4.8.0)
Expand All @@ -424,6 +421,7 @@ DEPENDENCIES
rsolr (~> 2.5)
rufus-scheduler (~> 3.8, >= 3.8.2)
sass-rails (~> 6.0)
searchkick
shoulda-context (~> 2.0)
shoulda-matchers (~> 5.1)
simple_form (~> 5.1)
Expand Down
2 changes: 2 additions & 0 deletions app/models/course.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class Course < ApplicationRecord
searchkick

# COURSE FORMAT
# YEAR_FACULTY_SUBJECT_TERM_COURSEID__CREDITS_SECTION i.e. 2013_GL_ECON_S1_2500__3_A ignoring EN_A_LECT_01

Expand Down
2 changes: 2 additions & 0 deletions app/models/item.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class Item < ApplicationRecord
searchkick

########################################### CONSTANTS ############################################
METADATA_MANUAL = 'MANUAL'
METADATA_SOLR = 'SOLR'
Expand Down
2 changes: 2 additions & 0 deletions app/models/location.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class Location < ApplicationRecord
searchkick

# SETTING: setting_bcc_request_status_change

# SERIALIZATION
Expand Down
24 changes: 8 additions & 16 deletions app/models/request.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

class Request < ApplicationRecord
## searchable Concern
include Searchable
searchkick

## CONSTANTS
INCOMPLETE = 'incomplete'
Expand Down Expand Up @@ -135,19 +134,12 @@ def self.remove_incomplete(remove = false)
end

### ELASRTIC SEARCH HELPERS ##
def short_course_code
!course.nil? ? "#{course.subject} #{course.course_id}" : ''
end

def instructor_name
!course.nil? ? course.instructor.to_s : ''
end

def as_indexed_json(_options = {})
as_json(
only: [:id],
include: %i[course reserve_location assigned_to items requester],
methods: %i[short_course_code instructor_name]
)
def search_data
{
course_name: course.name,
course_code: course.code,
course_instructor: course.instructor,
requester_name: requester.name
}
end
end
5 changes: 2 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# frozen_string_literal: true

class User < ApplicationRecord
searchkick

# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :trackable, :lockable

## searchable Concern
include Searchable

## CONSTANTS
FACULTY = 'FACULTY'
Expand Down
8 changes: 8 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,13 @@ class Application < Rails::Application
# in config/environments, which are processed later.
#
# config.eager_load_paths << Rails.root.join("extras")

config.after_initialize do
if ENV['ELASTIC_SEARCH_URL']
Searchkick.client = Elasticsearch::Client.new(url: ENV['ELASTIC_SEARCH_URL'])
elsif defined?(Setting) && Setting.search_elastic_server && Setting.search_elastic_enabled.to_s == 'true'
Searchkick.client = Elasticsearch::Client.new(url: Setting.search_elastic_server)
end
end
end
end
6 changes: 0 additions & 6 deletions config/initializers/z_elasticsearch.rb

This file was deleted.

6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ services:
- RAILS_SERVE_STATIC_FILES=true
- NODE_OPTIONS=${NODE_OPTIONS}
- SELENIUM_REMOTE_URL=http://chrome:4444
- ELASTIC_SEARCH_URL=http://elasticsearch:9200
env_file:
- path: ./override.env
required: false
Expand All @@ -45,3 +46,8 @@ services:
ports:
- ${VNC_HTTP:-7904}:7900

elasticsearch:
image: elasticsearch:8.16.1
environment:
- discovery.type=single-node
- xpack.security.enabled=false
6 changes: 0 additions & 6 deletions lib/tasks/elasticsearch.rake

This file was deleted.

0 comments on commit 4e62e25

Please sign in to comment.