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
Mai Hoang Thai Ha
VenJob
Commits
951ee8fe
Commit
951ee8fe
authored
Oct 14, 2021
by
Thai Ha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed solr service add facet,....
parent
78a9beae
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
127 additions
and
31 deletions
+127
-31
app/controllers/application_controller.rb
+5
-0
app/controllers/cities_controller.rb
+2
-1
app/controllers/industries_controller.rb
+2
-1
app/controllers/jobs_controller.rb
+3
-2
app/controllers/top_controller.rb
+2
-0
app/helpers/application_helper.rb
+13
-0
app/services/solr.rb
+49
-13
app/views/cities/index.html.slim
+3
-3
app/views/industries/index.html.slim
+3
-3
app/views/shared/_search.html.slim
+22
-7
lib/tasks/web_crawler.rake
+1
-1
q
+22
-0
No files found.
app/controllers/application_controller.rb
View file @
951ee8fe
...
@@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
...
@@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
before_action
:configure_permitted_parameters
,
if: :devise_controller?
before_action
:configure_permitted_parameters
,
if: :devise_controller?
protected
protected
def
configure_permitted_parameters
def
configure_permitted_parameters
...
@@ -20,4 +21,8 @@ class ApplicationController < ActionController::Base
...
@@ -20,4 +21,8 @@ class ApplicationController < ActionController::Base
redirect_to
new_user_session_path
redirect_to
new_user_session_path
end
end
end
end
def
salary_search
@salary_range
=
[
0
,
3_000_000
,
7_000_000
,
10_000_000
,
15_000_000
,
20_000_000
,
30_000_000
]
end
end
end
app/controllers/cities_controller.rb
View file @
951ee8fe
class
CitiesController
<
ApplicationController
class
CitiesController
<
ApplicationController
def
index
def
index
solr
=
Solr
.
new
@regions
=
City
.
regions
.
keys
@regions
=
City
.
regions
.
keys
@job_quantity_by_region
=
City
.
job_quantity_by_region
@job_quantity_by_region
=
solr
.
facet_query
(
'city_id'
)
end
end
end
end
app/controllers/industries_controller.rb
View file @
951ee8fe
class
IndustriesController
<
ApplicationController
class
IndustriesController
<
ApplicationController
def
index
def
index
@job_quantity_by_industry
=
Industry
.
job_quantity_by_industry
solr
=
Solr
.
new
@job_quantity_by_industry
=
solr
.
facet_query
(
'industry_id'
)
end
end
end
end
app/controllers/jobs_controller.rb
View file @
951ee8fe
class
JobsController
<
ApplicationController
class
JobsController
<
ApplicationController
before_action
:history
,
only: :show
before_action
:history
,
only: :show
before_action
:salary_search
def
index
def
index
@search
=
params
@search
=
params
...
@@ -34,8 +35,8 @@ class JobsController < ApplicationController
...
@@ -34,8 +35,8 @@ class JobsController < ApplicationController
end
end
def
get_jobs
(
query
)
def
get_jobs
(
query
)
jobs_ids
=
query
[
'docs'
].
map
{
|
j
|
j
[
'job_id'
]
}
jobs_ids
=
query
[
'
response'
][
'
docs'
].
map
{
|
j
|
j
[
'job_id'
]
}
@jobs
=
Job
.
includes
(
:cities
,
:cities_jobs
,
:company
).
find
(
jobs_ids
)
@jobs
=
Job
.
eager_load
(
:cities
,
:cities_jobs
,
:company
).
find
(
jobs_ids
)
@jobs_count
=
query
[
'numFound'
]
@jobs_count
=
query
[
'numFound'
]
end
end
end
end
app/controllers/top_controller.rb
View file @
951ee8fe
class
TopController
<
ApplicationController
class
TopController
<
ApplicationController
before_action
:salary_search
def
index
def
index
@total_job
=
Job
.
count
@total_job
=
Job
.
count
@latest_jobs
=
Job
.
sort_by_date
(
per_page:
Job
::
LATEST_JOBS_LIMIT
)
@latest_jobs
=
Job
.
sort_by_date
(
per_page:
Job
::
LATEST_JOBS_LIMIT
)
...
...
app/helpers/application_helper.rb
View file @
951ee8fe
...
@@ -26,9 +26,22 @@ module ApplicationHelper
...
@@ -26,9 +26,22 @@ module ApplicationHelper
def
view_search_result
def
view_search_result
if
params
[
:search
].
blank?
if
params
[
:search
].
blank?
if
params
[
:salary
].
to_i
.
zero?
@name
.
to_s
@name
.
to_s
else
else
"Totals
#{
@jobs_count
}
jobs"
end
else
"Totals
#{
@jobs_count
}
result for
#{
params
[
:search
]
}
in
#{
@name
}
"
"Totals
#{
@jobs_count
}
result for
#{
params
[
:search
]
}
in
#{
@name
}
"
end
end
end
end
def
vnd_format
(
num
)
if
num
.
zero?
'Tất cả'
else
num_groups
=
num
.
to_s
.
chars
.
to_a
.
reverse
.
each_slice
(
3
)
"Từ
#{
num_groups
.
map
(
&
:join
).
join
(
'.'
).
reverse
}
đ"
end
end
end
end
app/services/solr.rb
View file @
951ee8fe
class
Solr
class
Solr
def
initialize
(
params
=
{
search:
'*:*'
})
def
initialize
(
params
=
{
search:
'*:*'
})
@solr
=
RSolr
.
connect
(
url:
'http://
192.168.1.8
:8983/solr/VenJob/'
)
@solr
=
RSolr
.
connect
(
url:
'http://
localhost
:8983/solr/VenJob/'
)
@params
=
params
@params
=
params
end
end
...
@@ -14,14 +14,15 @@ class Solr
...
@@ -14,14 +14,15 @@ class Solr
job_level:
job
.
position
,
job_level:
job
.
position
,
min_salary:
job
.
min_salary
,
min_salary:
job
.
min_salary
,
max_salary:
job
.
max_salary
,
max_salary:
job
.
max_salary
,
cities_name:
job
.
cities
.
map
{
|
c
|
c
.
name
.
gsub
(
' / '
,
', '
)
}
,
cities_name:
job
.
cities
.
map
(
&
:name
)
,
city_id:
job
.
cities
&
.
ids
,
city_id:
job
.
cities
&
.
ids
,
industries_name:
job
.
industries
.
map
{
|
i
|
i
.
name
.
gsub
(
' / '
,
', '
)
}
,
industries_name:
job
.
industries
.
map
(
&
:name
)
,
industry_id:
job
.
industries
&
.
ids
industry_id:
job
.
industries
&
.
ids
}
}
end
end
jobs_index
.
each
do
|
add_jobs
|
jobs_index
.
each
do
|
add_jobs
|
# byebug
@solr
.
add
(
add_jobs
)
@solr
.
add
(
add_jobs
)
rescue
Exception
rescue
Exception
next
next
...
@@ -38,8 +39,11 @@ class Solr
...
@@ -38,8 +39,11 @@ class Solr
def
query_all
def
query_all
q
=
"search:*
#{
@params
[
:search
]
}
*"
q
=
"search:*
#{
@params
[
:search
]
}
*"
fq
=
''
fq
=
if
@params
[
:salary
]
"min_salary: [
#{
@params
[
:salary
]
}
TO *]"
else
''
end
send_request
(
q
,
fq
)
send_request
(
q
,
fq
)
end
end
...
@@ -50,7 +54,11 @@ class Solr
...
@@ -50,7 +54,11 @@ class Solr
city_name
=
city
.
name
city_name
=
city
.
name
q
=
"search:*
#{
@params
[
:search
]
}
*"
q
=
"search:*
#{
@params
[
:search
]
}
*"
fq
=
"cities_name:
\"
#{
escape_str
(
city_name
)
}
\"
"
fq
=
if
@params
[
:salary
]
[
"cities_name:
\"
#{
escape_str
(
city_name
)
}
\"
"
,
"min_salary: [
#{
@params
[
:salary
]
}
TO *]"
]
else
"cities_name:
\"
#{
escape_str
(
city_name
)
}
\"
"
end
send_request
(
q
,
fq
)
send_request
(
q
,
fq
)
end
end
...
@@ -62,21 +70,49 @@ class Solr
...
@@ -62,21 +70,49 @@ class Solr
industry_name
=
industry
.
name
industry_name
=
industry
.
name
q
=
"search:*
#{
@params
[
:search
]
}
*"
q
=
"search:*
#{
@params
[
:search
]
}
*"
fq
=
"industries_name:
\"
#{
escape_str
(
industry_name
)
}
\"
"
fq
=
if
@params
[
:salary
]
[
"industries_name:
\"
#{
escape_str
(
industry_name
)
}
\"
"
,
"min_salary: [
#{
@params
[
:salary
]
}
TO *]"
]
else
"industries_name:
\"
#{
escape_str
(
industry_name
)
}
\"
"
end
send_request
(
q
,
fq
)
send_request
(
q
,
fq
)
end
end
def
send_request
(
q_param
,
fq_param
)
def
facet_query
(
facet_param
)
response
=
@solr
.
get
'select'
,
params:
{
q
=
'*:*'
q:
q_param
,
fq
=
'*:*'
fq:
fq_param
,
facet
=
facet_param
rows:
Job
.
count
response
=
send_request
(
q
,
fq
,
facet
)
query
=
response
[
'facet_counts'
][
'facet_fields'
][
facet
]
ids
=
query
.
each_slice
(
2
).
map
{
|
a
,
_
|
a
}
jobs_count
=
query
.
each_slice
(
2
).
map
{
|
_
,
b
|
b
}
return
city_handle
(
ids
,
jobs_count
)
if
facet
==
'city_id'
return
industry_handle
(
ids
,
jobs_count
)
if
facet
==
'industry_id'
end
def
send_request
(
q_param
,
fq_param
,
facet_param
=
nil
)
@solr
.
get
'select'
,
params:
{
'facet'
:
true
,
'facet.field'
:
facet_param
,
'q'
:
q_param
,
'fq'
:
fq_param
,
'rows'
:
Job
.
count
}
}
response
[
'response'
]
end
end
def
escape_str
(
str
)
def
escape_str
(
str
)
RSolr
.
solr_escape
(
str
)
RSolr
.
solr_escape
(
str
)
end
end
def
city_handle
(
ids
,
jobs_count
)
city
=
City
.
find
(
ids
).
map
{
|
c
|
[
c
.
region
,
c
.
name
,
c
.
slug
]
}
city_count
=
city
.
zip
(
jobs_count
).
flatten
.
compact
.
each_slice
(
4
).
map
{
|
c
|
c
}
city_count
.
group_by
(
&
:shift
)
end
def
industry_handle
(
ids
,
jobs_count
)
industry
=
Industry
.
find
(
ids
).
map
{
|
i
|
[
i
.
name
,
i
.
slug
]
}
industry
.
zip
(
jobs_count
).
flatten
.
compact
.
each_slice
(
3
).
map
{
|
c
|
c
}
end
end
end
app/views/cities/index.html.slim
View file @
951ee8fe
...
@@ -18,9 +18,9 @@
...
@@ -18,9 +18,9 @@
=
region
.
upcase
=
region
.
upcase
hr
.my-4
hr
.my-4
.row
.row
-
city_job_count
.
each
do
|
city
,
count
|
-
city_job_count
.
each
do
|
city
|
.col-lg-4.col-md-6.text-center
.col-lg-4.col-md-6.text-center
.mt-5
.mt-5
.city-item
.city-item
h3
.h4.mb-2.see-more-text
=
link_to
city
[
0
],
city_jobs_path
(
city_slug:
city
[
1
])
,
class
:'text-decoration-none fw-normal text-reset'
h3
.h4.mb-2.see-more-text
=
link_to
city
[
0
],
city_jobs_path
(
city_slug:
city
[
1
])
,
class
:'text-decoration-none fw-normal text-reset'
p
.text-muted.mb-0
=
pluralize
(
count
,
'job'
)
p
.text-muted.mb-0
=
pluralize
(
city
[
2
],
'job'
)
\ No newline at end of file
\ No newline at end of file
app/views/industries/index.html.slim
View file @
951ee8fe
...
@@ -3,10 +3,10 @@
...
@@ -3,10 +3,10 @@
h2
.mt-0
INDUSTRIES
h2
.mt-0
INDUSTRIES
hr
.my-4
hr
.my-4
#info-box
.row
#info-box
.row
-
@job_quantity_by_industry
.
each
do
|
name
,
job_count
|
-
@job_quantity_by_industry
.
each
do
|
industry
|
.col-lg-6.col-md-6.text-center
.col-lg-6.col-md-6.text-center
.mt-5
.mt-5
h3
.h4.mb-2.see-more-text
=
link_to
name
[
0
],
industry_jobs_path
(
industry_slug:
name
[
1
])
,
class
:'text-decoration-none fw-normal text-reset'
h3
.h4.mb-2.see-more-text
=
link_to
industry
[
0
],
industry_jobs_path
(
industry_slug:
industry
[
1
])
,
class
:'text-decoration-none fw-normal text-reset'
p
.text-muted.mb-0
=
pluralize
(
job_count
,
'job'
)
p
.text-muted.mb-0
=
pluralize
(
industry
[
2
]
,
'job'
)
hr
.divider.my-4
hr
.divider.my-4
app/views/shared/_search.html.slim
View file @
951ee8fe
...
@@ -3,22 +3,38 @@
...
@@ -3,22 +3,38 @@
-
if
params
[
:city_slug
]
-
if
params
[
:city_slug
]
=
form_tag
(
city_jobs_path
(
city_slug:
params
[
:city_slug
]),
method: :get
,
class:
"form-inline"
)
do
=
form_tag
(
city_jobs_path
(
city_slug:
params
[
:city_slug
]),
method: :get
,
class:
"form-inline"
)
do
.row
.row
.col-md-10.mb-md-0.no-padding
.col-md-8.mb-md-0.no-padding
=
search_field_tag
:search
,
params
[
:search
],
placeholder:
'Find a job in this location'
,
class:
'form-control rounded-left no-border-radius bg-light h-100'
=
search_field_tag
:search
,
params
[
:search
],
placeholder:
'Find a job (name, company, position)'
,
class:
'form-control rounded-left no-border-radius bg-light h-100'
.col-md-2.mb-md-0.no-padding
=
select_tag
(
:salary
,
options_for_select
(
@salary_range
.
collect
{
|
s
|
[
vnd_format
(
s
),
s
]},
params
[
:salary
]
),
class
:"form-select
bg-light
h-100")
.col-md-2.mb-md-0.no-padding
.col-md-2.mb-md-0.no-padding
=
submit_tag
"Search"
,
class:
"h-100 w-100 btn btn-block btn-lg btn-info"
=
submit_tag
"Search"
,
class:
"h-100 w-100 btn btn-block btn-lg btn-info"
-
elsif
params
[
:industry_slug
]
-
elsif
params
[
:industry_slug
]
=
form_tag
(
industry_jobs_path
(
industry_slug:
params
[
:industry_slug
]),
method: :get
,
class:
"form-inline"
)
do
=
form_tag
(
industry_jobs_path
(
industry_slug:
params
[
:industry_slug
]),
method: :get
,
class:
"form-inline"
)
do
.row
.row
.col-md-10.mb-md-0.no-padding
.col-md-8.mb-md-0.no-padding
=
search_field_tag
:search
,
params
[
:search
],
placeholder:
'Find a job in this industy'
,
class:
'form-control rounded-left no-border-radius bg-light h-100'
=
search_field_tag
:search
,
params
[
:search
],
placeholder:
'Find a job (name, company, position)'
,
class:
'form-control rounded-left no-border-radius bg-light h-100'
.col-md-2.mb-md-0.no-padding
=
select_tag
(
:salary
,
options_for_select
(
@salary_range
.
collect
{
|
s
|
[
vnd_format
(
s
),
s
]},
params
[
:salary
]
),
class
:"form-select
bg-light
h-100")
.col-md-2.mb-md-0.no-padding
.col-md-2.mb-md-0.no-padding
=
submit_tag
"Search"
,
class:
"h-100 w-100 btn btn-block btn-lg btn-info"
=
submit_tag
"Search"
,
class:
"h-100 w-100 btn btn-block btn-lg btn-info"
-
else
-
else
=
form_tag
(
jobs_path
,
method: :get
,
class:
"form-inline"
)
do
=
form_tag
(
jobs_path
,
method: :get
,
class:
"form-inline"
)
do
.row
.row
.col-md-
10
.mb-md-0.no-padding
.col-md-
8
.mb-md-0.no-padding
=
search_field_tag
:search
,
params
[
:search
],
placeholder:
'Find a job (name, company, position)'
,
class:
'form-control rounded-left no-border-radius bg-light h-100'
=
search_field_tag
:search
,
params
[
:search
],
placeholder:
'Find a job (name, company, position)'
,
class:
'form-control rounded-left no-border-radius bg-light h-100'
.col-md-2.mb-md-0.no-padding
.col-md-2.mb-md-0.no-padding
=
select_tag
(
:salary
,
options_for_select
(
@salary_range
.
collect
{
|
s
|
[
vnd_format
(
s
),
s
]},
params
[
:salary
]
),
class
:"form-select
bg-light
h-100")
.col-md-2.mb-md-0.no-padding
=
submit_tag
"Search"
,
class:
"h-100 w-100 btn btn-block btn-lg btn-info"
=
submit_tag
"Search"
,
class:
"h-100 w-100 btn btn-block btn-lg btn-info"
\ No newline at end of file
lib/tasks/web_crawler.rake
View file @
951ee8fe
...
@@ -64,7 +64,7 @@ namespace :crawler do
...
@@ -64,7 +64,7 @@ namespace :crawler do
end
end
# salary
# salary
if
salary
.
include?
(
'USD'
)
if
salary
.
include?
(
'USD'
)
parsed
=
parse_salary
(
salary
.
remove
(
'USD'
),
23_000
)
parsed
=
parse_salary
(
salary
.
remove
(
'USD'
,
','
),
23_000
)
if
parsed
.
length
==
1
if
parsed
.
length
==
1
min_salary
=
parsed
[
0
]
min_salary
=
parsed
[
0
]
max_salary
=
parsed
[
0
]
max_salary
=
parsed
[
0
]
...
...
q
0 → 100644
View file @
951ee8fe
[1mFrom:[0m /home/hamht/ThaiHa/VenJob/app/controllers/jobs_controller.rb:21 JobsController#index:
[1;34m5[0m: [32mdef[0m [1;34mindex[0m
[1;34m6[0m: @search = params
[1;34m7[0m: solr = [1;34;4mSolr[0m.new(@search)
[1;34m8[0m: [32mif[0m params[[33m:city_slug[0m]
[1;34m9[0m: jobs_query = solr.query_by_city
[1;34m10[0m: @name = [1;34;4mCity[0m.find_by([35mslug[0m: params[[33m:city_slug[0m]).name
[1;34m11[0m: [32melsif[0m params[[33m:industry_slug[0m]
[1;34m12[0m: jobs_query = solr.query_by_industry
[1;34m13[0m: @name = [1;34;4mIndustry[0m.find_by([35mslug[0m: params[[33m:industry_slug[0m]).name
[1;34m14[0m: [32melse[0m
[1;34m15[0m: jobs_query = solr.query_all
[1;34m16[0m: @name = [31m[1;31m'[0m[31mJobs[1;31m'[0m[31m[0m
[1;34m17[0m: [32mend[0m
[1;34m18[0m:
[1;34m19[0m: get_jobs(jobs_query)
[1;34m20[0m: @jobs = [1;34;4mKaminari[0m.paginate_array(@jobs).page(params[[33m:page[0m]).per([1;34;4mJob[0m::[1;34;4mJOB_PER_PAGE[0m)
=> [1;34m21[0m: binding.pry
[1;34m22[0m: [32mend[0m
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