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
66f58ce6
Commit
66f58ce6
authored
Nov 10, 2021
by
Mai Hoang Thai Ha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
toppage using solr
parent
1c74344a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
15 deletions
+31
-15
app/controllers/top_controller.rb
+12
-4
app/models/job.rb
+0
-4
app/services/solr.rb
+14
-3
app/views/top/index.html.slim
+5
-4
No files found.
app/controllers/top_controller.rb
View file @
66f58ce6
...
@@ -3,9 +3,17 @@ class TopController < ApplicationController
...
@@ -3,9 +3,17 @@ class TopController < ApplicationController
before_action
:city_industry_list
before_action
:city_industry_list
def
index
def
index
@total_job
=
Job
.
count
solr
=
Solr
.
new
(
params
)
@latest_jobs
=
Job
.
sort_by_date
(
per_page:
Job
::
LATEST_JOBS_LIMIT
)
@latest_jobs
=
get_jobs
(
solr
.
latest_jobs
)
@top_cities
=
City
.
top_jobs
@total_job
=
solr
.
query_all
[
'response'
][
'numFound'
]
@top_industries
=
Industry
.
top_jobs
@top_cities
=
solr
.
facet_query
(
'city_id'
)[
'vietnam'
].
take
(
City
::
TOP_JOB_COUNT
)
@top_industries
=
solr
.
facet_query
(
'industry_id'
).
take
(
Industry
::
TOP_JOB_COUNT
)
end
private
def
get_jobs
(
query
)
jobs_ids
=
query
[
'response'
][
'docs'
].
map
{
|
j
|
j
[
'job_id'
]
}
Job
.
eager_load
(
:cities
,
:cities_jobs
,
:company
).
find
(
jobs_ids
)
end
end
end
end
app/models/job.rb
View file @
66f58ce6
...
@@ -14,8 +14,4 @@ class Job < ApplicationRecord
...
@@ -14,8 +14,4 @@ class Job < ApplicationRecord
has_many
:apply_jobs
,
dependent: :destroy
has_many
:apply_jobs
,
dependent: :destroy
has_many
:favorite_jobs
,
dependent: :destroy
has_many
:favorite_jobs
,
dependent: :destroy
has_many
:history_jobs
,
dependent: :destroy
has_many
:history_jobs
,
dependent: :destroy
def
self
.
sort_by_date
(
page:
1
,
per_page:
1
)
includes
(
:cities
,
:cities_jobs
,
:company
).
order
(
created_at: :desc
).
page
(
page
).
per
(
per_page
).
references
(
:cities
)
end
end
end
app/services/solr.rb
View file @
66f58ce6
...
@@ -10,6 +10,7 @@ class Solr
...
@@ -10,6 +10,7 @@ class Solr
{
{
job_id:
job
.
id
,
job_id:
job
.
id
,
job_title:
job
.
title
,
job_title:
job
.
title
,
date_submitted:
job
.
updated_at
,
company_name:
job
.
company
.
name
,
company_name:
job
.
company
.
name
,
job_level:
job
.
position
,
job_level:
job
.
position
,
min_salary:
job
.
min_salary
,
min_salary:
job
.
min_salary
,
...
@@ -45,6 +46,15 @@ class Solr
...
@@ -45,6 +46,15 @@ class Solr
send_request
(
q
,
fq
)
send_request
(
q
,
fq
)
end
end
def
latest_jobs
facet
=
nil
q
=
'*:*'
fq
=
''
sort
=
'date_submitted asc'
rows
=
Job
::
LATEST_JOBS_LIMIT
send_request
(
q
,
fq
,
facet
,
sort
,
rows
)
end
def
query_by_city
def
query_by_city
city
=
City
.
find_by
(
slug:
@params
[
:city_slug
])
city
=
City
.
find_by
(
slug:
@params
[
:city_slug
])
return
{
"numFound"
:
0
,
"docs"
:
[]
}
unless
city
return
{
"numFound"
:
0
,
"docs"
:
[]
}
unless
city
...
@@ -89,19 +99,20 @@ class Solr
...
@@ -89,19 +99,20 @@ class Solr
return
industry_handle
(
ids
,
jobs_count
)
if
facet
==
'industry_id'
return
industry_handle
(
ids
,
jobs_count
)
if
facet
==
'industry_id'
end
end
def
send_request
(
q_param
,
fq_param
,
facet_param
=
nil
)
def
send_request
(
q_param
,
fq_param
,
facet_param
=
nil
,
sort
=
''
,
rows
=
Job
.
count
)
@solr
.
get
'select'
,
params:
{
@solr
.
get
'select'
,
params:
{
'facet'
:
true
,
'facet'
:
true
,
'facet.field'
:
facet_param
,
'facet.field'
:
facet_param
,
'q'
:
q_param
,
'q'
:
q_param
,
'fq'
:
fq_param
,
'fq'
:
fq_param
,
'rows'
:
Job
.
count
'sort'
:
sort
,
'rows'
:
rows
}
}
end
end
def
escape_str
(
str
)
def
escape_str
(
str
)
# RSolr.solr_escape(str)
# RSolr.solr_escape(str)
CGI
::
escapeHTML
(
str
)
CGI
.
escapeHTML
(
str
)
end
end
def
city_handle
(
ids
,
jobs_count
)
def
city_handle
(
ids
,
jobs_count
)
...
...
app/views/top/index.html.slim
View file @
66f58ce6
...
@@ -35,12 +35,12 @@
...
@@ -35,12 +35,12 @@
h2
Top
cities
h2
Top
cities
hr
.my-2
hr
.my-2
.row.align-items-start.mb-3
.row.align-items-start.mb-3
-
@top_cities
.
each
do
|
city
,
city_jobs
|
-
@top_cities
.
each
do
|
city
|
.col-4.city-item
.col-4.city-item
=
link_to
city
[
0
],
city_jobs_path
(
city_slug:
city
[
1
]),
class:
'city-name'
=
link_to
city
[
0
],
city_jobs_path
(
city_slug:
city
[
1
]),
class:
'city-name'
span
.job-count
span
.job-count
|
(
|
(
=
pluralize
(
city
_jobs
,
'job'
)
=
pluralize
(
city
[
2
]
,
'job'
)
|)
|)
=
link_to
'See all cities'
,
cities_path
,
class
:'all-cities-btn'
=
link_to
'See all cities'
,
cities_path
,
class
:'all-cities-btn'
/ top industries
/ top industries
...
@@ -49,11 +49,11 @@
...
@@ -49,11 +49,11 @@
h2
Top
industries
h2
Top
industries
hr
.my-2
hr
.my-2
.row.align-items-start
.row.align-items-start
-
@top_industries
.
each
do
|
industry
,
industry_jobs
|
-
@top_industries
.
each
do
|
industry
|
.col-4.industry-item
.col-4.industry-item
=
link_to
industry
[
0
],
industry_jobs_path
(
industry_slug:
industry
[
1
]),
class:
'industry-name'
=
link_to
industry
[
0
],
industry_jobs_path
(
industry_slug:
industry
[
1
]),
class:
'industry-name'
span
.job-count
span
.job-count
|
(
|
(
=
pluralize
(
industry
_jobs
,
'job'
)
=
pluralize
(
industry
[
2
]
,
'job'
)
|)
|)
=
link_to
'See all industries'
,
industries_path
,
class
:'all-industries-btn'
=
link_to
'See all industries'
,
industries_path
,
class
:'all-industries-btn'
\ No newline at end of file
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