Commit edd8e6cc by Ngô Trung Hưng

fix method sub_space_params!

parent 8d2405f1
Pipeline #1071 canceled with stages
in 0 seconds
# frozen_string_literal: true
class IndexedJob
attr_accessor :job
def initialize(job)
@job = job
end
def do
index_strategy = Sync::Entities::Job.new(job)
Sync::Indexer.new.do(index_strategy)
end
end
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
batchSize="-1"
url="jdbc:mysql://127.0.0.1:3306/hungnt_development"
user="root"
password="Trunghung5055@"/>
<document>
<entity name="jobs"
pk="id"
query="SELECT jobs.*, companies.name AS company_name FROM jobs, companies WHERE jobs.company_id = companies.id">
<field column="id" name="id"/>
<field column="name" name="name"/>
<field column="company_name" name="company_name"/>
<field column="salary" name="salary"/>
<field column="description" name="description"/>
<!-- QUERY INDUSTRIES -->
<entity name="industries"
query="SELECT industries.id AS industry_id, industries.name AS industry_name FROM industries, industry_jobs, jobs WHERE jobs.id = industry_jobs.job_id AND industry_jobs.industry_id = industries.id AND jobs.id='${jobs.id}'">
<field column="industry_name" name="industries" />
<field column="industry_id" name="industry_id" />
</entity>
<!-- QUERY CITIES -->
<entity name="cities"
query="SELECT cities.id AS location_id, cities.name AS location_name FROM cities, city_jobs, jobs WHERE jobs.id = city_jobs.job_id AND city_jobs.city_id = cities.id AND jobs.id='${jobs.id}'">
<field column="location_name" name="locations" />
<field column="location_id" name="location_id" />
</entity>
</entity>
</document>
</dataConfig>
......@@ -52,8 +52,7 @@ class ImportData
end
if record.new_record?
record.save
index_strategy = Sync::Entities::Job.new(record)
Sync::Indexer.new.do(index_strategy)
IndexedJob.new(job).do
end
rescue StandardError => e
logger.error "Import_jobs: #{e}"
......
# frozen_string_literal: true
module Searches
class Query
def search(params)
solr = connect_solr
# Escape input & Convert space to asterisks
data = sub_space_params!(params[:search][:keyword], params[:search][:industry_id], params[:search][:city_id])
query = if [params[:search][:keyword], params[:search][:industry_id], params[:search][:city_id]].all? { |v| v.blank?}
query = if [params[:search][:keyword], params[:search][:industry_id], params[:search][:city_id]].all?(&:blank?)
'*:*'
else
"solr((name: #{data[:keyword]}) OR (company_name: #{data[:keyword]})) AND (industry_id: #{data[:industry_id]}) AND (location_id: #{data[:location_id]})"
end
response = solr.paginate(params[:page], Settings.number_result_search_in_page, 'select', params: { q: query })
results = 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)
end
def sub_space_params!(keyword, industry_id, location_id)
arr_params = {}
arr_params[:keyword] = RSolr.solr_escape(keyword)
arr_params[:industry_id] = RSolr.solr_escape(industry_id)
arr_params[:location_id] = RSolr.solr_escape(location_id)
arr_params[:keyword] = RSolr.solr_escape(keyword || '')
arr_params[:industry_id] = RSolr.solr_escape(industry_id || '')
arr_params[:location_id] = RSolr.solr_escape(location_id || '')
arr_params.each_value { |val| val.sub!('', '*') if val.blank? }
end
......
......@@ -9,9 +9,9 @@ module Sync::Entities
data[:company_name] = job.company.name
data[:salary] = job.salary
data[:description] = job.description
data[:industries] = job.industry_jobs.map(&:industry).map(&:name)
data[:industries] = job.industries.pluck(:name)
data[:industry_id] = job.industry_jobs.map(&:industry_id)
data[:locations] = job.city_jobs.map(&:city).map(&:name)
data[:locations] = job.cities.pluck(:name)
data[:location_id] = job.city_jobs.map(&:city_id)
data
end
......
......@@ -57,8 +57,7 @@ class CrawlerJob < Crawler
create_industry_relation(data[:industry_name], job)
create_city_relation(data[:city_name], job)
# Index data to solr
index_strategy = Sync::Entities::Job.new(job)
Sync::Indexer.new.do(index_strategy)
IndexedJob.new(job).do
rescue StandardError => e
logger.error "Crawler data jobs has error: #{e}"
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