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
f286a516
Commit
f286a516
authored
Oct 21, 2021
by
Nguyen Hoang Mai Phuong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix method query job from solr and pagination
parent
ebd5b445
Pipeline
#1492
failed with stages
in 0 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
20 deletions
+18
-20
app/controllers/jobs_controller.rb
+3
-3
app/helpers/application_helper.rb
+2
-2
app/views/jobs/search.html.slim
+7
-7
lib/solr/solr_search.rb
+6
-8
No files found.
app/controllers/jobs_controller.rb
View file @
f286a516
...
@@ -23,9 +23,9 @@ class JobsController < ApplicationController
...
@@ -23,9 +23,9 @@ class JobsController < ApplicationController
def
search
def
search
@keyword
=
job_params
[
:search
].
gsub!
(
/[^[:alnum:]]/
,
' '
)
@keyword
=
job_params
[
:search
].
gsub!
(
/[^[:alnum:]]/
,
' '
)
search_param
=
SolrSearch
.
new
.
search
(
@keyword
)
response
=
SolrSearch
.
new
.
search
(
@keyword
)
@result_search
=
Kaminari
.
paginate_array
(
search_param
).
page
(
params
[
:page
])
@result_search
=
Kaminari
.
paginate_array
(
response
).
page
(
params
[
:page
])
@total
=
search_param
.
count
@total
=
response
.
count
end
end
private
private
...
...
app/helpers/application_helper.rb
View file @
f286a516
...
@@ -29,7 +29,7 @@ module ApplicationHelper
...
@@ -29,7 +29,7 @@ module ApplicationHelper
FavoriteJob
.
find_by
(
job:
job
,
user:
current_user
).
present?
?
'Unfavorite'
:
'Favorite'
FavoriteJob
.
find_by
(
job:
job
,
user:
current_user
).
present?
?
'Unfavorite'
:
'Favorite'
end
end
def
search
(
input
)
def
query_job
(
job
)
Job
.
find_by
(
id:
input
[
'job_id'
])
Job
.
find_by
(
id:
job
[
'job_id'
])
end
end
end
end
app/views/jobs/search.html.slim
View file @
f286a516
...
@@ -12,23 +12,23 @@
...
@@ -12,23 +12,23 @@
.row.bg-white
.row.bg-white
.col-10.p-3.card-body.text-dark
.col-10.p-3.card-body.text-dark
h5
.mb-1
h5
.mb-1
=
link_to
search
(
job
).
title
,
detail_path
(
job
[
'slug'
])
=
link_to
query_job
(
job
).
title
,
detail_path
(
job
[
'slug'
])
p
.mb-1
p
.mb-1
=
search
(
job
).
company
.
name
=
query_job
(
job
).
company
.
name
p
.mb-1
p
.mb-1
i
.fas.fa-dollar-sign.m-1
i
.fas.fa-dollar-sign.m-1
|
Lương:
|
Lương:
=
search
(
job
).
salary
=
query_job
(
job
).
salary
p
.mb-1
p
.mb-1
i
.fas.fa-map-marker-alt.m-1
i
.fas.fa-map-marker-alt.m-1
=
search
(
job
).
cities
.
map
(
&
:name
).
uniq
.
join
(
' | '
)
=
query_job
(
job
).
cities
.
map
(
&
:name
).
uniq
.
join
(
' | '
)
p
.mb-1
p
.mb-1
i
.fas.fa-map-marker-alt.m-1
i
.fas.fa-map-marker-alt.m-1
=
search
(
job
).
industries
.
map
(
&
:name
).
uniq
.
join
(
' | '
)
=
query_job
(
job
).
industries
.
map
(
&
:name
).
uniq
.
join
(
' | '
)
p
.mb-1
p
.mb-1
=
truncate
(
search
(
job
).
overview
,
length:
250
)
=
truncate
(
query_job
(
job
).
overview
,
length:
250
)
.col-sm-2.p-3.favourite
.col-sm-2.p-3.favourite
=
render
partial:
"favorite_jobs/favorite"
,
locals:
{
job:
search
(
job
)
}
=
render
partial:
"favorite_jobs/favorite"
,
locals:
{
job:
query_job
(
job
)
}
-
if
@result_search
.
any?
-
if
@result_search
.
any?
.d-flex.justify-content-center.p-2
.d-flex.justify-content-center.p-2
=
page_entries_info
@result_search
=
page_entries_info
@result_search
...
...
lib/solr/solr_search.rb
View file @
f286a516
...
@@ -4,11 +4,9 @@ class SolrSearch
...
@@ -4,11 +4,9 @@ class SolrSearch
end
end
def
search
(
keyword
)
def
search
(
keyword
)
response
=
@solr
.
get
'select'
,
params:
{
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
}
*"
,
q:
"cities_name:
#{
keyword
}
or title:
#{
keyword
}
or industries_name:
#{
keyword
}
* or company_name:
#{
keyword
}
*"
,
fl:
%w[job_id slug]
,
fl:
%w[job_id slug]
start:
0
,
rows:
2_147_483_647
}
}
response
[
'response'
][
'docs'
]
response
[
'response'
][
'docs'
]
end
end
...
@@ -24,13 +22,13 @@ class SolrSearch
...
@@ -24,13 +22,13 @@ class SolrSearch
cities
=
record
.
cities
.
uniq
.
map
(
&
:name
)
cities
=
record
.
cities
.
uniq
.
map
(
&
:name
)
industries
=
record
.
industries
.
uniq
.
map
(
&
:name
)
industries
=
record
.
industries
.
uniq
.
map
(
&
:name
)
slug
=
record
.
slug
slug
=
record
.
slug
@solr
.
add
(
job_id:
job_id
,
title:
title
,
company_name:
company_name
,
cities_name:
cities
,
@solr
.
add
(
job_id:
job_id
,
title:
title
,
company_name:
company_name
,
cities_name:
cities
,
industries_name:
industries
,
slug:
slug
)
industries_name:
industries
,
slug:
slug
)
@solr
.
commit
@solr
.
commit
rescue
StandardError
=>
error
rescue
StandardError
=>
error
logger
.
error
"The job has error:
#{
job_id
}
"
logger
.
error
(
"The job has error:
#{
job_id
}
"
)
logger
.
error
error
logger
.
error
(
error
)
next
next
end
end
logger
.
info
"End add data at:
#{
Time
.
current
}
"
logger
.
info
"End add data at:
#{
Time
.
current
}
"
...
...
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