1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FOS\ElasticaBundle\Finder; |
4
|
|
|
|
5
|
|
|
use Elastica\Document; |
6
|
|
|
use FOS\ElasticaBundle\Paginator\HybridPaginatorAdapter; |
7
|
|
|
use FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface; |
8
|
|
|
use FOS\ElasticaBundle\Paginator\TransformedPaginatorAdapter; |
9
|
|
|
use FOS\ElasticaBundle\Paginator\FantaPaginatorAdapter; |
10
|
|
|
use Pagerfanta\Pagerfanta; |
11
|
|
|
use Elastica\SearchableInterface; |
12
|
|
|
use Elastica\Query; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Finds elastica documents and map them to persisted objects. |
16
|
|
|
*/ |
17
|
|
|
class TransformedFinder implements PaginatedFinderInterface |
18
|
|
|
{ |
19
|
|
|
protected $searchable; |
20
|
|
|
protected $transformer; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param SearchableInterface $searchable |
24
|
|
|
* @param ElasticaToModelTransformerInterface $transformer |
25
|
|
|
*/ |
26
|
8 |
|
public function __construct(SearchableInterface $searchable, ElasticaToModelTransformerInterface $transformer) |
27
|
|
|
{ |
28
|
8 |
|
$this->searchable = $searchable; |
29
|
8 |
|
$this->transformer = $transformer; |
30
|
8 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
1 |
|
public function find($query, $limit = null, $options = array()) |
36
|
|
|
{ |
37
|
1 |
|
$results = $this->search($query, $limit, $options); |
38
|
|
|
|
39
|
1 |
|
return $this->transformer->transform($results); |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
public function findHybrid($query, $limit = null, $options = array()) |
43
|
|
|
{ |
44
|
1 |
|
$results = $this->search($query, $limit, $options); |
45
|
|
|
|
46
|
1 |
|
return $this->transformer->hybridTransform($results); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Find documents similar to one with passed id. |
51
|
|
|
* |
52
|
|
|
* @param integer $id |
53
|
|
|
* @param array $params |
54
|
|
|
* @param array $query |
55
|
|
|
* |
56
|
|
|
* @return array of model objects |
57
|
|
|
**/ |
58
|
1 |
|
public function moreLikeThis($id, $params = array(), $query = array()) |
59
|
|
|
{ |
60
|
1 |
|
$doc = new Document($id); |
61
|
1 |
|
$results = $this->searchable->moreLikeThis($doc, $params, $query)->getResults(); |
|
|
|
|
62
|
|
|
|
63
|
1 |
|
return $this->transformer->transform($results); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param $query |
68
|
|
|
* @param null|int $limit |
69
|
|
|
* @param array $options |
70
|
|
|
* |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
1 |
|
protected function search($query, $limit = null, $options = array()) |
74
|
|
|
{ |
75
|
1 |
|
$queryObject = Query::create($query); |
76
|
1 |
|
if (null !== $limit) { |
77
|
1 |
|
$queryObject->setSize($limit); |
78
|
|
|
} |
79
|
1 |
|
$results = $this->searchable->search($queryObject, $options)->getResults(); |
80
|
|
|
|
81
|
1 |
|
return $results; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
1 |
|
public function findPaginated($query, $options = array()) |
88
|
|
|
{ |
89
|
1 |
|
$queryObject = Query::create($query); |
90
|
1 |
|
$paginatorAdapter = $this->createPaginatorAdapter($queryObject, $options); |
91
|
|
|
|
92
|
1 |
|
return new Pagerfanta(new FantaPaginatorAdapter($paginatorAdapter)); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritdoc} |
97
|
|
|
*/ |
98
|
2 |
|
public function createPaginatorAdapter($query, $options = array()) |
99
|
|
|
{ |
100
|
2 |
|
$query = Query::create($query); |
101
|
|
|
|
102
|
2 |
|
return new TransformedPaginatorAdapter($this->searchable, $query, $options, $this->transformer); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
1 |
|
public function createHybridPaginatorAdapter($query) |
109
|
|
|
{ |
110
|
1 |
|
$query = Query::create($query); |
111
|
|
|
|
112
|
1 |
|
return new HybridPaginatorAdapter($this->searchable, $query, $this->transformer); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* {@inheritdoc} |
117
|
|
|
*/ |
118
|
|
|
public function createRawPaginatorAdapter($query) |
119
|
|
|
{ |
120
|
|
|
$query = Query::create($query); |
121
|
|
|
|
122
|
|
|
return new RawPaginatorAdapter($this->searchable, $query); |
|
|
|
|
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.