Commit 38655032 by Thanh Hung Pham

Inport solr

parent 156a27e7
...@@ -9,21 +9,11 @@ class JobsController < ApplicationController ...@@ -9,21 +9,11 @@ class JobsController < ApplicationController
@search_conditions = params[:text_search] @search_conditions = params[:text_search]
rsolr = RSolr.connect url: 'http://localhost:8983/solr/veNJOBDATA/' rsolr = RSolr.connect url: 'http://localhost:8983/solr/veNJOBDATA/'
# rsolr.add(job_id: 1, job_name: 'a', job_description: 'b')
# rsolr.update data: '<commit/>', headers: { 'Content-Type' => 'text/xml' }
# rsolr.update data: { optimize: true }.to_json, headers: { 'Content-Type' => 'application/json' }
# rsolr.commit
response = rsolr.get 'select', params: { q: @search_conditions, start: 0, rows: 10 } response = rsolr.get 'select', params: { q: @search_conditions }
response['response']['docs'] job_ids = response['response']['docs']['job_id']
raise 'test' redirect_to jobs_show_path(job_ids: job_ids)
# search = rsolr.select params: { q: @search_conditions }
# search['response']['docs']
redirect_to jobs_show_path
end end
def detail def detail
...@@ -52,6 +42,7 @@ class JobsController < ApplicationController ...@@ -52,6 +42,7 @@ class JobsController < ApplicationController
end end
def show def show
raise 'test'
unless params[:city_id].nil? unless params[:city_id].nil?
@job_count = Job.where(city_id: params[:city_id]).count @job_count = Job.where(city_id: params[:city_id]).count
@jobs = Job.where(city_id: params[:city_id]).page params[:page] @jobs = Job.where(city_id: params[:city_id]).page params[:page]
......
class Job < ApplicationRecord class Job < ApplicationRecord
after_save :import_solr
belongs_to :city, optional: true belongs_to :city, optional: true
belongs_to :company, optional: true belongs_to :company, optional: true
belongs_to :job_type, optional: true belongs_to :job_type, optional: true
...@@ -9,4 +10,12 @@ class Job < ApplicationRecord ...@@ -9,4 +10,12 @@ class Job < ApplicationRecord
paginates_per 20 paginates_per 20
validates :name, presence: true, length: { maximum: 200 } validates :name, presence: true, length: { maximum: 200 }
private
def import_solr
rsolr = RSolr.connect url: 'http://localhost:8983/solr/veNJOBDATA/'
rsolr.add(job_id: id, job_name: name, job_description: description)
rsolr.commit
end
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