|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Solr\Filter; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
use Jobs\Entity\Location; |
|
14
|
|
|
use Jobs\Entity\Job; |
|
15
|
|
|
use Solr\Bridge\Util; |
|
16
|
|
|
use Solr\Entity\JobProxy; |
|
17
|
|
|
use SolrDisMaxQuery; |
|
18
|
|
|
use SolrQuery; |
|
19
|
|
|
use ArrayAccess; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class JobBoardPaginationQuery |
|
23
|
|
|
* |
|
24
|
|
|
* @author Anthonius Munthi <[email protected]> |
|
25
|
|
|
* @author Miroslav Fedeleš <[email protected]> |
|
26
|
|
|
* @since 0.26 |
|
27
|
|
|
* @package Solr\Filter |
|
28
|
|
|
*/ |
|
29
|
|
|
class JobBoardPaginationQuery extends AbstractPaginationQuery |
|
30
|
|
|
{ |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @inheritdoc |
|
34
|
|
|
*/ |
|
35
|
|
|
public function createQuery(array $params, SolrDisMaxQuery $query) |
|
36
|
|
|
{ |
|
37
|
|
|
$search = isset($params['search']) ? trim($params['search']) : ''; |
|
38
|
|
|
|
|
39
|
|
|
if (!empty($search)) { |
|
40
|
|
|
$q = \SolrUtils::escapeQueryChars($search); |
|
41
|
|
|
} else { |
|
42
|
|
|
$q = '*:*'; |
|
43
|
|
|
$query->addSortField('datePublishStart', SolrQuery::ORDER_DESC); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$query->setQuery($q); |
|
47
|
|
|
$query->addFilterQuery('entityName:job'); |
|
48
|
|
|
$query->addFilterQuery('isActive:1'); |
|
49
|
|
|
$query->addField('*'); |
|
50
|
|
|
|
|
51
|
|
|
if(isset($params['location'])){ |
|
52
|
|
|
/* @var Location $location */ |
|
53
|
|
|
$location = $params['location']; |
|
54
|
|
|
if(is_object($location->getCoordinates())){ |
|
55
|
|
|
$coordinate = Util::convertLocationCoordinates($location); |
|
56
|
|
|
|
|
57
|
|
|
$query->addFilterQuery( |
|
58
|
|
|
sprintf( |
|
59
|
|
|
'{!parent which="entityName:job" childQuery="entityName:location"}{!geofilt pt=%s sfield=point d=%d score="kilometers"}', |
|
60
|
|
|
$coordinate, |
|
61
|
|
|
$params['d'] |
|
62
|
|
|
)); |
|
63
|
|
|
$query->addParam( |
|
64
|
|
|
'locations.q', |
|
65
|
|
|
sprintf( |
|
66
|
|
|
'entityName:location AND {!terms f=_root_ v=$row.id} AND {!geofilt pt=%s sfield=point d=%s}', |
|
67
|
|
|
$coordinate, |
|
68
|
|
|
$params['d'] |
|
69
|
|
|
)); // join |
|
70
|
|
|
|
|
71
|
|
|
$query->addField('locations:[subquery]') |
|
72
|
|
|
->addField('distance:min(geodist(points,'.$coordinate.'))'); |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$query->addField('score'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
// boost newest jobs |
|
80
|
|
|
$query->addParam('bf', 'recip(abs(ms(NOW/HOUR,datePublishStart)),3.16e-11,1,.1)'); |
|
81
|
|
|
|
|
82
|
|
|
// adds an additional 'highlights' section into the result set |
|
83
|
|
|
$query->setHighlight(true); |
|
84
|
|
|
$query->addHighlightField('title'); |
|
85
|
|
|
|
|
86
|
|
|
return $query; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @see \Solr\Filter\AbstractPaginationQuery::proxyFactory() |
|
91
|
|
|
*/ |
|
92
|
|
|
public function proxyFactory($entity, ArrayAccess $solrResult) |
|
93
|
|
|
{ |
|
94
|
|
|
return new JobProxy($entity, $solrResult); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @see \Solr\Filter\AbstractPaginationQuery::getRepositoryName() |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getRepositoryName() |
|
101
|
|
|
{ |
|
102
|
|
|
return 'Jobs/Job'; |
|
103
|
|
|
} |
|
104
|
|
|
} |