Completed
Pull Request — master (#64)
by Thibaud
03:06
created

SearchRepository::search()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
3
namespace PhraseanetSDK\Search;
4
5
use PhraseanetSDK\Exception\RuntimeException;
6
use PhraseanetSDK\AbstractRepository;
7
8
class SearchRepository extends AbstractRepository
9
{
10
11
    /**
12
     * Search for records or stories, returning only references to the matching entities.
13
     *
14
     * @param  mixed[] $parameters Query parameters
15
     * @return SearchResults object
16
     * @throws RuntimeException
17
     */
18
    public function search(array $parameters = array())
19
    {
20
        $parameters = array_merge([
21
            'search_type' => SearchResult::TYPE_RECORD
22
        ], $parameters);
23
24
        $response = $this->query('POST', 'v2/search/', array(), $parameters);
25
26
        if ($response->isEmpty()) {
27
            throw new RuntimeException('Response content is empty');
28
        }
29
30
        return SearchResults::fromValue($this->em, $parameters['search_type'], $response->getResult());
31
    }
32
}
33