public function indexAction()
 {
     if (null === ($q = $this->getRequest()->getParam('q'))) {
         $this->getResponse()->setHeader('X-Error-Msg', 'Missing required parameter `q`');
         throw new Zend_Controller_Exception('Missing required parameter `q`', 400);
     }
     $q = Api_Models_Utils::addStatusToQuery($q);
     $concepts = $this->model->getConcepts($q, $this->shouldIncludeDeleted($q), false, $this->getRequest()->getParam('sort'));
     $context = $this->_helper->contextSwitch()->getCurrentContext();
     if ($context === 'json' || $context === 'jsonp') {
         foreach ($concepts as $key => $val) {
             foreach ($val['docs'] as &$doc) {
                 unset($doc['xml']);
             }
             $this->view->{$key} = $val;
         }
     } elseif ($context === 'xml') {
         $xpath = new DOMXPath($concepts);
         foreach ($xpath->query('/response/result/doc/str[@name="xml"]') as $node) {
             $node->parentNode->removeChild($node);
         }
         $this->view->response = $concepts;
     } else {
         $model = new OpenSKOS_Db_Table_Namespaces();
         $this->view->namespaces = $model->fetchPairs();
         $this->view->response = $concepts;
     }
 }
 public function indexAction()
 {
     if (null === ($q = $this->getRequest()->getParam('q'))) {
         $this->getResponse()->setHeader('X-Error-Msg', 'Missing required parameter `q`');
         throw new Zend_Controller_Exception('Missing required parameter `q`', 400);
     }
     $q = Api_Models_Utils::addStatusToQuery($q);
     $this->_helper->contextSwitch()->setAutoJsonSerialization(false);
     $this->getResponse()->setBody(json_encode($this->model->getConcepts($q, null, true)));
 }
 public function autocomplete($label, $includeDeleted = false, $autoStatus = true)
 {
     $lang = $this->lang;
     $label = strtolower($label);
     $labelSearchField = 'LexicalLabels';
     $labelReturnField = $this->_getLabelReturnField();
     if (null !== ($labelField = $this->getQueryParam('searchLabel', 'prefLabel'))) {
         if (preg_match('/^(pref|alt|hidden)Label$/', $labelField)) {
             $labelSearchField = $labelField;
         }
     }
     $labelSearchFieldAutocomplete = $labelSearchField . 'Autocomplete';
     $labelSearchFieldAutocomplete .= null === $lang ? '' : '@' . $lang;
     $labelSearchFieldText = $labelSearchField . 'Text';
     $labelSearchFieldText .= null === $lang ? '' : '@' . $lang;
     // Quotes or spaces not working if the search is not escaped.
     // We do not escape * and ? because they sometimes are used for searching.
     $labelEscaped = OpenSKOS_Solr_Queryparser_Editor_ParseSearchText::escapeSpecialChars($label);
     $q = "({$labelSearchFieldAutocomplete}:{$labelEscaped} OR {$labelSearchFieldText}:{$labelEscaped}*)";
     //only return non-deleted items:
     if (false === $includeDeleted) {
         $q = "({$q}) AND deleted:false";
     }
     if ($autoStatus) {
         $q = Api_Models_Utils::addStatusToQuery($q);
     }
     $params = array('facet' => 'true', 'facet.field' => $labelReturnField, 'fq' => $q, 'facet.mincount' => 1);
     $response = $this->solr()->setFields(array('uuid', $labelReturnField))->limit(0, 0)->search($q, $params);
     $this->solr()->setFields(array());
     $labels = array();
     foreach ($response['facet_counts']['facet_fields'][$labelReturnField] as $label => $count) {
         $labels[] = $label;
     }
     return $labels;
 }