|
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\ElasticsearchDSL\SearchEndpoint; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Factory for search endpoints. |
|
16
|
|
|
*/ |
|
17
|
|
|
class SearchEndpointFactory |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var array Holds namespaces for endpoints. |
|
21
|
|
|
*/ |
|
22
|
|
|
private static $endpoints = [ |
|
23
|
|
|
'query' => 'ONGR\ElasticsearchDSL\SearchEndpoint\QueryEndpoint', |
|
24
|
|
|
'post_filter' => 'ONGR\ElasticsearchDSL\SearchEndpoint\PostFilterEndpoint', |
|
25
|
|
|
'sort' => 'ONGR\ElasticsearchDSL\SearchEndpoint\SortEndpoint', |
|
26
|
|
|
'highlight' => 'ONGR\ElasticsearchDSL\SearchEndpoint\HighlightEndpoint', |
|
27
|
|
|
'aggregations' => 'ONGR\ElasticsearchDSL\SearchEndpoint\AggregationsEndpoint', |
|
28
|
|
|
'suggest' => 'ONGR\ElasticsearchDSL\SearchEndpoint\SuggestEndpoint', |
|
29
|
|
|
'inner_hits' => 'ONGR\ElasticsearchDSL\SearchEndpoint\InnerHitsEndpoint', |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Returns a search endpoint instance. |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $type Type of endpoint. |
|
36
|
|
|
* |
|
37
|
|
|
* @return SearchEndpointInterface |
|
38
|
|
|
* |
|
39
|
|
|
* @throws \RuntimeException Endpoint does not exist. |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function get($type) |
|
42
|
|
|
{ |
|
43
|
|
|
if (!array_key_exists($type, self::$endpoints)) { |
|
44
|
|
|
throw new \RuntimeException('Endpoint does not exist.'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return new self::$endpoints[$type](); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|