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
def
search
@keyword
=
job_params
[
:search
].
gsub!
(
/[^[:alnum:]]/
,
' '
)
search_param
=
SolrSearch
.
new
.
search
(
@keyword
)
@result_search
=
Kaminari
.
paginate_array
(
search_param
).
page
(
params
[
:page
])
@total
=
search_param
.
count
response
=
SolrSearch
.
new
.
search
(
@keyword
)
@result_search
=
Kaminari
.
paginate_array
(
response
).
page
(
params
[
:page
])
@total
=
response
.
count
end
private
...
...
app/helpers/application_helper.rb
View file @
f286a516
...
...
@@ -29,7 +29,7 @@ module ApplicationHelper
FavoriteJob
.
find_by
(
job:
job
,
user:
current_user
).
present?
?
'Unfavorite'
:
'Favorite'
end
def
search
(
input
)
Job
.
find_by
(
id:
input
[
'job_id'
])
def
query_job
(
job
)
Job
.
find_by
(
id:
job
[
'job_id'
])
end
end
app/views/jobs/search.html.slim
View file @
f286a516
...
...
@@ -12,23 +12,23 @@
.row.bg-white
.col-10.p-3.card-body.text-dark
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
=
search
(
job
).
company
.
name
=
query_job
(
job
).
company
.
name
p
.mb-1
i
.fas.fa-dollar-sign.m-1
|
Lương:
=
search
(
job
).
salary
=
query_job
(
job
).
salary
p
.mb-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
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
=
truncate
(
search
(
job
).
overview
,
length:
250
)
=
truncate
(
query_job
(
job
).
overview
,
length:
250
)
.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?
.d-flex.justify-content-center.p-2
=
page_entries_info
@result_search
...
...
lib/solr/solr_search.rb
View file @
f286a516
...
...
@@ -4,11 +4,9 @@ class SolrSearch
end
def
search
(
keyword
)
response
=
@solr
.
get
'select'
,
params:
{
q:
"cities_name:
#{
keyword
}
* or title:
#{
keyword
}
* or industries_name:
#{
keyword
}
* or company_name:
#{
keyword
}
*"
,
fl:
%w[job_id slug]
,
start:
0
,
rows:
2_147_483_647
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]
}
response
[
'response'
][
'docs'
]
end
...
...
@@ -24,13 +22,13 @@ class SolrSearch
cities
=
record
.
cities
.
uniq
.
map
(
&
:name
)
industries
=
record
.
industries
.
uniq
.
map
(
&
:name
)
slug
=
record
.
slug
@solr
.
add
(
job_id:
job_id
,
title:
title
,
company_name:
company_name
,
cities_name:
cities
,
industries_name:
industries
,
slug:
slug
)
@solr
.
commit
rescue
StandardError
=>
error
logger
.
error
"The job has error:
#{
job_id
}
"
logger
.
error
error
logger
.
error
(
"The job has error:
#{
job_id
}
"
)
logger
.
error
(
error
)
next
end
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