-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConditionGenerator.php
94 lines (86 loc) · 2.86 KB
/
ConditionGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
declare(strict_types=1);
/*
* This file is part of the RollerworksSearch package.
*
* (c) Sebastiaan Stok <s.stok@rollerscapes.net>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Rollerworks\Component\Search\Elasticsearch;
use Elastica\Query;
use Rollerworks\Component\Search\SearchCondition;
/**
* ConditionGenerator.
*
* Sample usage with Elastica:
*
* ```
* <?php
* $search = new \Elastica\Search();
*
* // TODO: properly create a search condition here
* $searchCondition = \Rollerworks\Component\SearchSearchCondition();
*
* $generator = Rollerworks\Component\Search\Elasticsearch\QueryConditionGenerator($searchCondition);
* $generator
* ->registerField('fieldset-alias', '/elasticsearch-index/elasticsearch-type#elasticsearch.property');
*
* $mappings = $generator->getMappings();
* foreach ($mappings as $mapping) {
* $search
* ->addIndex($mapping->indexName)
* ->addType($mapping->typeName);
* }
*
* $query = $generator->getQuery();
* $results = $search->search($query);
* ```
*/
interface ConditionGenerator
{
/**
* Supported Elasticsearch property mapping formats:
* - <property>
* - <sub.property>
* - <nested[].property>
* - <sub.nested[].property>
* - <index>#<property>
* - <index>#<nested[].property>
* - <index>#<sub.nested[].property>
* - <index>/<type>#<property>
* - <index>/<type>#<sub.nested[].property>
* with object dot-notation and [] indicating nested objects.
*
* See references for objects and nested objects.
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/object.html
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html
*
* @param string $fieldName Field set name
* @param string $mapping Elasticsearch property mapping
* @param array $conditions Additional conditions to apply if this mapping is used
* @param array $options Additional options to send directly to Elasticsearch
*
* @return static
*/
public function registerField(string $fieldName, string $mapping, array $conditions = [], array $options = []);
/**
* Return a valid Elastica\Query search query. Query can be sent to a _search endpoint as is.
*/
public function getQuery(): Query;
/**
* Return mappings actually used in the query. It allows to restrict the query on specific indices/types.
*
* @return FieldMapping[]
*/
public function getMappings(): array;
/**
* Returns the assigned SearchCondition.
*
* @internal
*/
public function getSearchCondition(): SearchCondition;
}