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 Ngoc Nghia
VeNJOB
Commits
fed36eef
Commit
fed36eef
authored
Feb 11, 2020
by
nnnghia98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
search form
parent
67778ac4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
23 deletions
+44
-23
app/controllers/jobs_controller.rb
+5
-2
app/services/solr_service.rb
+21
-14
app/views/jobs/_job.html.erb
+4
-4
app/views/jobs/index.html.erb
+8
-2
lib/tasks/task.rake
+6
-1
No files found.
app/controllers/jobs_controller.rb
View file @
fed36eef
...
...
@@ -3,17 +3,20 @@ class JobsController < ApplicationController
before_action
:find_user
,
only: :apply_available
def
index
@search
=
params
[
:search
]
||
"*:*"
if
params
[
:city_id
]
@city
=
City
.
find
(
params
[
:city_id
])
@jobs
=
@city
.
jobs
@jobs
=
@jobs
.
page
(
params
[
:page
]).
per
(
Settings
.
job
.
per_page
).
decorate
elsif
params
[
:industry_id
]
@industry
=
Industry
.
find
(
params
[
:industry_id
])
@jobs
=
@industry
.
jobs
@jobs
=
@jobs
.
page
(
params
[
:page
]).
per
(
Settings
.
job
.
per_page
).
decorate
else
@jobs
=
Job
.
all
@jobs
=
SolrService
.
new
.
search
(
@search
)
end
@jobs
=
@jobs
.
page
(
params
[
:page
]).
per
(
Settings
.
job
.
per_page
).
decorate
@jobs
=
Kaminari
.
paginate_array
(
@jobs
).
page
(
params
[
:page
]).
per
(
Settings
.
job
.
per_page
)
end
def
show
...
...
app/services/solr_service.rb
View file @
fed36eef
...
...
@@ -3,10 +3,10 @@ require "rsolr"
class
SolrService
def
initialize
@solr
=
RSolr
.
connect
(
:url
=>
Settings
.
solr
.
connection
.
server_url
,
:read_timeout
=>
Settings
.
solr
.
connection
.
read_timeout
,
:open_timeout
=>
Settings
.
solr
.
connection
.
open_timeout
,
:retry_503
=>
Settings
.
solr
.
connection
.
retry_503
url:
Settings
.
solr
.
connection
.
server_url
,
read_timeout:
Settings
.
solr
.
connection
.
read_timeout
,
open_timeout:
Settings
.
solr
.
connection
.
open_timeout
,
retry_503:
Settings
.
solr
.
connection
.
retry_503
)
end
...
...
@@ -16,13 +16,12 @@ class SolrService
{
id:
job
.
id
,
title:
job
.
title
,
category:
job
.
category
,
industry:
job
.
industries
&
.
first
&
.
name
,
description:
job
.
description
,
short_des:
job
.
short_des
,
salary:
job
.
salary
,
company:
job
.
company
.
name
,
city:
job
.
cities
&
.
first
&
.
name
,
industry:
job
.
industries
&
.
first
&
.
name
}
end
@solr
.
add
jobs_solr_index
...
...
@@ -30,14 +29,22 @@ class SolrService
end
def
delete_data
jobs
=
Job
.
includes
(
:cities
,
:industries
,
:company
).
all
jobs_solr_delete
=
jobs
.
map
do
|
job
|
{
id:
job
.
id
}
end
@solr
.
delete_by_id
jobs_solr_delete
@solr
.
delete_by_query
(
"*:*"
)
@solr
.
commit
end
def
search
(
params
)
# city = @city.present? ? "city:\"#{escape_str(@city.name)}\"" : ""
# industry = @industry.present? ? "industry:\"#{escape_str(@industry.name)}\"" : ""
response
=
@solr
.
get
"select"
,
params:
{
q:
"
#{
params
}
"
,
# fq: [industry, city],
rows:
Job
.
count
}
response
[
"response"
][
"docs"
]
end
def
escape_str
(
str
)
RSolr
.
solr_escape
(
str
)
end
end
app/views/jobs/_job.html.erb
View file @
fed36eef
...
...
@@ -2,19 +2,19 @@
<div
class=
"job_data"
>
<dl
class=
"job_data_row"
>
<dt>
Title
</dt>
<dd>
<%=
link_to
job
.
title
,
job_path
(
job
.
id
)
%>
</dd>
<dd>
<%=
link_to
job
[
"title"
],
job_path
(
job
[
"id"
]
)
%>
</dd>
</dl>
<dl
class=
"job_data_row"
>
<dt>
Short description
</dt>
<dd>
<%=
job
.
display_short_des
%>
</dd>
<dd>
<%=
job
[
"short_des"
]
&
.
truncate
(
250
)
%>
</dd>
</dl>
<dl
class=
"job_data_row"
>
<dt>
Salary
</dt>
<dd>
<%=
job
.
salary
%>
</dd>
<dd>
<%=
job
[
"salary"
]
%>
</dd>
</dl>
<dl
class=
"job_data_row"
>
<dt>
Location
</dt>
<dd>
<%=
job
.
city_name
%>
</dd>
<dd>
<%=
job
[
"city"
]
%>
</dd>
</dl>
</div>
<button
type=
"button"
class=
"btn btn-outline-secondary"
>
Favorite
</button>
...
...
app/views/jobs/index.html.erb
View file @
fed36eef
<%=
form_tag
(
jobs_path
,
method: :get
,
class:
"form-inline"
)
do
%>
<%=
search_field_tag
:search
,
params
[
:search
],
class:
"form-control mb-2 mr-sm-2"
%>
<%=
submit_tag
"Search"
,
class:
"btn btn-primary mb-2"
%>
<%
end
%>
<h3>
Total:
<%=
params
[
:city_id
]
?
@city
.
job_count
:
(
params
[
:industry_id
]
?
@industry
.
job_count
:
Job
.
count
)
%>
</h3>
<h3>
Result for:
</h3>
(
params
[
:industry_id
]
?
@industry
.
job_count
:
"Will be count on Solr"
)
%>
</h3>
<h3>
Result for:
<%=
params
[
:city_id
]
?
"City:
#{
@city
.
name
}
"
:
(
params
[
:industry_id
]
?
"Industry:
#{
@industry
.
name
}
"
:
params
[
:search
])
%>
</h3>
<%=
paginate
@jobs
%>
...
...
lib/tasks/task.rake
View file @
fed36eef
...
...
@@ -22,6 +22,11 @@ namespace :solr do
SolrService
.
new
.
delete_data
delete
=
ActiveSupport
::
Logger
.
new
(
"log/solr_service.log"
)
delete
.
info
"Solr delete data succesfully at
#{
Time
.
current
}
"
delete
.
info
"Solr delete all data succesfully at
#{
Time
.
current
}
"
end
desc
"solr search"
task
solr_search: :environment
do
SolrService
.
new
.
search
(
@search
)
end
end
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