|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the ONGR package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace ONGR\FilterManagerBundle\Filter\Widget\Search; |
|
13
|
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchDSL\Query\BoolQuery; |
|
15
|
|
|
use ONGR\ElasticsearchDSL\Query\MatchQuery; |
|
16
|
|
|
use ONGR\ElasticsearchDSL\Search; |
|
17
|
|
|
use ONGR\FilterManagerBundle\Filter\FilterState; |
|
18
|
|
|
use ONGR\FilterManagerBundle\Search\SearchRequest; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* This class runs match search. |
|
22
|
|
|
*/ |
|
23
|
|
|
class MatchSearch extends AbstractSingleValue |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) |
|
29
|
|
|
{ |
|
30
|
|
|
if ($state && $state->isActive()) { |
|
31
|
|
|
if (strpos($this->getField(), ',') !== false) { |
|
32
|
|
|
$subQuery = new BoolQuery(); |
|
33
|
|
|
foreach (explode(',', $this->getField()) as $field) { |
|
34
|
|
|
if (strpos($field, '^') === false) { |
|
35
|
|
|
$subQuery->add(new MatchQuery($field, $state->getValue()), 'should'); |
|
36
|
|
|
} else { |
|
37
|
|
|
list ($field, $boost) = explode('^', $field); |
|
38
|
|
|
|
|
39
|
|
|
$subQuery->add(new MatchQuery($field, $state->getValue(), ['boost' => $boost]), 'should'); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
$search->addQuery($subQuery, 'must'); |
|
43
|
|
|
} else { |
|
44
|
|
|
$search->addQuery(new MatchQuery($this->getField(), $state->getValue()), 'must'); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|