Commit 56fa3250 by Ngô Trung Hưng

refactor code function search

parent edd8e6cc
Pipeline #1075 canceled with stages
in 0 seconds
...@@ -2,6 +2,7 @@ class SearchController < ApplicationController ...@@ -2,6 +2,7 @@ class SearchController < ApplicationController
before_action :load_data_dropdown before_action :load_data_dropdown
def search def search
return render 'error/internal_server_error' if params[:search].blank?
@keyword = params[:search][:keyword] @keyword = params[:search][:keyword]
@industry = Industry.find_by(id: params[:search][:industry_id]) @industry = Industry.find_by(id: params[:search][:industry_id])
@city = City.find_by(id: params[:search][:city_id]) @city = City.find_by(id: params[:search][:city_id])
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
# Description/Explanation of Person class # Description/Explanation of Person class
class Job < ApplicationRecord class Job < ApplicationRecord
after_update :indexed_job
NUMBER_LASTED_JOB = 5 NUMBER_LASTED_JOB = 5
belongs_to :company belongs_to :company
...@@ -16,4 +18,8 @@ class Job < ApplicationRecord ...@@ -16,4 +18,8 @@ class Job < ApplicationRecord
has_many :histories has_many :histories
has_many :favorites has_many :favorites
def indexed_job
IndexedJob.new(self).do
end
end end
...@@ -9,7 +9,7 @@ module Searches ...@@ -9,7 +9,7 @@ module Searches
query = if [params[:search][:keyword], params[:search][:industry_id], params[:search][:city_id]].all?(&:blank?) query = if [params[:search][:keyword], params[:search][:industry_id], params[:search][:city_id]].all?(&:blank?)
'*:*' '*:*'
else else
"solr((name: #{data[:keyword]}) OR (company_name: #{data[:keyword]})) AND (industry_id: #{data[:industry_id]}) AND (location_id: #{data[:location_id]})" "#{data[:keyword]} AND (industry_id: #{data[:industry_id]}) AND (location_id: #{data[:location_id]})"
end end
response = solr.paginate(params[:page], Settings.number_result_search_in_page, 'select', params: { q: query }) response = solr.paginate(params[:page], Settings.number_result_search_in_page, 'select', params: { q: query })
Kaminari.paginate_array(response['response']['docs'], total_count: response['response']['numFound']).page(params[:page]).per(Settings.number_result_search_in_page) Kaminari.paginate_array(response['response']['docs'], total_count: response['response']['numFound']).page(params[:page]).per(Settings.number_result_search_in_page)
...@@ -17,7 +17,7 @@ module Searches ...@@ -17,7 +17,7 @@ module Searches
def sub_space_params!(keyword, industry_id, location_id) def sub_space_params!(keyword, industry_id, location_id)
arr_params = {} arr_params = {}
arr_params[:keyword] = RSolr.solr_escape(keyword || '') arr_params[:keyword] = RSolr.solr_escape(keyword.downcase || '')
arr_params[:industry_id] = RSolr.solr_escape(industry_id || '') arr_params[:industry_id] = RSolr.solr_escape(industry_id || '')
arr_params[:location_id] = RSolr.solr_escape(location_id || '') arr_params[:location_id] = RSolr.solr_escape(location_id || '')
arr_params.each_value { |val| val.sub!('', '*') if val.blank? } arr_params.each_value { |val| val.sub!('', '*') if val.blank? }
......
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