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 Hoang Mai Phuong
VeNJOB
Commits
42fd7020
Commit
42fd7020
authored
Oct 22, 2021
by
Nguyen Hoang Mai Phuong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix paginaion and refactor controller
parent
f286a516
Pipeline
#1493
failed with stages
in 0 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
25 deletions
+23
-25
app/controllers/jobs_controller.rb
+5
-3
app/helpers/application_helper.rb
+0
-4
app/models/job.rb
+1
-1
app/views/jobs/search.html.slim
+13
-12
lib/solr/solr_search.rb
+4
-5
No files found.
app/controllers/jobs_controller.rb
View file @
42fd7020
...
...
@@ -23,9 +23,11 @@ class JobsController < ApplicationController
def
search
@keyword
=
job_params
[
:search
].
gsub!
(
/[^[:alnum:]]/
,
' '
)
response
=
SolrSearch
.
new
.
search
(
@keyword
)
@result_search
=
Kaminari
.
paginate_array
(
response
).
page
(
params
[
:page
])
@total
=
response
.
count
response
=
SolrSearch
.
new
.
search
(
@keyword
,
params
[
:page
])
job_ids
=
response
[
'response'
][
'docs'
].
map
{
|
job
|
job
[
'job_id'
]
}
jobs
=
Job
.
latest_jobs
.
find
(
job_ids
)
@total
=
response
[
'response'
][
'numFound'
]
@jobs
=
Kaminari
.
paginate_array
(
jobs
,
total_count:
@total
).
page
(
params
[
:page
])
end
private
...
...
app/helpers/application_helper.rb
View file @
42fd7020
...
...
@@ -28,8 +28,4 @@ module ApplicationHelper
def
favorite_text
(
job
)
FavoriteJob
.
find_by
(
job:
job
,
user:
current_user
).
present?
?
'Unfavorite'
:
'Favorite'
end
def
query_job
(
job
)
Job
.
find_by
(
id:
job
[
'job_id'
])
end
end
app/models/job.rb
View file @
42fd7020
...
...
@@ -8,7 +8,7 @@ class Job < ApplicationRecord
has_and_belongs_to_many
:industries
has_and_belongs_to_many
:cities
LATEST_JOB_NUMBER
=
5
scope
:latest_jobs
,
->
{
includes
(
:cities
,
:company
).
order
(
'created_at DESC'
)
}
scope
:latest_jobs
,
->
{
includes
(
:cities
,
:company
,
:industries
).
order
(
'created_at DESC'
)
}
def
normalize_friendly_id
(
string
)
string
.
to_s
.
to_slug
.
normalize
(
transliterations: :vietnamese
).
to_s
...
...
app/views/jobs/search.html.slim
View file @
42fd7020
...
...
@@ -6,34 +6,34 @@
|
Result for:
=
@keyword
.d-flex.justify-content-center.p-2
=
paginate
@
result_search
,
window:
1
=
paginate
@
jobs
,
window:
1
.job-list
-
@
result_search
.
each
do
|
job
|
-
@
jobs
.
each
do
|
job
|
.row.bg-white
.col-10.p-3.card-body.text-dark
h5
.mb-1
=
link_to
query_job
(
job
).
title
,
detail_path
(
job
[
'slug'
]
)
=
link_to
job
.
title
,
detail_path
(
job
.
slug
)
p
.mb-1
=
query_job
(
job
)
.
company
.
name
=
job
.
company
.
name
p
.mb-1
i
.fas.fa-dollar-sign.m-1
|
Lương:
=
query_job
(
job
)
.
salary
=
job
.
salary
p
.mb-1
i
.fas.fa-map-marker-alt.m-1
=
query_job
(
job
)
.
cities
.
map
(
&
:name
).
uniq
.
join
(
' | '
)
=
job
.
cities
.
map
(
&
:name
).
uniq
.
join
(
' | '
)
p
.mb-1
i
.fas.fa-map-marker-alt.m-1
=
query_job
(
job
)
.
industries
.
map
(
&
:name
).
uniq
.
join
(
' | '
)
=
job
.
industries
.
map
(
&
:name
).
uniq
.
join
(
' | '
)
p
.mb-1
=
truncate
(
query_job
(
job
)
.
overview
,
length:
250
)
=
truncate
(
job
.
overview
,
length:
250
)
.col-sm-2.p-3.favourite
=
render
partial:
"favorite_jobs/favorite"
,
locals:
{
job:
query_job
(
job
)
}
-
if
@
result_search
.
any?
=
render
partial:
"favorite_jobs/favorite"
,
locals:
{
job:
job
}
-
if
@
jobs
.
any?
.d-flex.justify-content-center.p-2
=
page_entries_info
@
result_search
=
page_entries_info
@
jobs
.d-flex.justify-content-center.p-2
=
paginate
@
result_search
,
window:
1
=
paginate
@
jobs
,
window:
1
-
else
h4
.text-center
|
Not have any jobs you need
\ No newline at end of file
lib/solr/solr_search.rb
View file @
42fd7020
...
...
@@ -3,12 +3,11 @@ class SolrSearch
@solr
=
RSolr
.
connect
url:
'http://localhost:8983/solr/VeNJOB'
end
def
search
(
keyword
)
response
=
@solr
.
paginate
1
,
2_147_483_647
,
'select'
,
params:
{
q:
"cities_name:
#{
keyword
}
or title:
#{
keyword
}
or industries_name:
#{
keyword
}
* or company_name:
#{
keyword
}
*
"
,
fl:
%w[job_id slug]
def
search
(
keyword
,
current_page
)
@solr
.
paginate
current_page
,
20
,
'select'
,
params:
{
q:
"cities_name:
#{
keyword
}
or title:
#{
keyword
}
or industries_name:
#{
keyword
}
or company_name:
#{
keyword
}
"
,
fl:
'job_id'
}
response
[
'response'
][
'docs'
]
end
def
add_data
...
...
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