Commit 4e3ee992 by Ngô Trung Hưng

use form object

parent 202b4d6d
Pipeline #1053 failed with stages
in 0 seconds
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
# Ignore master key for decrypting credentials and more. # Ignore master key for decrypting credentials and more.
/config/master.key /config/master.key
/lib/csv /lib/csv
/.vscode .vscode/settings.json
config/settings.local.yml config/settings.local.yml
config/settings/*.local.yml config/settings/*.local.yml
......
...@@ -37,6 +37,7 @@ gem 'rails-i18n' ...@@ -37,6 +37,7 @@ gem 'rails-i18n'
gem 'i18n-js' gem 'i18n-js'
gem 'rsolr' gem 'rsolr'
gem 'config' gem 'config'
# Use ActiveStorage variant # Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8' # gem 'mini_magick', '~> 4.8'
...@@ -52,6 +53,7 @@ group :development, :test do ...@@ -52,6 +53,7 @@ group :development, :test do
gem 'rubocop' gem 'rubocop'
gem 'dotenv-rails' gem 'dotenv-rails'
gem 'pry' gem 'pry'
gem 'pry-nav'
end end
group :development do group :development do
......
...@@ -54,7 +54,7 @@ GEM ...@@ -54,7 +54,7 @@ GEM
ast (2.4.1) ast (2.4.1)
bcrypt (3.1.15) bcrypt (3.1.15)
bindex (0.8.1) bindex (0.8.1)
bootsnap (1.4.7) bootsnap (1.4.8)
msgpack (~> 1.0) msgpack (~> 1.0)
breadcrumbs_on_rails (4.0.0) breadcrumbs_on_rails (4.0.0)
rails (>= 5.0) rails (>= 5.0)
...@@ -88,7 +88,7 @@ GEM ...@@ -88,7 +88,7 @@ GEM
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.12.2) coffee-script-source (1.12.2)
concurrent-ruby (1.1.6) concurrent-ruby (1.1.7)
config (2.2.1) config (2.2.1)
deep_merge (~> 1.2, >= 1.2.1) deep_merge (~> 1.2, >= 1.2.1)
dry-validation (~> 1.0, >= 1.0.0) dry-validation (~> 1.0, >= 1.0.0)
...@@ -181,19 +181,19 @@ GEM ...@@ -181,19 +181,19 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4) rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7) rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2) ruby_dep (~> 1.2)
loofah (2.6.0) loofah (2.7.0)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.7.1) mail (2.7.1)
mini_mime (>= 0.1.1) mini_mime (>= 0.1.1)
marcel (0.3.3) marcel (0.3.3)
mimemagic (~> 0.3.2) mimemagic (~> 0.3.2)
method_source (1.0.0) method_source (0.9.2)
mimemagic (0.3.5) mimemagic (0.3.5)
mini_magick (4.10.1) mini_magick (4.10.1)
mini_mime (1.0.2) mini_mime (1.0.2)
mini_portile2 (2.4.0) mini_portile2 (2.4.0)
minitest (5.14.1) minitest (5.14.2)
msgpack (1.3.3) msgpack (1.3.3)
multipart-post (2.1.1) multipart-post (2.1.1)
mysql2 (0.5.3) mysql2 (0.5.3)
...@@ -204,9 +204,11 @@ GEM ...@@ -204,9 +204,11 @@ GEM
parallel (1.19.2) parallel (1.19.2)
parser (2.7.1.4) parser (2.7.1.4)
ast (~> 2.4.1) ast (~> 2.4.1)
pry (0.13.1) pry (0.12.2)
coderay (~> 1.1) coderay (~> 1.1.0)
method_source (~> 1.0) method_source (~> 0.9.0)
pry-nav (0.3.0)
pry (>= 0.9.10, < 0.13.0)
public_suffix (4.0.5) public_suffix (4.0.5)
puma (3.12.6) puma (3.12.6)
rack (2.2.3) rack (2.2.3)
...@@ -284,7 +286,7 @@ GEM ...@@ -284,7 +286,7 @@ GEM
selenium-webdriver (3.142.7) selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0) childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2) rubyzip (>= 1.2.2)
spring (2.1.0) spring (2.1.1)
spring-watcher-listen (2.0.1) spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0) listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0) spring (>= 1.2, < 3.0)
...@@ -306,8 +308,8 @@ GEM ...@@ -306,8 +308,8 @@ GEM
uglifier (4.2.0) uglifier (4.2.0)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
unicode-display_width (1.7.0) unicode-display_width (1.7.0)
warden (1.2.8) warden (1.2.9)
rack (>= 2.0.6) rack (>= 2.0.9)
web-console (3.7.0) web-console (3.7.0)
actionview (>= 5.0) actionview (>= 5.0)
activemodel (>= 5.0) activemodel (>= 5.0)
...@@ -343,6 +345,7 @@ DEPENDENCIES ...@@ -343,6 +345,7 @@ DEPENDENCIES
mysql2 (>= 0.4.4, < 0.6.0) mysql2 (>= 0.4.4, < 0.6.0)
nokogiri nokogiri
pry pry
pry-nav
puma (~> 3.11) puma (~> 3.11)
rails (~> 5.2.4, >= 5.2.4.3) rails (~> 5.2.4, >= 5.2.4.3)
rails-i18n rails-i18n
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# Home page # Home page
class HomeController < ApplicationController class HomeController < ApplicationController
def index def index
@search = SendDataToApplyForm.new
@industries = Industry.order(name: :asc).all @industries = Industry.order(name: :asc).all
Please register or sign in to reply
@job_count = Job.count @job_count = Job.count
@cities = City.all_cities @cities = City.all_cities
......
...@@ -2,10 +2,11 @@ class SearchController < ApplicationController ...@@ -2,10 +2,11 @@ class SearchController < ApplicationController
before_action :load_data_dropdown before_action :load_data_dropdown
def search def search
@keyword = params[:keyword] debugger
@keyword = params[:send_data_to_apply_form][:keyword]
@industry = Industry.find_by(id: params[:industry_id]) if params[:industry_id].present? @industry = Industry.find_by(id: params[:industry_id]) if params[:industry_id].present?
@city = City.find_by(id: params[:city_id]) if params[:city_id].present? @city = City.find_by(id: params[:city_id]) if params[:city_id].present?
@results = Search::Query.new.search(params[:keyword], params[:industry_id], params[:city_id], params[:page]) @results = Search::Query.new.search(@keyword, params[:industry_id], params[:city_id], params[:page])
  • Truyền trực tiếp params vào thì có vấn đề gì không ?

    Vd :

    Search::Query.new.search(params)
Please register or sign in to reply
return render 'error/page_not_found' if params[:page].to_i > @results.total_pages return render 'error/page_not_found' if params[:page].to_i > @results.total_pages
render :result render :result
end end
......
# frozen_string_literal: true
class SendDataToApplyForm
Please register or sign in to reply
include ActiveModel::Model
attr_accessor :keyword, :industry_id, :city_id
end
<% provide(:title, "#{t('title.home')}") %> <% provide(:title, "#{t('title.home')}") %>
<%= render 'home/banner_and_search' %> <%= render 'search/new' %>
<div class="padding_index"></div> <div class="padding_index"></div>
<% unless @job_count.nil? %> <% unless @job_count.nil? %>
<div class="box_text_five_jobs"> <div class="box_text_five_jobs">
......
<div class = "box-banner">
<%= image_tag 'banner-search-box-home.png', class: "banner-top" %>
<div class="row">
<div class="col-xs-12">
<div class = "slogan">
<h2 class = "slogan_text">
<%= t('pages.banner.slogan') %>
</h2>
<h5 class = "slogan_text_h5">
<%= t('pages.banner.slogan') %>
</h5>
</div>
</div>
</div>
<!-- Process search pc-->
<div class="box-search">
<div class="search_scaffold">
<div class = "total_job">
<% if @job_count.blank? %>
<h4 class="show_total_job"><%= t('pages.banner.slogan_2') %></h4>
<% else %>
<h4 class="show_total_job"><%= t('pages.banner.slogan_3', job_count: @job_count) %></h4>
<% end %>
</div>
<%= form_with url: search_path, method: :get, local: true, skip_enforcing_utf8: true do |f| %>
<div class="filter_box">
<div class="search_input">
<%= f.search_field :keyword, value: @keyword, class: 'custom_input_search', placeholder: t('pages.banner.search_placeholder') %>
</div>
<div class="search_industries">
<div class="icon_list">
<i class="fa fa-list-ul" aria-hidden="true"></i>
</div>
<% selected = @industry.blank? ? '*' : @industry.id %>
<%= select_tag 'industry_id', options_from_collection_for_select(@industries, 'id', 'name', selected), prompt: t('pages.banner.all_industries'), class: 'show_list_industries' %>
</div>
<div class="search_location">
<div class="icon_list">
<i class="fas fa-map-marker-alt"></i>
</div>
<% selected = @city.blank? ? '*' : @city.id %>
<%= select_tag 'city_id', options_from_collection_for_select(@cities, 'id', 'name', selected), prompt: t('pages.banner.all_locations'), class: 'show_list_cities' %>
</div>
<div class="search_submit">
<%= f.submit t('pages.banner.btn_text_search'), name: nil, class: 'btn_search_submit'%>
</div>
</div>
<% end %>
</div>
</div>
<!-- Process search tablet-->
<div class="box-search-tablet">
<div class="search_scaffold-tablet">
<div class = "total_job">
<h4 class="show_total_job"><%= t('pages.banner.slogan_3', job_count: @job_count) %> </h4>
</div>
<%= form_with url: search_path, method: :get, local: true, skip_enforcing_utf8: true do |f| %>
<div class="filter_box filter_box_tablet">
<div class="search_input">
<%= f.search_field :keyword, value: @keyword, class: 'custom_input_search', placeholder: t('pages.banner.search_placeholder') %>
</div>
<div class="search_industries">
<div class="icon_list">
<i class="fa fa-list-ul" aria-hidden="true"></i>
</div>
<% selected = @industry.blank? ? '*' : @industry.id %>
<%= select_tag 'industry_id', options_from_collection_for_select(@industries, 'id', 'name', selected), prompt: t('pages.banner.all_industries'), class: 'show_list_industries' %>
</div>
<div class="search_location">
<div class="icon_list">
<i class="fas fa-map-marker-alt"></i>
</div>
<% selected = @city.blank? ? '*' : @city.id %>
<%= select_tag 'city_id', options_from_collection_for_select(@cities, 'id', 'name', selected), prompt: t('pages.banner.all_locations'), class: 'show_list_cities' %>
</div>
<div class="search_submit">
<%= f.submit t('pages.banner.btn_text_search'), name: nil, class: 'btn_search_submit'%>
</div>
</div>
<% end %>
</div>
</div>
<div class="box-show-total-jobs-mobile">
<span><%= t('pages.banner.slogan_3', job_count: @job_count) %> </span>
</div>
<!-- Process search mobile-->
<div class="box-search-mobile">
<%= form_with url: search_path, method: :get, local: true, skip_enforcing_utf8: true do |f| %>
<div class="fillter-search-mobile">
<div class="container">
<div class="row no-gutters">
<div class="col-md-12">
<%= f.search_field :keyword, value: @keyword, class: 'custom_input_mobile_search', placeholder: t('pages.banner.search_placeholder') %>
</div>
<div class="col-sm-6 col-xs-12">
<div class="search_industries_mobile">
<% selected = @industry.blank? ? '*' : @industry.id %>
<%= select_tag 'industry_id', options_from_collection_for_select(@industries, 'id', 'name', selected), prompt: t('pages.banner.all_industries'), class: 'show_list_industries_mobile' %>
</div>
</div>
<div class="col-sm-6 col-xs-12">
<div class="search_location_mobile">
<% selected = @city.blank? ? '*' : @city.id %>
<%= select_tag 'city_id', options_from_collection_for_select(@cities, 'id', 'name', selected), prompt: t('pages.banner.all_locations'), class: 'show_list_cities_mobile' %>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row no-gutters">
<div class="col-sm-12">
<%= f.submit t('pages.banner.btn_text_search'), name: nil, class: 'btn_search_submit'%>
</div>
</div>
</div>
</div>
<% end %>
</div>
<div class = "box-banner">
Please register or sign in to reply
<%= image_tag 'banner-search-box-home.png', class: "banner-top" %>
<div class="row">
<div class="col-xs-12">
<div class = "slogan">
<h2 class = "slogan_text">
<%= t('pages.banner.slogan') %>
</h2>
<h5 class = "slogan_text_h5">
<%= t('pages.banner.slogan') %>
</h5>
</div>
</div>
</div>
<!-- Process search pc-->
<div class="box-search">
<div class="search_scaffold">
<div class = "total_job">
<% if @job_count.blank? %>
<h4 class="show_total_job"><%= t('pages.banner.slogan_2') %></h4>
  • Giữ lại phần cố định, tách phần thay đổi.

    <h4 class="show_total_job">
      <%= @job_count.blank? ? t('pages.banner.slogan_2') : t('pages.banner.slogan_3', job_count: @job_count) %>
    </h4>
Please register or sign in to reply
<% else %>
<h4 class="show_total_job"><%= t('pages.banner.slogan_3', job_count: @job_count) %></h4>
<% end %>
</div>
<%= form_for @search, method: :get do |f| %>
<div class="filter_box">
<div class="search_input">
<%= f.search_field :keyword, value: @keyword, class: 'custom_input_search', placeholder: t('pages.banner.search_placeholder') %>
</div>
<div class="search_industries">
<div class="icon_list">
<i class="fa fa-list-ul" aria-hidden="true"></i>
</div>
<% selected = @industry.blank? ? '*' : @industry.id %>
<%= select_tag 'industry_id', options_from_collection_for_select(@industries, 'id', 'name', selected), prompt: t('pages.banner.all_industries'), class: 'show_list_industries' %>
</div>
<div class="search_location">
<div class="icon_list">
<i class="fas fa-map-marker-alt"></i>
</div>
<% selected = @city.blank? ? '*' : @city.id %>
Please register or sign in to reply
<%= select_tag 'city_id', options_from_collection_for_select(@cities, 'id', 'name', selected), prompt: t('pages.banner.all_locations'), class: 'show_list_cities' %>
Please register or sign in to reply
</div>
<div class="search_submit">
<%= f.submit t('pages.banner.btn_text_search'), name: nil, class: 'btn_search_submit'%>
</div>
</div>
<% end %>
</div>
</div>
<!-- Process search tablet-->
<div class="box-search-tablet">
<div class="search_scaffold-tablet">
<div class = "total_job">
<h4 class="show_total_job"><%= t('pages.banner.slogan_3', job_count: @job_count) %> </h4>
</div>
<%= form_with url: search_path, method: :get, local: true, skip_enforcing_utf8: true do |f| %>
<div class="filter_box filter_box_tablet">
<div class="search_input">
<%= f.search_field :keyword, value: @keyword, class: 'custom_input_search', placeholder: t('pages.banner.search_placeholder') %>
</div>
<div class="search_industries">
<div class="icon_list">
<i class="fa fa-list-ul" aria-hidden="true"></i>
</div>
<% selected = @industry.blank? ? '*' : @industry.id %>
<%= select_tag 'industry_id', options_from_collection_for_select(@industries, 'id', 'name', selected), prompt: t('pages.banner.all_industries'), class: 'show_list_industries' %>
</div>
<div class="search_location">
<div class="icon_list">
<i class="fas fa-map-marker-alt"></i>
</div>
<% selected = @city.blank? ? '*' : @city.id %>
<%= select_tag 'city_id', options_from_collection_for_select(@cities, 'id', 'name', selected), prompt: t('pages.banner.all_locations'), class: 'show_list_cities' %>
</div>
<div class="search_submit">
<%= f.submit t('pages.banner.btn_text_search'), name: nil, class: 'btn_search_submit'%>
</div>
</div>
<% end %>
</div>
</div>
<div class="box-show-total-jobs-mobile">
<span><%= t('pages.banner.slogan_3', job_count: @job_count) %> </span>
</div>
<!-- Process search mobile-->
<div class="box-search-mobile">
<%= form_with url: search_path, method: :get, local: true, skip_enforcing_utf8: true do |f| %>
<div class="fillter-search-mobile">
<div class="container">
<div class="row no-gutters">
<div class="col-md-12">
<%= f.search_field :keyword, value: @keyword, class: 'custom_input_mobile_search', placeholder: t('pages.banner.search_placeholder') %>
</div>
<div class="col-sm-6 col-xs-12">
<div class="search_industries_mobile">
<% selected = @industry.blank? ? '*' : @industry.id %>
<%= select_tag 'industry_id', options_from_collection_for_select(@industries, 'id', 'name', selected), prompt: t('pages.banner.all_industries'), class: 'show_list_industries_mobile' %>
</div>
</div>
<div class="col-sm-6 col-xs-12">
<div class="search_location_mobile">
<% selected = @city.blank? ? '*' : @city.id %>
<%= select_tag 'city_id', options_from_collection_for_select(@cities, 'id', 'name', selected), prompt: t('pages.banner.all_locations'), class: 'show_list_cities_mobile' %>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row no-gutters">
<div class="col-sm-12">
<%= f.submit t('pages.banner.btn_text_search'), name: nil, class: 'btn_search_submit'%>
</div>
</div>
</div>
</div>
<% end %>
</div>
...@@ -6,6 +6,8 @@ Rails.application.routes.draw do ...@@ -6,6 +6,8 @@ Rails.application.routes.draw do
devise_for :users, controllers: { registrations: 'registrations', passwords: 'passwords'} devise_for :users, controllers: { registrations: 'registrations', passwords: 'passwords'}
root 'home#index' root 'home#index'
# Search # Search
get 'search', to: 'search#search', as: :send_data_to_apply_forms
get 'search', to: 'search#search', as: :search get 'search', to: 'search#search', as: :search
get 'register/:code', to: 'users#confirm_sign_up', as: :confirm_sign_up get 'register/:code', to: 'users#confirm_sign_up', as: :confirm_sign_up
get 'industries', to: 'industry#index', as: :industry_index get 'industries', to: 'industry#index', as: :industry_index
......
...@@ -50,7 +50,11 @@ class ImportData ...@@ -50,7 +50,11 @@ class ImportData
job.city_ids.blank? ? job.cities << city : job.cities == city job.city_ids.blank? ? job.cities << city : job.cities == city
job.industry_ids.blank? ? job.industries << industry : job.industries == industry job.industry_ids.blank? ? job.industries << industry : job.industries == industry
end end
record.save && IndexData.indexed(record) if record.new_record? if record.new_record?
record.save
index_strategy = Sync::Entities::Job.new(record)
Sync::Indexer.new.do(index_strategy)
end
rescue StandardError => e rescue StandardError => e
logger.error "Import_jobs: #{e}" logger.error "Import_jobs: #{e}"
end end
......
module StrategySolr
class IndexData
attr_reader :data, :collection_name
def initialize(data, collection_name)
@data = data
@collection_name = collection_name
end
def indexed
collection_name.indexed(data)
end
end
end
# frozen_string_literal: true
module Sync::Entities
class Base
def initialize(entity)
@entity = entity
end
def to_h
raise 'Not implemented error'
end
end
end
# frozen_string_literal: true # frozen_string_literal: true
module StrategySolr
class JobIndexed < BaseIndex
def indexed(job) module Sync::Entities
solr = SolrSetting::SolrServer.connection class Job < Sync::Entities::Base
def to_h
data = {} data = {}
data[:id] = job.id data[:id] = job.id
data[:name] = job.name data[:name] = job.name
...@@ -14,9 +13,11 @@ module StrategySolr ...@@ -14,9 +13,11 @@ module StrategySolr
data[:industry_id] = job.industry_jobs.map(&:industry_id) data[:industry_id] = job.industry_jobs.map(&:industry_id)
data[:locations] = job.city_jobs.map(&:city).map(&:name) data[:locations] = job.city_jobs.map(&:city).map(&:name)
data[:location_id] = job.city_jobs.map(&:city_id) data[:location_id] = job.city_jobs.map(&:city_id)
solr.add data, add_attributes: {commitWithin: 10} data
rescue StandardError => e end
logger.error "Indexed data to Solr have error: #{e}"
def job
@entity
end end
end end
end end
module StrategySolr # frozen_string_literal: true
class BaseIndex
module Sync
class Indexer
def logger def logger
@logger ||= Logger.new(Rails.root.join('log', 'indexed_data_to_solr.log')) @logger ||= Logger.new(Rails.root.join('log', 'indexed_data_to_solr.log'))
end end
def indexed def do(data)
puts 'Indexed data from db to solr' solr = SolrSetting::SolrServer.connection
solr.add data.to_h, add_attributes: { commitWithin: 10 }
rescue StandardError => e
logger.error "Indexed data to Solr have error: #{e}"
end end
end end
end end
...@@ -56,7 +56,9 @@ class CrawlerJob < Crawler ...@@ -56,7 +56,9 @@ class CrawlerJob < Crawler
description: data[:description]) description: data[:description])
create_industry_relation(data[:industry_name], job) create_industry_relation(data[:industry_name], job)
create_city_relation(data[:city_name], job) create_city_relation(data[:city_name], job)
StrategySolr::IndexData.new(job, StrategySolr::JobIndexed.new).indexed # Index data to solr
index_strategy = Sync::Entities::Job.new(job)
Sync::Indexer.new.do(index_strategy)
rescue StandardError => e rescue StandardError => e
logger.error "Crawler data jobs has error: #{e}" logger.error "Crawler data jobs has error: #{e}"
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment