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
3550ad23
Commit
3550ad23
authored
Feb 18, 2020
by
nnnghia98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring queries code
parent
cb872093
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
33 deletions
+40
-33
app/controllers/jobs_controller.rb
+9
-12
app/helpers/job_helper.rb
+2
-2
app/services/solr_service.rb
+29
-19
No files found.
app/controllers/jobs_controller.rb
View file @
3550ad23
...
@@ -3,23 +3,20 @@ class JobsController < ApplicationController
...
@@ -3,23 +3,20 @@ class JobsController < ApplicationController
before_action
:find_user
,
only: :apply_available
before_action
:find_user
,
only: :apply_available
def
index
def
index
@search
=
params
[
:search
]
||
":"
@search
=
params
[
:search
]
||
params
[
:city_id
]
||
params
[
:industry_id
]
||
":"
@solr
=
SolrService
.
new
solr
=
SolrService
.
new
(
@search
)
if
params
[
:city_id
]
if
params
[
:city_id
]
@city
=
City
.
find
(
params
[
:city_id
])
@jobs
=
solr
.
query_by_city
[
"docs"
]
@city_name
=
@city
.
name
@jobs_count
=
solr
.
query_by_city
[
"numFound"
]
@jobs
=
@solr
.
query_by_city
(
@city_name
)[
"docs"
]
@jobs_count
=
@solr
.
query_by_city
(
@city_name
)[
"numFound"
]
elsif
params
[
:industry_id
]
elsif
params
[
:industry_id
]
@industry
=
Industry
.
find
(
params
[
:industry_id
])
@jobs
=
solr
.
query_by_industry
[
"docs"
]
@industry_name
=
@industry
.
name
@jobs_count
=
solr
.
query_by_industry
[
"numFound"
]
@jobs
=
@solr
.
query_by_industry
(
@industry_name
)[
"docs"
]
@jobs_count
=
@solr
.
query_by_industry
(
@industry_name
)[
"numFound"
]
else
else
@jobs
=
@solr
.
search
(
@search
)
[
"docs"
]
@jobs
=
solr
.
query_all
[
"docs"
]
@jobs_count
=
@solr
.
search
(
@search
)
[
"numFound"
]
@jobs_count
=
solr
.
query_all
[
"numFound"
]
end
end
@jobs
=
Kaminari
.
paginate_array
(
@jobs
).
page
(
params
[
:page
]).
per
(
Settings
.
job
.
per_page
)
@jobs
=
Kaminari
.
paginate_array
(
@jobs
).
page
(
params
[
:page
]).
per
(
Settings
.
job
.
per_page
)
end
end
...
...
app/helpers/job_helper.rb
View file @
3550ad23
...
@@ -4,7 +4,7 @@ module JobHelper
...
@@ -4,7 +4,7 @@ module JobHelper
end
end
def
view_search_result
def
view_search_result
params
[
:city_id
]
?
"City:
#{
@
city
.
name
}
"
:
params
[
:city_id
]
?
"City:
#{
@
jobs
[
0
][
"city"
]
}
"
:
(
params
[
:industry_id
]
?
"Industry:
#{
@
industry
.
name
}
"
:
params
[
:search
])
(
params
[
:industry_id
]
?
"Industry:
#{
@
jobs
[
0
][
"industry"
]
}
"
:
params
[
:search
])
end
end
end
end
app/services/solr_service.rb
View file @
3550ad23
...
@@ -2,13 +2,15 @@ require "rsolr"
...
@@ -2,13 +2,15 @@ require "rsolr"
require
'benchmark'
require
'benchmark'
class
SolrService
class
SolrService
def
initialize
def
initialize
(
search_keyword
)
@solr
=
RSolr
.
connect
(
@solr
=
RSolr
.
connect
(
url:
Settings
.
solr
.
connection
.
server_url
,
url:
Settings
.
solr
.
connection
.
server_url
,
read_timeout:
Settings
.
solr
.
connection
.
read_timeout
,
read_timeout:
Settings
.
solr
.
connection
.
read_timeout
,
open_timeout:
Settings
.
solr
.
connection
.
open_timeout
,
open_timeout:
Settings
.
solr
.
connection
.
open_timeout
,
retry_503:
Settings
.
solr
.
connection
.
retry_503
retry_503:
Settings
.
solr
.
connection
.
retry_503
)
)
@search_keyword
=
search_keyword
end
end
def
add_data
def
add_data
...
@@ -47,29 +49,37 @@ class SolrService
...
@@ -47,29 +49,37 @@ class SolrService
@solr
.
commit
@solr
.
commit
end
end
def
search
(
params
)
def
query_all
response
=
@solr
.
get
"select"
,
params:
{
q
=
"*
#{
@search_keyword
}
*"
q:
"*
#{
params
}
*"
,
fq
=
""
rows:
Job
.
count
}
send_request
(
q
,
fq
)
response
[
"response"
]
end
end
def
query_by_city
(
city_name
)
def
query_by_city
city
=
"city:
#{
escape_str
(
city_name
)
}
"
city
=
City
.
find
(
@search_keyword
)
response
=
@solr
.
get
"select"
,
params:
{
@city_name
=
city
.
name
q:
"*:*"
,
fq:
city
,
q
=
"*:*"
rows:
Job
.
count
fq
=
"city:
#{
escape_str
(
@city_name
)
}
"
}
response
[
"response"
]
send_request
(
q
,
fq
)
end
def
query_by_industry
industry
=
Industry
.
find
(
@search_keyword
)
@industry_name
=
industry
.
name
q
=
"*:*"
fq
=
"city:
#{
escape_str
(
@industry_name
)
}
"
send_request
(
q
,
fq
)
end
end
def
query_by_industry
(
industry_name
)
def
send_request
(
q
,
fq
)
industry
=
"industry:
#{
escape_str
(
industry_name
)
}
"
response
=
@solr
.
get
"select"
,
params:
{
response
=
@solr
.
get
"select"
,
params:
{
q:
"*:*"
,
q:
q
,
fq:
industry
,
fq:
fq
,
rows:
Job
.
count
rows:
Job
.
count
}
}
response
[
"response"
]
response
[
"response"
]
...
...
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