Commit 0ec291d2 by Hoang Phuc

Rake task import Solr

parent da165766
...@@ -25,6 +25,8 @@ gem 'bcrypt', '~> 3.1.7' ...@@ -25,6 +25,8 @@ gem 'bcrypt', '~> 3.1.7'
gem 'devise' gem 'devise'
gem 'rsolr'
gem 'settingslogic' gem 'settingslogic'
# Use Active Storage variant # Use Active Storage variant
# gem 'image_processing', '~> 1.2' # gem 'image_processing', '~> 1.2'
......
...@@ -86,6 +86,8 @@ GEM ...@@ -86,6 +86,8 @@ GEM
responders responders
warden (~> 1.2.3) warden (~> 1.2.3)
erubi (1.9.0) erubi (1.9.0)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
ffi (1.12.2) ffi (1.12.2)
ffi (1.12.2-java) ffi (1.12.2-java)
ffi (1.12.2-x64-mingw32) ffi (1.12.2-x64-mingw32)
...@@ -128,6 +130,7 @@ GEM ...@@ -128,6 +130,7 @@ GEM
msgpack (1.3.3-java) msgpack (1.3.3-java)
msgpack (1.3.3-x64-mingw32) msgpack (1.3.3-x64-mingw32)
msgpack (1.3.3-x86-mingw32) msgpack (1.3.3-x86-mingw32)
multipart-post (2.1.1)
mysql2 (0.5.3) mysql2 (0.5.3)
mysql2 (0.5.3-x64-mingw32) mysql2 (0.5.3-x64-mingw32)
mysql2 (0.5.3-x86-mingw32) mysql2 (0.5.3-x86-mingw32)
...@@ -193,6 +196,9 @@ GEM ...@@ -193,6 +196,9 @@ GEM
responders (3.0.0) responders (3.0.0)
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_dep (1.5.0) ruby_dep (1.5.0)
rubyzip (2.3.0) rubyzip (2.3.0)
sass-rails (6.0.0) sass-rails (6.0.0)
...@@ -281,6 +287,7 @@ DEPENDENCIES ...@@ -281,6 +287,7 @@ DEPENDENCIES
pry pry
puma (~> 4.1) puma (~> 4.1)
rails (~> 6.0.2, >= 6.0.2.2) rails (~> 6.0.2, >= 6.0.2.2)
rsolr
sass-rails (>= 6) sass-rails (>= 6)
selenium-webdriver selenium-webdriver
settingslogic settingslogic
......
require "rsolr"
namespace :solr do
desc "Solr management"
solr = RSolr.connect :url => "http://localhost:8983/solr/venjob"
task import: :environment do
job = Job.last(1)
hash_jobs = job.map { |item|
salary = 0
min_salary = 0
max_salary = 0
{
job_id: item.id,
title: item.title,
updated_date_job: DateTime.parse(item.updated_date_job).to_i,
level: item.level,
years_of_experience: item.years_of_experience,
salary: salary,
min_salary: min_salary,
max_salary: max_salary,
expiration_date: DateTime.parse(item.expiration_date).to_i,
job_description: item.job_description,
created_at: item.created_at.to_i,
industry_ids: item.industries.map { |industry| industry.id },
industry_names: item.industries.map { |industry| industry.title },
city_ids: item.cities.map { |city| city.id },
city_names: item.cities.map { |city| city.title },
company_id: item.company_id,
company_name: item.company.title,
company_address: item.company.address,
company_description: item.company.description,
company_logo: item.company.logo,
favorite_count: Favorite.where("job_id = ?", item.id).count,
apply_count: Apply.where("job_id = ?", item.id).count
}
}
solr.add hash_jobs
solr.commit
end
task delete_all: :environment do
solr.delete_by_query "*:*"
solr.commit
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