Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VeNJOB
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nguyen Ngoc Nghia
VeNJOB
Commits
ca3f0a29
Commit
ca3f0a29
authored
Feb 20, 2020
by
nnnghia98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check if city/industry id valid
parent
a9f7ae86
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
11 deletions
+25
-11
app/controllers/jobs_controller.rb
+9
-0
app/services/solr_service.rb
+12
-7
lib/tasks/task.rake
+4
-4
No files found.
app/controllers/jobs_controller.rb
View file @
ca3f0a29
class
JobsController
<
ApplicationController
class
JobsController
<
ApplicationController
before_action
:authenticate_user!
,
only:
[
:apply
,
:confirm_apply
,
:finish_apply
,
:applied_jobs
]
before_action
:authenticate_user!
,
only:
[
:apply
,
:confirm_apply
,
:finish_apply
,
:applied_jobs
]
before_action
:find_user
,
only: :apply_available
before_action
:find_user
,
only: :apply_available
before_action
:validate_city_industry
,
only: :index
def
index
def
index
@search
=
params
[
:search
]
||
params
[
:city_id
]
||
params
[
:industry_id
]
||
":"
@search
=
params
[
:search
]
||
params
[
:city_id
]
||
params
[
:industry_id
]
||
":"
...
@@ -59,4 +60,12 @@ class JobsController < ApplicationController
...
@@ -59,4 +60,12 @@ class JobsController < ApplicationController
def
find_user
def
find_user
@user
=
User
.
find_by
(
:id
)
@user
=
User
.
find_by
(
:id
)
end
end
def
validate_city_industry
if
params
[
:city_id
]
redirect_to
jobs_path
unless
City
.
find_by
(
id:
params
[
:city_id
])
elsif
params
[
:industry_id
]
redirect_to
jobs_path
unless
Industry
.
find_by
(
id:
params
[
:industry_id
])
end
end
end
end
app/services/solr_service.rb
View file @
ca3f0a29
require
"rsolr"
require
"rsolr"
class
SolrService
class
SolrService
def
initialize
(
search_keyword
)
def
initialize
(
search_keyword
=
{}
)
@solr
=
RSolr
.
connect
(
@solr
=
RSolr
.
connect
(
url:
Settings
.
solr
.
connection
.
server_url
,
url:
Settings
.
solr
.
connection
.
server_url
,
read_timeout:
Settings
.
solr
.
connection
.
read_timeout
,
read_timeout:
Settings
.
solr
.
connection
.
read_timeout
,
...
@@ -28,11 +28,11 @@ class SolrService
...
@@ -28,11 +28,11 @@ class SolrService
}
}
end
end
jobs_solr_index
.
each_slice
(
5000
)
do
|
job
|
jobs_solr_index
.
each_slice
(
5000
)
do
|
job
s
|
@solr
.
add
job
@solr
.
add
job
s
rescue
Exception
rescue
Exception
job
.
each
do
|
j
|
job
s
.
each
do
|
job
|
@solr
.
add
j
@solr
.
add
j
ob
rescue
rescue
solr_index_error
=
ActiveSupport
::
Logger
.
new
(
"log/solr_errors.log"
)
solr_index_error
=
ActiveSupport
::
Logger
.
new
(
"log/solr_errors.log"
)
solr_index_error
.
info
"This block got error! Cannot add job with id
#{
job
.
id
}
"
solr_index_error
.
info
"This block got error! Cannot add job with id
#{
job
.
id
}
"
...
@@ -56,9 +56,12 @@ class SolrService
...
@@ -56,9 +56,12 @@ class SolrService
end
end
def
query_by_city
def
query_by_city
city
=
City
.
find
(
@search_keyword
)
city
=
City
.
find_by
(
id:
@search_keyword
)
return
{
"numFound"
:
0
,
"docs"
:
[]
}
unless
city
city_name
=
city
.
name
city_name
=
city
.
name
q
=
"*:*"
q
=
"*:*"
fq
=
"city:
#{
escape_str
(
city_name
)
}
"
fq
=
"city:
#{
escape_str
(
city_name
)
}
"
...
@@ -66,7 +69,9 @@ class SolrService
...
@@ -66,7 +69,9 @@ class SolrService
end
end
def
query_by_industry
def
query_by_industry
industry
=
Industry
.
find
(
@search_keyword
)
industry
=
Industry
.
find_by
(
id:
@search_keyword
)
return
{
"numFound"
:
0
,
"docs"
:
[]
}
unless
industry
industry_name
=
industry
.
name
industry_name
=
industry
.
name
q
=
"*:*"
q
=
"*:*"
...
...
lib/tasks/task.rake
View file @
ca3f0a29
...
@@ -13,15 +13,15 @@ namespace :solr do
...
@@ -13,15 +13,15 @@ namespace :solr do
task
solr_index: :environment
do
task
solr_index: :environment
do
SolrService
.
new
.
add_data
SolrService
.
new
.
add_data
solr_index_
data
=
ActiveSupport
::
Logger
.
new
(
"log/solr_service.log"
)
solr_index_
logger
=
ActiveSupport
::
Logger
.
new
(
"log/solr_service.log"
)
solr_index_
data
.
info
"Solr index data succesfully at
#{
Time
.
current
}
"
solr_index_
logger
.
info
"Solr index data succesfully at
#{
Time
.
current
}
"
end
end
desc
"solr delete data"
desc
"solr delete data"
task
solr_delete: :environment
do
task
solr_delete: :environment
do
SolrService
.
new
.
delete_data
SolrService
.
new
.
delete_data
solr_delete_
data
=
ActiveSupport
::
Logger
.
new
(
"log/solr_service.log"
)
solr_delete_
logger
=
ActiveSupport
::
Logger
.
new
(
"log/solr_service.log"
)
solr_delete_
data
.
info
"Solr delete all data succesfully at
#{
Time
.
current
}
"
solr_delete_
logger
.
info
"Solr delete all data succesfully at
#{
Time
.
current
}
"
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment