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
9ccd2f4c
Commit
9ccd2f4c
authored
Nov 10, 2021
by
Mai Hoang Thai Ha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
search
parent
c4008be4
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
18 deletions
+45
-18
app/controllers/application_controller.rb
+6
-1
app/controllers/jobs_controller.rb
+17
-10
app/controllers/top_controller.rb
+1
-0
app/services/solr.rb
+6
-6
app/views/shared/_search.html.slim
+15
-1
No files found.
app/controllers/application_controller.rb
View file @
9ccd2f4c
...
...
@@ -14,7 +14,12 @@ class ApplicationController < ActionController::Base
private
def
city_industry_list
@city_slug_list
=
City
.
pluck
(
:name
)
@industry_slug_list
=
Industry
.
pluck
(
:name
)
end
def
salary_search
@salary_range
=
[
0
,
3_000_000
,
7_000_000
,
10_000_000
,
15_000_000
,
20_000_000
,
30_000_000
]
@salary_range
=
[
3_000_000
,
7_000_000
,
10_000_000
,
15_000_000
,
20_000_000
,
30_000_000
]
end
end
app/controllers/jobs_controller.rb
View file @
9ccd2f4c
class
JobsController
<
ApplicationController
before_action
:history
,
only: :show
before_action
:salary_search
before_action
:city_industry_list
before_action
:name
,
only: :index
def
index
@search
=
params
solr
=
Solr
.
new
(
@search
)
if
params
[
:city_slug
]
jobs_query
=
solr
.
query_by_city
@name
=
City
.
find_by
(
slug:
params
[
:city_slug
]).
name
solr
=
Solr
.
new
(
params
)
jobs_query
=
if
params
[
:city_slug
]
solr
.
query_by_city
elsif
params
[
:industry_slug
]
jobs_query
=
solr
.
query_by_industry
@name
=
Industry
.
find_by
(
slug:
params
[
:industry_slug
]).
name
solr
.
query_by_industry
else
jobs_query
=
solr
.
query_all
@name
=
'Jobs'
solr
.
query_all
end
get_jobs
(
jobs_query
)
@jobs
=
Kaminari
.
paginate_array
(
@jobs
).
page
(
params
[
:page
]).
per
(
Job
::
JOB_PER_PAGE
)
end
...
...
@@ -34,6 +31,16 @@ class JobsController < ApplicationController
history
.
update
(
updated_at:
Time
.
current
)
end
def
name
@name
=
if
params
[
:city_slug
]
City
.
find_by
(
slug:
params
[
:city_slug
]).
name
elsif
params
[
:industry_slug
]
Industry
.
find_by
(
slug:
params
[
:industry_slug
]).
name
else
'Jobs'
end
end
def
get_jobs
(
query
)
jobs_ids
=
query
[
'response'
][
'docs'
].
map
{
|
j
|
j
[
'job_id'
]
}
@jobs
=
Job
.
eager_load
(
:cities
,
:cities_jobs
,
:company
).
find
(
jobs_ids
)
...
...
app/controllers/top_controller.rb
View file @
9ccd2f4c
class
TopController
<
ApplicationController
before_action
:salary_search
before_action
:city_industry_list
def
index
@total_job
=
Job
.
count
...
...
app/services/solr.rb
View file @
9ccd2f4c
...
...
@@ -38,11 +38,10 @@ class Solr
def
query_all
q
=
"search:*
#{
@params
[
:search
]
}
*"
fq
=
if
@params
[
:salary
]
"min_salary: [
#{
@params
[
:salary
]
}
TO *]"
else
''
end
fq
=
[]
fq
.
push
(
"min_salary: [
#{
@params
[
:salary
]
}
TO *]"
)
if
@params
[
:salary
].
present?
fq
.
push
(
"cities_name:
\"
#{
escape_str
(
@params
[
:city
])
}
\"
"
)
if
@params
[
:city
].
present?
fq
.
push
(
"industries_name:
\"
#{
escape_str
(
@params
[
:industry
])
}
\"
"
)
if
@params
[
:industry
].
present?
send_request
(
q
,
fq
)
end
...
...
@@ -101,7 +100,8 @@ class Solr
end
def
escape_str
(
str
)
RSolr
.
solr_escape
(
str
)
# RSolr.solr_escape(str)
CGI
::
escapeHTML
(
str
)
end
def
city_handle
(
ids
,
jobs_count
)
...
...
app/views/shared/_search.html.slim
View file @
9ccd2f4c
...
...
@@ -29,12 +29,26 @@
-
else
=
form_tag
(
jobs_path
,
method: :get
,
class:
"form-inline"
)
do
.row
.col-md-
8
.mb-md-0.no-padding
.col-md-
4
.mb-md-0.no-padding
=
search_field_tag
:search
,
params
[
:search
],
placeholder:
'Find a job (name, company, position)'
,
class:
'form-control rounded-left no-border-radius bg-light h-100'
.col-md-2.mb-md-0.no-padding
=
select_tag
(
:city
,
options_for_select
(
@city_slug_list
,
params
[
:city
]
),
include_blank
:
'Select
city',
class
:"form-select
bg-light
h-100")
.col-md-2.mb-md-0.no-padding
=
select_tag
(
:industry
,
options_for_select
(
@industry_slug_list
,
params
[
:industry
]
),
include_blank
:
'Select
city',
class
:"form-select
bg-light
h-100")
.col-md-2.mb-md-0.no-padding
=
select_tag
(
:salary
,
options_for_select
(
@salary_range
.
collect
{
|
s
|
[
vnd_format
(
s
),
s
]},
params
[
:salary
]
),
include_blank
:
'Select
salary',
class
:"form-select
bg-light
h-100")
.col-md-2.mb-md-0.no-padding
=
submit_tag
"Search"
,
class:
"h-100 w-100 btn btn-block btn-lg btn-info"
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