Completed
Pull Request — develop (#259)
by ANTHONIUS
09:01
created

JobBoardPaginationQuery::convertOrganizationName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
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 Organizations\Entity\Organization;
16
use Organizations\Entity\OrganizationImage;
17
use Organizations\Entity\OrganizationName;
18
use Solr\Bridge\Util;
19
use Solr\Entity\SolrJob;
20
21
/**
22
 * Class JobBoardPaginationQuery
23
 *
24
 * @author  Anthonius Munthi <[email protected]>
25
 * @since   0.26
26
 * @package Solr\Filter
27
 */
28
class JobBoardPaginationQuery extends AbstractPaginationQuery
29
{
30
    /**
31
     * @var array
32
     */
33
    protected $sortPropertiesMap = [
34
        'company' => 'companyName',
35
        'date'    => 'dateCreated',
36
    ];
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function createQuery(array $params, $query)
42
    {
43
        $search = isset($params['search']) ? $params['search']:'';
44
45
        if(!empty($search)){
46
            $q = \SolrUtils::escapeQueryChars($search);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $q is correct as \SolrUtils::escapeQueryChars($search) (which targets SolrUtils::escapeQueryChars()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
47
        }else{
48
            $q = '*:*';
49
        }
50
51
        $query->setQuery($q);
52
        $query->addFilterQuery('entityName:job');
53
        $query->addFilterQuery('isActive:1');
54
        $query->addField('*');
55
        
56
        if(isset($params['location'])){
57
            /* @var Location $location */
58
            $location = $params['location'];
59
            if(is_object($location->getCoordinates())){
60
                $coordinate = Util::convertLocationCoordinates($location);
61
62
                $query->addFilterQuery(
63
                    sprintf(
64
                        '{!parent which="entityName:job" childQuery="entityName:location"}{!geofilt pt=%s sfield=point d=%d score="kilometers"}',
65
                        $coordinate,
66
                        $params['d']
67
                    ));
68
                $query->addParam(
69
                    'locations.q',
70
                    sprintf(
71
                        'entityName:location AND {!terms f=_root_ v=$row.id} AND {!geofilt pt=%s sfield=point d=%s}',
72
                        $coordinate,
73
                        $params['d']
74
                    )); // join
75
76
                $query->addField('locations:[subquery]')
77
                      ->addField('distance:min(geodist(points,'.$coordinate.'))');
78
79
            }
80
81
            $query->addField('score');
82
        }
83
        
84
        // boost newest jobs
85
        $query->addParam('bf', 'recip(abs(ms(NOW/HOUR,datePublishStart)),3.16e-11,1,.1)');
86
87
88
        // adds facets into the result set.
89
        $query->setFacet(true);
90
        $query->addFacetField('regionList');
91
        $query->addFacetDateField('datePublishStart');
92
93
        // adds an additional 'highlights' section into the result set
94
        $query->setHighlight(true);
95
        $query->addHighlightField('title');
96
97
        return $query;
98
    }
99
100
    /**
101
     * @inheritdoc
102
     */
103
    public function getProxyClass()
104
    {
105
        return SolrJob::class;
106
    }
107
108
    public function getRepositoryName()
109
    {
110
        return 'Jobs/Job';
111
    }
112
}