/** * Parses the part of the query for searching inside labels and document properties. * * @return OpenSKOS_Solr_Queryparser_Editor */ protected function _parseSearchForText() { $fields = array(); $searchLanguages = $this->_getSearchLanguages(); // Search in notation if (isset($this->_searchOptions['searchNotation']) && !empty($this->_searchOptions['searchNotation'])) { $fields[] = 'notation'; } // Search in uri if (isset($this->_searchOptions['searchUri']) && !empty($this->_searchOptions['searchUri'])) { $fields[] = 'uri'; } // Search in labels. $allLabels = array(); if (isset($this->_availableSearchOptions['labels'])) { $allLabels = $this->_availableSearchOptions['labels']; } // If all labels are selected - use LexicalLabelsPhrase for search if (isset($this->_searchOptions['label']) && count($allLabels) != count($this->_searchOptions['label'])) { if (!empty($this->_searchOptions['label'])) { foreach ($this->_searchOptions['label'] as $label) { $fields = array_merge($fields, $this->_buildPerLanguageFields($label . 'Phrase', $searchLanguages)); } } else { // If there are no labels selected - do not search in labels. } } else { $fields = array_merge($fields, $this->_buildPerLanguageFields('LexicalLabelsPhrase', $searchLanguages)); } // Search in document properties. $allProperties = array(); if (isset($this->_availableSearchOptions['docproperties'])) { $allProperties = $this->_availableSearchOptions['docproperties']; } // If properties option not set or all options are selected - use DocumentationPropertiesText for search if (isset($this->_searchOptions['properties']) && count($allProperties) != count($this->_searchOptions['properties'])) { if (!empty($this->_searchOptions['properties'])) { foreach ($this->_searchOptions['properties'] as $property) { $fields = array_merge($fields, $this->_buildPerLanguageFields($property . 'Text', $searchLanguages)); } } else { // If there are no doc properties selected - do not search in doc properties. } } else { $fields = array_merge($fields, $this->_buildPerLanguageFields('DocumentationPropertiesText', $searchLanguages)); } if (!empty($fields)) { $searchText = isset($this->_searchOptions['searchText']) ? $this->_searchOptions['searchText'] : ''; $truncate = isset($this->_searchOptions['truncate']) ? $this->_searchOptions['truncate'] : ''; $query = OpenSKOS_Solr_Queryparser_Editor_ParseSearchText::factory()->parse($searchText, $truncate, $fields); if (!empty($query)) { $this->_addDefaultQuerySeparator(); $this->_query .= '(' . $query . ')'; } } return $this; }
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; }