Commit fff98354 by Ngô Trung Hưng

create func search

parent ef3031b4
Pipeline #1008 failed with stages
in 0 seconds
...@@ -27,3 +27,8 @@ ...@@ -27,3 +27,8 @@
# 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
solr/data
solr/test/data
solr/development/data
solr/default/data
solr/pids
\ No newline at end of file
...@@ -35,6 +35,7 @@ gem 'devise' ...@@ -35,6 +35,7 @@ gem 'devise'
gem 'carrierwave' gem 'carrierwave'
gem 'rails-i18n' gem 'rails-i18n'
gem 'i18n-js' gem 'i18n-js'
gem 'sunspot_rails', github: 'sunspot/sunspot'
# Use ActiveStorage variant # Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8' # gem 'mini_magick', '~> 4.8'
...@@ -49,6 +50,7 @@ group :development, :test do ...@@ -49,6 +50,7 @@ group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'dotenv-rails' gem 'dotenv-rails'
gem 'pry' gem 'pry'
gem 'sunspot_solr'
end end
group :development do group :development do
......
GIT
remote: https://github.com/sunspot/sunspot.git
revision: c0270e6a49697fccfbac25844dd3edb04e61169f
specs:
sunspot (2.5.0)
pr_geohash (~> 1.0)
rsolr (>= 1.1.1, < 3)
sunspot_rails (2.5.0)
rails (>= 3)
sunspot (= 2.5.0)
sunspot_solr (2.5.0)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
...@@ -107,6 +119,8 @@ GEM ...@@ -107,6 +119,8 @@ GEM
request_store (>= 1.0) request_store (>= 1.0)
erubi (1.9.0) erubi (1.9.0)
execjs (2.7.0) execjs (2.7.0)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
ffi (1.13.1) ffi (1.13.1)
globalid (0.4.2) globalid (0.4.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
...@@ -150,11 +164,13 @@ GEM ...@@ -150,11 +164,13 @@ GEM
mini_portile2 (2.4.0) mini_portile2 (2.4.0)
minitest (5.14.1) minitest (5.14.1)
msgpack (1.3.3) msgpack (1.3.3)
multipart-post (2.1.1)
mysql2 (0.5.3) mysql2 (0.5.3)
nio4r (2.5.2) nio4r (2.5.2)
nokogiri (1.10.10) nokogiri (1.10.10)
mini_portile2 (~> 2.4.0) mini_portile2 (~> 2.4.0)
orm_adapter (0.5.0) orm_adapter (0.5.0)
pr_geohash (1.0.0)
pry (0.13.1) pry (0.13.1)
coderay (~> 1.1) coderay (~> 1.1)
method_source (~> 1.0) method_source (~> 1.0)
...@@ -200,6 +216,9 @@ GEM ...@@ -200,6 +216,9 @@ GEM
responders (3.0.1) responders (3.0.1)
actionpack (>= 5.0) actionpack (>= 5.0)
railties (>= 5.0) railties (>= 5.0)
rsolr (2.3.0)
builder (>= 2.1.2)
faraday (>= 0.9.0)
ruby-vips (2.0.17) ruby-vips (2.0.17)
ffi (~> 1.9) ffi (~> 1.9)
ruby_dep (1.5.0) ruby_dep (1.5.0)
...@@ -282,6 +301,8 @@ DEPENDENCIES ...@@ -282,6 +301,8 @@ DEPENDENCIES
selenium-webdriver selenium-webdriver
spring spring
spring-watcher-listen (~> 2.0.0) spring-watcher-listen (~> 2.0.0)
sunspot_rails!
sunspot_solr
turbolinks (~> 5) turbolinks (~> 5)
tzinfo-data tzinfo-data
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
# Home page # Home page
class HomeController < ApplicationController class HomeController < ApplicationController
before_action :load_data_dropdown
def index def index
@industries = Industry.order(name: :asc).all @industries = Industry.order(name: :asc).all
@job_count = Job.count @job_count = Job.count
...@@ -10,4 +12,17 @@ class HomeController < ApplicationController ...@@ -10,4 +12,17 @@ class HomeController < ApplicationController
@top_cities = City.top_cities(9) @top_cities = City.top_cities(9)
@top_industries = Industry.top_industries(9) @top_industries = Industry.top_industries(9)
end end
def search
@search = Job.search do
fulltext params[:key]
paginate :page => params[:page], per_page: 7
end
@keyword = params[:key]
end
def load_data_dropdown
@industries = Industry.order(name: :asc).all
@cities = City.select(:id, :name)
end
end end
...@@ -16,4 +16,10 @@ class Job < ApplicationRecord ...@@ -16,4 +16,10 @@ class Job < ApplicationRecord
has_many :histories has_many :histories
has_many :favorites has_many :favorites
searchable do
text :name
text :company do
company.map(&:name)
end
end
end end
...@@ -23,9 +23,10 @@ ...@@ -23,9 +23,10 @@
<h4 class="show_total_job"><%= t('pages.banner.slogan_3', job_count: @job_count) %></h4> <h4 class="show_total_job"><%= t('pages.banner.slogan_3', job_count: @job_count) %></h4>
<% end %> <% end %>
</div> </div>
<%= form_with url: search_path, method: :get, local: true, skip_enforcing_utf8: true do |f| %>
<div class="filter_box"> <div class="filter_box">
<div class="search_input"> <div class="search_input">
<input type="search" name="" id="" class="custom_input_search" placeholder="<%= t('pages.banner.search_placeholder') %>"> <%= f.search_field :key, class: 'custom_input_search', value: @keyword, placeholder: t('pages.banner.search_placeholder') %>
</div> </div>
<div class="search_industries"> <div class="search_industries">
<div class="icon_list"> <div class="icon_list">
...@@ -40,12 +41,10 @@ ...@@ -40,12 +41,10 @@
<%= select_tag 'city', options_from_collection_for_select(@cities, 'id', 'name'), prompt: t('pages.banner.all_locations'), class: 'show_list_cities' %> <%= select_tag 'city', options_from_collection_for_select(@cities, 'id', 'name'), prompt: t('pages.banner.all_locations'), class: 'show_list_cities' %>
</div> </div>
<div class="search_submit"> <div class="search_submit">
<button type="submit" class="btn_search_submit"> <%= f.submit t('pages.banner.btn_text_search'), name: nil, class: 'btn_search_submit' %>
<i class="fas fa-search"></i>
<%= t('pages.banner.btn_text_search') %>
</button>
</div> </div>
</div> </div>
<% end %>
</div> </div>
</div> </div>
<!-- Process search tablet--> <!-- Process search tablet-->
......
<% provide(:title ,"#{t('pages.detail.br_title')}") %>
<%= render 'home/banner_and_search' %>
<div class="padding_index"></div>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="breadcrumb_total_search">
<span class="breadcrumb-item active">
<div style="word-wrap: break-word;">
<%= t('pages.result.result_find', job: @search.total, key: @keyword).html_safe if @search.total.positive? %>
<%= t('pages.result.no_result_find', key: @keyword).html_safe if @search.total.zero? %>
</div>
</span>
</div>
</div>
<div class="col-lg-12">
<div class="breadcrumb_total_search_pagination_jobs">
<div class="pagination_jobs">
<div id="paginator">
<%= paginate @search.hits %>
</div>
</div>
</div>
</div>
</div>
</div>
<%= render 'job/modal_login' %>
<% @search.each_hit_with_result do |hit, result| %>
<%= render 'job/block_info_job', data: result %>
<% end %>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="breadcrumb_total_search_pagination_jobs">
<div class="pagination_jobs">
<div class="paginator">
<%= paginate @search.hits %>
</div>
</div>
</div>
</div>
</div>
</div>
<%= render 'shared/scroll_top' %>
...@@ -5,7 +5,7 @@ Rails.application.routes.draw do ...@@ -5,7 +5,7 @@ Rails.application.routes.draw do
scope '(:locale)', locale: /en|vi/ do scope '(:locale)', locale: /en|vi/ do
devise_for :users, controllers: { registrations: 'registrations' } devise_for :users, controllers: { registrations: 'registrations' }
root 'home#index' root 'home#index'
get 'search', to: 'home#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
get 'cities', to: 'city#index', as: :city_index get 'cities', to: 'city#index', as: :city_index
......
production:
solr:
hostname: localhost
port: 8983
log_level: WARNING
path: /solr/production
# read_timeout: 2
# open_timeout: 0.5
development:
solr:
hostname: localhost
port: 8982
log_level: INFO
path: /solr/development
test:
solr:
hostname: localhost
port: 8981
log_level: WARNING
path: /solr/test
\ No newline at end of file
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