/** * Performs the search function calls. And wraps the result in a json-ld object. * @param Request $request */ public function search($request) { $maxhits = $request->getQueryParam('maxhits'); $offset = $request->getQueryParam('offset'); $term = $request->getQueryParam('query'); if (!$term) { return $this->returnError(400, "Bad Request", "query parameter missing"); } if ($maxhits && (!is_numeric($maxhits) || $maxhits <= 0)) { return $this->returnError(400, "Bad Request", "maxhits parameter is invalid"); } if ($offset && (!is_numeric($offset) || $offset < 0)) { return $this->returnError(400, "Bad Request", "offset parameter is invalid"); } $vocid = $request->getVocabId(); # optional $lang = $request->getQueryParam('lang'); # optional $labellang = $request->getQueryParam('labellang'); # optional $types = $request->getQueryParam('type') ? explode(' ', $request->getQueryParam('type')) : array('skos:Concept'); $parent = $request->getQueryParam('parent'); $group = $request->getQueryParam('group'); $fields = $request->getQueryParam('fields') ? explode(' ', $request->getQueryParam('fields')) : null; // convert to vocids array to support multi-vocabulary search $vocids = !empty($vocid) ? explode(' ', $vocid) : null; $results = $this->model->searchConcepts($term, $vocids, $labellang, $lang, $types, $parent, $group, $offset, $maxhits, true, $fields); // before serializing to JSON, get rid of the Vocabulary object that came with each resource foreach ($results as &$res) { unset($res['voc']); } $ret = array('@context' => array('skos' => 'http://www.w3.org/2004/02/skos/core#', 'onki' => 'http://schema.onki.fi/onki#', 'uri' => '@id', 'type' => '@type', 'results' => array('@id' => 'onki:results', '@container' => '@list'), 'prefLabel' => 'skos:prefLabel', 'altLabel' => 'skos:altLabel', 'hiddenLabel' => 'skos:hiddenLabel', 'broader' => 'skos:broader'), 'uri' => '', 'results' => $results); if ($labellang) { $ret['@context']['@language'] = $labellang; } elseif ($lang) { $ret['@context']['@language'] = $lang; } return $this->returnJson($ret); }