Skip to content

Commit

Permalink
Merge pull request #7 from hayk-manasyan/related-jobs-suggestions
Browse files Browse the repository at this point in the history
- Added Similar jobs suggestions
- Code cleanup
  • Loading branch information
hayk-manasyan authored Jul 24, 2019
2 parents c60fa9a + 9b4bbde commit 1eb2cd0
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 11 deletions.
Empty file.
13 changes: 9 additions & 4 deletions module/Application/src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function searchAction()
try {
$viewModel->result = $php = $this->jobsManager->searchByTagName( $queryParam );
}catch (\Exception $ex) {
var_dump($ex->getMessage()); die;
return $this->redirect()->toRoute( 'home' );
}

return $viewModel;
Expand All @@ -68,9 +68,14 @@ public function detailAction()
}

$viewModel = new ViewModel();
$jobDetail = $this->jobsManager->searchById( $jobId );

$viewModel->job = $jobDetail;
try {
$jobDetail = $this->jobsManager->searchById( $jobId );
$relatedJobs = $this->jobsManager->getRelatedJobs($jobDetail->getTitle(), $jobDetail->getTag());
$viewModel->job = $jobDetail;
$viewModel->relatedJobs = $relatedJobs;
} catch (\Exception $ex) {
return $this->redirect()->toRoute( 'home' );
}
return $viewModel;
}

Expand Down
22 changes: 17 additions & 5 deletions module/Application/view/application/index/detail.phtml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/** @var \Jobs\Entity\Jobs $job */
$job = $this->job;
/** @var \Jobs\Entity\Jobs[] $job */
$relatedJobs = $this->relatedJobs;
if (!is_null($job)) :
/**
* @var \Jobs\Entity\Jobs
*/
$job = $this->job;
echo $this->headTitle($job->getTitle());
?>
<div class="row">
Expand All @@ -16,7 +16,7 @@ if (!is_null($job)) :
<div class="x_content">
<div class="">
<div class="row">
<div class="col-md-12">
<div class="col-md-9">
<div class="row hidden-md hidden-lg">
<h1 class="text-center">
<?php echo $job->getTitle() ?>
Expand Down Expand Up @@ -50,6 +50,18 @@ if (!is_null($job)) :
</div>
</div>
</div>
<div class="col-md-3 similar-jobs">
<h1 class="text-center text-info">Similar Jobs</h1>
<hr>
<?php foreach ($relatedJobs as $value): ?>
<h4>
<a href="<?php echo $this->basePath() . '/application/detail/' . $value->getId(); ?>">
<?php echo $value->getTitle(); ?>
</a>
</h4>
<hr>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
Expand Down
44 changes: 43 additions & 1 deletion module/Jobs/src/Manager/JobsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public function saveNewJob( $data, $source = null, $tag = null )

$hydrator = new ClassMethods();
$job = $hydrator->hydrate($data, new Jobs());
$patterns = [
'<br>',
'<br >',
'<br/>',
'<br />',
];
$description = str_replace($patterns, '', $job->getDescription());
$job->setDescription($description);

$job->setCreatedAt(date('Y-m-d H:i:s'));
$job->setCreatedAtExternal(date('Y-m-d H:i:s', strtotime($data[ 'created_at' ])));
Expand Down Expand Up @@ -132,6 +140,7 @@ public function searchByDescription($description)
ORDER BY created_at desc ";

$stmt = $db->prepare($sql);
$description .= ':*';
$stmt->bindParam("description", $description);
$stmt->execute();

Expand All @@ -145,4 +154,37 @@ public function searchByDescription($description)
return $converted;
}

}
/**
* @param $title
* @return array
* @throws \Doctrine\DBAL\DBALException
*/
public function getRelatedJobs($title, $tag)
{
$db = $this->entityManager->getConnection();
$sql = "SELECT * FROM jobs j
where to_tsvector('english', description) @@ plainto_tsquery('english', :description)
AND tag = :tag
ORDER BY created_at desc
LIMIT 15;";


$stmt = $db->prepare($sql);
$temp = explode(' ', $title);
$searchTerm = $temp[0] . ':* ' . $temp[1] . ':*';

$stmt->bindParam("description", $searchTerm);
$stmt->bindParam("tag", $tag);
$stmt->execute();

$result = $stmt->fetchAll();
$converted = [];
foreach ($result as $res) {
$res['source'] = $res['job_source'];
$converted[] = ObjectService::convertArrayToObj($res, new Jobs());
}

return $converted;
}

}
6 changes: 5 additions & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@

.top_search {
margin-top: 15px;
}
}

.similar-jobs {
border-left: 1px solid #eee;
}

0 comments on commit 1eb2cd0

Please sign in to comment.